]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Prevent wasted memory in guard regions
authorAndrew Hunter <ahh@google.com>
Tue, 23 Jun 2015 19:58:32 +0000 (12:58 -0700)
committerAndrew Hunter <ahh@google.com>
Tue, 23 Jun 2015 19:58:32 +0000 (12:58 -0700)
nptl/allocatestack.c

index 2a5ac22117141a1a0b7d04e46fcba458feec80e0..e8dfbbb8deb15c864b994aa2e4e6c531048ba5a8 100644 (file)
@@ -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;
        }