From patchwork Mon Nov 17 14:15:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 124533 X-Patchwork-Delegate: fweimer@redhat.com 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 A6520385840E for ; Mon, 17 Nov 2025 14:16:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6520385840E 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-2025-04-25 header.b=TnB4z1iR; 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=sCMTjW9a X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 54A963858CD1 for ; Mon, 17 Nov 2025 14:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54A963858CD1 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 54A963858CD1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1763388927; cv=pass; b=vasuZ7GM7seW8SCfTYSFmvH9lhGa8vjbqV+IZv6DuPkdkurq49YqITcBh0gSapZk3tMH88ge9PD65H3+1CQoKmFvFovbQ2qBpKiCyba5wLxdOQ9XwQu4jKMgywuIpnmU3S6NV4D4/S5vwTNjFV4L6bQbOSN9uc9T/FC8ebZt8r8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1763388927; c=relaxed/simple; bh=LFqMPGv0Kmb8F9rO3O/eQAmaBnEhDEBEYlY9b5onzjs=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=HvQWT1VnZzYT2SYHMMyTVAs3dBRKwEevObwH1FqGCH52ODzoE3dTnvBotcfDMfqrKrBTrKs6husmD6FnCMLTCnponUnX3LR2si2jPGtNe9cHo9/ylqFFQAQpnkKKZ0iM4IYor3vn0DNCN/98HVRv/e31r8o4lEmfUz71+r3AC3k= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54A963858CD1 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AHC8LoD014539; Mon, 17 Nov 2025 14:15:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2025-04-25; bh=TzBydJqI58UMXVIH 0U1FSC8PAwIh+8FxAnn6CT6f/pw=; b=TnB4z1iRm0PQA2I5JktkR8tqI4ASVxHD uWz0QDH0xsqXTSrFoaexXN2klT8x790EjuHwX0KhfUmAPNlv467wCmBmr+wfQM0m NOJH9L4Oww5CohjaIKnrMw/D68jLuyi8CtWEYLZJyQu44QzQKX3mhn86UAn0MLu9 ZfymO3msdFelzcZ4hTEPJ+sxsQOssAK7I+eIQEGixh3pmlCJXGlz/EXiWvS5ExJm 2V5dTxOhJQ57oZiTekt+vLRHqV0juCv46nN6o08wIBwcqLV86REVkSjK/LC5aWlD Ny/hEcuROO4tTCeGEfXFA2BjrkkWdi6AZt3QPg03D3yYup+CteCKZg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej8j2jmy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Nov 2025 14:15:25 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AHCrXSh009691; Mon, 17 Nov 2025 14:15:24 GMT Received: from co1pr03cu002.outbound.protection.outlook.com (mail-westus2azon11010017.outbound.protection.outlook.com [52.101.46.17]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefybs46r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Nov 2025 14:15:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x2V+bNz0PXAjNjR+m95YqA/Pgj/4x/w+DSXIY6tCYsialjbxyXLgxNYl3mclw/5vXLL+Z3k0XsOmVIpu9WScA34oi48JmKCda/m8pKEWwKyr9cw/JjXQaZE9Kna68vfulXGhRdIlIRB7oWAFIvWRtUJkA2w40mABZmSddEAk7aOD/qfC8dPTZWH2UMHIYdEDGzY1xF0PwCpjI65jmgDS66HggkvGtEqwFxgYZniRBPFlZsz6/hayC895/IDIbVYh2f5N5G9/Sbjp3VXYI7qsg9QnFqTnKO1ffRzViCBAYTqXJpdfCH7+TbUXj+JdmJdetmRIjGSCGXVaboiWyjJX0w== 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=TzBydJqI58UMXVIH0U1FSC8PAwIh+8FxAnn6CT6f/pw=; b=xRquYrfCK7Sem1lJqi87gpiP4ldvd455QW7WN6Vg6X5B+1Of/K+OWQzwyMX5hJ6mV+Mgi9CMGIx/DzC50XmteGhaWVH5ET/IPTZ48dhlDXa4my9vqPK7kDBpDwcdmEd6jah4oIwPWlSyBIpytpAbUokohoTfk2S7VSQ2rCbnfMivK35EY2fqTg5sQZ58Xc5ngLfwZh5coPmAyUq+pRyV8ze1dBHraTH7PuZHSlj2l/UYlkANGg2wCp48qRs13FZGX/loIg97eBSWiWmsdiARB4BM1ioBwNd7uzKqOhvUbgeGi2HSc8mX36+qFeUY71pM0oIrxqE3nBj9hhXUTOus8w== 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=TzBydJqI58UMXVIH0U1FSC8PAwIh+8FxAnn6CT6f/pw=; b=sCMTjW9aea1cjcqFfAUTeSghVthqnYxbw+bQMpmwMjlnBSNl9t8XMPOSXZvioUSC0fyoXGqnE7NV2iWLeB5Ttm5vFpVVSQ3A3mLvuQ+yQp0PNVFXdmDhTit2iN6f9o55Z43uSLtaqWZTphcAMxBHXwOA4hh6u65MvVXcbItjaEU= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by CH3PR10MB7416.namprd10.prod.outlook.com (2603:10b6:610:156::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Mon, 17 Nov 2025 14:15:19 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb%5]) with mapi id 15.20.9320.013; Mon, 17 Nov 2025 14:15:19 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, fweimer@redhat.com, Cupertino Miranda Subject: [PATCH] malloc: retire mechanism for older non used tcached chunks Date: Mon, 17 Nov 2025 14:15:09 +0000 Message-Id: <20251117141509.14066-1-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: FR0P281CA0192.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ab::11) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|CH3PR10MB7416:EE_ X-MS-Office365-Filtering-Correlation-Id: 42ce9b84-c45a-4a9a-80e7-08de25e3bcf6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: T2pv9uEhbWIB/9I+AiggQ41J/qZIvOC87MeCe+M2XpjAr/O+6E94+3EiYCEsJI0T73oEoO0P/j/aQPeC8UfN4hMq9TCBLMpU8IGi9HLqwNOIMx5RBrB7Uw7yQi7VvPl7e5iRk5c4GGS28WVNJJwkx6qJE+qtop611srpeFbVehX0ajIKx2v9WdEa7zMsEBWd8yx5TMh/PkmLytNMN/nz7/qfSdxloGLZ3ajOWgtSV873I69nfBJxeSYYVqdy2u2ZQW06b0eMXVd1NldhBGxZraHPtyCiXN1nSsVmVRaOBMKlnOnRNvOl4aksnmqZ/lZPS4+PfE8+Xxn2v3JtCrZ17Y/hSaP//swyvxK0s/19ZHPXrDcSW0alXteCx114kDbhG2IQnEMySW95gs5J4nP9i7X0bRe/sCG4UwLxBKL7b4MCxewhJqDXulHhgup726ft1MGdTirVDwK+8pznsj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:MN2PR10MB4382.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GTBzs+g8q/N6ubRC0y1CzmyX6EvAnRbecuq36FI5AX8WX5JZuPvlfFO26JkfRE5FuqhTU0wa4wFnuFeJdcVqj9fXkRY6iRIrzRup/t/xVasxNHj+kZwgMIsvM8WzWebUN+espkJbnFc6NCBmix4Kauhj2MU344sXJ1iC9qB+ooI6qF/VcsENj8mZR0n2E1LUDM33qHwo8tY0L0HN49wLpj/7bjzRU4pGVQDy3UuZEEAPiMrM41Fe9zrwFyU0g5Rnoz2Qdz0cABCY4IpFddNFZLoj/7vfz51TyIV/aQ+axmquQr2HpdgIr4NR9uCn/Iuksm/krCL2edgvmtleXYaAUjvK2ZacIczlsIC4glORVaJmIbiEQmOoxyxp+gJoFPjsvqc5joMPITm1SoG8bKX0HWwq1gMNUfheK6cUa9XXfkgfzD8A5UUVYj+YLzj6REIa8oTPTPWxgEVUmTAXWwPyoVWTChjhRDC7Vh3sb2wH1TPfBKOj9sdcOe22+HOdhJHXxPTfGbLzVbI0PtVf+0gEsvWm+G8HG72oXP9yUtMo82kTUtdxoh3N+EtRdX51pYuaFotaoGasLvufvypndEZNhlVefcbyoX2brp6irMwKPzlayG2UDY8y1NaWY2h7ENSnZO3cQwHz761iS6O4o/dHQuG6kb9SW/Dj2o+qemhQjeb1/e55R+TjD5xPhzN1Mu8WcEx/monlP9rrq2X0/02qi2EIr4bxUk1GQ5Ty9hsIvu+T5xJWh875yrZMMpO+J2MVn01fcuoW/Y9sfp2NL51dX/XL4K/4gJSmo7sbQCwWRdDF8Y3GGodIU34ACNm2eeZWQ08bO4J/HQF/WaDAuysWOwwcnV4Z3hyfPYZURRF4wYKhVVirsxcOItWNxd5sQyYZdj8vsB/T4J4REheeAEhh7wc5z85MNylalLE/rfsJk18ekqjlT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yrp7tQTBaVyXeCed1BL2Ld8YgCWMR9jCxNfwzddsVAO2GaFnTAf8JJrnrx9SBMToqoLQgHYsMZFtOo7M0ksIDv5bffNA/n285ca3EX/ysNF1A16kyOzkygyknGIUK+Mce+QzqxgjFmCzjJPQZcs0UbS9PHLadpXFRXV+Y5rxaZmSTtI5yKmHFPZ5UKiU5dbdltgKC9i83fuMgxTFA1FM2FjVwPAMtNXF1eewD5r/LyEgskOUWlCDlCqBGSczynHHnMlCmceYO0W3jxC0O5usNNz1A0WRw4zSjJ7s6vVu1zZYqM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42ce9b84-c45a-4a9a-80e7-08de25e3bcf6 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2025 14:15:19.3708 (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: J0poKNaw2U6XGj/2/xB/h38haiNjyw3krYHkoSN+oa6VZujSbUvcTylBDHGFJ007TvBtQF51tDIq1tM+7ZkcdPVD0XkkZuj7yl6U7ydq6FE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7416 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_03,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511170121 X-Proofpoint-ORIG-GUID: 6NugavLd5HDthoKDEYCgAv9Co-dOu2K6 X-Proofpoint-GUID: 6NugavLd5HDthoKDEYCgAv9Co-dOu2K6 X-Authority-Analysis: v=2.4 cv=I7xohdgg c=1 sm=1 tr=0 ts=691b2dfd b=1 cx=c_pps a=e1sVV491RgrpLwSTMOnk8w==:117 a=e1sVV491RgrpLwSTMOnk8w==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=3AWGc11_ZBoR9dK_t0cA:9 cc=ntf awl=host:13643 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX8rOfARZdzUi0 T4bw+uTiXsx2efcfyivqQihGTrNEMNIPohMztCnVNyRN0ep4GstH7dMoe62QkFPB8wXuqahz01M aGOMqCJIuxrYNYP/xW6uzm6DWemDLzYJyH2p4C+Te60NVRUYeI7Doj37T2hUsRLjLCfU2HTINZq 5YT+ezwOxz4BemUN9qFBusSlKn6hHtELSZx0lWkCt52AAAwW+6mnWj41ccsNTKLoE3TkRLggNEn rEsZAk2n5lEYb07fXshHVsNolGEyuzCkhsiTq1POYeHs/VP2aplLAYoUip4LjevKbFi783vL8r8 HzvcMIzgb9mVhr+t7D4eV73+wj5Sp0HxXmFi67ZOWew5A24szYo4fTM+jpTt1CT1s3M8aRMWW+K VcofRDpoJwF/RLHzmMX7WY54sGMuWuBNbPKUwvEZSpic0pzcI1o= X-Spam-Status: No, score=-12.3 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 implements a different retention mechanism for large tcaches. With this mechanism large cached chunks no longer will be retained indefinitely by tcache if they are never requested by the application. Each thread will contain in the tcache structure a monotonically increasing value (alloc_size_state). Each time any chunk is added to a tcache this value will be increased by the chunk size. Also, when a chunk is added to a large tcache bin, it will be annotated (in cached_at) with the current value of alloc_size_state. Each time a large tcache bin is traversed (by tcache_location_large), it will compare alloc_size_state to cached_at values to verify if the chunk should be retired from the cache. The retiring should happen if the difference is bigger than tcache_retire_size. The tcache_retire_size is set by default to be 5 times the size of tcache_max value. In any case this patch implements the tunable glibc.malloc.tcache_retire_size to allow to override it. In order to quickly get the number of elements in each of the tcache entries (bins) the implementation still increments and decrements the num_slots values for large tcaches. It now uses num_slots, not to limit the number of chunks to cache but rather to decide to force a full traversal of the bin in order to retire larger older bins. Retired chunks are added to a special bin (return_to_arena) which will only actually free the chunks back to arena, when: - it fails to find a proper chunk in tcache during allocation, - the num_slots for a deallocation are filled up (i.e. num_slots is equal or lower to 0) during deallocation, - and malloc_trim is executed by the application. This strategy gives priority for performance, instead of memory usage, by delaying the release of the chunks back to the the arena only the next time an actual arena lock is required. Changes from v1: - Fix mistake in RETIRE_OLD_CACHED_CHUNKS definition and usage in tcache_put_large. - Fixed comments style. - Change __libc_free to _int_free_chunk also preemptively locking the arena and allowing to do multiple frees with a single lock. --- Rules | 2 +- elf/dl-tunables.list | 4 ++ malloc/arena.c | 3 + malloc/malloc.c | 159 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 146 insertions(+), 22 deletions(-) diff --git a/Rules b/Rules index dd319e8013..07fdcf676e 100644 --- a/Rules +++ b/Rules @@ -362,7 +362,7 @@ $(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 define malloc-largetcache-ENVS -$(1)-malloc-largetcache-ENV += GLIBC_TUNABLES=glibc.malloc.tcache_max=1048576 +$(1)-malloc-largetcache-ENV += GLIBC_TUNABLES=glibc.malloc.tcache_max=1048576:glibc.malloc.mmap_threshold=1048576 endef $(foreach t,$(tests-malloc-largetcache),$(eval $(call malloc-largetcache-ENVS,$(t)))) diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index c03c9967f0..b169aaf7c1 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -74,6 +74,10 @@ glibc { tcache_unsorted_limit { type: SIZE_T } + tcache_retire_size { + type: SIZE_T + minval: 1 + } mxfast { type: SIZE_T minval: 0 diff --git a/malloc/arena.c b/malloc/arena.c index 2551cb7749..61413fb03a 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -239,6 +239,7 @@ TUNABLE_CALLBACK_FNDECL (set_arena_test, size_t) TUNABLE_CALLBACK_FNDECL (set_tcache_max, size_t) TUNABLE_CALLBACK_FNDECL (set_tcache_count, size_t) TUNABLE_CALLBACK_FNDECL (set_tcache_unsorted_limit, size_t) +TUNABLE_CALLBACK_FNDECL (set_tcache_retire_size, size_t) #endif TUNABLE_CALLBACK_FNDECL (set_mxfast, size_t) TUNABLE_CALLBACK_FNDECL (set_hugetlb, size_t) @@ -293,6 +294,8 @@ __ptmalloc_init (void) TUNABLE_GET (tcache_count, size_t, TUNABLE_CALLBACK (set_tcache_count)); TUNABLE_GET (tcache_unsorted_limit, size_t, TUNABLE_CALLBACK (set_tcache_unsorted_limit)); + TUNABLE_GET (tcache_retire_size, size_t, + TUNABLE_CALLBACK (set_tcache_retire_size)); # endif TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast)); TUNABLE_GET (hugetlb, size_t, TUNABLE_CALLBACK (set_hugetlb)); diff --git a/malloc/malloc.c b/malloc/malloc.c index 0b21bdf1bd..eaa6d10563 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -299,6 +299,7 @@ # define TCACHE_LARGE_BINS 12 /* Up to 4M chunks */ # define TCACHE_MAX_BINS (TCACHE_SMALL_BINS + TCACHE_LARGE_BINS) # define MAX_TCACHE_SMALL_SIZE tidx2csize (TCACHE_SMALL_BINS-1) +# define TCACHE_DEFAULT_RETIRE_MULTIPLIER 5 # define tidx2csize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE) # define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ) @@ -1947,6 +1948,8 @@ struct malloc_par /* Maximum number of chunks to remove from the unsorted list, which aren't used to prefill the cache. */ size_t tcache_unsorted_limit; + uintptr_t tcache_retire_size; + size_t tcache_trim; #endif }; @@ -1979,7 +1982,12 @@ static struct malloc_par mp_ = .tcache_count = TCACHE_FILL_COUNT, .tcache_small_bins = TCACHE_SMALL_BINS, .tcache_max_bytes = MAX_TCACHE_SMALL_SIZE + 1, - .tcache_unsorted_limit = 0 /* No limit. */ + .tcache_unsorted_limit = 0, /* No limit. */ + /* The default does not enables large tcache support. + Capacity default is set to 0 to allow to set a default capacity of 10 + times the tcache_max value when the tunable is set. */ + .tcache_retire_size = 0, + .tcache_trim = 0 #endif }; @@ -3088,6 +3096,7 @@ typedef struct tcache_entry struct tcache_entry *next; /* This field exists to detect double frees. */ uintptr_t key; + uintptr_t cached_at; } tcache_entry; /* There is one of these for each thread, which contains the @@ -3100,6 +3109,9 @@ typedef struct tcache_perthread_struct { uint16_t num_slots[TCACHE_MAX_BINS]; tcache_entry *entries[TCACHE_MAX_BINS]; + tcache_entry *return_to_arena; + uintptr_t alloc_size_state; + size_t trim_id; } tcache_perthread_struct; static const union @@ -3201,7 +3213,7 @@ large_csize2tidx(size_t nb) /* Caller must ensure that we know tc_idx is valid and there's room for more chunks. */ static __always_inline void -tcache_put_n (mchunkptr chunk, size_t tc_idx, tcache_entry **ep, bool mangled) +tcache_put_n (mchunkptr chunk, tcache_entry **ep, uint16_t *num_slots, bool mangled) { tcache_entry *e = (tcache_entry *) chunk2mem (chunk); @@ -3219,14 +3231,14 @@ tcache_put_n (mchunkptr chunk, size_t tc_idx, tcache_entry **ep, bool mangled) e->next = PROTECT_PTR (&e->next, REVEAL_PTR (*ep)); *ep = PROTECT_PTR (ep, e); } - --(tcache->num_slots[tc_idx]); + --(*num_slots); } /* Caller must ensure that we know tc_idx is valid and there's 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, bool mangled) +tcache_get_n (tcache_entry **ep, uint16_t *num_slots, bool mangled) { tcache_entry *e; if (!mangled) @@ -3242,7 +3254,7 @@ tcache_get_n (size_t tc_idx, tcache_entry **ep, bool mangled) else *ep = PROTECT_PTR (ep, REVEAL_PTR (e->next)); - ++(tcache->num_slots[tc_idx]); + ++(*num_slots); e->key = 0; return (void *) e; } @@ -3250,25 +3262,38 @@ tcache_get_n (size_t tc_idx, tcache_entry **ep, bool mangled) static __always_inline void tcache_put (mchunkptr chunk, size_t tc_idx) { - tcache_put_n (chunk, tc_idx, &tcache->entries[tc_idx], false); + tcache_put_n (chunk, &tcache->entries[tc_idx], &tcache->num_slots[tc_idx], false); } /* Like the above, but removes from the head of the list. */ static __always_inline void * tcache_get (size_t tc_idx) { - return tcache_get_n (tc_idx, &tcache->entries[tc_idx], false); + return tcache_get_n (&tcache->entries[tc_idx], &tcache->num_slots[tc_idx], false); } static __always_inline tcache_entry ** -tcache_location_large (size_t nb, size_t tc_idx, +tcache_location_large (tcache_entry **tep, size_t nb, uint16_t *num_slots, bool *mangled, tcache_entry **demangled_ptr) { - tcache_entry **tep = &(tcache->entries[tc_idx]); - tcache_entry *te = *tep; + tcache_entry *te = *mangled == false ? *tep : REVEAL_PTR (*tep); while (te != NULL && __glibc_unlikely (chunksize (mem2chunk (te)) < nb)) { + /* Move chunk to retire bin if chunk is beyond tcache capacity. + We should always do (alloc_size_state - cached_at) before attempting + any comparissons. This is a requirement to keep the comparisson valid + in the cases where one of the values has wraparound. */ + if (tcache->alloc_size_state - te->cached_at > mp_.tcache_retire_size) + { + uint16_t not_used = 1; + tcache_entry *e = tcache_get_n (tep, num_slots, *mangled); + tcache_put_n (mem2chunk (e), &tcache->return_to_arena, ¬_used, + false); + te = *mangled == false ? *tep : REVEAL_PTR (*tep); + continue; + } + tep = & (te->next); te = REVEAL_PTR (te->next); *mangled = true; @@ -3278,15 +3303,79 @@ tcache_location_large (size_t nb, size_t tc_idx, return tep; } +/* Force for tcache_location_large to traverse the full bin by requesting a too + big of chunk. This allows it to mark old chunks to be released from tcache. */ +#define RETIRE_OLD_CACHED_CHUNKS(ENTRY_PTR, TC_IDX, MANGLED_PTR) { \ + tcache_entry *te; \ + tcache_location_large (ENTRY_PTR, PTRDIFF_MAX, &tcache->num_slots[TC_IDX], \ + MANGLED_PTR, &te); \ +} + +static __always_inline void +tcache_large_cleanup (void) +{ + if (!tcache_enabled ()) + return; + + mstate current_locked_arena = NULL; + while (tcache->return_to_arena) + { + tcache_entry *e = tcache->return_to_arena; + if (__glibc_unlikely (misaligned_mem (e))) + malloc_printerr ("tcache_thread_shutdown(): " + "unaligned tcache chunk detected"); + tcache->return_to_arena = REVEAL_PTR (e->next); + mchunkptr p = mem2chunk (e); + size_t size = chunksize (p); + mstate chunk_arena = arena_for_chunk (p); + + if (current_locked_arena != chunk_arena) + { + if (current_locked_arena != NULL) + __libc_lock_unlock (current_locked_arena->mutex); + __libc_lock_lock (chunk_arena->mutex); + current_locked_arena = chunk_arena; + } + _int_free_chunk (arena_for_chunk (p), p, size, 1); + } + if (current_locked_arena != NULL) + __libc_lock_unlock (current_locked_arena->mutex); + + /* Traverse all tcache bins and retire old cached chunks. */ + if (mp_.tcache_trim - tcache->trim_id != 0) + { + tcache->trim_id += mp_.tcache_trim; + for (size_t tc_idx = TCACHE_SMALL_BINS; tc_idx < TCACHE_MAX_BINS; tc_idx++) + { + bool mangled = false; + tcache_entry **tep = &(tcache->entries[tc_idx]); + RETIRE_OLD_CACHED_CHUNKS (tep, tc_idx, &mangled); + } + } +} + static __always_inline void tcache_put_large (mchunkptr chunk, size_t tc_idx) { tcache_entry **entry; + tcache_entry *e = chunk2mem (chunk); bool mangled = false; tcache_entry *te; - entry = tcache_location_large (chunksize (chunk), tc_idx, &mangled, &te); + tcache_entry **tep = &(tcache->entries[tc_idx]); + entry = tcache_location_large (tep, chunksize (chunk), + &tcache->num_slots[tc_idx], &mangled, &te); - return tcache_put_n (chunk, tc_idx, entry, mangled); + e->cached_at = tcache->alloc_size_state; + tcache->alloc_size_state += chunksize (chunk); + tcache_put_n (chunk, entry, &tcache->num_slots[tc_idx], mangled); + + /* If the bin is full, execute tcache_location_large again from entry forward + with a much bigger size entry such that it would traverse the full bin. */ + if (tcache->num_slots[tc_idx] <= 0) + { + RETIRE_OLD_CACHED_CHUNKS (entry, tc_idx, &mangled); + tcache_large_cleanup (); + } } static __always_inline void * @@ -3295,12 +3384,16 @@ tcache_get_large (size_t tc_idx, size_t nb) tcache_entry **entry; bool mangled = false; tcache_entry *te; - entry = tcache_location_large (nb, tc_idx, &mangled, &te); + tcache_entry **tep = &(tcache->entries[tc_idx]); + entry = tcache_location_large (tep, nb, &tcache->num_slots[tc_idx], &mangled, &te); if (te == NULL || nb != chunksize (mem2chunk (te))) - return NULL; + { + tcache_large_cleanup (); + return NULL; + } - return tcache_get_n (tc_idx, entry, mangled); + return tcache_get_n (entry, &tcache->num_slots[tc_idx], mangled); } static void tcache_init (mstate av); @@ -3312,7 +3405,7 @@ tcache_get_align (size_t nb, size_t alignment) { size_t tc_idx = csize2tidx (nb); if (__glibc_unlikely (tc_idx >= TCACHE_SMALL_BINS)) - tc_idx = large_csize2tidx (nb); + tc_idx = large_csize2tidx (nb); /* The tcache itself isn't encoded, but the chain is. */ tcache_entry **tep = & tcache->entries[tc_idx]; @@ -3338,7 +3431,7 @@ tcache_get_align (size_t nb, size_t alignment) if (te != NULL && csize == nb && PTR_IS_ALIGNED (te, alignment)) - return tag_new_usable (tcache_get_n (tc_idx, tep, mangled)); + return tag_new_usable (tcache_get_n (tep, &tcache->num_slots[tc_idx], mangled)); DIAG_POP_NEEDS_COMMENT; } return NULL; @@ -3358,7 +3451,7 @@ tcache_double_free_verify (tcache_entry *e) tmp; tmp = REVEAL_PTR (tmp->next), ++cnt) { - if (cnt >= mp_.tcache_count) + if (tc_idx < TCACHE_SMALL_BINS && cnt >= mp_.tcache_count) malloc_printerr ("free(): too many chunks detected in tcache"); if (__glibc_unlikely (misaligned_mem (tmp))) malloc_printerr ("free(): unaligned chunk detected in tcache 2"); @@ -3398,6 +3491,15 @@ tcache_thread_shutdown (void) tcache_tmp->entries[i] = REVEAL_PTR (e->next); __libc_free (e); } + while (tcache_tmp->return_to_arena) + { + tcache_entry *e = tcache_tmp->return_to_arena; + if (__glibc_unlikely (misaligned_mem (e))) + malloc_printerr ("tcache_thread_shutdown(): " + "unaligned tcache chunk detected"); + tcache_tmp->return_to_arena = REVEAL_PTR (e->next); + __libc_free (e); + } } __libc_free (tcache_tmp); @@ -3430,6 +3532,9 @@ tcache_init (mstate av) memset (tcache, 0, bytes); for (int i = 0; i < TCACHE_MAX_BINS; i++) tcache->num_slots[i] = mp_.tcache_count; + tcache->alloc_size_state = 0; + tcache->return_to_arena = NULL; + tcache->trim_id = 0; } } @@ -3559,8 +3664,7 @@ __libc_free (void *mem) else { tc_idx = large_csize2tidx (size); - if (size >= MINSIZE - && __glibc_likely (tcache->num_slots[tc_idx] != 0)) + if (size >= MINSIZE && tcache_enabled ()) return tcache_put_large (p, tc_idx); } @@ -5281,6 +5385,9 @@ int __malloc_trim (size_t s) { int result = 0; +#if USE_TCACHE + mp_.tcache_trim += 1; +#endif mstate ar_ptr = &main_arena; do @@ -5569,11 +5676,13 @@ do_set_tcache_max (size_t value) LIBC_PROBE (memory_tunable_tcache_max_bytes, 2, value, mp_.tcache_max_bytes); - if (tc_idx < TCACHE_MAX_BINS) + if (tc_idx < TCACHE_MAX_BINS || mp_.tcache_retire_size == 0) { if (tc_idx < TCACHE_SMALL_BINS) mp_.tcache_small_bins = tc_idx + 1; mp_.tcache_max_bytes = nb + 1; + if (tc_idx >= TCACHE_SMALL_BINS && mp_.tcache_retire_size == 0) + mp_.tcache_retire_size = nb * TCACHE_DEFAULT_RETIRE_MULTIPLIER; return 1; } @@ -5599,6 +5708,14 @@ do_set_tcache_unsorted_limit (size_t value) mp_.tcache_unsorted_limit = value; return 1; } + +static __always_inline int +do_set_tcache_retire_size (size_t value) +{ + LIBC_PROBE (memory_tunable_tcache_retire_size, 2, value, mp_.tcache_retire_size); + mp_.tcache_retire_size = value; + return 1; +} #endif static __always_inline int