mmap return 是否对齐指针值
Does mmap return aligned pointer values
mmap()
是否保证 return 值与系统上的最大对齐对齐?也就是说,POSIX 标准是否保证 mmap 必须 return 指针值是 alignof(std::max_align_t)
的倍数?
我无法在 Ubuntu linux mmap(2) 手册页或 mac osx mmap(2) 手册页上找到此信息
是的。
http://man7.org/linux/man-pages/man2/mmap.2.html
在大多数情况下 "popular" NULL 映射
If addr is NULL, then the kernel chooses the address at which to
create the mapping; this is the most portable method of creating a new
mapping. 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. The address of the new mapping is
returned as the result of the call.
即使您指定 MAP_FIXED 也比
Don't interpret addr as a hint: place the mapping at exactly that
address. addr must be a multiple of the page size. If the memory
region specified by addr and len overlaps pages of any existing
mapping(s), then the overlapped part of the existing mapping(s) will
be discarded. If the specified address cannot be used, mmap() will
fail. Because requiring a fixed address for a mapping is less
portable, the use of this option is discouraged.
事实上最小的页面是 4096B(对于 x86,但对于其他平台它无论如何是 1024B 的倍数)并且由于 std::max_align_t 在 64 位系统上最有可能是 16B,它将被对齐。
mmap()
是否保证 return 值与系统上的最大对齐对齐?也就是说,POSIX 标准是否保证 mmap 必须 return 指针值是 alignof(std::max_align_t)
的倍数?
我无法在 Ubuntu linux mmap(2) 手册页或 mac osx mmap(2) 手册页上找到此信息
是的。
http://man7.org/linux/man-pages/man2/mmap.2.html
在大多数情况下 "popular" NULL 映射
If addr is NULL, then the kernel chooses the address at which to create the mapping; this is the most portable method of creating a new mapping. 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. The address of the new mapping is returned as the result of the call.
即使您指定 MAP_FIXED 也比
Don't interpret addr as a hint: place the mapping at exactly that address. addr must be a multiple of the page size. If the memory region specified by addr and len overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap() will fail. Because requiring a fixed address for a mapping is less portable, the use of this option is discouraged.
事实上最小的页面是 4096B(对于 x86,但对于其他平台它无论如何是 1024B 的倍数)并且由于 std::max_align_t 在 64 位系统上最有可能是 16B,它将被对齐。