path: root/shm.c
diff options
authorAdam Litke <agl@us.ibm.com>2008-10-02 09:54:27 +0100
committerAndy Whitcroft <apw@shadowen.org>2008-10-14 17:36:08 +0100
commit87fbfd1133d1c15d4b9df834767ad83ade05b61d (patch)
tree4c6ebd2d5e8cca50ece59cc0d6d9696338097fff /shm.c
parent5722a40b46908b561390028ed2c8c1dee93ad2ea (diff)
shm: Shared memory always uses the meminfo page size
This patch fixes two intertwined issues: When the SHM_HUGETLB flag is passed to shmget(), the system default huge page size is used to back the shared memory segment. Unlike with mmap() there is not yet a way to use an alternate huge page size for shared memory segments. This exception must be taken into account by the shmget override function -- it cannot call gethugepagesize() but must discover the effective huge page size by direct examination of /proc/meminfo. Make the shmoverride test case discover the huge page size in the same manner. The shmoverride_* test case does not always link against libhugetlbfs. Therefore, it cannot use the new mechanism for manipulating pool counters. Unfortunately, this means that the logic to read /proc/meminfo must be duplicated in order for shmoverride_unlinked to build as a NOLIB test. [apw@shadowen.org: consolidate makefile updates in one place] Signed-off-by: Adam Litke <agl@us.ibm.com>
Diffstat (limited to 'shm.c')
1 files changed, 6 insertions, 1 deletions
diff --git a/shm.c b/shm.c
index cc9995d..8a56725 100644
--- a/shm.c
+++ b/shm.c
@@ -56,7 +56,12 @@ int shmget(key_t key, size_t size, int shmflg)
/* Align the size and set SHM_HUGETLB on request */
if (hugetlbshm_enabled) {
- aligned_size = ALIGN(size, gethugepagesize());
+ /*
+ * Use /proc/meminfo because shm always uses the system
+ * default huge page size.
+ */
+ long hpage_size = read_meminfo("Hugepagesize:") * 1024;
+ aligned_size = ALIGN(size, hpage_size);
if (size != aligned_size) {
DEBUG("hugetlb_shmem: size growth align %zd -> %zd\n",
size, aligned_size);