From mboxrd@z Thu Jan 1 00:00:00 1970 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 56433C369A5 for ; Tue, 8 Apr 2025 17:55:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB7E06B00D1; Tue, 8 Apr 2025 13:55:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A408D6B00D2; Tue, 8 Apr 2025 13:55:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8935F6B00D3; Tue, 8 Apr 2025 13:55:48 -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 682236B00D1 for ; Tue, 8 Apr 2025 13:55:48 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D8A341A1406 for ; Tue, 8 Apr 2025 17:55:48 +0000 (UTC) X-FDA: 83311629576.11.D9D40DA Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id A4E2F4000E for ; Tue, 8 Apr 2025 17:55:46 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=R4XmL1B+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NtYIA8XS; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=R4XmL1B+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NtYIA8XS; spf=pass (imf04.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=1744134946; 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=ILcTKFwHSs+Kj97k6bGMomNdzQtsb2/Hina4A04EDn8=; b=TFFuBZd/nRJGr9991eyvDGlgSTIQnIIaOgqJcr+9jhGgXUmINM4nN3RYLxosrTFIozInCb YjunAZidyUstOVO7xUQgKyXWBD188fKKNUXYnlsLMtxLWLS97dDbeIVQ7nn44IkthODFhF 7IH6+oMyUSd0R4IpL/7aa9uCxpSYfFY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744134946; a=rsa-sha256; cv=none; b=YzNmSNvllqPWukdcSpBk7fXLEzsYFbzLNqynSOWmbN9CcqOVr6P4v7S6nLBE+JzdUnJF81 6H6q0wpNvuzKlTl7Frd9WumjrsBR56CKKmWa6IKtYs8tgHVd9lY1mA+hWXQJkhqEaFVbHC D6IHJL5i+lSyFzGfENiH7tE9F6uDZE4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=R4XmL1B+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NtYIA8XS; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=R4XmL1B+; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NtYIA8XS; spf=pass (imf04.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 07F0F2116C; Tue, 8 Apr 2025 17:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1744134945; 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=ILcTKFwHSs+Kj97k6bGMomNdzQtsb2/Hina4A04EDn8=; b=R4XmL1B+eODZABxcxJrDlqF/5AhLatuwjT3EuGejEz0/edvN0ou4ndGl+VXwu6BrWE9fr/ 9rPmiFhtFCtH4O3SXaCtc/lx9uQrKKwpa7o0xE7uEPKzCgMSmHmIkEW5s9gKvg4oUJdbtp nbOwbzWPZPEpPqJpBzmSSi/7A79Pv1o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1744134945; 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=ILcTKFwHSs+Kj97k6bGMomNdzQtsb2/Hina4A04EDn8=; b=NtYIA8XSHu5jGlHZmTyi3M8CVErqjaovkFMLuuKLmJHOiHR60L5AVCEoSC1og2fbKdx7dJ an6grO8U4lOo+pCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1744134945; 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=ILcTKFwHSs+Kj97k6bGMomNdzQtsb2/Hina4A04EDn8=; b=R4XmL1B+eODZABxcxJrDlqF/5AhLatuwjT3EuGejEz0/edvN0ou4ndGl+VXwu6BrWE9fr/ 9rPmiFhtFCtH4O3SXaCtc/lx9uQrKKwpa7o0xE7uEPKzCgMSmHmIkEW5s9gKvg4oUJdbtp nbOwbzWPZPEpPqJpBzmSSi/7A79Pv1o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1744134945; 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=ILcTKFwHSs+Kj97k6bGMomNdzQtsb2/Hina4A04EDn8=; b=NtYIA8XSHu5jGlHZmTyi3M8CVErqjaovkFMLuuKLmJHOiHR60L5AVCEoSC1og2fbKdx7dJ an6grO8U4lOo+pCQ== 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 E70A213A1E; Tue, 8 Apr 2025 17:55:44 +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 gBf7NyBj9WcmBAAAD6G6ig (envelope-from ); Tue, 08 Apr 2025 17:55:44 +0000 Message-ID: Date: Tue, 8 Apr 2025 19:55:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/3] mm,slub: Do not special case N_NORMAL nodes for slab_nodes Content-Language: en-US To: David Hildenbrand , Harry Yoo Cc: Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jonathan Cameron , linux-cxl@vger.kernel.org References: <20250408084153.255762-1-osalvador@suse.de> <20250408084153.255762-2-osalvador@suse.de> <92ff4f7f-90d2-48ab-8f7d-7fc3485276b5@redhat.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: o7pq6mw671roa758uq78hthie7ssdpu8 X-Rspam-User: X-Rspamd-Queue-Id: A4E2F4000E X-Rspamd-Server: rspam08 X-HE-Tag: 1744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X8GHbIzvXRmetiRBwWO7Y1sYdUVBT1+mJo/wo1AAO1h7bC5sSDw68I25DIB7d1ULlkwAp51MaalOQtxN2z78E2HX4Mgy1GcgYdrpIaBmdKdzOoTIznfnT98wW+MWMQtJ3OY5URNpzWsAr/qpd4ykMKdIhBGQcgT8U79ezSV0ouf4ebKZUv0tIGzsomLOOpONpUZl/U/ZKWyhuN60XNmurQ/JvC+geMdPxAP2hiaWyGXr/NVVQ7vz4= 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: On 4/8/25 16:25, David Hildenbrand wrote: > On 08.04.25 16:18, Harry Yoo wrote: >> On Tue, Apr 08, 2025 at 12:17:52PM +0200, David Hildenbrand wrote: >>> On 08.04.25 10:41, Oscar Salvador wrote: >>>> Currently, slab_mem_going_going_callback() checks whether the node has >>>> N_NORMAL memory in order to be set in slab_nodes. >>>> While it is true that gettind rid of that enforcing would mean >>>> ending up with movables nodes in slab_nodes, the memory waste that comes >>>> with that is negligible. >>>> >>>> So stop checking for status_change_nid_normal and just use status_change_nid >>>> instead which works for both types of memory. >>>> >>>> Also, once we allocate the kmem_cache_node cache for the node in >>>> slab_mem_online_callback(), we never deallocate it in >>>> slab_mem_off_callback() when the node goes memoryless, so we can just >>>> get rid of it. >>>> >>>> The only side effect is that we will stop clearing the node from slab_nodes. >>>> >>> >>> Feel free to add a Suggested-by: if you think it applies. >>> >>> >>> Do we have to take care of the N_NORMAL_MEMORY check in kmem_cache_init() ? Likely it >>> would have to be a N_MEMORY check. >>> >>> >>> But, I was wondering if we could get rid of the "slab_nodes" thingy as a first step? >> >> The following commit says that SLUB has slab_nodes thingy for a reason... >> kmem_cache_node might not be ready yet even when N_NORMAL_MEMORY check >> says it now has normal memory. > > node_states_set_node() is called from memory hotplug code after > MEM_GOING_ONLINE and after online_pages_range(). > > Pages might be isolated at that point, but node_states_set_node() is set > only after the memory notifier (MEM_GOING_ONLINE) was triggered. > > So I don't immediately see the problem assuming that we never free the > structures. Hm, I think it still exists. So consider: - slab_mem_going_online_callback() creates kmem_cache_node for the new node for existing caches under the mutex Then a cache creation races with "node_states_set_node() is set only after the memory notifier (MEM_GOING_ONLINE) was triggered" in a way that it doesn't see the node set yet - kmem_cache_node for the new node on the new cache will be missing. The root issue is node_states_set_node() doesn't happen under slab_mutex. slab_nodes update happens under the slab_mutex to avoid this race. And once we have slab_nodes for this cache creation vs hotplug synchronization then it's also to use it for the ___slab_alloc() checks, although they could indeed now use node_state(node, N_NORMAL_MEMORY) once we create the node structures and set bits in slab_nodes for N_MEMORY. Maybe it could be solved at the memory hotplug level if it we had a new state e.g. N_GOING_ONLINE that was set before calling MEM_GOING_ONLINE callbacks and was never reset. Then init_kmem_cache_nodes() could iterate on that. But I'm not sure if slab_mutex would provide necessary synchronization guarantees here so that the addition of node to MEM_GOING_ONLINE can't be missed, hm. > But yeah, this is what I raised below: "Not sure if there are any races > to consider" :) > >> >> @Vlastimil maybe a dumb question but why not check s->node[nid] >> instead of having slab_nodes bitmask? You mean check i.e. in ___slab_alloc()? We'd still be prone to miss a kmem_cache_node creation and degrade the particular cache that way, we'd just avoid a NULL pointer dereference.