@@ -369,6 +369,12 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
if (__glibc_unlikely (mem == MAP_FAILED))
return errno;
+ /* Do madvise in case the tunable glibc.pthread.stack_hugetlb is
+ set to 0, disabling hugetlb. */
+ if (__glibc_unlikely (__nptl_stack_hugetlb == 0)
+ && __madvise(mem, size, MADV_NOHUGEPAGE) != 0)
+ return errno;
+
/* SIZE is guaranteed to be greater than zero.
So we can never get a null pointer back from mmap. */
assert (mem != NULL);
@@ -21,6 +21,7 @@
#include <pthreadP.h>
size_t __nptl_stack_cache_maxsize = 40 * 1024 * 1024;
+int32_t __nptl_stack_hugetlb = 1;
void
__nptl_stack_list_del (list_t *elem)
@@ -27,6 +27,9 @@
/* Maximum size of the cache, in bytes. 40 MiB by default. */
extern size_t __nptl_stack_cache_maxsize attribute_hidden;
+/* Should allow stacks to use hugetlb. 1 is default */
+extern int32_t __nptl_stack_hugetlb;
+
/* Check whether the stack is still used or not. */
static inline bool
__nptl_stack_in_use (struct pthread *pd)
@@ -45,6 +45,12 @@ TUNABLE_CALLBACK (set_stack_cache_size) (tunable_val_t *valp)
__nptl_stack_cache_maxsize = valp->numval;
}
+static void
+TUNABLE_CALLBACK (set_stack_hugetlb) (tunable_val_t *valp)
+{
+ __nptl_stack_hugetlb = (int32_t) valp->numval;
+}
+
void
__pthread_tunables_init (void)
{
@@ -52,5 +58,7 @@ __pthread_tunables_init (void)
TUNABLE_CALLBACK (set_mutex_spin_count));
TUNABLE_GET (stack_cache_size, size_t,
TUNABLE_CALLBACK (set_stack_cache_size));
+ TUNABLE_GET (stack_hugetlb, int32_t,
+ TUNABLE_CALLBACK (set_stack_hugetlb));
}
#endif
@@ -33,5 +33,11 @@ glibc {
maxval: 1
default: 1
}
+ stack_hugetlb {
+ type: INT_32
+ minval: 0
+ maxval: 1
+ default: 0
+ }
}
}