memory management:Bookkeeping of dealt out pages
Posted: Wed Jan 19, 2005 3:45 am
Here is the problem:
I keep book of each and every page dealt out to any process in a linked list - currently stored in kernel heap. Due to some limitations, this list seems to be trashed at some point - I keep receiving pagefaults when releasing pages of a process - because the chain gets broken at some point.
I've tracked it down to a certain degree, then it became too much a hassle - because something gets overwritten - and I started to think different:
What about this:
set aside a dedicated region of memory for this page book keeping - inside kernel space of course - in the size of (nr of pages available*sizeof(bookkeepingelement)) rounded up to page alignment.
then, I'd allocate the needed pages somewhere behind the kernel heap, but outta way of it and guarded. I'd set aside two lists: one for the free page-entry-elements, one for the used ones. Currently, I don't bookkeep kernel memory this way, I just decrement the amount of available pages accordingly. Might change.
When I allocate pages: just pick the first off the pile of free pages, add it to the pile of used pages, add information about who uses it and increment reference count to one. If a page is referenced by more than one process - increase the reference counter and insert the process to the list of pageowners. (kinda reverse lookup)
Deallocating a page: remove the page from the list of used pages and simply add the element to the list of free ones.
This requires some dedicated allocating/deallocating mechanism, but that's nothing I care too much about *gg*
Upon init of the pile of free pages I'd just stroll throu memory as if it were an array and say:
some border checking included of course.
I admit, this method would require some memory to be preallocated, but on the other hand - it would keep the page bookkeeping away from malloc - which isn't that performant - mostatime.
I use this system to easily deal out and keep book of shared memory (which is a set of pages inside a pagearray associated to a named shared-memory-entity)
What do you think of it? could it be useable?
I keep book of each and every page dealt out to any process in a linked list - currently stored in kernel heap. Due to some limitations, this list seems to be trashed at some point - I keep receiving pagefaults when releasing pages of a process - because the chain gets broken at some point.
I've tracked it down to a certain degree, then it became too much a hassle - because something gets overwritten - and I started to think different:
What about this:
set aside a dedicated region of memory for this page book keeping - inside kernel space of course - in the size of (nr of pages available*sizeof(bookkeepingelement)) rounded up to page alignment.
then, I'd allocate the needed pages somewhere behind the kernel heap, but outta way of it and guarded. I'd set aside two lists: one for the free page-entry-elements, one for the used ones. Currently, I don't bookkeep kernel memory this way, I just decrement the amount of available pages accordingly. Might change.
When I allocate pages: just pick the first off the pile of free pages, add it to the pile of used pages, add information about who uses it and increment reference count to one. If a page is referenced by more than one process - increase the reference counter and insert the process to the list of pageowners. (kinda reverse lookup)
Deallocating a page: remove the page from the list of used pages and simply add the element to the list of free ones.
This requires some dedicated allocating/deallocating mechanism, but that's nothing I care too much about *gg*
Upon init of the pile of free pages I'd just stroll throu memory as if it were an array and say:
Code: Select all
element[x].next=element[x+1];
I admit, this method would require some memory to be preallocated, but on the other hand - it would keep the page bookkeeping away from malloc - which isn't that performant - mostatime.
I use this system to easily deal out and keep book of shared memory (which is a set of pages inside a pagearray associated to a named shared-memory-entity)
What do you think of it? could it be useable?