Freeing pages

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
oh boy

Freeing pages

Post by oh boy »

What is the best way to free to a process allocated page? Keeping a list of all page allocatins within the process would be quite big, but is it the way to go?

What if I share pages? Should I put a counter into my memory regions that counts how many processes have the region attached, and when it's zero I release all pages allocated?

Another design question, should I use my memory regions for all data? IE, when I create a new process, I also create a new memory region.
oh boy

Re:Freeing pages

Post by oh boy »

Note: I already have the mechanism for allocating physical and virtual memory, and I do have memory regions and objects implemented.
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re:Freeing pages

Post by gaf »

What is the best way to free to a process allocated page? Keeping a list of all page allocatins within the process would be quite big, but is it the way to go?
Hello,
when you're using linked list to keep track of your allocations there's unfortunatly hardly any other way to go - you'll need a linked list with free regions and a second one with allocated regions. A less memory consuming solution would be the usage of a bitmap, but from what I know the performance isn't that good.
What if I share pages? Should I put a counter into my memory regions that counts how many processes have the region attached, and when it's zero I release all pages allocated?
It's pretty easy to allocate shared memory like this but you'll have a problem once one of the two user program decides to unmap the page.

a) Search all lists
-> very slow
b) Keep the ID of the (next) task that also uses this page
-> consumes even more memory
Another design question, should I use my memory regions for all data? IE, when I create a new process, I also create a new memory region.
The 'normal' way is to create one pair of lists for each address-space.

btw:
I'm currently having a closer look at the L4 design which takes an approach that I wasn't aware of before. The kernel keeps a tree for each pageframe which keeps track to which address spaces and at which address it was mapped.

o--------------------o--------------------o--------
| 0x0000 - 0x1000 | 0x1000 - 0x2000 | ...
o--------------------o--------------------o--------
-> mapped to task1 -> mapped to task1
at 0x57696000 at 0x87346000
-> mapped to task2
at 0x12123000

That way you won't have any problems when task1 decides to unmap page 0x57696000.

regards,
gaf
Post Reply