Questions about Paging (x86)
Posted: Thu Oct 20, 2016 5:33 pm
Hi,
I've been getting paging working on my OS, and I've mostly been following James Molloy's tutorials on them. I'm extending his code but there are a few things I'm not sure how to handle.
1. Currently I'm parsing the multiboot memory map and allocating pages for all the reserved memory. This could clearly be quite expensive if there are large chunks of reserved memory. What's a good way of handling this? I was thinking a function which would take a physical memory address and a size, and allocate pages to facilitate that, while returning the virtual address. All the other reserved memory would remain unallocated until that function gets called.
2. If a page table has 1024 entries, each representing a 4096-byte chunk, that means that a maximum of 1024 * 4096 = 4194304 bytes can be addressed using one table alone. If process use a page table each, then does that mean that only a maximum of 4mb can be addressed at one time? (I would assume that the other pages are written out to disk as needed after triggering a page fault, but 4mb does seem like quite a small limit, does it not?)
3. The wiki states:
4. Is there any good way to convert a physical address to a virtual one? I can see that the Linux kernel has one (I can't find out how it's implemented), although I'm not really sure why it would be needed. The only way I can see to do it would be to scan every page table entry for the specified virtual address, but that would be quite inefficient.
I've been getting paging working on my OS, and I've mostly been following James Molloy's tutorials on them. I'm extending his code but there are a few things I'm not sure how to handle.
1. Currently I'm parsing the multiboot memory map and allocating pages for all the reserved memory. This could clearly be quite expensive if there are large chunks of reserved memory. What's a good way of handling this? I was thinking a function which would take a physical memory address and a size, and allocate pages to facilitate that, while returning the virtual address. All the other reserved memory would remain unallocated until that function gets called.
2. If a page table has 1024 entries, each representing a 4096-byte chunk, that means that a maximum of 1024 * 4096 = 4194304 bytes can be addressed using one table alone. If process use a page table each, then does that mean that only a maximum of 4mb can be addressed at one time? (I would assume that the other pages are written out to disk as needed after triggering a page fault, but 4mb does seem like quite a small limit, does it not?)
3. The wiki states:
I'm not sure quite what it means 'itself'. Does it mean that the last 4 megabytes of the total 4GB address space are identity-mapped? I don't quite see how this would provide any benefits.Many prefer to map the last PDE to itself. The page directory will look like a page table to the system.
4. Is there any good way to convert a physical address to a virtual one? I can see that the Linux kernel has one (I can't find out how it's implemented), although I'm not really sure why it would be needed. The only way I can see to do it would be to scan every page table entry for the specified virtual address, but that would be quite inefficient.