Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get linux kernel page size programmatically

I am working on a Linux module for IA64. My current problem is that the driver uses the PAGE_SIZE and PAGE_SHIFT macros for dma page allocation. The problem I am having is that the machine compiling the driver is not the ones that needed to run the driver. So, if the PAGE_SIZE on the compiling machine is 2^14K and the destination machine is 2^16K then the driver fails.

I don't want to turn this question into a 'best practice' issue about compiling modules on machines which are not the ones running the modules. I understand the issues about that. What I found is that people mostly uses getpagesize() or sysconf(_SC_PAGE_SIZE). These two options are out of the ia64 kernel headers so I can't use them. Is there another way that I could get the runtime PAGE_SIZE?

Options I am looking at:

  • Reading some file in /proc?
  • syscall?
  • Other function that let me calculate the PAGE_SIZE by inference (e.g ORDER, getpageshift, etc)?
  • Other?
like image 701
Freddy Avatar asked Feb 03 '11 15:02

Freddy


2 Answers

Try using the getconf utility, which will allow you to retrieve the page size easily.

getconf PAGESIZE 
like image 104
vetri Avatar answered Sep 21 '22 03:09

vetri


One approximate method is to read /proc/meminfo and check Mapped size ( on mine its 52544 kB as of now ) and then check nr_mapped in /proc/vmstat ( on mine its 131136 as of now ). Finally PAGE_SIZE = Mapped/nr_mapped. Sometimes this gives you an accurate value ( as in the current example I've quoted ) and sometimes its approximate but very close. Hope this helps!

like image 43
Pavan Manjunath Avatar answered Sep 22 '22 03:09

Pavan Manjunath