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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53423C47247 for ; Mon, 4 May 2020 19:57:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0F94220707 for ; Mon, 4 May 2020 19:56:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tg5QFlhw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F94220707 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BBA288E007B; Mon, 4 May 2020 15:56:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6A6D8E0058; Mon, 4 May 2020 15:56:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A59D28E007B; Mon, 4 May 2020 15:56:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 905988E0058 for ; Mon, 4 May 2020 15:56:58 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 526BF173F8 for ; Mon, 4 May 2020 19:56:58 +0000 (UTC) X-FDA: 76780094916.20.love87_1fb77c6408c5c X-HE-Tag: love87_1fb77c6408c5c X-Filterd-Recvd-Size: 4131 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 19:56:57 +0000 (UTC) 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 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: 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; > }