Contiguous physical memory

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Contiguous physical memory

Post 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
If a trainstation is where trains stop, what is a workstation ?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Contiguous physical memory

Post 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.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Contiguous physical memory

Post 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>
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Contiguous physical memory

Post 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
If a trainstation is where trains stop, what is a workstation ?
Post Reply