From patchwork Wed Nov 12 23:28:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 124109 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 27F6B3858D38 for ; Wed, 12 Nov 2025 23:29:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27F6B3858D38 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=ptBatA2n; 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=svcQ5mK9 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 9FCD43858D20 for ; Wed, 12 Nov 2025 23:28:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FCD43858D20 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 9FCD43858D20 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=1762990123; cv=pass; b=ZyErEgTvAKbDX+g7RGDUsGb7a6aZluwH2952LFCYn9vbwQr0GsJw8+dpU+RXqI9TAABgNHQLV9go4ypHnhUz+qo/6CcupXoyuRg8420O8hqUOGUGEfatFZ+C9nJ1SrZDF40l2XURGbqAuevVdoNiUmdQmT9QCGTDvgM3tohuvkU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1762990123; c=relaxed/simple; bh=OZLBbkrBukEGQvS/Pti5MM1DFj81ET/zbIyQjokMreM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=n/qvgZagFUcY3I5Syv5HlEsMrtFwx77dUr36g5Bbx6yAD+p25UGgbfCET93gGggXuZUvTscxrKWsFYvY4p9sKwucgZBqxvlatNSuiDr1/vdqs9osXKy0pdClT/VfwI1dGvIdG4gQVsNnSKBwl6ENxxuz3WnDLM4L77wfbHQ+1EU= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FCD43858D20 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACLCCu7019611 for ; Wed, 12 Nov 2025 23:28:43 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=uMhVE01pPHJcPhhc SrTNm6a52gdYpvnJaJj+cV/aO0M=; b=ptBatA2n22nJSHzqg8eTdLqpHPHnoPX1 ki5Hu5REkm5LTS3p3PzkDPeBKvlvoh7QB/743lLZ+bGturn8rbdz++UFevpmpQlx 87K+2NxqmfZEdle4jL2O8cBwOGFUClBsK0NsfJFcvqDrQOYS+zexG9QcJ0oioWYb gulKzjkP/r4Wu+3Bt5qwKl+kMuXCz0jDo3ksrFiV4M/5AiiqqY4tORqK8L+aPglf C97eW7XAtE3S/6UFFN888KJFaaTXdGP/2LFMDigwuwKDO4wUwJjTt7y/Zbp0s8F7 RkEgAHFx31qNyZ7ZWPxtY3u1VQrEHmZY+BWHp9PlxX3V/D3QX+sdwA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpngnxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 12 Nov 2025 23:28:43 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACMMeBT018605 for ; Wed, 12 Nov 2025 23:28:42 GMT Received: from dm5pr21cu001.outbound.protection.outlook.com (mail-centralusazon11011071.outbound.protection.outlook.com [52.101.62.71]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vabcgsh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 12 Nov 2025 23:28:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ab5RXHjLBGB78lUp5Ogih63WsyI4me1LsUkA3+SDcbDf45dBLvwLitUuKgm5Uex1z/D6rIvO1fjmmA4Xy1hIYFjEN/UJPF186uYkAlqFOyLQm2xign44B1dy3MouL3VYO+af3ocsb1bzjJ8ZMQyjZvKwbJDluuOdo28qbpsr6crxvxkRMJB26+SoZeJGK9PgS4soSP3MjgorCj4TWfLuKXp+KLTamEEbOMfUg48svcnqSj8ibE3nQaR59jgMc0gB7Zl3hm4CyDN6/PA7YwdK+RxNpLJwmFv38GUtTcabZihuSAEli1/NPk8MIiuNmjz6AP8BepoXVfwGOOzQNdSN+A== 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=uMhVE01pPHJcPhhcSrTNm6a52gdYpvnJaJj+cV/aO0M=; b=W8NqUZ+/xFmbfR+6II0o0czN2demNf9qqsgVygNnIgwVp3wjD2Be473uTJv5FUFzsRi5rsgkSoO+yJ5BamPYjot8GGKaswJ1AxVaIaWiA8azPNek1hCD0v2L4sFA71mXLttQz518EQJp0DX7WDAkjqA3fT4VypPuKleAju/pJ+JgBCkhosDOyDWd2Aw0d9C+kGW6r+jgquQw7JhL498YNP5HuHa6RahQeyxrV015sZxrjYWyoAO9blgrOjymlLtXFtbzmqYj+ARItXzsgtQNO/gVCg61mONTZbsmPnXLhWqh840ZfAX0PVxi8w8aA0TwqlqM1Mb7SSoyRfvETwh7jQ== 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=uMhVE01pPHJcPhhcSrTNm6a52gdYpvnJaJj+cV/aO0M=; b=svcQ5mK9URFyyVF/VGO5GynZZ3MrXJq0thkmMI+z6CzOcxTSUoz+K4D/OtFKmI+3R+vQ7IPTe2wgNhMkJc7XebjytBeCZGXAUt/qzamVTiKeI6eb0UrtRmaUWEI2pXjvtTc+EHav5sNpyQ8C/HUuhmyNW4rWykyV0hlD2ZJ10c8= Received: from BY5PR10MB4371.namprd10.prod.outlook.com (2603:10b6:a03:210::10) by SJ5PPF07759F8B1.namprd10.prod.outlook.com (2603:10b6:a0f:fc02::787) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.17; Wed, 12 Nov 2025 23:28:37 +0000 Received: from BY5PR10MB4371.namprd10.prod.outlook.com ([fe80::904f:81d0:5a98:b544]) by BY5PR10MB4371.namprd10.prod.outlook.com ([fe80::904f:81d0:5a98:b544%5]) with mapi id 15.20.9320.013; Wed, 12 Nov 2025 23:28:37 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Cupertino Miranda Subject: [PATCH] malloc: retire mechanism for older non used tcached chunks Date: Wed, 12 Nov 2025 23:28:23 +0000 Message-Id: <20251112232823.668737-1-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: LO2P265CA0219.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::15) To BY5PR10MB4371.namprd10.prod.outlook.com (2603:10b6:a03:210::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4371:EE_|SJ5PPF07759F8B1:EE_ X-MS-Office365-Filtering-Correlation-Id: a42585ad-3416-4e59-8710-08de2243343a 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: nb4QPzezrp5U8oDxjIuiHFMDDTTw1H8+6KKqm7o4EbTUeS24fy/uWZ0eJ1SFqaV0xbG3zr2T73K4W9he/z0YZ5v+qOqLHoufojxwBYZdoMZfJzL3AceY/7j0LmGgssQL0dD5FDN92UPaSSo9UxXH0DE4QIVFmaXXNi2X40t3nQ+qBP1vCcvm1pV+46pqPXOyuJN3wRnUV3eWQgwhU+xN/1ohjcO/D6gJghw0vhWRiVHeNFCozWai486L9Tj0haOXaDxpfPggSIi2eo0brU1Q6R4K1n3I5oh4k5Px4ECJDIimiWVBXySk0uz+kSMs/V31C+pifgfodJxl9MkWGEbPnsKzXcY+iHLx1qlAqSlG17rzuxcCfS7e26d4aZokt/x3T1VYLnW5kqiLk4PIS7c/nhToqDh/+wrFT1UucuquMy1Vw7tHqV4tPAJfmwaYUds8U1WgNJkAh/GzEaa4xc+qKTBqGHmWyjrQzDuKjZT90W9wcv+2fpAH29hCw7NqHd2iafaMyWncox/r/3zqKmUPHpx146jTxC7Bq42iUMeDjNS0LHDQA9FA6Zl3lwoTFlUYmA9bG3LkAK8ASj60pLIuRVV7zxAYEAH0ijKNoubEG1h77RzDImlP5lS4zjXm33C0+ZIHfUYwlr4SLqABIGw3r+ro/KvJdffj/JdOkZNZKXIQXQ0B7vXSuWVCYAL7f9emt1gLTYtibrnDZP/4EgQINO7ix1lmWrcFFOSciBjwZrbQ9i3LPS/a9U28fwJAHaNTiJvVOt03kSSHfjGraHoaNrjfBalv2LXVhXwtf/6DP1mk6zWy4PDi0UQLy012FJyXp5+ry+8/oykviKXJPAsueeXo88P3biCNmlDbIl5HX/vmzhLksfsaz4kcvXfVn31qbLw4eaNj/CGE21b5TkWGbjs9oOTYxTK6gmlYxIScFtOd3JSn3MVqkQKKMaN7o/DxtiZPuyaiFkqKc6gKC+295J+iby6+f/FVHyHKAEp9QlKvIaRfvhISfdvTevyoGLetNslasfU4HECyC/Iw+L/eJLzyX+YykOLFC+UDEP1D0ztWNnBaPu+BKzTmi7m6u0+Oja4orq8bXQ5EQi/YZjnMn6SyvGl+tOuXFVeJFqj6IaY/ulMn+9IwojgzKEIytJLCLaHz+5hRCSAS7fKrD/79ocOi7DL02g/6VILnzk/5JU2fBSIKrfkBerloP2m+pymSNz/mSkyxMJ1AujtIcvbNecvZq4AAdCOPODPhj/uzieo5IUinviKo/5AluoipiANIBVMbRPQUaRGmjEA4/qXQc8/75TE+BEi9m/6dU351gH4jS73XT6MgSlnM98qtUl0Y1ChaXGkXrVWnigWJh/3H8X6MmEi50yeed2efNbHXRbRYi/jvdmcIA9zeKjADlfNIBrFrjJn/z2sDtjOjHBIvh161/qt3fhO4Fn/wI54UNhDorAVuA5FKcEbSHEMUYwON X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BY5PR10MB4371.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: iKONv9o354FMi5uka06PrBUagk5z8y0RRVNZTvKw/23oQaU+d13+r+xwzTfBIqSIAmI/zqNhJwBVvZzPEmzLUEPNoh3BdMKLZjv6YOFxrTywuWaiZUeEEssuel7dvK6T0ZmqrLlMpTPlipiIH0pgkfRovH4EUxG9aE6/xwGj3RxwYhLRbo3SME0df0i0/lwSor96X6YBDARKcUyiD5ylIua7RVDfXlgyy0AxT9yZrl2fKIvUjbqkilUWP9Zirq9b+CQSO8xw9dfvZrqYvlboqEeeNCZ/nSft1VOV51oiU0ATnBJl/oqhWwlnHZPO8lg05r7rnLlqQUImK7Mn8gq4EiW13yXyl8WhQPTgk2dZwJZPWwoKEUfe1Ba7dFzJaYO9MHAOkp28bRbbSewMPqgquSLavi6wCVoeWBM9gL3Trb/IPRTLQfFIAm3MxRrpY3RRcurWfB5J3ElByRN9O4Z/WbJ5on6wi3u4l5fJkwOFXTAzBL5qXVdCQzA65A+0R34WRGL/lqH3NoWnryslEruLkKSwTe3cANo9Z+WwcZIb+NYveQ2rRmUJLbisaXYNMJKXheP8ELwqKMzDMmcM/OlO34ol7joLuH3yd/5b7Gp6gTeehGwtQq59a/Ua6thWzr/mb3lBKBpEmeLJHsz6uJ6lF7TcVy04vXxSR3t1U+FaI1tYhgCEwV301/GH9mq6AAf+YehBJiUvgPntpi9jdWTg04cZS1Vc1W+873i0hhwe4G5Nc6imaM+w83bMiSrjRPVsK9/iSaLmPUV0gDp+kJhGuxzKQxrIYxjpjrGfRF9pJUOKoj4n8i28icMcVhZte+6eueThXBXVUsu6wZYflYeS4gf4pU/+as3hNCWho1SXk/9unBk8DI8uKgvwjfXinHQDn5lfAR6O5jqOEATLT3Fiq35EbM57Nt3NaKttSegWLuiOcSH6/7ZA49Yv/kHQ7/32YObNAorW5Ljd/evAPOw46vXG70Ko/vhQLirSO5gSjpeSv3TgF0mE7n70bYBLNrm8TnisW6HxL41vo2oRF2KGPPYQwmlm6pfXp29jXi7kLQspGTP0ACI5wQmEXOvQ3GShOu+z0jhnD8HSR0R6Vybtfxkl2XAaaWopVeqWJTVbo72Z9Loiqri8JQyuSxfsQigv4GDCLDfhVThQkdQ02+OiJat50O7x0wHwlL8KIAbfAFxI+sVI5Y3jZwUx/SDZRSPzxqKMSNBHURRQ6WpoGylcQjHXeTNIj9MFhII/epFKBeabcAlvQVS4Pb7isnjPcGn9d8pNaMJmXU+U1RtdZHBMqoYNss1oDJ40BJnzEMUhU9Rlbj73nnNTiehtKWRRZmJuKUNto2Ss4fjdbIRhfOcBE0+3uU1nUG82xkZvzpyQkEp2jAgXs/lRcnz8+0cjT2NKP5UGoMB1nbhKRmCdjQh6PWZFy8OO9xFUDz4jsX960YkeZNepfw2Sch405O/T9rSHSkjAebdJXQUEH/gTKiiNp2AmfdM7zXgx7eSG9/n2PLbYl8o+1ze1s+i0Z7i9dIeFV2jF5vZZVGM198mI6uRJR+M6IR+1rrsX8IcmGdXuGd0f9Hvub2CLA4n3npl/4gLB9613Lpdi++7WJG5taFrINg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Ai4+RrD6P7NhjlHOuWsByM6TUfe+UCYzge6d+yNpIgSOuK/93mwItiRfD5aEG4Gu0D/oalZVJQoRHLCW9GcEooUO7cp01SDkeAsPWyTG/DKcvmzS27dIUNZsBCsaOYXYCt71W2cgYSUEPOY2u9yqnzdiFXnmgmxhrBcKbBB6ufiVAQbxBbumP653hFh87OsRG2sxLkxjQig0IyLsOQjJMkvaRUvpEQbf1hRipLzXPsp3kvPVAHA2+UNO31RQSwjJnlq5m4SwF9KBPiDL9F6OJVQTJDFrYNkNq3eA22G42Av21rGx3e2C7ZpSA51l7k7ACH+YsxM4JhhvuCTqCBvkcIKL+gTtpsbVeTMk9rI5fYKBAVdvBwzLyJtbLmreFEaDf4swn9aTvQ7mvXWTO2GuGweL312vYdrfxuBzRmdonwveSNcgAHS9BQ0R9JXBSImXqCQ/a9+NSSWRTm3nhVek7fsyp7qxPRG24anaRdQ5vYabBrVvOIPeU/8EA7N9joSjMpyd/6poU9a7xTp5dVNhjhfzW+SJASgqmosn6/Luqo6PhUpfaR/7ZZixDVXzdSk4w0E8hkfeVFLJRrMkWtIVJDAxZMJW5PdMg/jqfQ2ZG/g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a42585ad-3416-4e59-8710-08de2243343a X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4371.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2025 23:28:37.1167 (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: V0S3zq0d61ZdTOhOu0DX1lTIKQJQ2H/3jhmv+X8fTpuwkQgasI9Q6iqJ8ieKBbZIc5+CA1WUaK+PPsYYiHTaz6AEkisqKOBk5rXigOrmwuo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF07759F8B1 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-12_06,2025-11-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120190 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=6915182b b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==: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=zaPaRzg23l9tlmtVhW8A:9 X-Proofpoint-GUID: M0gzbna7HODW8wVd0jBC_TBCSRZra46l X-Proofpoint-ORIG-GUID: M0gzbna7HODW8wVd0jBC_TBCSRZra46l X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX8FupfJ7yneiV 9j+QXb9WyvmAo3FYP+6m+LDEnKqik9vnfmlDjDZ6sQJ1gU0FiUcD8rNagLj02f8O74bWO5R/qEF GKuZiENccR8qkAuP+FufREmbKryTjKrgptNwTcBEKIhPQKt5/UXCoHoiLOf40EB/Hzt6fGFKAWj 1rIiu4Blfxyh6fmbD9v7T40kNXpZ1cfdMAXTjwjQqHwRD9Mxw6jqYIJKeWp0/57tcrzrP5UiNAV yCRQTiKOQ3+76V368Z2DLEYAgHonkIW4XWmpEn3sxDxPU2PGYjsix5kKB1OsjQ3L7KmKXceuHEE Siv7Evzh6ztWhR9WBlZZ3zfajAlFINNNwpkOCakplfgOCJaoR7Fo4wSClQCEM9lWvjkSaj3WOvL ZLI8JqmRMxtbpNyqpoR3od8Ynl4uFQ== X-Spam-Status: No, score=-12.2 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. --- Rules | 2 +- elf/dl-tunables.list | 4 ++ malloc/arena.c | 3 + malloc/malloc.c | 148 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 135 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..071f7963fa 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,68 @@ 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(TC_IDX) { \ + bool mangled = false; \ + tcache_entry **tep = &(tcache->entries[TC_IDX]); \ + tcache_entry *te; \ + tcache_location_large (tep, PTRDIFF_MAX, &tcache->num_slots[TC_IDX], \ + &mangled, &te); \ +} + +static __always_inline void +tcache_large_cleanup (void) +{ + if (tcache == NULL || mp_.tcache_retire_size == 0) + return; + + 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); + _int_free_chunk (arena_for_chunk (p), p, size, 0); + } + + /* 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++) + { + RETIRE_OLD_CACHED_CHUNKS (tc_idx); + } + } +} + 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); + + e->cached_at = tcache->alloc_size_state; + tcache->alloc_size_state += chunksize (chunk); + tcache_put_n (chunk, entry, &tcache->num_slots[tc_idx], mangled); - return tcache_put_n (chunk, tc_idx, entry, 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 (tc_idx); + tcache_large_cleanup (); + } } static __always_inline void * @@ -3295,12 +3373,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 +3394,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 +3420,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 +3440,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 +3480,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 +3521,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 +3653,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 +5374,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 +5665,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 +5697,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