From patchwork Mon Mar 20 15:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 1759096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ajy4otX6; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PgJs46skBz246f for ; Tue, 21 Mar 2023 02:42:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAA4B3850430 for ; Mon, 20 Mar 2023 15:42:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAA4B3850430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679326951; bh=t9IJxDE+AwGS7bLfodmOSru7lq1XWrvYNtASCs6gWg8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ajy4otX6BA1N3UtiwQuDrgmEns3e6juNnp+k3iR9BdVvw1S9K8gLur1CDT0fEi8+d cECaCwHPk8A8fPUDTJvPhAIn3DDoquKIDViJwytpzJchqd0JX3yZyCKmKnfAo7+j7K aJ/whwZ4tWBGhyz6snFErUePuPYnd6rJnh/TciQo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 2290F385F014 for ; Mon, 20 Mar 2023 15:42:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2290F385F014 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32KFa3DH011870 for ; Mon, 20 Mar 2023 15:42:14 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pd56auq72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 20 Mar 2023 15:42:14 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32KFVCEE010762 for ; Mon, 20 Mar 2023 15:42:12 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3peqjmgehc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 20 Mar 2023 15:42:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mb5jX049JBJTnXbpDmL9rh2wErYTTZi7hNysQ6Ctf6gmIpgCZB+jUJW7H+eVe1FVXMbH5yfDtP9euGhUizxbKx0HTJgAvEDZI6gRAZN/FUeVLFClhUgEJbRA3ULq+V5Sa06ZUsrY9XFdcabLc6mvWJenxdRDWD5gxMea6uuuj27Q/4C1Yxz0fs7+Eban15eOE/11v0WTt8pEK2WeHX4oResCUjD9xj0fZwqs36BZn6NT/C5XHvJKT1/keJOHUIKwI3CfSDUxD8fseOWEnpVzIKVn51LGYDMiaE3dBScup7D578nJEJKo/t6fI6Exu9jLyRP01b0w11psAlD5uazqdQ== 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=t9IJxDE+AwGS7bLfodmOSru7lq1XWrvYNtASCs6gWg8=; b=QWRRQqpIJ3nro7mELKI/+GOrjF3Yr3yJX0L3eqh5IX5OFJyEDAthbRgCvgFyeercX8TtKoMzw8WIAgR4DotKxTVWPfyducSmYg03Kp3LHTno3cfe+4encyRBhC+j5c3E3OmbDDVpgb20rlW5etGAhLz44l9Y7valpe7wlEoX9adHgyELAMI/2ftYpAAvDcuT93ac3LKJLqF0adkc+8j7k3LrbAFoaKReHp1jK954PKlugMwM4dcWFXgZrQlT3O1EF+Qp7kQJtQ8RhovCTPwtqT4JEdbF+to9G/5hbjlRGcQ70+DdGgbLKvkmNq2CM48hdXULl6u1DphofizOCflpEw== 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 Received: from BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) by CO1PR10MB4403.namprd10.prod.outlook.com (2603:10b6:303:9a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Mon, 20 Mar 2023 15:42:06 +0000 Received: from BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::a502:c948:c3f6:9728]) by BN6PR1001MB2340.namprd10.prod.outlook.com ([fe80::a502:c948:c3f6:9728%6]) with mapi id 15.20.6178.036; Mon, 20 Mar 2023 15:42:05 +0000 To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Cupertino Miranda Subject: [PATCH] Created tunable to force small pages on stack allocation. Date: Mon, 20 Mar 2023 15:41:55 +0000 Message-Id: <20230320154155.549206-2-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230320154155.549206-1-cupertino.miranda@oracle.com> References: <20230320154155.549206-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AS4P250CA0014.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:5df::17) To BN6PR1001MB2340.namprd10.prod.outlook.com (2603:10b6:405:30::36) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR1001MB2340:EE_|CO1PR10MB4403:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b87bb11-d13e-4cee-2a6b-08db2959a7cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +K2MhwnnRqeGO3LNxhpNEfFqikUVLiEqTJgkw2w3qwmKVNsZxKLQPU92V15hlSSxRRtrWh5q82haDTM+RLbaez0qiJGwHd5R9vxWr1WokwxEfSmfMsCKkoCxGBKJWd/Uj5QqYSNfWlzDap4VVnK8T4ttMBcdhOwbSF+fN0lP9yHCRbMuBJ3w8U+MnLiE/qbYj1hsNncfBPnX/VV43Nl6cOgGwR7HUnFAt9C8NIj1NrIDR9nxnVlKsZPzHeJmqznUUURTFtJERzEdj+cgqWBJBydJstblzsIvgVnQkSJHr7dSUNQnjR/SLU74bfVfRDpBX/9DZUHItN8G4kqYXQJNjeGFwO/hblp6du2Svjscnw11AyHpleIL2eBUdUnsrGXwIoPGZYDzz1DYKJXI4XedUWJGOA7PQiHoCoKZ9GhqTs+6++kipWWFrYLumnD+TFalKdXNkTarebHVFhVSkFKQ7FKK/vj/CUiqAjjAsZj76SQCqB8vjj4+yWGUgkJjpx4Jf701rciQD9YqPY49ooieCkV0DDswveMHZ123LLX2CUDOLf60thZM3E+eM5CpgEZ4Bkt2cjsTpvzdBKgb5FwfisBCZxFshAO1QQDgZ6j8uKY350ro3g1XVwMZdDBuCsYujq+corm1t7K8tvr6FoNU+g== 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:(13230025)(39860400002)(366004)(396003)(136003)(376002)(346002)(451199018)(2616005)(478600001)(6486002)(186003)(6666004)(5660300002)(316002)(1076003)(6506007)(6512007)(107886003)(6916009)(86362001)(38100700002)(2906002)(44832011)(8936002)(66946007)(4326008)(66556008)(36756003)(66476007)(8676002)(41300700001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TNb+WCmXupHAlFX6WnDYfTYCKJJVXkLahPaG77d9TlNJp2HfORA4OPPLSqOZOtPgkUdxgTcGN3kgYFJb4F+roobeeQOlXrO4HtQcrl2XyD9ek4B19U/91ZK74SZVkOcCsf88nClGkwqqFKROe/XIGOns3J4R28aD0Qa0VtQzAI/yoAs0zD3qFyUQW9KCvvBPgGNpfAtswYZpPnMXdUkAvFWYzaQ76stqOT/ROCi1Yr4hnuuT6fYzLkdoORId3Tniq7UxqMnXtyJWpywV5Mb4epBUXNuMKaVRfJI8eQJGcvsEsWZvBIu1MSHaC6HsAv7l6VczMcjGzxkbjqq6zZv6cfOs9sPPXvGu1Hl9X9KTM31HEFFbx3PjAkXPC+bJOtKaADYCaeXROTSI5A7mfMeaOqFd3jbHHXVAC8jj8UuhlMo1Fms4VDdW6+ALOl0wllNAkCa5KHQP5JAUug+DsfAlJL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AaOEWtvwqkh+bhzdi1mKxfE9Tw517pJhlhL5aJwyMFe98ht6IHGxjM2NvQOx2halQgzGKeb/zGOhYz4HRst7YRD0Us7ZD279ByAh0QX9/lIhrA4A X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 637wUr5/G1iAxYnSuj5BHPNlQ9bK53xY4fwXd+g33T7/rMzaK4Q2yhjRs9GT5v5U4X7C1kZm1T6A9ptT7sQi2kaRzQaVZ/0bBXtXBY6bSuIOEZ8LMECJG5gEgv8KY8SlGZIf1+Lim+9bXYPEzzzAhfSecqQOlpxLrczmT5bUhHHEkurWzRQ+Ep9/KHVBnQso+vArwoSDHDFtZLegdmev5IFa4cUgNIagpeETK/d6ZoceKV9duEh2cwT757DXeJ0F8lPiMvKP2BAIC9/QAjMxh0kBB0q5jpmvjObWw3g71C5V+owSKB1GxbnJibUgpS+Cr45k4ppxTpGmQvze5HrggmGlWtzAv0SzyV3cWyOLLLVI3Tl89a/VTHjEIuipIZU66BfMJHzW3LfxFRtt2jwHEAHRKGO09mIi8PX5bMUmL2MalIO0fQ8oY8JEqfJqUZvTmdISJIqu+m/igyo6mC92igVwBr6eqQnneo810XH810P4hfrksiOK0hJcRemWcHBpBgKELGgPoJbRvzU22Ry8MLm/HX/FVQLi0KGVmJxle4yJozYbAYP+KQLIr7fnZ6PVnJfzcn/pZDgzuOWIe4AIScQIEA6qv3gQpKOsscRbhfz72c1JyjDG1fOP1P2rf36ScdWdbIBPEJvylQm0fcjF+dcRVY6yTqoxMwvZfffEqL2YvIxNx0QLz9RU3J9l6JFcUYDBP1jYu2rVSOlHJb1x2+6iKYPhXjewzy7G6qxwUPBbTnCY4onWMjI2DNXA68hr X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b87bb11-d13e-4cee-2a6b-08db2959a7cd X-MS-Exchange-CrossTenant-AuthSource: BN6PR1001MB2340.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2023 15:42:05.3531 (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: +4DUM0X4yiuFJwtYBy8rdFKEre3tPFj4fnyBbn63ohhqOmPJz8UmmFYL4i9Zt387SVr7I1S8yZRyrQteMeZoxn7xLlZaZSJBo12tebFDHMQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4403 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-03-20_12,2023-03-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303200132 X-Proofpoint-ORIG-GUID: uNAwit4KG5TlfEqBxH1e_eM8ZEpODYLh X-Proofpoint-GUID: uNAwit4KG5TlfEqBxH1e_eM8ZEpODYLh X-Spam-Status: No, score=-11.8 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Cupertino Miranda via Libc-alpha From: Cupertino Miranda Reply-To: Cupertino Miranda Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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. --- 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) + 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 */ +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 + } } }