Paging questions
Paging questions
I have some questions about paging. Can I say, use paging in a bootloader so my kernel only sees ram that's actually available, then use another level of paging for the memory manager, then another level, and another, etc., or can I only use one?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Paging questions
What do you mean by "another level"? You want logical addresses that are translated to other logical addresses that are translated to pysical pages? I can't see the point of that, but I can't see what else you mean.
Re: Paging questions
Yes, that way my kernel can basically "map out" all the non usable ram (memory mapped devices, etc.) from the view of my memory manager. Then the mm can find available ram to assign to running programs. It would really simplify algorithms if available - otherwise the mm would have to look both at what is non available and non usable when finding ram.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Paging questions
The memory manager typically doesn't need to map unusable or free ram to anything. It is only the allocated memory that needs to be mapped in the paging structures. How you manage free and unavailable ram is your own choice.m12 wrote:Yes, that way my kernel can basically "map out" all the non usable ram (memory mapped devices, etc.) from the view of my memory manager. Then the mm can find available ram to assign to running programs. It would really simplify algorithms if available - otherwise the mm would have to look both at what is non available and non usable when finding ram.
Re: Paging questions
One way of handling physical memory is to keep a bitmap of unallocated and allocated pages. Pages that you never want to allocate are marked in this bitmap as used when you initialize the memory structures and variables at boot time. When the memory manager needs a free page it searchs through the bitmap for unallocated memory. The areas that you have marked as reserved will never be considered available for allocation. No need for complicated multi-level memory mapping (which the hardware doesn't support). I don't know if people have other methods of allocating pages, but that works for me.
KISS.
KISS.
Re: Paging questions
But then if, say, the ram is full and needs to be swapped out, the memory manager might swap out the bios or memory mapped devices, etc. My idea would be simpler to implement if there is hardware support for it, otherwise i'll just do it the normal way.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Paging questions
No. When determining what memory to swap out you will be looking at page tables to see which pages are dirty, which have been accessed, which are read only, that sort of thing. And it's in the page tables that you record that the page has been swapped out (with the "Not Present" flag and record details of its location on the swap device). So you are only concerned with looking at pages that have been mapped in some page table. You certainly wouldn't just look at the bitmap of allocated pages. Pages that haven't been allocated to some page table simply aren't available for swapping.
If for some reason you want to do things your way, just make the bitmap slightly more complicated so that it records a number of values rather than just on/off. You could have free/allocated/don't_touch, for example. I'm afraid that multiple levels of logical mappings would not be simpler; it would just be an added level of complication, and an added level of lookup to potentially slow down memory access.
If for some reason you want to do things your way, just make the bitmap slightly more complicated so that it records a number of values rather than just on/off. You could have free/allocated/don't_touch, for example. I'm afraid that multiple levels of logical mappings would not be simpler; it would just be an added level of complication, and an added level of lookup to potentially slow down memory access.
Re: Paging questions
Ok, thank you. a couple other questions:
- Does paging apply to ring 0 processes (eg kernel)
- Do the GDT and IDT reference physical or virtual addresses? I'm guessing the GDT references physical, but what about IDT?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
- Griwes
- Member
- Posts: 374
- Joined: Sat Jul 30, 2011 10:07 am
- Libera.chat IRC: Griwes
- Location: Wrocław/Racibórz, Poland
- Contact:
Re: Paging questions
I am calling RTFM on this one.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Re: Paging questions
I've been reading through and rereading through the wiki for months. It's a lot of information
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Paging questions
Hi,
There are 3 kinds of addresses - virtual addresses, linear addresses and physical addresses. The CPU converts a virtual address into a linear address by applying segmentation (e.g. adding "segment register base"). The CPU converts a linear address into a physical address by using paging. If segmentation is effectively disabled (e.g. all segment register bases set to zero and segment limits set to "max") then there's no difference between virtual addresses and linear addresses. If paging is disabled then there's no difference between linear addresses and physical addresses. If both paging and segmentation are disabled then virtual addresses are the same as physical addresses.
Most things use virtual addresses (e.g. for "lgdt [foo]", foo is a virtual address). Some things use linear addresses (e.g. for "lgdt [foo]", the structure at foo contains the base address and limit for the GDT, and the base address is a linear address). The only thing that uses physical addresses is the paging structures (e.g. CR3, page table entries, page directory entries, etc).
Cheers,
Brendan
Paging applies to all privilege levels (e.g. including kernels).m12 wrote:
- Does paging apply to ring 0 processes (eg kernel)
- Do the GDT and IDT reference physical or virtual addresses? I'm guessing the GDT references physical, but what about IDT?
There are 3 kinds of addresses - virtual addresses, linear addresses and physical addresses. The CPU converts a virtual address into a linear address by applying segmentation (e.g. adding "segment register base"). The CPU converts a linear address into a physical address by using paging. If segmentation is effectively disabled (e.g. all segment register bases set to zero and segment limits set to "max") then there's no difference between virtual addresses and linear addresses. If paging is disabled then there's no difference between linear addresses and physical addresses. If both paging and segmentation are disabled then virtual addresses are the same as physical addresses.
Most things use virtual addresses (e.g. for "lgdt [foo]", foo is a virtual address). Some things use linear addresses (e.g. for "lgdt [foo]", the structure at foo contains the base address and limit for the GDT, and the base address is a linear address). The only thing that uses physical addresses is the paging structures (e.g. CR3, page table entries, page directory entries, etc).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Paging questions
Thank you.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.