Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3958663ybz; Mon, 4 May 2020 12:58:56 -0700 (PDT) X-Google-Smtp-Source: APiQypITF7ytgoGe4sQ00A7LLK9osnKPKivHVzIpc4rLRs/jaFC+qXFHJPMvDeqQ5/1M+Cwy2WTf X-Received: by 2002:a50:e8c1:: with SMTP id l1mr16467294edn.81.1588622336510; Mon, 04 May 2020 12:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588622336; cv=none; d=google.com; s=arc-20160816; b=dA+igVScRf3lepFMm+SWJy/zNpUVUPZJcdhJfQfiP6ra3AGmuZ313FBXNp4xKhZCg5 45aR1S0r6S3C4Zyu8/ZOugYgmiLYcVEfn5eXzuN1iVSTRRU+9R1hAqx0NEiod3MZ44EM AZ0eZLIk6mStGcnzApK2aBSoOZnZaL6/4nkTSkr7tEuG5VddVOoyICZVxVJ5exuwM4Mj B0AYCpMrAfBbHkTVPh/i9b0UitbPNpoFEB270hMR83nmJDlljzaLzDVZjP5F1a1P7U9y BMSXutGaz2GqNB19Swz89AVG2AK1q7ikXgtiOFgPmemYSA7285s0qIbLx/qH4wKbQDpy 0jew== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=h2AxJHPYwHtevQ9bQE8AAbQkviEBNqSwiF/NsE2+Sqs=; b=pdXOVZO212WJKFpeZa7hJeBqQpZ//iCr6zFxb8mw5keRfxc218FypUY99NCZe44IQH tmEYa1xkO8BajNJXti0UoL9wboezuJ9hT2VbZkwNUutq0nVgLtG/WL4rXdW4z93V1Aot 4kklQi9YpRH403z19P1GaY3zoor4N2B+3n4xVSjVs4zknxfD57Kk+QmqMv9XMokfZulQ AmWEs3Fjphi4PsN9SwF5BSWLsBB+LQsawOafUQwyT4GToOWuToUyim/zf5GOjijE5ZAv NlD/yadGxnUPSXC7sycLrgZewIPInbR/kcrub9SD4nzxc/AhOP4o7RMHHwILGP4WX0bq KfiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tg5QFlhw; 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 z70si8174595ede.463.2020.05.04.12.58.33; Mon, 04 May 2020 12:58:56 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Tg5QFlhw; 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 S1726922AbgEDT47 (ORCPT + 99 others); Mon, 4 May 2020 15:56:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:52354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbgEDT46 (ORCPT ); Mon, 4 May 2020 15:56:58 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 985F1206B8; Mon, 4 May 2020 19:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588622216; bh=oHMQloXxyrl24y13J91piTNe8Aacl9gxAnSKSNGhPtI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Tg5QFlhwm+Z9uA105367UbiGVChmwB2HiWa2NADvkVdnw/b71CX4o1gElaoC/TyIw nugCDU17zZY/VmH1jBbg1EzV3oxfcIoPNDEbGO1fEkGIBCqFvtp74A9MvHmt0OtggL jUAmIzeKzl0bIAklRuWtLx4q4DaYbqTp0aSUqIxs= Date: Mon, 4 May 2020 12:56:56 -0700 From: Andrew Morton To: Konstantin Khlebnikov Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim Subject: Re: [PATCH] slub: limit count of partial slabs scanned to gather statistics Message-Id: <20200504125656.e3d04b350c807aba8a2a7271@linux-foundation.org> In-Reply-To: <158860845968.33385.4165926113074799048.stgit@buzz> References: <158860845968.33385.4165926113074799048.stgit@buzz> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 04 May 2020 19:07:39 +0300 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 I assume this could trigger the softlockup detector or even NMI watchdog in some situations? > 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. > > 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. That's a pretty sad "solution" :( But I guess it's better than nothing at all, unless there are alternative ideas? > --- 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; > }