I would like to know a way to determine whether a pointer belongs to a mmaped memory page.
A post on StackOverflow suggest using msync() on the pointer to determine whether it passes or not. But what I found is msync() will success as long as the pointer is a multiple of the page size, no matter the page is mmaped or not.
I calculate the start address of the page by the macro:
#define align_to_page(addr,pagesize) (addr & ~(pagesize - 1))
Please help me, I have been working on it for a long time and blocked here. Thank you in advance :)
Background: I am developing an extension to Python and Numpy. In some functions, it has to distinguish a normal numpy.ndarray and a numpy.memmap which is a subclass of numpy.ndaraay with its data buffer created by mmap() backed by a file on disk.
All non-empty process address space is mmaped. Either using mmap syscall or indirectly via brk/sbrk syscalls .
You probably need to find another way to distinguish numpy arrays.
numpy.memmap documentation says these arrays have additional attributes filename, offset and mode, may be you can use these to detect whether an array is backed by a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With