Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of dwAllocationGranularity in Linux?

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.)

like image 484
user541686 Avatar asked Sep 14 '25 09:09

user541686


1 Answers

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.

like image 112
flodin Avatar answered Sep 15 '25 23:09

flodin