Multitasking without paging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
verynewbienoob
Posts: 9
Joined: Mon Nov 30, 2020 6:24 pm
Libera.chat IRC: verynewbienoob

Multitasking without paging

Post by verynewbienoob »

Hello,
Like in topic, is it possible? Every one guide that I see on osdev-oriented websites describe it but with paging already implemented. My goal is to first implement multitasking and then maybe in future implement paging.
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: Multitasking without paging

Post by pvc »

Shouldn't be a problem. Just treat all your tasks just as you would treat threads of a single process. The thing is that you lose address space separation, so one misbehaving task can break others.
In the code, 2 major differences would be that
  • You have to be able to load any executable (and library) anywhere in the address space
  • You never swap address spaces (reload CR3 on x86)
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Multitasking without paging

Post by bzt »

verynewbienoob wrote:Hello,
Like in topic, is it possible?
Absolutely yes. Read viewtopic.php?f=15&t=37283 too.
verynewbienoob wrote:Every one guide that I see on osdev-oriented websites describe it but with paging already implemented.
Because that's simpler. Most implementations also switch address spaces, because it's easier to create tasks with separate address spaces (no task-specific addresses needed).
verynewbienoob wrote:My goal is to first implement multitasking and then maybe in future implement paging.
That could be tricky, but doable. You can make shortcuts if you implement paging first; and you can develop bad practices if not. The main difference is, without paging all tasks must use different addresses for their code segments, while with paging all tasks use the same address for their code.

Cheers,
bzt
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Multitasking without paging

Post by bloodline »

My OS doesn’t use memory protection or paging. Feel free to browse the source code on GitHub and ask questions if you need pointers about how to do it.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
thewrongchristian
Member
Member
Posts: 426
Joined: Tue Apr 03, 2018 2:44 am

Re: Multitasking without paging

Post by thewrongchristian »

verynewbienoob wrote:Hello,
Like in topic, is it possible? Every one guide that I see on osdev-oriented websites describe it but with paging already implemented. My goal is to first implement multitasking and then maybe in future implement paging.
If you're just doing threading in kernel space, such as you might do with an embedded platform, multitasking without paging is not only desirable, but also mandatory for embedded processors that don't have paged MMU.

One of the benefits of doing multitasking before paging is you can do so entirely in user space in a hosted process, and use regular host debugging tools to work on your multitasking implementation to get to grips with the details. Essentially, it allows you to model it as a user space threading library, then once you're comfortable, move the code you've written to bare metal.

Paging, however, is so fundamental to general purpose operating systems that it is worth understanding and implementing early. Apart from anything else, it makes management of free memory much easier, as you don't have to deal with external fragmentation, and once you move to user space with potentially multiple address spaces, it's the only sensible way of protecting those address spaces from each other (other protection mechanism exist, such as base/limit segmentation, but they're not portable.)
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Re: Multitasking without paging

Post by clementttttttttt »

Well LDT exists so it shouldn't be that hard.
Post Reply