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 tha
If you are trying to build a kernel module, you will need to have at least the kernel headers that are configured for the kernel the module will run on. Those will define the page size macros you need. If you don't have the correctly configured headers, the kernel will refuse to load your module.
And there is nothing wrong with compiling a module on one machine to run on another, even if it's a different architecture. You just need to build against the correct kernel source.
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!
This is what I finally did:
PAGE_SIZE (PAGE_SIZE = 1 << PAGE_SHIFT)
PAGE_SHIFT
using getconf
API from libc. This wrapper gets the current system page shift and pass it as a module parameter. Right now the module is being loaded on different architectures with different PAGE_SIZE without any problems.
Try using the getconf utility, which will allow you to retrieve the page size easily.
getconf PAGESIZE
One way to find the page size is to obtain it from smaps for a process.
For example:
cd /proc/1
grep -i pagesize smaps
KernelPageSize: 4 kB
MMUPageSize: 4 kB
You could just run a test, just mmap a file with different offsets and see which fail. Might be annoying in a kernel module though, but maybe there is some other test like that you could use.