4

What is the equivalent of dwAllocationGranularity in Linux? In Windows, it's defined as:

The granularity for the starting address at which virtual memory can be allocated.

Note that this is not the same thing as PAGE_SIZE, which is the granularity of a physical page.
(On Windows, the virtual address granularity is 64 KiB on x86, whereas the page size is of course 4 KiB.)

user541686
  • 205,094
  • 128
  • 528
  • 886
  • Perhaps it does not have one; perhaps the granularity is always guaranteed to be PAGE_SIZE on Linux? Do you have a specific case where you would need a number such as this? – flodin Jul 18 '14 at 07:17
  • @flodin: Yeah I do have a specific case in front of me, but the code is not relevant here. If it doesn't have one then please post that as an answer. – user541686 Jul 18 '14 at 07:22

1 Answers1

6

The nearest equivalent of VirtualAlloc on Linux is mmap which, like VirtualAlloc, allows you to specify a desired allocation target address of the allocated memory. On Windows, this address must be aligned on the allocation granularity. On Linux, I quote from the mmap man page:

If addr is not NULL, then the kernel takes it as a hint about where to place the mapping; on Linux, the mapping will be created at a nearby page boundary.

As far as I know, there is no situation where the allocation granularity is higher than the page size of the system, so you should be able to safely use PAGE_SIZE as a substitute.

flodin
  • 5,215
  • 4
  • 26
  • 39