1

I was going through the manual of the mmap function and came across this line:

pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) - 1);
/* offset for mmap() must be page aligned */

I think I understand what this line does. It gets the page size and makes sure that pa_offset is either zero or a multiple of the page size (4096 here). But I do not understand how. I know what the bitwise operators do, but is it possible to explain how exactly this is being achieved?

Ujan
  • 103
  • 1
  • 8
  • Assuming the page size is a power of two, then then one less than the page-size will have all bits set, until the bit that represents the power of two corresponding to the page size. – EOF Jan 27 '18 at 18:45
  • Thanks a lot. I didn't notice the power of two – Ujan Jan 27 '18 at 18:57

0 Answers0