MM Questions
- chris
MM Questions
Post by chris »
I'm still trying to get my head around all the MM stuff, I have a few questions :).
This is what I need to do, from what I understand (not in order):
1. I need to setup a page directory (probably at the end of my kernel?) and set up the page directory entries.
2. I need some assembly functions to load the page directory address into cr3, and set some bit in cr0.
3. I need to use a bitmap, stack or linked list approach to be able to tell if pages are used or not.
4. I need an allocator to mark pages as used and give the addresses to whoever requested it.
5. I need a deallocator (reverse allocation process).
6. I need a mapper that will map virtual pages to physical ones (page frames) ???. Still pretty confused here.
Can anybody correct me where I'm wrong?
Now this is where I'm really confused...
Is all what i've mentioned above for managing memory in kernel space? What about user space? Are you supposed to setup page tables or something for all of the physical memory? I don't really get this part at all... I'm probably babbling about nothing :-\
I still have other questions but I'll wait and see if they get answered, if I get replys to this.
- BI lazy
Re:MM Questions
Post by BI lazy »
second, Tim Robinson has written a text about Memory Management, which should give you some hold to get a grip on the topic.
now your questions:
1. Yes, you need a page duirectory and yes, you need page tables and yes, you need page table entries. Best is, you map PG Dir to itself (at index 0x3ff) and with this locate it to adress 0xfffff000 of the virtual adress space.
2. Yes.
3. correct. 4. correct. 5. correct.
6. No need to get confused: you map Physical Pages to Virtual ones. Your physical page allocator hands out 4 kb pages at request. It's straight forward.
your last question: It is also for user processes: all you need to do is add som algorithms for building a process adress space. The Memory Manager doesn't hand out malloc sized memory chunks. It deals with pages and with adress spaces.
and no, don't set up pagetables for ALL physical memory: hand out physical memory at needs upon page fault: the memory in question isn't valid, but the process has the right to get it: fetch a physical page of 4 kb and enter it at the appropriate place in the process adress space. this is a Per Page directory operation in my opinion.
For your physical memory: ask the Bios, how much of it is installed. Then calculate, how much it is in KB; these KB's you divide by Page size and know now, how many Pages you have at hands to deal with. Then set up a stack or Bitmap or what so ever which represents your physical memory. Hand out memroy pages at request or take them back.
HtH
- chris
Re:MM Questions
Post by chris »
Btw, I did read Tim's tutorials, they helped alot. I'm going to read them again, though.
I still have a few questions :-\
How much memory will one page directory map? Am I supposed to loop throught the page directory and set the proper bits (ie not-present) in the beginning, then add page tables when needed? Also, for mapping. Do you hand the mapper a virtual and physical address, then it makes the proper PTE's?
- Tim
Re:MM Questions
Post by Tim »
All of it -- the whole 4GB virtual address space. To get multiple address spaces, switch page directories.chris wrote:How much memory will one page directory map?
Yes, although it's enough to zero the whole page directory, because the present/nonpresent bit is 1=present, 0=not present. Note that if the present bit is not set, the MMU won't look at the other bits.Am I supposed to loop throught the page directory and set the proper bits (ie not-present) in the beginning, then add page tables when needed?
No, you have to assemble the PDEs and PTEs yourself.Also, for mapping. Do you hand the mapper a virtual and physical address, then it makes the proper PTE's?
- chris
Re:MM Questions
Post by chris »
Thank you for your previous reply.
- Tim
Re:MM Questions
Post by Tim »
The zero page list is there because there is a zero page thread running in the background. Normal allocations come from the zero page list. The zero page thread grabs pages from the free list, clears (zeroes) them, and adds them to the zero list.
- chris
Re:MM Questions
Post by chris »
- Tim
Re:MM Questions
Post by Tim »
Unfortunately, the problem comes in allocating this array before the memory manager has been initialised.
- chris
Re:MM Questions
Post by chris »
- chris
Re:MM Questions
Post by chris »
???
- BI lazy
Re:MM Questions
Post by BI lazy »
- zloba
Re:MM Questions
Post by zloba »
what if deallocated memory happens to contain some sensitive data? (from another process or the operating system)I'm not sure why you'd need to (or want to) zero pages at all before mapping them into a processes' address space, though ?
- Tim
Re:MM Questions
Post by Tim »
In any case, zeroing all memory at startup would take ages. Better to have a low-priority thread doing it in the background. It doesn't matter how many zeroed pages there are available as long as there enough to satisfy allocation requests.