From patchwork Mon Jul 15 20:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13733870 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 5A72BC3DA59 for ; Mon, 15 Jul 2024 20:29:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D11006B00A0; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C66E96B009E; 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 A1BFC6B00AA; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 76D716B009E for ; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 001E7140238 for ; Mon, 15 Jul 2024 20:29:42 +0000 (UTC) X-FDA: 82343127804.03.535ED42 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf04.hostedemail.com (Postfix) with ESMTP id C89804001D for ; Mon, 15 Jul 2024 20:29:40 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ANbEASdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4eHOsmkR; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ANbEASdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4eHOsmkR; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 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=1721075361; 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=hyldqlnDVTk50xyhWcs4CPBsygxILHPWHa8A+BcY6BU=; b=vfMvi9RzG/idelA3aLJGg87s7pO370iSY7BNf4fDyihcMeXV+ORC0aC2MJaZZOXFCyXoXK T4Wvzy4AyDSwY817amwKQbKhcQaOijNLc0cyHLXJNeVw+HIW14Fewkhqt35JLH5f/GtXlF z5GPNjNB82yUKJaJhhbsu/iFBaJh9gw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ANbEASdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4eHOsmkR; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ANbEASdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4eHOsmkR; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721075361; a=rsa-sha256; cv=none; b=XHy5QPvXxOVMQMWZhx5M9rEogX4mRJKhBowA1IBxnlcEyuUsCHCUC+TR3rlL8v8vHPZ2E3 lVJ3s+M6yupQsC7tiCduu7PS6WG/OJnstoxIIecklmoypypvwV6oH+50zqXEp6cUJ2GkPC wAUt85WNpVwICF/5ixPkn9dZ18Gt7No= 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-out2.suse.de (Postfix) with ESMTPS id D58861F843; 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=hyldqlnDVTk50xyhWcs4CPBsygxILHPWHa8A+BcY6BU=; b=ANbEASdWGMdwl5qIXdPygLN5quDOUggtjyZj/rdVEODhlm+iIA64uMIgVwJdDUCncYcZI/ tNq53zYt3Ul/jLQpY+x02fL4MVwUY8mNk5iXoMQnwDUWRpXZfQyw2WHe5Tyltx22YZ/FyD 08Qt9lzqZt5wXVKR6LmkjZKOBINn3gw= 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=hyldqlnDVTk50xyhWcs4CPBsygxILHPWHa8A+BcY6BU=; b=4eHOsmkRnhgqg1SSKo/heKcjThC68ZpN46jp+qFZPiqyFx4W5r7bcXY6t1L+lrj+mOkH2t quc3a/glQGts+RAQ== 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=hyldqlnDVTk50xyhWcs4CPBsygxILHPWHa8A+BcY6BU=; b=ANbEASdWGMdwl5qIXdPygLN5quDOUggtjyZj/rdVEODhlm+iIA64uMIgVwJdDUCncYcZI/ tNq53zYt3Ul/jLQpY+x02fL4MVwUY8mNk5iXoMQnwDUWRpXZfQyw2WHe5Tyltx22YZ/FyD 08Qt9lzqZt5wXVKR6LmkjZKOBINn3gw= 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=hyldqlnDVTk50xyhWcs4CPBsygxILHPWHa8A+BcY6BU=; b=4eHOsmkRnhgqg1SSKo/heKcjThC68ZpN46jp+qFZPiqyFx4W5r7bcXY6t1L+lrj+mOkH2t quc3a/glQGts+RAQ== 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 B38921396E; 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 CBWUK7KGlWbvUwAAD6G6ig (envelope-from ); Mon, 15 Jul 2024 20:29:38 +0000 From: Vlastimil Babka Date: Mon, 15 Jul 2024 22:29:28 +0200 Subject: [PATCH RFC 2/6] mm, slab: always maintain per-node slab and object count MIME-Version: 1.0 Message-Id: <20240715-b4-slab-kfree_rcu-destroy-v1-2-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-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: C89804001D X-Stat-Signature: yowb3bameiecxqhmxp34p6pgse9efr5u X-Rspam-User: X-HE-Tag: 1721075380-290124 X-HE-Meta: U2FsdGVkX19zPuphRY0b+yHHLGJGQBi8BfYtDOyEtMQWkt0xmJA8d1lk1sDONCRrNLOIms+535EP3j97gJjnCrG/OrIo62EQFpD1OlEiYeI5dVO/Xvy8KUEkDmZB1ewiMFXSYtKtZZjs2bTEgaAc+PAuPlVo9dhvNUaleL8b+8v5IO5JVhQ6mcNEvRaIueGsbIhDC7oba22o9PG9lXKGumaqfT3jiHJz290ZGD71UP5Mxe3jc0/B5X3DTsy+uixtdtw5Y68jUGoj5chx3VCUGusy8u4GRy0gdXR59w9mlIPpK0bOZBmnpGu4IVztgUsvOj2wM0A9TmNTgXby/3BC1jWsncHTG2xngraUUIGEQTvK6TRCfyQ7I0XiFALWlM7TWQsmpJsGMntOR9gHWAyD0yl7TSgSa1G6BSUvZJMQIEzs/n0Uo1mNlZPSZs9X0IBUn2oJZSw4rYuBRBEbPEeYyDjN75PlZtwhdMF5+KadHoZwVgJWfCtaF2xAYFbwVwtzBUJzBl/xxo+jNryLH2HiQrWuBYLSpPF0c5ZCjez+fQIa6h/QOk9XaLjJaDoPY9Zt9rQsJfYqzBAh7j/LWbFtAjhtMsQodkqBAwxN7iyizW+pR5CXhEekjXA6vbtIV/NEwVyuxI5e0A2jFOGLHOqydqSgWaklg+FTmbDAIaGzs6f/HBp6m/WCatrA8TP3/eJQA5bIiq+tv4r2coOtB39L5LWRJYn3J33CdQ2U6SQ6qfWl7K8SiouFzFLRw8GIi2SqwiL+Atc929CX8lQs7Znbjo/e+fzF7OdhcBALRK6L3aNMSOe0yaQ7nIAb0Q95kexdd1nKWVGkD9Ahr+OCC7/kdHD6OxNr89pHBLmcJHzig5qyiKWmx5UbQe1lnuR+uGPSNFxt8zky4kWBUliCfzSHv5Y9FLiRqGM+OqgkcRY8NeU8bGtRVbxQKmyOPXuRTKiay2Kzo0ocizscApjbkw4 Nrs6YPWk Uel9lVfJ1WJJpgX9hOux9H5tKER3QUqMEVGdmWIqDevDgRlekjQQ5mW9QH9SAFxr+2vtzNnDgD06MgX1iLm9XaJjsgsxhomQ0unCmPff/RO+b8Joi9bwfxxTuUGTgche1MvxATvAHYNCyxRndcfa16QNhPNiEfom59ZJkInY4dU5OAtZaS2PdTWuYyDOB6d9JlzpCirjmh4Tyi9ML/tCBHmldfNSCDmmhdxL5bLGZgnUKgZSEX8+hGH032rOpITOLHujxeBqjf4z7Ei8sTjDv6lSgoPusVIt4496XqqtyxsjqIW8= 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: Currently SLUB counts per-node slabs and total objects only with CONFIG_SLUB_DEBUG, in order to minimize overhead. However, the detection in __kmem_cache_shutdown() whether there are no outstanding object relies on the per-node slab count (node_nr_slabs()) so it may be unreliable without CONFIG_SLUB_DEBUG. Thus we might be failing to warn about such situations, and instead destroy a cache while leaving its slab(s) around (due to a buggy slab user creating such a scenario, not in normal operation). We will also need node_nr_slabs() to be reliable in the following work to gracefully handle kmem_cache_destroy() with kfree_rcu() objects in flight. Thus make the counting of per-node slabs and objects unconditional. Note that CONFIG_SLUB_DEBUG is the default anyway, and the counting is done only when allocating or freeing a slab page, so even in !CONFIG_SLUB_DEBUG configs the overhead should be negligible. Signed-off-by: Vlastimil Babka Acked-by: David Rientjes --- mm/slub.c | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 829a1f08e8a2..aa4d80109c49 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -426,9 +426,9 @@ struct kmem_cache_node { spinlock_t list_lock; unsigned long nr_partial; struct list_head partial; -#ifdef CONFIG_SLUB_DEBUG atomic_long_t nr_slabs; atomic_long_t total_objects; +#ifdef CONFIG_SLUB_DEBUG struct list_head full; #endif }; @@ -438,6 +438,26 @@ static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node) return s->node[node]; } +static inline unsigned long node_nr_slabs(struct kmem_cache_node *n) +{ + return atomic_long_read(&n->nr_slabs); +} + +static inline void inc_slabs_node(struct kmem_cache *s, int node, int objects) +{ + struct kmem_cache_node *n = get_node(s, node); + + atomic_long_inc(&n->nr_slabs); + atomic_long_add(objects, &n->total_objects); +} +static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects) +{ + struct kmem_cache_node *n = get_node(s, node); + + atomic_long_dec(&n->nr_slabs); + atomic_long_sub(objects, &n->total_objects); +} + /* * Iterator over all nodes. The body will be executed for each node that has * a kmem_cache_node structure allocated (which is true for all online nodes) @@ -1511,26 +1531,6 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct list_del(&slab->slab_list); } -static inline unsigned long node_nr_slabs(struct kmem_cache_node *n) -{ - return atomic_long_read(&n->nr_slabs); -} - -static inline void inc_slabs_node(struct kmem_cache *s, int node, int objects) -{ - struct kmem_cache_node *n = get_node(s, node); - - atomic_long_inc(&n->nr_slabs); - atomic_long_add(objects, &n->total_objects); -} -static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects) -{ - struct kmem_cache_node *n = get_node(s, node); - - atomic_long_dec(&n->nr_slabs); - atomic_long_sub(objects, &n->total_objects); -} - /* Object debug checks for alloc/free paths */ static void setup_object_debug(struct kmem_cache *s, void *object) { @@ -1871,13 +1871,6 @@ slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name) #define disable_higher_order_debug 0 -static inline unsigned long node_nr_slabs(struct kmem_cache_node *n) - { return 0; } -static inline void inc_slabs_node(struct kmem_cache *s, int node, - int objects) {} -static inline void dec_slabs_node(struct kmem_cache *s, int node, - int objects) {} - #ifndef CONFIG_SLUB_TINY static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab, void **freelist, void *nextfree)