Page 1 of 1

How to allocate multiple pages without multiple page tables

Posted: Thu Sep 10, 2020 8:34 pm
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,

Re: How to allocate multiple pages without multiple page tab

Posted: Thu Sep 10, 2020 8:54 pm
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.

Re: How to allocate multiple pages without multiple page tab

Posted: Thu Sep 10, 2020 9:33 pm
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.

Re: How to allocate multiple pages without multiple page tab

Posted: Thu Sep 10, 2020 10:30 pm
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.

Re: How to allocate multiple pages without multiple page tab

Posted: Fri Sep 11, 2020 12:01 am
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.

Re: How to allocate multiple pages without multiple page tab

Posted: Fri Sep 11, 2020 11:35 am
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.