Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2233958rbb; Tue, 27 Feb 2024 15:36:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVl4BVnTZ3CJntGxS/NZ5IRIT0KSm1fBwLtbgIb+ZmBXDsB0UAgXclm12MW2B2nMVxOi6Q6sQbdRAzPwPVGfE4Sxcs1ccgj/HJvmYYMvg== X-Google-Smtp-Source: AGHT+IGxd9NsGeuWYpz/3gwH+PWF4Xf5lcqovZMhuqQZ0MLluNxB0LnQcO1XYIb/s17JNM07TaU6 X-Received: by 2002:a05:6870:1816:b0:21f:d114:ef58 with SMTP id t22-20020a056870181600b0021fd114ef58mr13644912oaf.2.1709076975703; Tue, 27 Feb 2024 15:36:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709076975; cv=pass; d=google.com; s=arc-20160816; b=WBwwymMBoV0RKoYE47G/JjRoi3eglgnZMOwiVEihu8wUADAPRs0ho49iBnM1KtA26H PBo0b7IUk8PPrFAmnfy+iT3qygrCvsFsVIv747D+AwwbLcRYVA7U4tjPDNN+OaRKCU9E /OQJEGpr5PZyXFpLaHLMJxtAn0z/HUUzAvGMdkkszb6xUyZeiJdvM8gFyMA8SF8iP8jK xU4lb4r3Qauc4nzH8J2LpmqWpoFm4uvHXjnaRqwU8FHbEN8Hw/QGOlY2Su0BPBrXnwNA ziBT6U1tpoB/kfBZRBzQV+mHncHbicdSEe+7C6qJgsgiyYJUZoLRoSTHrqbe7y0Hvy6i od5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date; bh=Khf3NkS+x9fCYAZtpJKeUC1pvc+BVOLRy6VrNdIRkPk=; fh=3IPYB30O0FuWQ/WqzwUtQ/nqvtXmLOVeVgo37F/qqzo=; b=hxF62J6pcvtRI7NbKx8+/4X3sJ4eP2+moEUmRvotClQ2k12Bl0LJCDCpcfzqXXkJE4 a3eCpZ6QIY2rtNdtk/NjvBurS50wedoFfXjbs+jZqb1ThuBxgr8hvJaPPSEnhLTmql9x NTFLcyAyxQQVYzgyCzVldiA00aN0UX56kSo+RP1Eyn2y4HiFtpGaI5Dvticj7jyz3CMC SA5pbz8R6e0G5l0k5Ge/rjM0ADAX2lh2/4E47YF2QscPfjCQ/O8aslXUZ9d058aN+OJf oV/2SxWhb3VROmqL2c0r4jY4ILFGS3TPcPrCJBBaB2weBKShcpU3HtJk9ELktYMtfNZN acjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-84149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z13-20020aa785cd000000b006e37a65f716si6140322pfn.193.2024.02.27.15.36.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:36:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-84149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B3BFC288632 for ; Tue, 27 Feb 2024 22:55:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18C5655C2B; Tue, 27 Feb 2024 22:55:25 +0000 (UTC) Received: from gentwo.org (gentwo.org [62.72.0.81]) (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 55E7753E07 for ; Tue, 27 Feb 2024 22:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.72.0.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709074524; cv=none; b=rL39KgtitGlfYXJJZ33paz9NLiXV1MWi/5yYRNACXEdGq0IBQJy4AwvqEKu9N560v2PGYXbACtGyQQXVH6Ni5mq+Y+gPPJPYCv5FP3KGM1sYTed363aQOjttiiUxQsl+f1elY8+OfjR8qkv4Rn/USEpurySFDEmiLWyyzHeMUis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709074524; c=relaxed/simple; bh=q5QxgcX7+T+9PWSY+6fPy/pMpMaEHQGVkTrDcbx2WCY=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=HsL4s8a6JLhp/OtzZlkhKM0YACb4CFL/5ANlNe5xUsy66Y31UUCbcQs1gFXgj2lla2Zy3JjBTYB1RUclRKSAAnZ85H9LzQK1BtsDD25txRc7VlWhXHj3UNu00KcQpTE4bRa5WChh6ABHaPXli6pMzSOw6niJJVRzuEDrHTF0DQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com; spf=fail smtp.mailfrom=linux.com; arc=none smtp.client-ip=62.72.0.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.com Received: by gentwo.org (Postfix, from userid 1003) id 7110540AB1; Tue, 27 Feb 2024 14:55:15 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id 7052F40941; Tue, 27 Feb 2024 14:55:15 -0800 (PST) Date: Tue, 27 Feb 2024 14:55:15 -0800 (PST) From: "Christoph Lameter (Ampere)" To: Chengming Zhou 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 Subject: Re: [PATCH] slub: avoid scanning all partial slabs in get_slabinfo() In-Reply-To: Message-ID: <1eeb84d4-42b1-d204-ece1-b76bfbc548bf@linux.com> 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-782571119-1709074515=:1258276" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-782571119-1709074515=:1258276 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT 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. > 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. So this would be redo: rcu_read_lock(); h = ; while (h && h->type == ) { /* Maybe check h->type again */ if (h->type != ) break; 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. --8323329-782571119-1709074515=:1258276--