How to allocate multiple pages without multiple page tables

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
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

How to allocate multiple pages without multiple page tables

Post by clementttttttttt »

Is there any way to allocate multiple pages without a large amount of page tables? I can't think of anyway of doing this,
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to allocate multiple pages without multiple page tab

Post by Octocontrabass »

That's a strange question. Why do you want to do that?

Each page table has 1024 (without PAE) or 512 (with PAE) entries, which covers 4MiB / 2MiB of address space.
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Re: How to allocate multiple pages without multiple page tab

Post by clementttttttttt »

Octocontrabass wrote:That's a strange question. Why do you want to do that?

Each page table has 1024 (without PAE) or 512 (with PAE) entries, which covers 4MiB / 2MiB of address space.
I'm currently porting liballoc, and it need a page map/unmap function. I will also implement multitasking in my os, and multiple programs might run malloc, which will call the page map functions multiple times.
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to allocate multiple pages without multiple page tab

Post by Octocontrabass »

Does each program get its own address space, like a typical OS? If so, memory allocations in one program will not affect the others (as long as you have enough available memory).

Do all programs share a single address space, like some embedded OSes? If so, you'll probably need to determine which program is calling the page map functions in order to allocate memory within that program's portion of the address space.
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Re: How to allocate multiple pages without multiple page tab

Post by clementttttttttt »

Octocontrabass wrote:Does each program get its own address space, like a typical OS? If so, memory allocations in one program will not affect the others (as long as you have enough available memory).

Do all programs share a single address space, like some embedded OSes? If so, you'll probably need to determine which program is calling the page map functions in order to allocate memory within that program's portion of the address space.
Actually I haven't implemented multitasking yet, but I'm definitely going to let programs have its own address space.
thewrongchristian
Member
Member
Posts: 426
Joined: Tue Apr 03, 2018 2:44 am

Re: How to allocate multiple pages without multiple page tab

Post by thewrongchristian »

clementttttttttt wrote:Is there any way to allocate multiple pages without a large amount of page tables? I can't think of anyway of doing this,
So long as your mappings are clustered together, the amount of page table memory you'll use per process should be small. A 4K page table will map 4MB of virtual memory, fully utilised. So, if your process is less than 4MB in size, it could occupy only one page table (plus your page directory + kernel mappings,) which isn't very much memory.

If you treat your page tables as disposable, then you can just have a pool of page table pages set aside, and reuse page tables that haven't been referenced in a while. Using demand paging, the contents of the page tables can be transient, and will be built back up as they're referenced.
Post Reply