From 1153d5eaf41007c638e53bb41db3d93bbf548a23 Mon Sep 17 00:00:00 2001 From: Andrew Hunter Date: Tue, 23 Jun 2015 12:58:32 -0700 Subject: Prevent wasted memory in guard regions --- nptl/allocatestack.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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; } -- cgit v1.1