From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ABD7232786 for ; Tue, 8 Apr 2025 18:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744136323; cv=none; b=qvgf4iwqwfQGJA4AB5Kvv+6cZNh495pzjgcGJLoQ/PXHhwDacRmwEYKnvh+D8Ml2EsBcRAOccYSs67R3iO7Ag8RxC7TrsIMx55PByhKl9BD2Kht78Eb4DQnHUcGxFH5TxWkLih40GevP9twncuxQe9pgFNNgqLBWuiML75DayO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744136323; c=relaxed/simple; bh=33JDFRyvDs8HR1vl7NYCjQs8vBWEkaxL/bF60gGL8Uc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UVFFC17r/+l9jvHGDNotbKxHWorR+FZ84H16BjVgM4GrRLi9C2OFUfJu6uKDAYldLxMuPaRb94RNKN1ip9oNCC3Ac040wv2/rxlMezTYQkdihqcdO4HCZPXRX3+p1hoZb0FDKKYDWC3ZG22JUeBmSKWjDZ/5wUJD1uKHcTmc54A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a3tEIf5o; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a3tEIf5o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744136320; h=from:from: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:autocrypt:autocrypt; bh=a5MNTcQLVVXVMARql3CFcEx28D/XK8NJIFEW1cH0fos=; b=a3tEIf5oKiW8ZtT2gfpSq1LBkMZMqc51MPJoHR0Ped3ECoIB5UwX51zs0+Mw93ZPY6B4Kv XhZRyY5lVus5E4vJBbnyDcK5VQZ+biZs4ltn9p4kPGYzYmp1p3HMTp+8b7QPeMgEzB0/GY ysOg0SFgt3SZ9wHbCiHtncN8zoho7RI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-WoD2pnRsPAi-pUFTOlHCRQ-1; Tue, 08 Apr 2025 14:18:38 -0400 X-MC-Unique: WoD2pnRsPAi-pUFTOlHCRQ-1 X-Mimecast-MFC-AGG-ID: WoD2pnRsPAi-pUFTOlHCRQ_1744136317 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d3b211d0eso34704475e9.1 for ; Tue, 08 Apr 2025 11:18:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744136317; x=1744741117; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=a5MNTcQLVVXVMARql3CFcEx28D/XK8NJIFEW1cH0fos=; b=SzV3b7OFw1r3wa3T/tRgIuazU5AkszHgJV0q86fNVKQVn7Yapo68cDFWXC26uYQ1O3 iwqKwQb7scIUwC3oegcfSuHU/LY1s9gspFjN6VRFdyXTmxOaIk3Zkid7lYfhBTQKaILX 0ksIyqt8LFCuEaPdysjf8mFUtrTwpEcwJZxvMio8YxOHKwPfBxhM6panfuUn3ZYCYhuB INcsRta1C7MA3pl9+Jzv3orAdhLZRdirSDU3lD/2ubA+4/PCOdXNUAb1toRHeqBUOK1O mGNC5+NCACrj5x12oLgOv5rX2DJyVYwZzOFxpP9IT+qnWQO3wxEkSbwpd+bzylmX/K9b 1Vow== X-Forwarded-Encrypted: i=1; AJvYcCWTuC4Buy9MOO0QPfqwGq93wIqp0StpgAd6DGv8I6TWgxYKriJNu3loWZNoxzTOguaUbtAgChM5iyJ2/wA=@vger.kernel.org X-Gm-Message-State: AOJu0YzQw9NiEQAhCP3oAh5u/FPPKKhaiKn62TR60qbKmHM5zwi6H+CZ k2DlsI6bOGsoJLxC6UsgKSjzRKErjL3TAzWfa76ikkzXuub+1t7SW+e5XNn5pm2LPyZf4yX1THC hNPlBswsXcpfe7ymHu/1pvjLP4dpbXxQrKpT2zXqgiN2YFwZMlUJ2VV7RzE294A== X-Gm-Gg: ASbGnctCH6AmL35sezHfreOZC4ovA56QtpA4wadKGcfgGIkwFOpFt7MQexSbJtW/yGl CRdjKFE1d2Yq7h2kH2CQJE32KSfVtcD0IP7uo+fBGiuCScKPclJNdxPImviUbY9WQxHmgaJpxzY 4lw4VjzatCJjpPhm/bghW5IhtQP7nraTNnkwg9nn+HN+UM7jAVL7t2IFPgu6BrglIsoA9z02ZmH khAlPhtqKmbIP4ZfghMABciWB2G0V4zOMIcUVYy5LoSdSjdcCg944BzZZ/kLxqVw2CNt+l6Oq0J vYzbP2ji0QOasmOewa4PujWYVldyv4suMj0Y8rpWyNE2AItaN6scyjyqmthRn2tG0pQQtFGsGXr xDxSMv6KnTaNhvB3NmYmRQ12C//daOlqhtW6B9sDg X-Received: by 2002:a05:600c:cc7:b0:439:9737:675b with SMTP id 5b1f17b1804b1-43f1ef4ed59mr687675e9.7.1744136317494; Tue, 08 Apr 2025 11:18:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHt6LtzhtOCodKlEDsv24JUxo5GCvyjuPDd1u+OK+hcqeg+gGGG7/Q1UKS8qILxl7CGg59mw== X-Received: by 2002:a05:600c:cc7:b0:439:9737:675b with SMTP id 5b1f17b1804b1-43f1ef4ed59mr687595e9.7.1744136317185; Tue, 08 Apr 2025 11:18:37 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:4f00:a44a:5ad6:765a:635? (p200300cbc7074f00a44a5ad6765a0635.dip0.t-ipconnect.de. [2003:cb:c707:4f00:a44a:5ad6:765a:635]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec1630ddesm172061645e9.5.2025.04.08.11.18.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Apr 2025 11:18:33 -0700 (PDT) Message-ID: <60ae4d6b-3ace-482b-9945-1261003f3785@redhat.com> Date: Tue, 8 Apr 2025 20:18:32 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 To: Vlastimil Babka , 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: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQ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wEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 08.04.25 19:55, Vlastimil Babka wrote: > 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: Ah, now I understand the problem, thanks for pointing that out. > > - 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. We could by grabbing the mutex in MEM_GOING_ONLINE and putting it in MEM_CANCEL_ONLINE / MEM_ONLINE when a node is going online. We use something similar in virtio-mem code to sync over the whole onlining period. Of course, if someone would try creating a cache from inside a notifier, it would be problematic. (unlikely, but pointing it out) Onlining a node is not a particularly common operation, so maybe ... good enough. Let me think about other alternatives that require minimal adjustments. -- Cheers, David / dhildenb