Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2454223rbb; Wed, 28 Feb 2024 02:14:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUsuCYrLvWn3V+38Y5FAmDmnEvSq+giVbysPmj80+WQS0LZZRNNzBgSa6tXioZ0FSzqniWmBgXqFX09T+EojLH2SI6DPR+13Esy2iuYJQ== X-Google-Smtp-Source: AGHT+IEaKBYcBzECLuRyIIgYsuQlKnBQGzS3WTaeFqT9muMMp+jIXla/aiMYMAfME1rNWMPZ5h/d X-Received: by 2002:a17:903:2310:b0:1dc:b30b:505b with SMTP id d16-20020a170903231000b001dcb30b505bmr7721149plh.31.1709115259078; Wed, 28 Feb 2024 02:14:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709115259; cv=pass; d=google.com; s=arc-20160816; b=d4buh6V31YerF/+LZ28VtZMaTo1Ew7WsYzWvPrK02u/l+mNvS4YpXp0IJ44uhDmFHx 0Fjzhx19oXjCZ9oJu1pDavzyx2Q/sKW78JdBjMLCwqXrywDxtEK6JV4k9PK0rHxcqopi 22qrGZo2ebBLRqEJoKGL+aLhn4Zahr96tdtmAUkVDlZr85LCQaYiK24oq3U/qI4cItEw 6Z+ziaepPzsAhwmHX1cFu5beepjGLON9q74DopR73w+s0iPpM1U8b3wua8ea0UTR9t3w P2qsyzDhjBnUJMpE5+M5N+v2TM+PoKxjI1i1U1KBuOWDGE7qn8Ti4gJeEGGLrLMwU5tV k0ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=GPOCbdIrdO1UY9mjYpsvt7O6Jg6uWqYy//PM9B5ScNY=; fh=pMTjl89JUNsdj6JsChtd6gNMI7Wq7DO3BHiL2BED3FA=; b=GHsRoT2t4vux4ft4ICzYv4OKfzrIXaCZLnIOljqtCx35AbSeL5Tfc/0RxDD9gihpNY u8nHkdHnE2rJuceNkQ3hduW1XQg792bJ8W5btE13GUZAf5pzDc55KUL2RG6aJwG4fCjl B74QF/58rCom2MTGb4nsY0f4/324qyz6ahtQrvqYXV+Mz824qtbNUch/NLivmPEjIycc kX5dLK5rMjMZG/gcFGh9cshraXDLNTblVTSKuwOxtlDVtH4Y6kw3WudT1RkIS5Z2RKUR 7zXjMLko5XVwvh01zeyUn2WmI2TLS8caF+nKAZ9gGYzYQWMBx8iN44Av9x+uIHONu4O6 lePA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=s1R5wnrS; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-84795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id im22-20020a170902bb1600b001dcca096bacsi936052plb.365.2024.02.28.02.14.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 02:14:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=s1R5wnrS; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-84795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25777B24A81 for ; Wed, 28 Feb 2024 09:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66D2736132; Wed, 28 Feb 2024 09:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="s1R5wnrS" Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 DF90D33998 for ; Wed, 28 Feb 2024 09:52:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709113926; cv=none; b=t4P8bO8E6yFTchyPnyLZJHycFtTHnD2AYfovXhKFEl6IQitJ96/B0ja6JJDbC7sTuHh20wSS3FEOZ+fVwDaRMv+2zQ9TQmyVl5uw8qVxlVhK70smzh5fUz6sUSc6PlSKDxvwOM0BolxOUKLlAKYEIAXFSRuQh7XkoUL2w6fStF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709113926; c=relaxed/simple; bh=oCzaGK1+0J1qudbZZr79LyrkGbc7znv+r5ghZv1CEqQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nJxU3hzWrRF/D/mIlCkJCNE1Baj8QUgG+CuXMi+AET3ibWwFkmYkq9YuN/mRkBdvDsZbiXfft/mu9L11mL36j231grX5gAyyJcPsh+xdCKi0wOdziMB+uN8hFrYDY5QiF/1DqQJ9IxMDa9cFQR4Is4hBNHSU6xMe/FshCF00VBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=s1R5wnrS; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <0aa3ce20-438f-49fb-8f04-4fc1dbf49728@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709113920; 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=GPOCbdIrdO1UY9mjYpsvt7O6Jg6uWqYy//PM9B5ScNY=; b=s1R5wnrSmub+m/GNUcmW5SoCAvWOPfUnpZJ3sNCiLvnAuJI90E2wPvTlzquACpDevJKO2o Re+UOalb7q3w7JKklWSSb+F9lC8jCBFYfKTor2tEnxYwYjqmsDRFk+FiwqZKmyq1O4k0ui +oFB6QRijQg9Ehlv+To4TlynrwhG1k4= Date: Wed, 28 Feb 2024 17:51:49 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] slub: avoid scanning all partial slabs in get_slabinfo() Content-Language: en-US To: "Christoph Lameter (Ampere)" Cc: Vlastimil Babka , 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> <1eeb84d4-42b1-d204-ece1-b76bfbc548bf@linux.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <1eeb84d4-42b1-d204-ece1-b76bfbc548bf@linux.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2024/2/28 06:55, Christoph Lameter (Ampere) wrote: > On Tue, 27 Feb 2024, Chengming Zhou wrote: > >>> 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? > > No. > > If a slab is freed to the page allocator and the fields are reused in a different way then we would have to wait till the end of the RCU period. This could be done with a deferred free. Otherwise we have the type checking to ensure that nothing untoward happens in the RCU period. > > The usually shuffle of the pages between freelists/cpulists/cpuslab and fully used slabs would not require that. IIUC, your method doesn't need the slab struct (page) to be delay freed by RCU. So that page struct maybe reused to anything by buddy, even maybe freed, right? Not sure the RCU read lock protection is enough here, do we need to hold other lock, like memory hotplug lock? > >> 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) { > > Hmm... a linked list that forms a circle? Linked lists usually terminate in a NULL pointer. I think the node partial list should be a double-linked list? Since we need to add slab to its head or tail. > > So this would be > > > redo: > >      >     rcu_read_lock(); >     h = ; > >     while (h && h->type == ) { >           > >           /* Maybe check h->type again */ >           if (h->type != ) >             break; Another problem of this lockless recheck is that we may get a very false value: say a slab removed from the node list, then be added to our list in another position, so passed our recheck conditions here. Which may cause our counting is very mistaken? Thanks! > >           h = ; >     } > >     rcu_read_unlock(); > > >     if (!h) /* Type of list changed under us */ >         goto redo; > > > The check for type == is racy. Maybe we can ignore that or we could do something additional. > > Using RCU does not make sense if you add locking in the inner loop. Then it gets too complicated and causes delay. This must be a simple fast lockless loop in order to do what we need. > > Presumably the type and list pointers are in the same cacheline and thus could made to be updated in a coherent way if properly sequenced with fences etc.