From patchwork Tue Apr 15 13:49:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 110499 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E90A3857B94 for ; Tue, 15 Apr 2025 13:51:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E90A3857B94 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=ObqbT/4a; dkim=pass (1024-bit key, unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=tEwYrZhp 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 19ED93858430 for ; Tue, 15 Apr 2025 13:49:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19ED93858430 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19ED93858430 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744724989; cv=pass; b=RjzRamABRWg2qFVQlABRkKKqfgoE0JkzLjEExZ/5zGZeHxyhF867y2wIrsPb6XQH1PktXSWYRn+ChwKOWY1Hns0WtpSTNSNktkXlsGltdUnQFRkT5w6uPKtKpqCWiZh38HqkaVsFDGuby7NYLptM3bmft6eZVhH3dGOcQ14U/uM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744724989; c=relaxed/simple; bh=8vSrIqvNZsp2im/cYSIlgwzdr8Tdoi80G12Rxmn/qg0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=m5RH76LRU61VoNqPu4yfdDjlOcrv2jXw/riOY4wwZGIFt454009UQdfkB6Qo/cQk++I194ahaV/ANAbfPFdXVLYeZu6ZvWwMGMh7/1KDChjFvipx38fsedk06lXPMrXWtwHce0/6T9ib+0wijyUN11MY0JVTnUfDUnRb5APAn+c= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19ED93858430 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6ftac021602; Tue, 15 Apr 2025 13:49:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=v5A0zSIqJdnloLk3ZNjeNr8oN7ytvsX9wFOkkP0dgwA=; b= ObqbT/4aDYvHb1v1dRdD3pKt4pdkdpDziWodheJZOHI26e8UybLs7arUqpX9S7ui vCrze6SLPSq856vkGuZ1rcbSoXQg3GuEiHeS+Qa0yn0f0mEoPlFFUFzFpQEAPVaV kaH1cEVSQQNEtClflJbm2vWTrO2Kd78WU7FCDfo19MgpdUiBjqvoUvzbYYaUs4D7 dynvD6zOvnhy6sUYwTHwURs4tTFQaYX2bRO7rU7vVZ049hsuAP261mjuSa1Eg6t/ jE0SPSJqrmIBUlojWhr1txzAn1fCi9yB4JSk7cvtiND6qj+x0V0WD+gVPY8qBmnP lCxBzeh3KsmBemZpvM0yHA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4618rd1m3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:43 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53FD5d1v005684; Tue, 15 Apr 2025 13:49:43 GMT Received: from ch1pr05cu001.outbound.protection.outlook.com (mail-northcentralusazlp17010004.outbound.protection.outlook.com [40.93.20.4]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 460d5va94e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pNsYNpAiY2fwGHl4HPbXKmrg/V4wmr79qBp/U3j/hJnMc59nq0km3k4Dn58lcW/jVYgnQgYGvuH2E7BH38UesW5dEeLn6kcEhbx3CuShiLbbsfvmV5lCsSDdE66HibJOgPR/eNXgXlAVT9HAtDwkoaiyFutKYwqu3Kgv01CuaOQ0diBuznYT2vGqmvFMzA5PdrYLlCi6HV0IREuiJFvGIeE+ouaB4Vsbe4MonEVxXw0+exKvvw68tbVX1pHBFj4vP3XdO2rh4pwJA6EKFbYONuhzv1O+tSdFZ5sqkx9XoCQ7iArCdCWlSRWMqLhc8cWPgejGWCg/GadWFxsvKuNmqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=v5A0zSIqJdnloLk3ZNjeNr8oN7ytvsX9wFOkkP0dgwA=; b=jQItn3+9UFpmEM86SB9i2w1aBdfXtFY2J4GP1ZC9brXGKsja373Li3+3WidfSUfzKm5WGTLr8OhOMTDRA/+Mc/SNHeOGGB3qp9mgmatKp0tvt4Jwvk5BwKcGcHSvZzbYaY4+PCugQMlLgPP43UE9rLKBodHpLvO8E8n0qIWn0ohm59A04l+F6ejRj24WCVOgWh4Q/XBWEL/AbBg/hEXgtf2sN05wcQWGuN6gocMrzXoNgGva5/b5tHPm1ZzYLDXTy+0FEWR5MT0Vlri6WRTRRG3LgSa15yufchj03zmgdfiIgjHI2akcUERM5pXfxsEA8X2ptBIUuwYo/SqS28FScA== 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=v5A0zSIqJdnloLk3ZNjeNr8oN7ytvsX9wFOkkP0dgwA=; b=tEwYrZhpjziRzsFt4Wbva61Dzsa9IgbqtuUqyaaerzJ+HQ8ZxL15O6J5wjuM/UOzgrv2H3Fcn9Tp1+xF2hpukfLM7AQuLMb/FqeCpjTxk7cFYHH6ZyzrRXeRBOApkyY0jFRa4JyNsFrq5KufqND7wYiIhE8y9veJZz/8nsLYl1A= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by CY8PR10MB6705.namprd10.prod.outlook.com (2603:10b6:930:91::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.36; Tue, 15 Apr 2025 13:49:38 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb%4]) with mapi id 15.20.8632.030; Tue, 15 Apr 2025 13:49:38 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Wilco.Dijkstra@arm.com, fweimer@redhat.com, dj@redhat.com, Cupertino Miranda Subject: [PATCH v6 1/3] malloc: mangle tcache entries pointers Date: Tue, 15 Apr 2025 14:49:18 +0100 Message-Id: <20250415134920.287189-2-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250415134920.287189-1-cupertino.miranda@oracle.com> References: <20250415134920.287189-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO6P123CA0014.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:338::17) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|CY8PR10MB6705:EE_ X-MS-Office365-Filtering-Correlation-Id: 13dbeef5-6e7f-4f4c-8a9e-08dd7c245cfe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: k8/1LfgOdIYAcy/cFOe7Omu4O19IbEozXqTYQI0mkTp64xKkXXPJpI0Tc+q2ksK6pLQfkD7ofaa52E8Nqah8zPJbs1c2cDjKR/eFD0z4KkaIkHyvkctijNK2UQTP+2qScU81b0nFbk+R5Z64WufVshjVLlYlAM35ZTIfkPRYxiX7RABO8MVZCz0py74GKTb4F6PFAN3Bla7hCcp2wMMRtVNkkvPfxwbVYu/lG1vjxZxovUahuG1WUY6sYcFdA1WCSOqbwNcTuBEyiocgqx6YHHf5/UDpl3I/tOgl0dx5dB1jqMnPibb4oqJ/pJpKJrxwT1wrIUx52pRUXEfx81A1iaAB20PkCyO70Z9/BXtpfYaf5Su393A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X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4382.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YHZWPJervVwq+8UQBnjDMLtXmJAgJl9Vnu91wxCkChozepuyWKy6DD686PjNzkxiFzccTpfrvHan43ZfRW3LglfTZFYtubWIThuQorGNpY1G7g23Vrw2aNmtMxvfDgwq8hTVbzyj0rOvlCVgYuLb49TLbbcwfk+BtOHMr0PnZGnfBbzGvHzBDG7U67fyH1hx6H6j/rV6IFcJjhbhsDIPVj7+Fv8tyHiqf1B979wHvvc5yKmnxkHrP9d7BKfbntxF1gpLprFYNpdXYisJvqIhDSUcq5/rwILMmgpL4VIlB8KIi50j63eVf15sIQ7vHAqGmvRyr6phPhj3ELclXH8bV490Mb6GjpGCJAFHsgii1LAoH5DsEjSNh2wo0+NgIR9iBLFt8y7PzEtWE+7xqb2c2YT84cGJdR0fcC+nRU6wCQoqPR4mSIOuIF1pcG68bfMHl80tmkTyGaU38AiTH3s9FErBiAUDTTAUV5bLzOSHgOfy6TBCmTBX6ngUUUXp0rxZqjQXkZ4UYSQB12Yp68813YwxyakxmHpjsK70adI3cXayij9jKuOgThck5vIZH0P6yK3RLceg3z2aGc7ZOjCuVfHEbbZKucrvC7hpvv/u3mvQHNaD887z/nL9s2NRaRf6ECtU16eIHSV5+ZD/Cf1ZOFtSoCr2Pgw3tBjPAlgBnkmjfAkZKmA0aF7dv03FJSI0+fFvHQZZ5QA9wK54zVG8zt1VHpLL0yScQSV+rldgzGy5cxq8GOcqcn6mFROrXQjJfdSyiVFDFthNVPN/lOipkiwvvegr/p1d5UywSZ55nz308BHB3UFjSWK/LoHGHl2CQlVqaGl7NcrVXtqJKvPJl2VPaMo2LpRNKeqmg5goZj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C5tUZVVUk6Pc0CrwkmIVMVNUEwyR0RW4cIbO8EgA5CsNwWVUu/i614hDPae0wlwM/qHMdZDQyx1nQNK58KY787OyaRSs8oQinCPjd4NMLe+OgZ73h7tnMUGLEXVuteTAO4pHXiBOTr0BTfroV1Z8xIa/5YHDXWaWbFGdp624pFTyZbU2Qf8cX9tp9IqNXwvHDxN2Vlnz9ZBFrzZtWFhfgaoIJZkI+2ZkGrVHzzbjqylCwR0DWrs2Rzs2Hv26b7pKmxzCxpJxI3vk278QBlQAKIstKRupX/zZoUUYbbE/JX2p3Is0OQfNPVL6X01Ej9X+ib4jLfV/ISIwji8cdiMKU2XMxdLc3ge3Mbo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13dbeef5-6e7f-4f4c-8a9e-08dd7c245cfe X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 13:49:38.0781 (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: Rjk7zl25DfOrvO4hPc9VzNtXQNU4WaCRm31hUcoiRuCriIaYIvVcWhDsM9YQYWabw5bM0g1V/iOineD/RrpFqFcQwJpUj7oTUVYzp6V4zLo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6705 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_06,2025-04-15_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150098 X-Proofpoint-ORIG-GUID: 5Rm97yrXHPP_sD_uCRj8k_9ZNQddPKeW X-Proofpoint-GUID: 5Rm97yrXHPP_sD_uCRj8k_9ZNQddPKeW X-Spam-Status: No, score=-12.6 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_H5, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org tcache entries are store in mangled linked lists of chunks. However the initial pointer stored in tcache->entries[index] is stored unmangled. Due to this difference, tcache_get_n contains 2 extra conditions to disambiguate between the original pointer from tcache entries, or the next pointer within the content of the chunk. This patch slightly improves tcache_get_n by removing the condition related to refering to the first pointer by also mangling the pointers stored in tcache->entries. The mangling of the entries should also happen on tcache_init as NULL pointers are also mangled. --- malloc/malloc.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index f30fb4b1ba..c0423a2e10 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3167,8 +3167,8 @@ tcache_put (mchunkptr chunk, size_t tc_idx) detect a double free. */ e->key = tcache_key; - e->next = PROTECT_PTR (&e->next, tcache->entries[tc_idx]); - tcache->entries[tc_idx] = e; + e->next = PROTECT_PTR (&e->next, REVEAL_PTR (tcache->entries[tc_idx])); + tcache->entries[tc_idx] = PROTECT_PTR (&(tcache->entries[tc_idx]), e); ++(tcache->counts[tc_idx]); } @@ -3178,19 +3178,12 @@ tcache_put (mchunkptr chunk, size_t tc_idx) static __always_inline void * tcache_get_n (size_t tc_idx, tcache_entry **ep) { - tcache_entry *e; - if (ep == &(tcache->entries[tc_idx])) - e = *ep; - else - e = REVEAL_PTR (*ep); + tcache_entry *e = REVEAL_PTR (*ep); if (__glibc_unlikely (!aligned_OK (e))) malloc_printerr ("malloc(): unaligned tcache chunk detected"); - if (ep == &(tcache->entries[tc_idx])) - *ep = REVEAL_PTR (e->next); - else - *ep = PROTECT_PTR (ep, REVEAL_PTR (e->next)); + *ep = PROTECT_PTR (ep, REVEAL_PTR (e->next)); --(tcache->counts[tc_idx]); e->key = 0; @@ -3231,7 +3224,7 @@ tcache_double_free_verify (tcache_entry *e, size_t tc_idx) tcache_entry *tmp; size_t cnt = 0; LIBC_PROBE (memory_tcache_double_free, 2, e, tc_idx); - for (tmp = tcache->entries[tc_idx]; + for (tmp = REVEAL_PTR (tcache->entries[tc_idx]); tmp; tmp = REVEAL_PTR (tmp->next), ++cnt) { @@ -3267,13 +3260,13 @@ tcache_thread_shutdown (void) heap for coalescing. */ for (i = 0; i < TCACHE_MAX_BINS; ++i) { - while (tcache_tmp->entries[i]) + while (REVEAL_PTR (tcache_tmp->entries[i])) { - tcache_entry *e = tcache_tmp->entries[i]; + tcache_entry *e = REVEAL_PTR (tcache_tmp->entries[i]); if (__glibc_unlikely (!aligned_OK (e))) malloc_printerr ("tcache_thread_shutdown(): " "unaligned tcache chunk detected"); - tcache_tmp->entries[i] = REVEAL_PTR (e->next); + tcache_tmp->entries[i] = PROTECT_PTR (&(tcache_tmp->entries[i]), REVEAL_PTR (e->next)); __libc_free (e); } } @@ -3324,6 +3317,8 @@ tcache_init(void) memset (tcache, 0, sizeof (tcache_perthread_struct)); } + for (int i = 0; i < mp_.tcache_bins; i++) + tcache->entries[i] = PROTECT_PTR (&(tcache->entries[i]), NULL); } # define MAYBE_INIT_TCACHE() \ @@ -3690,7 +3685,7 @@ _mid_memalign (size_t alignment, size_t bytes, void *address) { /* The tcache itself isn't encoded, but the chain is. */ tcache_entry **tep = & tcache->entries[tc_idx]; - tcache_entry *te = *tep; + tcache_entry *te = REVEAL_PTR (*tep); while (te != NULL && !PTR_IS_ALIGNED (te, alignment)) { tep = & (te->next); From patchwork Tue Apr 15 13:49:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 110500 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F28BC3857BA0 for ; Tue, 15 Apr 2025 13:51:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F28BC3857BA0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=RZjhzi07; dkim=pass (1024-bit key, unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=dYu1KqXA 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 4EA023858290 for ; Tue, 15 Apr 2025 13:49:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EA023858290 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4EA023858290 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744724994; cv=pass; b=b/qNr8dZvHFVBGq9q4g3CNlpd6761HG9O1XAjUOgk6tMPoMoXfJ1wBH2Y4/dveRcj9UxUEkRn2ic3ntbgzSNb53t0B9IMQ3uhmXdFaxHM5YT0730Ci/xCkKPhmxdNxo8lSUbrsbe+PNrIqy1dWUSw7QQc0ywlvX51IjMG3+Blsg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744724994; c=relaxed/simple; bh=9yvT9KMSxZhW5+xZjm1sVZHgUKkLK3iyBpHPumGdZPY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=Zfw1uynemAXx7Hzwo8OwKDEvds0S2cDxzwWpTsc+nFYx3IMp5/Fl94ht1wa63OdSJVMDMhgq9OQnRKAEozlR/+427yp0KFoMchHLXRZ5FlWrovM/PvbQ5kSKm7lArVWlrUf1PHl+ZA7xPPrDcLxfG+zKOd1aJOMiK5lDKjEcvnM= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EA023858290 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fwqx021684; Tue, 15 Apr 2025 13:49:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=r/TgdVQceR9V7ss1Ig/6eOXB7epwHJyMTkyKGjNAgTg=; b= RZjhzi07k5cGIIpIW2shIUmkry/h1MzxjnSRTS8OdNcUFGiKFqA6rMhycoLxj7qf iPJB8DK5aTj01NnUHOKSRcvYhm/3rV7Yka/hbFHMMl0Qf2LeJ8HBg1lhzs+Ug7lA IMALZTBDTAI/A3DiUNyWzfJKDDvy1IPt9rvW5rPvwxdJATHjwrjFkJ0SK6hXhrPp x6I+KHn+XpJzHSv/aIrwcDbchIzstIJd6RcNLBnkTiDIJlHqiRHuLrNEhRBkb1NS DGG2if76rpJng6FpWcpwislwQGiKl5hDEzIfEN3Q3dHYgw8VnP/mULmzAJgsNW34 YapNc0cXmKBc4G000qsAww== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4618rd1m46-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:49 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53FCiC1w038842; Tue, 15 Apr 2025 13:49:47 GMT Received: from ch1pr05cu001.outbound.protection.outlook.com (mail-northcentralusazlp17010000.outbound.protection.outlook.com [40.93.20.0]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4rbt7n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tHvXD+Zw8x1psb7bu8DWk031NrrB881P3CeRe5imFRK0taIJbWvEMf9z9XvSk1LTQvwxtkhH3iq139omO6ylsI1Y6O1KcQ8VHA6LNdkWwrRlxChq4a9Nri0tk8WrbksYnpjIo7T4ZnVsPInwCdbn+dUal5Z8c0bGGmNfrQ78beAMs0zWiPi+j85cjk0BZXE3rH2bJBgWN2BSqmo7P1prAK7ysVWjLQWOt9ncRwrh6DSKyhshQ8Zxgdb1ZgJzE11yTe7Jx9ZmlQD5a4acv6mQbcVhs04MnJyvkw0ZRtrHKXGdzc2xMqZM2CCR2SzshAxkbI1AG5dCrAXYETq9spLvOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=r/TgdVQceR9V7ss1Ig/6eOXB7epwHJyMTkyKGjNAgTg=; b=jjNI+qfixLjEMyITTIKyByxuhwkyYHWdDh0+w1SwZI3wsHtiqjNBwSBBkaVIc6DbomsCLh9Fa2f+83WtbSI2xScgPPF3NNTnpPcrFbYLy/A6mbzQQCljZ+Wzh1DzJ0aV2YiSoRvBAiq2h5DzdS9/kp2rkFozmdqrZMumYQeEOvkvWhXY9S2wVgOwJMLU0v1suNiILIRBNB/hzlD/GsgKIbPDsTV385O7BsqBin6IUUVU5kK3Yo2i4N47N8AQ/7EwoJqi5CiBd/JCHvMI1CoECvL65lvCpMz3VQBLkKkH1GPVf4991dLqkYVGPpPpSZBCBQocehz/W/Y4jeA60dOGZQ== 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=r/TgdVQceR9V7ss1Ig/6eOXB7epwHJyMTkyKGjNAgTg=; b=dYu1KqXA+NEIDDYUA1tOLM69Fiodp0R6nn7S9eXSSZ9Iqn5meoYYbqHhnJ8DtBmOw/HCmcLdWuUYqg2s8KPr1SZHyjLKxCZFCruZ6FrnjmDqlDYn3marx8fboYcFXgz1r8BjDyfk6yj1IdsGGeuRCjOttum7uiFaLNauvEtOHQs= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by CY8PR10MB6705.namprd10.prod.outlook.com (2603:10b6:930:91::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.36; Tue, 15 Apr 2025 13:49:43 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb%4]) with mapi id 15.20.8632.030; Tue, 15 Apr 2025 13:49:43 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Wilco.Dijkstra@arm.com, fweimer@redhat.com, dj@redhat.com, Cupertino Miranda Subject: [PATCH v6 2/3] malloc: add tcache support for large chunk caching Date: Tue, 15 Apr 2025 14:49:19 +0100 Message-Id: <20250415134920.287189-3-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250415134920.287189-1-cupertino.miranda@oracle.com> References: <20250415134920.287189-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO4P123CA0245.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::16) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|CY8PR10MB6705:EE_ X-MS-Office365-Filtering-Correlation-Id: c960ee55-edbd-44d0-6727-08dd7c24606a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: vH1LBi8V6uiIJe+PaVyWFjN78RWIpNFLczfDaS+t/4di3KNVpq2pvmg39q2+770M5Ll6YSVlu5BIZqN63c6NXWsFB5XJX9suTSrQtHMRpDHRpQivpiRIO0u5ZVfMM/Y9+lmiFP2ctR5CCyOFw1KLQ5CD/sf8eUzw8FFUEcO55qKVqJwW7mbhgHa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zRq6NfoH/bF1cEoPcfr9Lmt/O1huQHeg7BwHYYnHEyZX5+rhs7ncMXTDBnhGcZc2BPQNU1u3DVmklzHw4lPgMZCr3UsUJGW9izhywCHL5ovEwJHnVGc4/AqamhyweTHRAyHB3pt3lh63zdMoL9L/4s89TglBbsNvb8Hrd11Nk4TP55pKpBD6TadITodgLdDB1paF+rOp/0xyRrbJrDshYM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4382.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sXOIzUv2JlNtBRx6xkL07a88nU+pVUBL1n1Tl27N0dK69IoLw7bbDOQNmTO2maLjP7XB6RZBefQpRDzkbn2O1o6YRcZo/aUAOURVBy0dzs8dPY4i5XBrJGImCCkIG3lsBdYfL7RniW6oCt7s1al7dyiiPbONWXrMB4cdiNMWI+eWfA82ptAe5CGAcfnI2L2dl95Q3ZJdx9nzeag6Sv/7AXOBB5o3zT5/0wcu8DEzgfQPWQ8DdvtXdqyOO2XiR1dG+cf3rulvfSMF9igy3scYKfp13ag61SLaxNwCQWgD60bEtef+sMEGGnRNLUfI/Ho3W8LvyGhchSm0AYxkOXJPDdkBu8htLOt7hGDY1/0hxWCHQ1T8TUnpeg+hdO65W45AfBLguoBJu4Wj97phUEfwcOUQFxxspHDs11PmTytUx5LOC+c/jVVrGEzGFGCZfoloaUMpitMDHRmTYFxRbQ40958puPl859E1aoYcYI3S4h7LBOWOZk+lriiwRgIMwhuiHFl6zTrVUOx+YJeoXmLkiX/Ha2GnX3hN+pl/m9JJzMncv6BI/U8ttgPPcyv6NKOkVKU+0AF67znapntIMWZMGidTFHX4QuFWm9mUVFapkE6Lcx5fD85Hfby3JZu8DaJeQDn7Sftv9toAMgAj3Or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hm3Bzfo5j/Au/jGB8IODAo1T+wC0kEKlyQMFbdxSR1Y+MIGTIO5ZZWqsa0FqXFUj01R00C2bXelRiSX8le6dXvZsaUEWkm1UA+CNC+/N1dDGWCNwLkAIik2EIyjpvWwxOf00lkYXSXeNGXXJfRL0soPNMP0v1BJkBCTL69IvGImxkb3wZVV6eQjOCBAbn8PAIIReaJes9vppcfcfuCdLFAXI3R/pa2l6FAXf1OU68Isl5q7hAdnNla6UH7vi0zdMcXjg3fuVYVgy8Wmi2jRgF8gfI0vs8pvPuFvmkqG3LAorDiMrumAgy0odnoy2wxdirvrNega1L+Mug9ijSiNC9QwcQ1SNr8LSFTm4Al7wCCCXcwguGIb43h+hFvdRgrXBs6ArFjtAXVd8ALxn+wr8wIh84rRPPPth5PG3o26vbJAbn41nXlpYnIr/ChZyogXXlBw38Qib0LDHiuar7Bt+CsbZC9EeETFsINhlWvvA+84YqdA24HReKKLPFpKEwghgKk5Pgmdfy8inMdXqFDYi+ZsiJ1FHC8Gb09O6v5I/2kvqbZH6cbGPVD0ZlKw7ni87Qe6TUly6V07Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c960ee55-edbd-44d0-6727-08dd7c24606a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 13:49:43.7048 (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: rXbPM3DGK5HTXViPdS0eDDFrWiVpZZbAN3+Hmj/2AzJzdhnAznqMLoP+lUV8yHvXwIYfKLy/rLbvBLkQRvWCMzSBjLJn4jVPKuFLWUh7/6M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6705 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_06,2025-04-15_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150098 X-Proofpoint-ORIG-GUID: HHhuzL24v9Uh0INcojGbP2LFPOIRNx-8 X-Proofpoint-GUID: HHhuzL24v9Uh0INcojGbP2LFPOIRNx-8 X-Spam-Status: No, score=-12.6 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_H5, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Existing tcache implementation in glibc seems to focus in caching smaller data size allocations, limiting the size of the allocation to 1KB. This patch changes tcache implementation to allow to cache any chunk size allocations. The implementation adds extra bins (linked-lists) which store chunks with different ranges of allocation sizes. Bin selection is done in multiples in powers of 2 and chunks are inserted in growing size ordering within the bin. The last bin contains all other sizes of allocations. This patch although by default preserves the same implementation, limitting caches to 1KB chunks, it now allows to increase the max size for the cached chunks with the tunable glibc.malloc.tcache_max. --- malloc/malloc.c | 159 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 44 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index c0423a2e10..54769cbbd6 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -292,13 +292,19 @@ #if USE_TCACHE /* We want 64 entries. This is an arbitrary limit, which tunables can reduce. */ # define TCACHE_MAX_BINS 64 +/* Number of bins beyond the TCACHE_MAX_BINS reserved for ranges of chunksizes + to allow tcaches to cache chunks beyond ~1k size. */ +# define TCACHE_UNBOUND_SIZE_BINS 10 +# define TCACHE_ALL_BINS (TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS) # define MAX_TCACHE_SIZE tidx2usize (TCACHE_MAX_BINS-1) +# define TCACHE_FIXED_SIZE_BINS \ + (mp_.tcache_bins < TCACHE_MAX_BINS ? mp_.tcache_bins : TCACHE_MAX_BINS) /* Only used to pre-fill the tunables. */ -# define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ) +# define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - MALLOC_ALIGNMENT + 1) -/* When "x" is from chunksize(). */ -# define csize2tidx(x) (((x) - MINSIZE) / MALLOC_ALIGNMENT) +/* When "x" is from chunksize(). Only usable for single sized tcache bins. */ +# define fast_csize2tidx(x) (((x) - MINSIZE) / MALLOC_ALIGNMENT) /* When "x" is a user-provided size. */ # define usize2tidx(x) csize2tidx (request2size (x)) @@ -1929,7 +1935,7 @@ static struct malloc_par mp_ = , .tcache_count = TCACHE_FILL_COUNT, .tcache_bins = TCACHE_MAX_BINS, - .tcache_max_bytes = tidx2usize (TCACHE_MAX_BINS-1), + .tcache_max_bytes = MAX_TCACHE_SIZE, .tcache_unsorted_limit = 0 /* No limit. */ #endif }; @@ -3122,8 +3128,8 @@ typedef struct tcache_entry time), this is for performance reasons. */ typedef struct tcache_perthread_struct { - uint16_t counts[TCACHE_MAX_BINS]; - tcache_entry *entries[TCACHE_MAX_BINS]; + uint16_t counts[TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS]; + tcache_entry *entries[TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS]; } tcache_perthread_struct; static __thread bool tcache_shutting_down = false; @@ -3156,6 +3162,45 @@ tcache_key_initialize (void) } } +static __always_inline size_t +csize2tidx(size_t nb) +{ + if (__glibc_likely (nb < tidx2usize (TCACHE_MAX_BINS))) + return fast_csize2tidx(nb); + else if (__glibc_likely (mp_.tcache_bins < TCACHE_MAX_BINS)) + return TCACHE_MAX_BINS; + else + { + size_t idx = TCACHE_MAX_BINS + + __builtin_clz (tidx2usize (TCACHE_MAX_BINS-1)) + - __builtin_clz (nb); + return idx < TCACHE_ALL_BINS ? idx : TCACHE_ALL_BINS - 1; + } +} + +/* Returns the position in the tcache bin where the specified size is first found in. + This function is used by both tcache_get and tcache_put to locate the proper + position in the tcache bin linked-list. */ +static __always_inline tcache_entry ** +tcache_location_for_size (size_t nb, size_t tc_idx) +{ + if (__glibc_likely (nb <= tidx2usize (TCACHE_MAX_BINS-1))) + return &(tcache->entries[tc_idx]); + else + { + tcache_entry **tep = &(tcache->entries[tc_idx]); + tcache_entry *te = REVEAL_PTR (*tep); + while (te != NULL + && __glibc_unlikely (chunksize (mem2chunk (te)) < nb)) + { + tep = & (te->next); + te = REVEAL_PTR (te->next); + } + + return tep; + } +} + /* Caller must ensure that we know tc_idx is valid and there's room for more chunks. */ static __always_inline void @@ -3167,8 +3212,9 @@ tcache_put (mchunkptr chunk, size_t tc_idx) detect a double free. */ e->key = tcache_key; - e->next = PROTECT_PTR (&e->next, REVEAL_PTR (tcache->entries[tc_idx])); - tcache->entries[tc_idx] = PROTECT_PTR (&(tcache->entries[tc_idx]), e); + tcache_entry **entry = tcache_location_for_size (chunksize (chunk), tc_idx); + e->next = PROTECT_PTR (&e->next, REVEAL_PTR (*entry)); + *entry = PROTECT_PTR (entry, e); ++(tcache->counts[tc_idx]); } @@ -3176,7 +3222,7 @@ tcache_put (mchunkptr chunk, size_t tc_idx) available chunks to remove. Removes chunk from the middle of the list. */ static __always_inline void * -tcache_get_n (size_t tc_idx, tcache_entry **ep) +tcache_remove_entry (size_t tc_idx, tcache_entry **ep) { tcache_entry *e = REVEAL_PTR (*ep); @@ -3190,18 +3236,18 @@ tcache_get_n (size_t tc_idx, tcache_entry **ep) return (void *) e; } -/* Like the above, but removes from the head of the list. */ +/* Like the above, but traverses the list to find proper location to get the + entry within the respective tcache bin. */ static __always_inline void * -tcache_get (size_t tc_idx) +tcache_get (size_t nb, size_t tc_idx) { - return tcache_get_n (tc_idx, & tcache->entries[tc_idx]); -} + tcache_entry **entry = tcache_location_for_size (nb, tc_idx); + tcache_entry *e = REVEAL_PTR (*entry); + if (__glibc_unlikely (tc_idx >= TCACHE_MAX_BINS) + && (e == NULL || chunksize (mem2chunk (e)) != nb)) + return NULL; -/* Iterates through the tcache linked list. */ -static __always_inline tcache_entry * -tcache_next (tcache_entry *e) -{ - return (tcache_entry *) REVEAL_PTR (e->next); + return tcache_remove_entry (tc_idx, entry); } /* Check if tcache is available for alloc by corresponding tc_idx. */ @@ -3258,7 +3304,7 @@ tcache_thread_shutdown (void) /* Free all of the entries and the tcache itself back to the arena heap for coalescing. */ - for (i = 0; i < TCACHE_MAX_BINS; ++i) + for (i = 0; i < TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS; ++i) { while (REVEAL_PTR (tcache_tmp->entries[i])) { @@ -3317,7 +3363,7 @@ tcache_init(void) memset (tcache, 0, sizeof (tcache_perthread_struct)); } - for (int i = 0; i < mp_.tcache_bins; i++) + for (int i = 0; i < TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS; i++) tcache->entries[i] = PROTECT_PTR (&(tcache->entries[i]), NULL); } @@ -3344,7 +3390,7 @@ tcache_try_malloc (size_t bytes, void **memptr) MAYBE_INIT_TCACHE (); if (tcache_available (tc_idx)) - *memptr = tcache_get (tc_idx); + *memptr = tcache_get (tbytes, tc_idx); else *memptr = NULL; @@ -3373,8 +3419,20 @@ __libc_malloc2 (size_t bytes) if (!__malloc_initialized) ptmalloc_init (); +#if USE_TCACHE MAYBE_INIT_TCACHE (); + size_t nb = checked_request2size (bytes); + size_t tc_idx = csize2tidx (nb); + + if (tcache_available (tc_idx)) + { + void *tmp = tcache_get (nb, tc_idx); + if (tmp != NULL) + return tag_new_usable (tmp); + } +#endif + if (SINGLE_THREAD_P) { victim = tag_new_usable (_int_malloc (&main_arena, bytes)); @@ -3409,10 +3467,17 @@ void * __libc_malloc (size_t bytes) { #if USE_TCACHE - size_t tc_idx = csize2tidx (checked_request2size (bytes)); + size_t nb = checked_request2size (bytes); + size_t tc_idx = fast_csize2tidx (nb); - if (tcache_available (tc_idx)) - return tag_new_usable (tcache_get (tc_idx)); + /* Limit this call to chunks that fit in same dimention tcache bins. + Large chunk sizes are cached inside __libc_malloc2. */ + if (tc_idx < TCACHE_MAX_BINS + && tcache_available (tc_idx)) + { + tcache_entry **entry = &tcache->entries[tc_idx]; + return tag_new_usable (tcache_remove_entry (tc_idx, entry)); + } #endif return __libc_malloc2 (bytes); @@ -3683,20 +3748,28 @@ _mid_memalign (size_t alignment, size_t bytes, void *address) if (tcache_available (tc_idx)) { - /* The tcache itself isn't encoded, but the chain is. */ - tcache_entry **tep = & tcache->entries[tc_idx]; + tcache_entry **tep = tcache_location_for_size (tbytes, tc_idx); tcache_entry *te = REVEAL_PTR (*tep); + + /* Make sure returned chunk is of expected size. */ + if (te == NULL + || (tc_idx >= TCACHE_MAX_BINS + && chunksize (mem2chunk (te)) != tbytes)) + goto tcache_memalign_abort; + + /* The tcache itself isn't encoded, but the chain is. */ while (te != NULL && !PTR_IS_ALIGNED (te, alignment)) { tep = & (te->next); - te = tcache_next (te); + te = REVEAL_PTR (te->next); } if (te != NULL) { - void *victim = tcache_get_n (tc_idx, tep); + void *victim = tcache_remove_entry (tc_idx, tep); return tag_new_usable (victim); } } +tcache_memalign_abort: } #endif @@ -3983,8 +4056,8 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunks of the same size, stash them in the tcache. */ - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) + size_t tc_idx = fast_csize2tidx (nb); + if (tcache != NULL && tc_idx < TCACHE_FIXED_SIZE_BINS) { mchunkptr tc_victim; @@ -4044,8 +4117,8 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunks of the same size, stash them in the tcache. */ - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) + size_t tc_idx = fast_csize2tidx (nb); + if (__glibc_likely (tcache != NULL) && tc_idx < TCACHE_FIXED_SIZE_BINS) { mchunkptr tc_victim; @@ -4106,8 +4179,8 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE INTERNAL_SIZE_T tcache_nb = 0; - size_t tc_idx = csize2tidx (nb); - if (tcache != NULL && tc_idx < mp_.tcache_bins) + size_t tc_idx = fast_csize2tidx (nb); + if (tcache != NULL && tc_idx < TCACHE_FIXED_SIZE_BINS) tcache_nb = nb; int return_cached = 0; @@ -4285,7 +4358,7 @@ _int_malloc (mstate av, size_t bytes) && mp_.tcache_unsorted_limit > 0 && tcache_unsorted_count > mp_.tcache_unsorted_limit) { - return tcache_get (tc_idx); + return tcache_get (nb, tc_idx); } #endif @@ -4298,7 +4371,7 @@ _int_malloc (mstate av, size_t bytes) /* If all the small chunks we found ended up cached, return one now. */ if (return_cached) { - return tcache_get (tc_idx); + return tcache_get (nb, tc_idx); } #endif @@ -5530,14 +5603,12 @@ do_set_arena_max (size_t value) static __always_inline int do_set_tcache_max (size_t value) { - if (value <= MAX_TCACHE_SIZE) - { - LIBC_PROBE (memory_tunable_tcache_max_bytes, 2, value, mp_.tcache_max_bytes); - mp_.tcache_max_bytes = value; - mp_.tcache_bins = csize2tidx (request2size(value)) + 1; - return 1; - } - return 0; + LIBC_PROBE (memory_tunable_tcache_max_bytes, 2, value, mp_.tcache_max_bytes); + mp_.tcache_max_bytes = value; + mp_.tcache_bins = TCACHE_MAX_BINS + TCACHE_UNBOUND_SIZE_BINS; + mp_.tcache_bins = csize2tidx (request2size(value)) + 1; + + return 1; } static __always_inline int From patchwork Tue Apr 15 13:49:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 110501 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83D073857C4F for ; Tue, 15 Apr 2025 13:53:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83D073857C4F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=b5w6YDb8; dkim=pass (1024-bit key, unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=DRZMSJal 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 5FDFC385840C for ; Tue, 15 Apr 2025 13:50:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FDFC385840C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FDFC385840C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744725000; cv=pass; b=hWJGrUAQ8RwLDASqJK12tIdd+cyDERqhlNSV9UhlU+igfrXqUBZZj9SP7Jh8qETYVYL9+uDF2IrusxOcS256OoD734f4NZ5oduEOmJYb9/t02ICmj2UHeBNV3x4HhxDC+ZIAF+GmNAgVCwTt6ZOPLiMivx64YBRPPI2MurTewAs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744725000; c=relaxed/simple; bh=wSzouqA/lP7w4E9Z5WMmaa/ma0Jp+BYkLnu2RPa9N/M=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=I/X80eoemi0ZTNEd6G5dv2I4EymRWqki3A10aAmoFOBqaZLdI1JS97c8Wd/g7lmQtYtZSHztdqtjCCBMCK4XUl0gjsTod8c9zHA6PvKfbMYR3upe0ijHgB/MzodhwCDoKA8091uTRwMzz/gWDJ49CzL64S1YvemYtC5dtxHW4pM= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FDFC385840C Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53F6fqBR021588; Tue, 15 Apr 2025 13:49:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=6RtpLXkZr6lmavEENec01tAila4CSDK0HAVVVX2Bq80=; b= b5w6YDb8T64w52g2kAdKxoHRqm/Zp8E13xrVUdKAasqNdHWH9WKJvormEajfsEY8 1VMRvBP2SkuNZuRPQfhuOnmN02Utiw29Jiun5LKU/2vq6i/iM++N/GqK8V6ikxXU iso9zhtM6eilxIdgcIfvwbi6zL4ZA1LZg3b2XsrmCLFmwjbuaJ55cFOg76XR3GDq jiUtBnvDbD9+l38zrecVTJ+dy/SDLDFSjgVF4ZI09m5TYd71qzOde0SIrJMShKNa FUINxFQHKX8sh8aurwLZz+dft6kV4wYyU7O8e5RdSdvX9b/XKD+Eo0X+aZVtbDDY iKr10WfBbAnv1jbnGjx7mg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4618rd1m4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:53 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53FCvIRL038806; Tue, 15 Apr 2025 13:49:52 GMT Received: from ch1pr05cu001.outbound.protection.outlook.com (mail-northcentralusazlp17010003.outbound.protection.outlook.com [40.93.20.3]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 460d4rbta1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Apr 2025 13:49:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V4wsbdHWAKs1W4iMG69lXElsELDlNg8GoBNxTmClxK9w1ZQPElzlHKtlLcG2KS/GfSA+zqsYIsMHDru3xb1TGThfG8DJU/WV9k4IboMPBthNTDHKo8iC/jqQVZmFg68pJzTcYGlK14oyEFUzQxNBSFIU7BN2ZNrbZwtZyogU+m/j6jQq1CQt1z4HZ5I36KyFlRbqU64SZpVVIJM446IY6BeEJnZbd5bx4ho2NL9eMISjVFJDEcv/VOdyiR0qyv7co5jZxO9Pfb2c2to7Z6UI3Oh/Itj+mEE3q9DZDmnpfdPTDHgIvjBOU7DbhQUoqJ5HOJ3d7Tr/4WVYyOAKf0w9CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=6RtpLXkZr6lmavEENec01tAila4CSDK0HAVVVX2Bq80=; b=EJRxsPtUzJp9+XiIMwQoL1UDeNRfJUgwCphDFivezG+YE/SZELhHGR3gKlZ7KtxKgYmlaT/akaZxZ6cQdiSMto6OpW5Poyg8h05BDIHTs88rBXsTug0CKZrIIHFok5wiE851vvh5qfbYu0BfvwtCI2B9xiFSR7g+8nDsBtiM9TTqI0CvjCG9EWypHgHAFNEXQHaZ17PRerBTjvdLgB044dpnYM2uZLYwM+2x/zzl2kK5ANIusZD2xpnDBVYcm3Mkm7sGj3HQN0Esjq3w7u2lm2HhGsHsd9D+Jq3Zpclkd/BYR+sgzZh4Pa3Dg4nY3B9Jtr0E8gYqjxqpLS8qTDh6qQ== 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=6RtpLXkZr6lmavEENec01tAila4CSDK0HAVVVX2Bq80=; b=DRZMSJalC1/RGpoWa3VF1Zh35rAGzDeCPxytFsoXV3HbEFbafifFcdNrtj30tudkFHEFMNU9UEzso+qpz/lgGA01TYBtxYVBN6xg7MJEn0BBdn5HhYkhhdyZXd0EYMnOlS2jlnBdXmHZHWxOCzGpzNpBfRcBlVzKwXuflwXECiw= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by CY8PR10MB6705.namprd10.prod.outlook.com (2603:10b6:930:91::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.36; Tue, 15 Apr 2025 13:49:49 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb%4]) with mapi id 15.20.8632.030; Tue, 15 Apr 2025 13:49:49 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Wilco.Dijkstra@arm.com, fweimer@redhat.com, dj@redhat.com, Cupertino Miranda Subject: [PATCH v6 3/3] malloc: add testing for large tcache support. Date: Tue, 15 Apr 2025 14:49:20 +0100 Message-Id: <20250415134920.287189-4-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250415134920.287189-1-cupertino.miranda@oracle.com> References: <20250415134920.287189-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: LO2P123CA0035.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::23) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|CY8PR10MB6705:EE_ X-MS-Office365-Filtering-Correlation-Id: 182287a5-d4c4-4b79-15af-08dd7c2463bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: j1/1MtsEWUlikvZ7rrAQr3miMez0Ctozl0Kcrv/pJAI1SZ9OJGS7yCEz8yDJTHjYoNIrDzNhp573da8UbsWZ6cSstqx9zah4QrqAqGWw1i6nszldDs9TM6TilUydTq3XGVSKE0NTy45/Q9IGeW3A0e3wTh4jtSwdgM48BJhuVh3r8rjA4Lagaea2IFxeWwGAtqw3w9DTvFVrGgwTs0GbgsQbM+oeJN4v9UHD0UJuiUZnsRV8ra3GwsaxLtZ0qOS0ATVOBNW9xh3IoBEgnse++Q8Dntl7Dr/TcF1aDJySoDC9lE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zdAFXa19bzx3AMOoYKuuyMu/t1mMdtJaPF2COFO1WmgMuuj5hPgUzknGX23vlQTaaM1kjyrdOkSV2vFTdSE2GfWeV88= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4382.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NaizcaX0I4f7E1NDlY5SO+vwBR1f9tjw4iu/tjUfg0JVYAx2obvTkzrGEQAzOqnldj3e9qAJbW2TQYrbIrFdgPWKADzttklg0/T7zjPHlObK4yuODpO8DzAORjTNxxxaR2jPXdXBKb5W77Dwrho0WO5hmAGeB0e/p3OPm0IA1O0IHzXSxfbKrXcPHhoVWS8Hay9oB8rm9A73VqRdxmVLD+quU84EL2Rgry4gkZQLSwRjEd2ba+/02Xmk+7RWgcALRPEjTO6C1m9D8BnhdFZdvlnc9tSZmO4sHcyG+o0EQIBtwPY4i75D49NJ6iVfDtCqYmsyIghcr+GhpKyDf87nb9RNXnpAO+PKojMpdMpTZcrCfC1HRqIsm3ls5zNyHYht4ygkrJ+76iWLIIfXbwqoE0yFsNVdjNb7qt01qGchcHQ5uSqOVZYCfKNH31ifmVtwIJm5s2a8NrjZER+rfAlWMXJXb6R2HY+8YkL8MErRYDEDdnWBd8ONoBec/PBDldIbqLMeOc3JyHsuvgn7ooF7Po3dnFeEwjtfzURY+T5W/sq2uhO3e/3B5KukNAQQT4MBAAXCgPxLnNrZAvIBRjf0ESO+pelnWtPnhiF1ocU+iikGhEyyN1T3uPU0WFZgU5CtlrnBhBDG1kxaD7Lt5n2UwnnPq7eYQILCdLinWcvpxkqiSaTUTQv5RraD/Y998nSy4BPG/K7SoWjdaRh+LHYne1yEI2+Xx90WXLb3nug90P8uaPOlCtZnI68hzEg3nfNzikL6w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UT9yuMpcaXlZ28zBkineSbmHdAowq43UbiC5vybwudvSZ4xpA9Qp8J+jwaDwXvksbv+2sT8dHszJlV94nQRDOSv7z0Dju46AI064AZyST+yZBEZvLAGp7BlZ7qwtATN0Z+HaTGFjsoJUPLM064wDkuIwm2/LauJT6nCV/GV5wZFx13wKZ+d+OZRUXLuo7Oce9YqXo5KWbSeVBXgECFrPzw1wHaEQEN7Ln8yl8MEcHKcPScrE1t4+VhEPE6qC/6Q97eaQIz4hTHDg8SyVZWxPfm119AQ6sM/SM03SVQ45Sh4JTs5qUavi7u+E93v5hkxagGHV8Fp1Hu9LD7yPcI4oqS9xSRU4Lco9XbdIh2aUMM7FDKao63XnpgcpfwrnkeWPbuJh8CzREz86f2zLEPfnKtfLSZeGp9WUcPyIZ3cnKxr9IBIRDNsWloHLXezEOG8J4xFqM9pYNbKYn0pvhqU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 182287a5-d4c4-4b79-15af-08dd7c2463bd X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 13:49:49.3396 (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: 20ASw5YUPPOiTX5xja4J7SbbiyJqYZ0TcRzTsilt+xja8GWoiAxsAVjW2EEstQheVaDcDZn4H+S490hIpJuTeocklV/H0wGbMBWc3QEf0Kg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6705 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-15_06,2025-04-15_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504150098 X-Proofpoint-ORIG-GUID: I4Kn3DwL5n5KwRZjs-85fy-YFVmKCFR7 X-Proofpoint-GUID: I4Kn3DwL5n5KwRZjs-85fy-YFVmKCFR7 X-Spam-Status: No, score=-12.6 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_H5, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This patch adds large tcache support tests by re-executing all of the malloc tests, using the tunables: glibc.malloc.tcache_max=1048576 glibc.mallc.tcache_max_large_capacity=4194304 Test names are prefixed with "largetcache". --- Rules | 19 +++++++++++++++++++ malloc/Makefile | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Rules b/Rules index ae23070845..0f8ff9e61b 100644 --- a/Rules +++ b/Rules @@ -153,6 +153,7 @@ tests: $(addprefix $(objpfx),$(filter-out $(tests-unsupported), \ $(tests-malloc-check:%=%-malloc-check) \ $(tests-malloc-hugetlb1:%=%-malloc-hugetlb1) \ $(tests-malloc-hugetlb2:%=%-malloc-hugetlb2)) \ + $(tests-malloc-largetcache:%=%-malloc-largetcache)) \ $(test-srcs)) $(tests-special) \ $(tests-printers-programs) xtests: tests $(xtests-special) @@ -165,6 +166,7 @@ tests: $(tests:%=$(objpfx)%.out) $(tests-internal:%=$(objpfx)%.out) \ $(tests-malloc-check:%=$(objpfx)%-malloc-check.out) \ $(tests-malloc-hugetlb1:%=$(objpfx)%-malloc-hugetlb1.out) \ $(tests-malloc-hugetlb2:%=$(objpfx)%-malloc-hugetlb2.out) \ + $(tests-malloc-largetcache:%=$(objpfx)%-malloc-largetcache.out) \ $(tests-special) $(tests-printers-out) xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-special) endif # $(run-built-tests) != no @@ -179,6 +181,7 @@ tests-expected = $(tests) $(tests-internal) $(tests-printers) \ $(tests-container) $(tests-malloc-check:%=%-malloc-check) \ $(tests-malloc-hugetlb1:%=%-malloc-hugetlb1) \ $(tests-malloc-hugetlb2:%=%-malloc-hugetlb2) \ + $(tests-malloc-largetcache:%=%-malloc-largetcache) \ $(tests-mcheck:%=%-mcheck) xtests-expected = $(xtests) endif # $(run-built-tests) != no @@ -211,6 +214,7 @@ binaries-mcheck-tests = $(tests-mcheck:%=%-mcheck) binaries-malloc-check-tests = $(tests-malloc-check:%=%-malloc-check) binaries-malloc-hugetlb1-tests = $(tests-malloc-hugetlb1:%=%-malloc-hugetlb1) binaries-malloc-hugetlb2-tests = $(tests-malloc-hugetlb2:%=%-malloc-hugetlb2) +binaries-malloc-largetcache-tests = $(tests-malloc-largetcache:%=%-malloc-largetcache) else binaries-all-notests = binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs) @@ -224,6 +228,7 @@ binaries-mcheck-tests = binaries-malloc-check-tests = binaries-malloc-hugetlb1-tests = binaries-malloc-hugetlb2-tests = +binaries-malloc-largetcache-tests = endif binaries-pie = $(binaries-pie-tests) $(binaries-pie-notests) @@ -290,6 +295,14 @@ $(addprefix $(objpfx),$(binaries-malloc-hugetlb2-tests)): %-malloc-hugetlb2: %.o $(+link-tests) endif +ifneq "$(strip $(binaries-malloc-largetcache-tests))" "" +$(addprefix $(objpfx),$(binaries-malloc-largetcache-tests)): %-malloc-largetcache: %.o \ + $(link-extra-libs-tests) \ + $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \ + $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit) + $(+link-tests) +endif + ifneq "$(strip $(binaries-pie-tests))" "" $(addprefix $(objpfx),$(binaries-pie-tests)): %: %.o \ $(link-extra-libs-tests) \ @@ -339,6 +352,12 @@ $(1)-malloc-hugetlb2-ENV += GLIBC_TUNABLES=glibc.malloc.hugetlb=2 endef $(foreach t,$(tests-malloc-hugetlb2),$(eval $(call malloc-hugetlb2-ENVS,$(t)))) +# All malloc-largetcache tests will be run with GLIBC_TUNABLE=glibc.malloc.tcache_max=1048576:glibc.mallc.tcache_max_large_capacity=4194304 +define malloc-largetcache-ENVS +$(1)-malloc-largetcache-ENV += GLIBC_TUNABLES=glibc.malloc.tcache_max=1048576:glibc.mallc.tcache_max_large_capacity=4194304 +endef +$(foreach t,$(tests-malloc-largetcache),$(eval $(call malloc-largetcache-ENVS,$(t)))) + # mcheck tests need the debug DSO to support -lmcheck. define mcheck-ENVS $(1)-mcheck-ENV = LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so diff --git a/malloc/Makefile b/malloc/Makefile index e2b2c1ae1b..a62252a489 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -147,6 +147,21 @@ tests-malloc-hugetlb1 = \ tests-malloc-hugetlb2 = \ $(filter-out $(tests-exclude-hugetlb2), $(tests)) +tests-exclude-largetcache = \ + tst-compathooks-off \ + tst-compathooks-on \ + tst-interpose-thread \ + tst-interpose-nothread \ + tst-interpose-static-nothread \ + tst-interpose-static-thread \ + tst-mallocstate \ + tst-malloc-backtrace \ + tst-malloc-usable \ + tst-malloc-usable-tunables + +tests-malloc-largetcache = \ + $(filter-out $(tests-exclude-largetcache), $(tests)) + # -lmcheck needs __malloc_initialize_hook, which was deprecated in 2.24. ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes) # Tests that don't play well with mcheck. They are either bugs in mcheck or