본문 바로가기

Programming/Linux_Kernel

vmalloc 대신에 kalloc 을 주로 사용하는 이유는?


많은 이유가 있지만, 주 이유는 성능 때문이라고 한다.

아래 글을 참고해보자.


원문 : http://stackoverflow.com/questions/116343/what-is-the-difference-between-vmalloc-and-kmalloc




Linux Kernel Development by Robert Love (Chapter 12, page 244 in 3rd edition) answers this very clearly.

Yes, physically contiguous memory is not required in many of the cases. Main reason for kmalloc being used more than vmalloc in kernel is performance. The book explains, when big memory chunks are allocated using vmalloc, kernel has to map the physically non-contiguous chunks (pages) into a single contiguous virtual memory region. Since the memory is virtually contiguous and physically non-contiguous, several virtual-to-physical address mappings will have to be added to the page table. And in the worst case, there will be (size of buffer/page size) number of mappings added to the page table.

This also adds pressure on TLB (the cache entries storing recent virtual to physical address mappings) when accessing this buffer. This can lead to thrashing.