Page 1 of 1
Contiguous physical memory
Posted: Fri Apr 23, 2010 7:50 am
by gerryg400
I'm converting my x86 kernel to 64 bit and in the process revamping the the physical memory allocator. Currently I keep the free physical pages in a 'stack' and after a while, the pages are not in order. When I do a large allocation I generally get a random list of pages.
Is there a performance benefit to allocating physical pages contiguously ? Or is it okay to map random physical pages ?
thanks
- gerryg400
Re: Contiguous physical memory
Posted: Fri Apr 23, 2010 8:49 am
by NickJohnson
In normal cases, no: the paging system has equal overhead for accessing consecutive and random frames. However, it can be useful to allocate a contiguous chunk of memory when doing DMA with various devices, because you can then make the amount of data transferred per DMA operation larger. IMO, I would save ripping out your entire physical memory manager for later, when a 5% speed increase for certain devices is no longer premature optimization.
Re: Contiguous physical memory
Posted: Fri Apr 23, 2010 8:52 am
by Colonel Kernel
There are also caching advantages to allocating physical memory in a certain way (not necessarily contiguously... contiguously is just a special case). See
Cache colouring.
<edit>
Forgot to mention NUMA as well... that's another reason to be careful how you allocate physical memory.
</edit>
Re: Contiguous physical memory
Posted: Fri Apr 23, 2010 10:00 am
by gerryg400
I already keep the pages in linux-like 'zones' for DMA. I'll leave NUMA and cache colouring for another day. I think I'll just get my old code ported with no design changes. There's plenty of other stuff to do!!!
Thanks
- gerryg400