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 BFD17C5478C for ; Tue, 27 Feb 2024 09:30:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5969B940017; Tue, 27 Feb 2024 04:30:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 545D5940008; Tue, 27 Feb 2024 04:30:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40E08940017; Tue, 27 Feb 2024 04:30:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 316A7940008 for ; Tue, 27 Feb 2024 04:30:46 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 79019C0C12 for ; Tue, 27 Feb 2024 09:30:45 +0000 (UTC) X-FDA: 81837064050.08.F79FC8C Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf01.hostedemail.com (Postfix) with ESMTP id 5A80540022 for ; Tue, 27 Feb 2024 09:30:43 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bKXLj5hL; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf01.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709026243; 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=7NHq+KgqSjtKqYa5MxxZSSs2Nj7Yc813r6gQt4rO1/Q=; b=uwpPUdTY2xml6JYeE0dPSnZR2vHrkI55Zw3IsFEepg+G80/PqR+qJqfRwDlLZE6vK7ysWp 10m7YPMUmFYsRbq7343heLEuuwUrGk2IROUHKsRMe+bIGA+dEBzG/m+nYPAqiQfYGtACzq Wp24eW5IhANd31N6dJTr5AJ99XNH69o= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bKXLj5hL; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf01.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709026243; a=rsa-sha256; cv=none; b=i/1RrXIDh/VL1NUaujARRjpIEfVcZH/oAZa2VkLaS4nJwLWb9GH5ULhByJvzq0ohi2zesA YnawKrxnwmHeIO9C1MdLrYcvOWt8x9L49iHkN1rdxS3nnPCTMXRCnSi1YTfBBfXoOl28c2 2pwT8s4yKY/60cZUKjyCS9LFV656W6U= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709026239; 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; bh=7NHq+KgqSjtKqYa5MxxZSSs2Nj7Yc813r6gQt4rO1/Q=; b=bKXLj5hLSJUsNyeI/gMIBNFFhBRmsfvMo8OQ4DToqA/j8a4vYcW3pLL+jSyweVPYuLlVwt wH14mGlA+eBwhXAH30k3y0ms5/A4Zx+QlQAUbeM0PURwjzlmkjHSqjn8dSPHXotfsByzZB hXsYhKpe8xrWy5M4rTZt441EoFHTpiM= Date: Tue, 27 Feb 2024 17:30:31 +0800 MIME-Version: 1.0 Subject: Re: [PATCH] slub: avoid scanning all partial slabs in get_slabinfo() Content-Language: en-US To: "Christoph Lameter (Ampere)" , Vlastimil Babka Cc: David Rientjes , Jianfeng Wang , penberg@kernel.org, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou References: <20240215211457.32172-1-jianfeng.w.wang@oracle.com> <6b58d81f-8e8f-3732-a5d4-40eece75013b@google.com> <55ccc92a-79fa-42d2-97d8-b514cf00823b@linux.dev> <6daf88a2-84c2-5ba4-853c-c38cca4a03cb@linux.com> <347b870e-a7d5-45df-84ba-4eee37b74ff6@linux.dev> <1a952209-fa22-4439-af27-bf102c7d742b@suse.cz> <2744dd57-e76e-4d80-851a-02898f87f9be@suse.cz> <036f2bb4-b086-2988-e46d-86d399405687@linux.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <036f2bb4-b086-2988-e46d-86d399405687@linux.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 5A80540022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: c1ig6pt1az8h6587a3g4dsw8wy67ecsg X-HE-Tag: 1709026243-52526 X-HE-Meta: U2FsdGVkX192ZDoHTuafLDOZzuuB7HuFy+zgiR525Rk8I2MDRgALfj7Aw1GxRdkMiWC0u4yW5ZG5z+MIWAbWSji3mN3LvDbUaJM041XSHXDDnnn/ymac4Y0DmbvxnL65A9fdMmKMi/H4rnZl0kekhbZnzB97nlbVFMX3K+rUIovIuGCi4iGG6G+iN559VuVPvUK40tLA80ObFqJb7AzhhrdKx0eJdX167/1AwISKMZlpww+rRGPPlZ6La2A7+y+t0b4aKOiYHgiRBkCm+8afVpWDUIInEF0nGcQlDWEj9VBNazAGNQ4TV3EUdzoJSmL+50H5DjNsjHFpqEpqMGbMGwjw3lFvldNks4iL+a3VunsfFL+3aT3GO2zyuAM8VD/euBFGGHHFznmh417U/eqwgjZQAQ6c3DGiiixwbkX/z/jloFnHy6jh27zz709gphuyq2zjoqVvMLvLzCvR2v58wDGLyRz+XBeTLh1BTAhBfodg80iJZxijwpw577jKzbs6c1D1oCWFyS4hkFx2C7sTe6U5EYV/3Sd4zayOm6YtY2QJ3HM0k/Z/OYrJcff2gzgl1JIQCXgj+l7sLMYpEZYXBxU9emOT+Pc4b4UoZDGe46M9DN93L9n/NC3TnZ7n5iBheaOe///B3D8wNgDhzbz5wgvN0N5aOR3tzYEIBMIx2jUU1uDQOzegNCMJszZivgWvN/PlRIvvBIadOhlZ/8YCUn21q+bCgu1O8J/UbcHQOi+QHBYYKVu0g3GXYFU0B4wo0P3elKkDvaKF2G1tbmwZGEhp9tOz4JPN41KPZ8GNxdiFUWHVS64qWX+LpqK8QTNsT523KV+Avsea0Djn3a8k7QsLN9Db4iLDhm8pDTz+YZhOJtIZzyuUnrBC1CgEnm8gc5QaPILHwOxAte9/YzMpjhu7sXjytFqXSo8o5dbdXgg= 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 2024/2/27 01:38, Christoph Lameter (Ampere) wrote: > On Fri, 23 Feb 2024, Vlastimil Babka wrote: > >> On 2/23/24 10:37, Chengming Zhou wrote: >>> On 2024/2/23 17:24, Vlastimil Babka wrote: >>>> >>>>>> >>>>> >>>>> I think this is a better direction! We can use RCU list if slab can be freed by RCU. >>>> >>>> Often we remove slab from the partial list for other purposes than freeing - >>>> i.e. to become a cpu (partial) slab, and that can't be handled by a rcu >>>> callback nor can we wait a grace period in such situations. >>> >>> IMHO, only free_slab() need to use call_rcu() to delay free the slab, >>> other paths like taking partial slabs from node partial list don't need >>> to wait for RCU grace period. >>> >>> All we want is safely lockless iterate over the node partial list, right? >> >> Yes, and for that there's the "list_head slab_list", which is in union with >> "struct slab *next" and "int slabs" for the cpu partial list. So if we >> remove a slab from the partial list and rewrite the list_head for the >> partial list purposes, it will break the lockless iterators, right? We would >> have to wait a grace period between unlinking the slab from partial list (so >> no new iterators can reach it), and reusing the list_head (so we are sure >> the existing iterators stopped looking at our slab). > > We could mark the state change (list ownership) in the slab metadata and then abort the scan if the state mismatches the list. It seems feasible, maybe something like below? But this way needs all kmem_caches have SLAB_TYPESAFE_BY_RCU, right? Not sure if this is acceptable? Which may cause random delay of memory free. ``` retry: rcu_read_lock(); h = rcu_dereference(list_next_rcu(&n->partial)); while (h != &n->partial) { slab = list_entry(h, struct slab, slab_list); /* Recheck slab with node list lock. */ spin_lock_irqsave(&n->list_lock, flags); if (!slab_test_node_partial(slab)) { spin_unlock_irqrestore(&n->list_lock, flags); rcu_read_unlock(); goto retry; } /* Count this slab's inuse. */ /* Get the next pointer with node list lock. */ h = rcu_dereference(list_next_rcu(h)); spin_unlock_irqrestore(&n->list_lock, flags); } rcu_read_unlock(); ``` > >> Maybe there's more advanced rcu tricks but this is my basic understanding >> how this works. > > This could get tricky but we already do similar things with RCU slabs objects/metadata where we allow the resuse of the object before the RCU period expires and there is an understanding that the user of those objects need to verify the type of object matching expectations when looking for objects. >