From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id BBD893858D28 for ; Wed, 12 Apr 2023 08:53:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBD893858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33C6UoYI018281; Wed, 12 Apr 2023 08:53:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=references : from : to : cc : subject : in-reply-to : date : message-id : content-type : mime-version; s=corp-2023-03-30; bh=QIkopWeE8CbVFn0nTvF+iPyIWG1YLELCbaXlyYL9c+I=; b=XBuiNwRy4zQQnrCmZkP+aILkFlyFICFeFFMBAASe7tQYEZI4hidlbmtpusRAaLf7QgEW 7xJwfLG+tZE59P7cItV+ecCgNd7O0WhweRdgVKgNI2f4sRtYoJDlHRwMIq3/r2v4m+3h FHQ7AxENODn/N+dqnuLluN/b1tpJb8wjucSyw2JLA5Uf+tnPGLSU3FxW8veekCY5T9LK lji2dlA0mewB5icXYwiG8NrEl2+6qCFBSRDReRVKJvbQnx1HFJ7c3sZ4+55ScTtExYWr XbKVv8waYSzSG43CMx1ZT1OMbgT70Jpm6fBimpC2FaxUs8lymdfg3mSSVZdpyy1P3mS+ fQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0ttqkx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Apr 2023 08:53:51 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33C8QJjP013201; Wed, 12 Apr 2023 08:53:51 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw92k49n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Apr 2023 08:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eywgGl3RgW6RvX1RwgzX5xOvY6GKN7GpD6a/pw7x7tYAEZaO/upZleJMEw3Z4sOvOsitffN2S3XA7JeSyCPJwpA4pyRVGRLBQoXoBJaVovxNG1CjwPmUA+dabQPFhcOT5yQdH26ThHtzvvnUOtcuEZYSdd109hpAOffugif2WzWpzGAUk6k2UIot0h7FNDyeGqx10UWcfbhDO0ZKQAsxN3MfX7crCLa0SkyFze089TFVORGFGRt8Yk2WqAb8OUxVXBTsNl6gl+UX6DVXgUtRXJidObUeO/OTy9PE8yj6Pvrz5ClPueMA+VHB0/dBc+PQMAUOcHDq8VeUJt6S19Ubnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QIkopWeE8CbVFn0nTvF+iPyIWG1YLELCbaXlyYL9c+I=; b=hcHBVLfvoeDc2yfzyLN4rLwCa7mgwDPV3MPzczsSLGdH4PL0zSrl2mHNUxQT6y43DmjMO1TFYk9Qzwh6CtUAJ+yM2xbDnkSKkS/8aj47d8zTvZDKAjp/Q4Hnq/5V30YEshkHoX1Hn4OI4j6kQAZnyIjxghyyEHQHbEfhjBkgwhO/oI0YI9bB9wV4zSoWfljfHQtGcIV0jc14nsozfxXTqgdN9QRK+yM5hFI/WMgB5TQkf3S4oMiZt71EoFKLuIQ9YCELiQTwsl1bTELXy9VOxGLmn/y+dF0IVxUWmL2e/m9bQImaLquv/RmE14fFTRwZxAY5Ql3nu0T++Dv31CchAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QIkopWeE8CbVFn0nTvF+iPyIWG1YLELCbaXlyYL9c+I=; b=frbeX7lRCHC0YuJHvfz6spuG83dpfYPpx5SpT9Vvu4fHfdbcZAOVG0tlEsnfX2fZTqowBuLwRtNcFJalCZzkxo2jdgHeDIbXB9edqAPbMMkDIPHMqkRnrUX76Nd5m186G7Dg7K9iuLxnHYJXmozd3c31ZcZewctkufQUJtxFZOs= Received: from BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) by SJ0PR10MB4623.namprd10.prod.outlook.com (2603:10b6:a03:2dc::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Wed, 12 Apr 2023 08:53:48 +0000 Received: from BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::4998:96fd:86b1:a388]) by BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::4998:96fd:86b1:a388%6]) with mapi id 15.20.6277.036; Wed, 12 Apr 2023 08:53:48 +0000 References: <20230328152258.54844-1-cupertino.miranda@oracle.com> <20230328152258.54844-2-cupertino.miranda@oracle.com> <8f313a5d-f16a-d682-1d78-f216c446099f@linaro.org> User-agent: mu4e 1.4.15; emacs 28.1 From: Cupertino Miranda To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org, Florian Weimer , jose.marchesi@oracle.com, elena.zannoni@oracle.com Subject: Re: [PATCH v5 1/1] Created tunable to force small pages on stack allocation. In-reply-to: <8f313a5d-f16a-d682-1d78-f216c446099f@linaro.org> Date: Wed, 12 Apr 2023 09:53:42 +0100 Message-ID: <873555cwh5.fsf@oracle.com> Content-Type: text/plain X-ClientProxiedBy: AM0PR02CA0022.eurprd02.prod.outlook.com (2603:10a6:208:3e::35) To BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR1001MB2340:EE_|SJ0PR10MB4623:EE_ X-MS-Office365-Filtering-Correlation-Id: 92680c7b-02fb-4cb9-0397-08db3b336def X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qqtM/mYApJmZDkGzTiE1lKA59/Z3F3chhzF31H0xM0QSAKSisIvNRF45SU/9YYxTcDjRTB6f25jgjnMSA77E2sgDfGVmnfZmkjAcIfLfA5IZVISQIyIZ2lBtpJInCWxio1tY3aPz1yjMm4u+/ZNQzoD8fC55bCT28HuuPj4dYExzdGHUblME43kxOJxmTPOuUS1LcZvvOeruEdiGEB6XE5PRia4M/3ptEN7jB7tZb6374J7OKNOB4m02OsxZhBeOz+dbwgRgga4vn5w8GB56ncma76dEBnVohFP/X8IMdmLdBR0PjHY9GlvYS90EXUy59kjMuU28M70TscNQ95mT8UXG38wM4ag7kQBxBnzQ3O4zB9uQ5LBd/nOcAXELn6sDfqDE6aKlXrsNKqcFFi6hLOgJKD4JEXJE+088qLiAipqTZZ3qvq2yq171hv9kA8c2Caxq3epGh4k5a/D2GHAF2bi7O9CEBaZy7WN3Us6Mojk1kJW2bhvnPL7rdp3PM6hSUDXi8al2yDxeGoRZOPKXQiDZ6Zfjvh364jfJs7cMgXIeAAV/Db1cvbW+HItigyvx2uquJthguMt8zhlhPeQfSA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR1001MB2340.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(136003)(39860400002)(376002)(396003)(366004)(451199021)(44832011)(2906002)(38100700002)(5660300002)(53546011)(8936002)(2616005)(478600001)(6512007)(36756003)(6506007)(966005)(41300700001)(86362001)(186003)(316002)(8676002)(66946007)(66556008)(6916009)(66476007)(4326008)(6486002)(6666004)(83380400001)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Cnlts842hzRDyaIPMgMPBclgJI1kwp416Oc4nnFmP0udFmmyUs2Lr48VUFw7?= =?us-ascii?Q?2diK0gglCc9+4EJZ1Pme8nUZMYBmDdoGCw23r1D4XLlFlREoqWdCqXALBsED?= =?us-ascii?Q?AMmouqsu6UxmNEZ6V9nVZvgPUUImtpWfCom/aBT1CPDVCoWl1366WDTnIu2o?= =?us-ascii?Q?ras6MHebeG95vnwZxJvVKeq+B2TngcPLpfPZUEgIrNLfCEKEtnvwjpSpBPGh?= =?us-ascii?Q?A9HkqhtOEZgBdYQuEsHeLVtz5yw7zuJJbbOCwCRAll05bQ2G8jJQxyUOow4E?= =?us-ascii?Q?4KKqik8gNsPVqFketuwpb7HYQ3m7OV0vhVrTFLUDQA+ZrFzSviXupVM71RUz?= =?us-ascii?Q?3a5Q81vKTKpKmd7hFIf9GaNzWDWJAfirL6i9qMRZgAdovQKtyUNbAo4Culw4?= =?us-ascii?Q?Ff3NAJouSiiDqHG1nECzarVEbY7Ob9PM/MS6kPyuoUAYQ3UBg4BdT0SL3OdU?= =?us-ascii?Q?L9xndt5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i28A6b1nzeDsOyAPt4e0aYj6XxZF9Tx1x/ZrquG+1Mxp7uRUg/qaPwF6eP3Xt0cGXkwz3GEemzK3mlQLNk4KajTxLY7z36iwgRvgA6PVXClZ5YohNhUjofQffedkiiKtCfzJdnqq8mamBQ7SqedFoSCL0d5bShKre05TJ5oo/iHrbu X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92680c7b-02fb-4cb9-0397-08db3b336def X-MS-Exchange-CrossTenant-AuthSource: BN6PR1001MB2340.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2023 08:53:48.2134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0QYKXIkp6+kbx3YCHNstftMVoCkT3Rd9Ah4ukMhzW2u6lO4LCAWZKhIH3xMiC8y6TY/pCee54jHv7EvSyUGE0QTjTg6VJkOMaMm7fIEu3rs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4623 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-12_02,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304120080 X-Proofpoint-ORIG-GUID: WrPL3oTtXpjB6stYzLKjxvIhx-ftwCqt X-Proofpoint-GUID: WrPL3oTtXpjB6stYzLKjxvIhx-ftwCqt X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: Hi Adhemerval, everyone, Thanks the approval, detailed analysis and time spent on the topic. Best regards, Cupertino Adhemerval Zanella Netto writes: > On 28/03/23 12:22, 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. >> >> Changed from v2: >> - Added entry in manual/tunables.texi >> - Fixed tunable default to description >> - Code style corrections. >> >> Changes from v3: >> - Improve tunables.texi. >> >> Changes from v4: >> - Improved text in tunables.texi by suggestion of Adhemerval. > > Florian has raised some concern [1] that reported RSS increase is not > technically correct because the once the kernel need to split the Huge > Page, it does not need keep all of them (only the one that actually > generate the soft fault). > > However this is not what I see using the previous testcase that creates > lot of threads to force the THP usage and checking the > /proc/self/smaps_rollout. The resulting 'Private_Dirty' still accounts > for *all* the default smalls pages once kernel decides to split the > page, and it seems to be same outcome from a recent OpenJDK thread [2]. > > Afaiu the kernel does not keep track which possible small pages from the > THP has been already hit when the guard page is mprotect (which forces > the split), so when the kernel reverts back to using default pages it > keeps all the pages. This is also a recent kernel discussion which > similar conclusion [3]. > > So this patch is LGTM, and I will install this shortly. > > I also discussed on the same call if it would be better to make the m > advise the *default* behavior if the pthread stack usage will always ended > up requiring the kernel to split up to use default pages, i.e: > > 1. THP (/sys/kernel/mm/transparent_hugepage/enabled) is set to > 'always'. > > 2. The stack size is multiple of THP size > (/sys/kernel/mm/transparent_hugepage/hpage_pmd_size). > > 3. And if stack size minus guard pages is still multiple of THP > size ((stack_size - guard_size) % thp_size == 0). > > It does not mean that the stack will automatically backup by THP, but > it also means that depending of the process VMA it might generate some > RSS waste once kernel decides to use THP for the stack. And it should > also make the tunables not required. > > [1] https://sourceware.org/glibc/wiki/PatchworkReviewMeetings > [2] https://bugs.openjdk.org/browse/JDK-8303215?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true > [3] https://lore.kernel.org/linux-mm/278ec047-4c5d-ab71-de36-094dbed4067c@redhat.com/T/ > >> --- >> manual/tunables.texi | 15 +++++++++++++++ >> 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 ++++++ >> 6 files changed, 39 insertions(+) >> >> diff --git a/manual/tunables.texi b/manual/tunables.texi >> index 70dd2264c5..130f94b2bc 100644 >> --- a/manual/tunables.texi >> +++ b/manual/tunables.texi >> @@ -459,6 +459,21 @@ registration on behalf of the application. >> Restartable sequences are a Linux-specific extension. >> @end deftp >> >> +@deftp Tunable glibc.pthread.stack_hugetlb >> +This tunable controls whether to use Huge Pages in the stacks created by >> +@code{pthread_create}. This tunable only affects the stacks created by >> +@theglibc{}, it has no effect on stack assigned with >> +@code{pthread_attr_setstack}. >> + >> +The default is @samp{1} where the system default value is used. Setting >> +its value to @code{0} enables the use of @code{madvise} with >> +@code{MADV_NOHUGEPAGE} after stack creation with @code{mmap}. >> + >> +This is a memory utilization optimization, since internal glibc setup of either >> +the thread descriptor and the guard page might force the kernel to move the >> +thread stack originally backup by Huge Pages to default pages. >> +@end deftp >> + >> @node Hardware Capability Tunables >> @section Hardware Capability Tunables >> @cindex hardware capability tunables >> diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c >> index c7adbccd6f..f9d8cdfd08 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) >> + 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..cf90b27c2b 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. */ >> +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..4cde9500b6 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: 1 >> + } >> } >> }