aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hunter <ahh@google.com>2015-06-23 12:58:32 -0700
committerAndrew Hunter <ahh@google.com>2015-06-23 12:58:32 -0700
commit1153d5eaf41007c638e53bb41db3d93bbf548a23 (patch)
tree8ef4f6ab1ed8420561df396cc80cc41b460bb51e
parent10d353539ff696806652b1c2e6691c953152c09b (diff)
downloadglibc-1153d5eaf41007c638e53bb41db3d93bbf548a23.zip
glibc-1153d5eaf41007c638e53bb41db3d93bbf548a23.tar.gz
glibc-1153d5eaf41007c638e53bb41db3d93bbf548a23.tar.bz2
Prevent wasted memory in guard regions
-rw-r--r--nptl/allocatestack.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 2a5ac22..e8dfbbb 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -656,6 +656,15 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
return errno;
}
+ /* We've marked this guard region unwritable, but it's
+ possible it already became resident, the most common case
+ being transparent hugepages; if stack + guard (+ adjacent
+ mmap regions) were more than 2MB, the kernel might have
+ filled in a full hugepage when we touched the thread
+ descriptor above. This can waste a lot of memory; mark
+ the guard unused. This shouldn't fail, but if it does,
+ we can't really do anything about it so ignore it. */
+ madvise (guard, guardsize, MADV_DONTNEED);
pd->guardsize = guardsize;
}