Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1760743ybj; Wed, 6 May 2020 04:58:22 -0700 (PDT) X-Google-Smtp-Source: APiQypJR+TvBWVmxN18dPRjBodNWl1LuD3s5kNha2yPeLm+Lk42c37HLEmwH/PtxpNFF+hZwyMrz X-Received: by 2002:aa7:d514:: with SMTP id y20mr6642082edq.28.1588766302725; Wed, 06 May 2020 04:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588766302; cv=none; d=google.com; s=arc-20160816; b=mMF1TpHLeahM25CYNWw6sAmbr2THciTdiKZ+jSKHocoeVQsvLwV1jpw7begwwTJ8kw 8PRaSSr801jNGoIR4FPXxalVqcmV5JnMyCfhyzSRD5sHHeADvkB08frsZ9wba6SSs1Rd AEzpqq2AZ22Qus7YtXwG8v4c4O7z9pk4YhnysMGCLBAI0fpTlJ5j2apmIqpCFl6IV6Jf H+PkF0uoXOYB4kVJ71DZVqFCzCUSqLkTUQKrs47mlZQvu4U2wzJrFALjoqlGY174FJHe eBqPzILejaIDv7jyFDKObOKHNhMpoPQHO1jFP33cr6/82uKYKb5SQcspS9RTkHa+Tul1 ozdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=tRHatASQpfsGPqjNWM5A+QTxXGC2YlhEkMIkdFsj0OI=; b=Tv7CXkO0AVlLAhHnf+skVSKK+snigurr9m0sQbkT5FzorfzZPSOltb/1CCeJlZ8gYn zi0ld9LX12zMuMbTCBasn6UPw/Qr+vT5+d5hQZ8L5RZeqtU3oTMsfV3QBsYrtzxUxk09 5YA3w5eUwvEDlM5FoX/UKSBW4LOqiBZBU9Qj4SgqeE9sB/50kmGFK0VxuiWcEkfV767V QV24ih47+SPgY7CNzCiO3OCZg5N577JVpdrJ81HhIetsDOdQuogaj8oJp9ZeB2JruC+C fXjJ8gGZ8yYJLwHIg/+HC4Tujn/jmG25cDFnh2Ppw/kxJ/q+m7xSoD5nevEc+OdAycGJ YxRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si725471ejh.494.2020.05.06.04.58.00; Wed, 06 May 2020 04:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgEFL4M (ORCPT + 99 others); Wed, 6 May 2020 07:56:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:37816 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbgEFL4M (ORCPT ); Wed, 6 May 2020 07:56:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 39BECAE0F; Wed, 6 May 2020 11:56:13 +0000 (UTC) Subject: Re: [PATCH] slub: limit count of partial slabs scanned to gather statistics To: Konstantin Khlebnikov , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Wen Yang References: <158860845968.33385.4165926113074799048.stgit@buzz> From: Vlastimil Babka Message-ID: <09e66344-4d30-9a67-24b8-14a910709157@suse.cz> Date: Wed, 6 May 2020 13:56:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <158860845968.33385.4165926113074799048.stgit@buzz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/4/20 6:07 PM, Konstantin Khlebnikov wrote: > To get exact count of free and used objects slub have to scan list of > partial slabs. This may take at long time. Scanning holds spinlock and > blocks allocations which move partial slabs to per-cpu lists and back. > > Example found in the wild: > > # cat /sys/kernel/slab/dentry/partial > 14478538 N0=7329569 N1=7148969 > # time cat /sys/kernel/slab/dentry/objects > 286225471 N0=136967768 N1=149257703 > > real 0m1.722s > user 0m0.001s > sys 0m1.721s > > The same problem in slab was addressed in commit f728b0a5d72a ("mm, slab: > faster active and free stats") by adding more kmem cache statistics. > For slub same approach requires atomic op on fast path when object frees. In general yeah, but are you sure about this one? AFAICS this is about pages in the n->partial list, where manipulations happen under n->list_lock and shouldn't be fast path. It should be feasible to add a counter under the same lock, so it wouldn't even need to be atomic? > Let's simply limit count of scanned slabs and print warning. > Limit set in /sys/module/slub/parameters/max_partial_to_count. > Default is 10000 which should be enough for most sane cases. > > Return linear approximation if list of partials is longer than limit. > Nobody should notice difference. > > Signed-off-by: Konstantin Khlebnikov BTW there was a different patch in that area proposed recently [1] for slabinfo. Christopher argued that we can do that for slabinfo but leave /sys stats precise. Guess not then? [1] https://lore.kernel.org/linux-mm/20200222092428.99488-1-wenyang@linux.alibaba.com/ > --- > mm/slub.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 9bf44955c4f1..86a366f7acb6 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2407,16 +2407,29 @@ static inline unsigned long node_nr_objs(struct kmem_cache_node *n) > #endif /* CONFIG_SLUB_DEBUG */ > > #if defined(CONFIG_SLUB_DEBUG) || defined(CONFIG_SYSFS) > + > +static unsigned long max_partial_to_count __read_mostly = 10000; > +module_param(max_partial_to_count, ulong, 0644); > + > static unsigned long count_partial(struct kmem_cache_node *n, > int (*get_count)(struct page *)) > { > + unsigned long counted = 0; > unsigned long flags; > unsigned long x = 0; > struct page *page; > > spin_lock_irqsave(&n->list_lock, flags); > - list_for_each_entry(page, &n->partial, slab_list) > + list_for_each_entry(page, &n->partial, slab_list) { > x += get_count(page); > + > + if (++counted > max_partial_to_count) { > + pr_warn_once("SLUB: too much partial slabs to count all objects, increase max_partial_to_count.\n"); > + /* Approximate total count of objects */ > + x = mult_frac(x, n->nr_partial, counted); > + break; > + } > + } > spin_unlock_irqrestore(&n->list_lock, flags); > return x; > } > >