From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 7F9E23858413 for ; Mon, 20 Mar 2023 17:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F9E23858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc33.google.com with SMTP id x19-20020a4a3953000000b00525191358b6so2017267oog.12 for ; Mon, 20 Mar 2023 10:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679331988; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=SZvm8XT22UxEXipRncS+g7YNS57gTn1HZy97OHvIzVU=; b=AvpiS9D/zBL7MMZldfH9Bkuw7mNrEQzcDOtki4brSNapOt2nK4Uhz7yo9mGfDfsI3A qPv0lPW0oCeeH/4k4Opf9nrlJquOvn6//E5JLAEBRoVQLXYZiCjDyVwv4aEGo0YAW/vk twCSAAcl3TfrAS41HXGL6ZpA1Kye+iN4JdQM9fVJ82RijGiLbK13QjMkxdz9omBXTH1G EOPnYSiFjdIK2CTvYLARiB2hUaLgUsi7JtoFik9IZd+DCncz9NuwbFwG8YkS1ul2gc3/ +Rq+pjG52KE97UFk7xvZYjhQh/6TBwEpIlG6JdKE6mcVA9x21nPxn9DZDMmxv/KzfZth QoeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679331988; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SZvm8XT22UxEXipRncS+g7YNS57gTn1HZy97OHvIzVU=; b=Txh7vlzS9AzExVrxA1hgH4eXxCNzdc9aSBGrUHWi2YlQZVtHpR7jtEfXHQjq5Ytkm8 oWdvqPN0btV68rBQ8UPBoijeUNgvmrvC+Ng9uHz4k39Yu+R/kQR2dxPoDmYJVz8IgOxL ewyFSBpRPwBDXcpSDmJbaLr6BIZ4cMBMQJwdDhpBFdNWz3me3BgDLft1WYP5hBh3WhnC LZ7w/IIcxPxQ5ZvHP6f1DBPaxauf9wifpS7qab+TVcimteltq/7f5wQqHLmtDzhFZamU mz+th2JZL7RG9VJLTccHS8pv+nJw2f31ig0hLxBqG5Y+C2cnZR/a/26+tiP6ey6cdYGC 3Rjw== X-Gm-Message-State: AO0yUKX15S6ArjCPpIrwAABcjqUEGh0A6mxweG7Xp4AugXVw4ltf/cZ4 yysdnY8tqQyZ4PNxSwJNswDi9g== X-Google-Smtp-Source: AK7set+ni6yT/q68vhjAg/GwgYnCqqUa943orpgJmVlbP34sO/ff+Gi1j6xo+PaFS7Q5m8ApIcKEhA== X-Received: by 2002:a4a:5296:0:b0:525:4058:2fcd with SMTP id d144-20020a4a5296000000b0052540582fcdmr175792oob.1.1679331987210; Mon, 20 Mar 2023 10:06:27 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:c260:d4b6:6c90:6159:ac3d? ([2804:1b3:a7c0:c260:d4b6:6c90:6159:ac3d]) by smtp.gmail.com with ESMTPSA id g1-20020a4ab041000000b00529cc3986c8sm3939057oon.40.2023.03.20.10.06.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Mar 2023 10:06:26 -0700 (PDT) Message-ID: Date: Mon, 20 Mar 2023 14:06:24 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v2 1/1] Created tunable to force small pages on stack allocation. Content-Language: en-US To: Cupertino Miranda , libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com References: <20230320162048.550179-1-cupertino.miranda@oracle.com> <20230320162048.550179-2-cupertino.miranda@oracle.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230320162048.550179-2-cupertino.miranda@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 20/03/23 13:20, Cupertino Miranda via Libc-alpha wrote: > Created tunable glibc.pthread.stack_hugetlb to control when hugepages > can be used for stack allocation. > In case THP are enabled and glibc.pthread.stack_hugetlb is set to > 0, glibc will madvise the kernel not to use allow hugepages for stack > allocations. > > Changed from v1: > - removed the __malloc_thp_mode calls to check if hugetlb is > enabled. Thanks for the patch, some comments below. > --- > nptl/allocatestack.c | 6 ++++++ > nptl/nptl-stack.c | 1 + > nptl/nptl-stack.h | 3 +++ > nptl/pthread_mutex_conf.c | 8 ++++++++ > sysdeps/nptl/dl-tunables.list | 6 ++++++ > 5 files changed, 24 insertions(+) > > diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c > index c7adbccd6f..c792c6ed1f 100644 > --- a/nptl/allocatestack.c > +++ b/nptl/allocatestack.c > @@ -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) Space before '('. > + return errno; > + > /* SIZE is guaranteed to be greater than zero. > So we can never get a null pointer back from mmap. */ > assert (mem != NULL); > diff --git a/nptl/nptl-stack.c b/nptl/nptl-stack.c > index 5eb7773575..e829711cb5 100644 > --- a/nptl/nptl-stack.c > +++ b/nptl/nptl-stack.c > @@ -21,6 +21,7 @@ > #include > > size_t __nptl_stack_cache_maxsize = 40 * 1024 * 1024; > +int32_t __nptl_stack_hugetlb = 1; > > void > __nptl_stack_list_del (list_t *elem) > diff --git a/nptl/nptl-stack.h b/nptl/nptl-stack.h > index 34f8bbb15e..d5b2612b4a 100644 > --- a/nptl/nptl-stack.h > +++ b/nptl/nptl-stack.h > @@ -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 */ Double space before '*/' and maybe put '1 is default' between brackets. > +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) > diff --git a/nptl/pthread_mutex_conf.c b/nptl/pthread_mutex_conf.c > index 329c4cbb8f..60ef9095aa 100644 > --- a/nptl/pthread_mutex_conf.c > +++ b/nptl/pthread_mutex_conf.c > @@ -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 > diff --git a/sysdeps/nptl/dl-tunables.list b/sysdeps/nptl/dl-tunables.list > index bd1ddb121d..22fa9e0d12 100644 > --- a/sysdeps/nptl/dl-tunables.list > +++ b/sysdeps/nptl/dl-tunables.list > @@ -33,5 +33,11 @@ glibc { > maxval: 1 > default: 1 > } > + stack_hugetlb { > + type: INT_32 > + minval: 0 > + maxval: 1 > + default: 0 This does not match the comment above. > + } > } > } Please also update manual/tunables.texi with brief explanation of what this tunable does, and what the possible options does.