From patchwork Mon Jul 15 20:29:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13733871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B89CBC3DA4B for ; Mon, 15 Jul 2024 20:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DC986B00A5; Mon, 15 Jul 2024 16:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F24486B00AA; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B55286B00AB; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 762836B009B for ; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0E859A01F2 for ; Mon, 15 Jul 2024 20:29:43 +0000 (UTC) X-FDA: 82343127846.21.4FFA45A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf14.hostedemail.com (Postfix) with ESMTP id BFC16100011 for ; Mon, 15 Jul 2024 20:29:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IchGYqVK; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=evMTmCrr; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IchGYqVK; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=evMTmCrr; spf=pass (imf14.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721075342; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=63ptlEDSf2NF4mqHOwhlrxuC2a4rLEbYrta5gvgyEc0=; b=1YBsdWbzabCYpwBObTxiR617KIpsdd68+c36tvjVE7HXnU+BxzG2iFnJiOJlX+9VQeloKC KerIAA34CG08+qmBpJM8OPv6D+xkagMvLFQ7pj98RkABuuu5UNOVr/QFxZJIPBrV4hBBgo ok/SrgwePki92JclZuiLitf7UvNINVw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721075342; a=rsa-sha256; cv=none; b=dKMMzmkINKTz3mUsf2RseTiXFwkvErfoF6OyOprNKMuFEf+aPx5YC1DQFthQ5kgnu74Zel Je/atJQhoWkcPIFfjsw2ZbOFfmE/X51XrkZJudPgqaWyLLYxKfChe4TwyVerprCE+AmCx+ S33CwFLZd07PaW/qZCTxfSglSVTrCrE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IchGYqVK; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=evMTmCrr; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IchGYqVK; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=evMTmCrr; spf=pass (imf14.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BA01B210F6; Mon, 15 Jul 2024 20:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721075378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ptlEDSf2NF4mqHOwhlrxuC2a4rLEbYrta5gvgyEc0=; b=IchGYqVKTSTLgxc6iItiNxB8xYcgyho9SGEIHdG4AvGblPLUEGncmz+QAw9gCZeuYszYBo hDpm2S4wepd1ry/XsrtRiysjqoo2aldpOROpoUxAii8f9lIRXpgYcd3Oh+mmqeLWCu2J2D eXC1GfxqvuZMh8bTQhOMVpnEuPoDI3w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721075378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ptlEDSf2NF4mqHOwhlrxuC2a4rLEbYrta5gvgyEc0=; b=evMTmCrrFOKvt+r76bJUkmHSGlLuXlmEdht9Fxt/VkvV8cIaoVObsQSvRCCjheyDPipECt Snp+IvBW3laNcQCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721075378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ptlEDSf2NF4mqHOwhlrxuC2a4rLEbYrta5gvgyEc0=; b=IchGYqVKTSTLgxc6iItiNxB8xYcgyho9SGEIHdG4AvGblPLUEGncmz+QAw9gCZeuYszYBo hDpm2S4wepd1ry/XsrtRiysjqoo2aldpOROpoUxAii8f9lIRXpgYcd3Oh+mmqeLWCu2J2D eXC1GfxqvuZMh8bTQhOMVpnEuPoDI3w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721075378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ptlEDSf2NF4mqHOwhlrxuC2a4rLEbYrta5gvgyEc0=; b=evMTmCrrFOKvt+r76bJUkmHSGlLuXlmEdht9Fxt/VkvV8cIaoVObsQSvRCCjheyDPipECt Snp+IvBW3laNcQCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 979351395F; Mon, 15 Jul 2024 20:29:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6Em9JLKGlWbvUwAAD6G6ig (envelope-from ); Mon, 15 Jul 2024 20:29:38 +0000 From: Vlastimil Babka Date: Mon, 15 Jul 2024 22:29:27 +0200 Subject: [PATCH RFC 1/6] mm, slab: make caches with refcount of 0 unmergeable MIME-Version: 1.0 Message-Id: <20240715-b4-slab-kfree_rcu-destroy-v1-1-46b2984c2205@suse.cz> References: <20240715-b4-slab-kfree_rcu-destroy-v1-0-46b2984c2205@suse.cz> In-Reply-To: <20240715-b4-slab-kfree_rcu-destroy-v1-0-46b2984c2205@suse.cz> To: "Paul E. McKenney" , Joel Fernandes , Josh Triplett , Boqun Feng , Christoph Lameter , David Rientjes Cc: Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Julia Lawall , Jakub Kicinski , "Jason A. Donenfeld" , "Uladzislau Rezki (Sony)" , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Stat-Signature: iwz3q66tfytp9xod9uxr6tu3974uj8wb X-Rspamd-Queue-Id: BFC16100011 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721075380-346428 X-HE-Meta: U2FsdGVkX18N1fF+JRmLSMS/giQ2flP9C/OG8ZcjNnMPL2U4v+l/LbYcJmgpZZk01UA/asApvBv4G6NJ2RcL1mGROAh3nACw/f7USWqSy5tT9DxfiUYtLtDJYcA8bNJnJrIypebndEdO6wbFuR0iGV7r55gsi2n57OS+/8AsESDynqT7YZntudkEq6o+XdJ1WTfAZoX8agln6gkW5+46fO4Ml3G5ly+7g+6W3Iz3Dlxdzwbae3ic2h1YDsAfqG6f6/jMe2GzU420hbQ1g4RrhzJ2CR47TgFMx2CADZe24CyfGLUYYTHJeDpeIwCoqs7XugT9Ez1KFbhbkj2v18IrYuwLAu/q2+Ozv+RS+2Y896lEfI/7QSG4dBI1yrjN35HhjYuWTZEfNGGr2fUHMpBlcR9if7c37mmWsOvEm8GkrDz66J9/lJeV2YKiL2GzdbKmS8/UTnnFybFjmtQb2oTnNGvktjTQiLHBZ1b/mq8qvuK9lHaOl6aNhinooR1KYPgXlodGjSLEbZur8Tg+7EYsuzfVB/eDEgp5gjXbp8L7Oamf166NXzLoqWObXDgDMyXvEmuV0mPSe/2Bx8jzOi/cQIzTKlp3roje5kNFKBD3I7R3jQrtVSt/Ag8ozBTMeEBo3U2PXh0sjTduPGLu+7CWhGGY/05IWkS7C+BjKcjADCPgukoninqHhssLmB5otOJ1fQGE8wiFckXFVkkTajJYk0Iqe3+KDXzZEWo8A7CNLq/cqfdCWh4x0s5HkZa27SpXNbPtvHWrVtHOXCl+iJyuwdvr7Kfpz9q3bjlEFjD7evXwB2rVGUnh8B6eyPkCEYH0eQChcgFL8ZK5tlv6gQvLpN4ynVWR5FwaIMBrGJrKekhnZ8rNvgXtDewsQKFzhMP7CLk+Raf9C/V0ed+MgYIZ7QneqOufrrJPXRy/+G8pevjTIXX/X65hLQ60ZqlDnP5mbgY/QvZcVcNlm7kMB2e yjz+/Adq iQ/hb/s3c87UDbFs0oeMCA19Jf1jREMWuec9GyKJPKR96C/GpB/6vhHrLUTLXTGggKPCQro9UIlibH6liSPly/+105uXRHXPQHVgoD52PIncdNaGRFCF+4O0lqCdcxRqI94/rofrxBE7bcBBKeL2d5oNPT2OimLZhDSXJ0nRhPPBxQg6d4Og9JY/A6SIgtOhK8zuIthGu8uHnrnFk/Uono+uTCxr9Tt1oKC4S7I4TlrWerAWZ8E48JgxD00lb47deGaEVkpYwxSp53y+qpaahWxEx5aEZdL0kvJgr8W4EP6uvsBA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Slab caches with refcount 0 are in the process of being destroyed so it's undesirable for new caches to attempt merging with them. A synchronous destruction happens under slab_mutex thus excluding concurrent cache creation and merging. Full destruction of SLAB_TYPESAFE_BY_RCU caches might be delayed, but the cache is still taken off the slab_caches list immediately, thus unreachable by cache creation. However a cache where __kmem_cache_shutdown() fails because it contains objects that were not freed (due to a bug in the cache user) will be left on the slab_caches list and might be considered for merging. Also the following patches will introduce a possibility of a cache with refcount 0 being temporarily reachable on the slab_list even in case of no bugs, due to kfree_rcu() in flight. For these reasons, prevent merging with caches that have zero refcount. Signed-off-by: Vlastimil Babka Acked-by: David Rientjes --- mm/slab_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 70943a4c1c4b..3ba205bda95d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -150,9 +150,11 @@ int slab_unmergeable(struct kmem_cache *s) #endif /* - * We may have set a slab to be unmergeable during bootstrap. + * We may have set a cache to be unmergeable (-1) during bootstrap. + * 0 is for cache being destroyed asynchronously, or cache that failed + * to destroy due to outstanding objects. */ - if (s->refcount < 0) + if (s->refcount <= 0) return 1; return 0;