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
Contiguous physical memory
Contiguous physical memory
If a trainstation is where trains stop, what is a workstation ?
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Contiguous physical memory
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.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Contiguous physical memory
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>
<edit>
Forgot to mention NUMA as well... that's another reason to be careful how you allocate physical memory.
</edit>
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re: Contiguous physical memory
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
Thanks
- gerryg400
If a trainstation is where trains stop, what is a workstation ?