Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp245315pxf; Wed, 17 Mar 2021 21:53:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWhbDTbtQCXsGwTpwXS22PAV1YvoMu8kcH9gomQmJF8zQl7kdpa0y/0b2Z6nv+z+9JKazn X-Received: by 2002:a50:f9c8:: with SMTP id a8mr1306259edq.270.1616043235934; Wed, 17 Mar 2021 21:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616043235; cv=none; d=google.com; s=arc-20160816; b=YHNoQ55HQp9EsiJE6GSpohCaBeG86aRq5oqd5bdKoiDQVhTDXzuI0YT/Xzmi1unc8W TP5f6wPx7t74S0pS2zZVnXa0Vs61l2dEiKADIU8BeZg1TUCFPjKJCEC/8aQ8x3JTTBNY LZLps+n3PIfyu6gqVbWonx2oQg+YQVGVzjdWjNTLkgWB/CO+FtXS/xohAMGHtM902Xj0 EVQZcBNxuq+qc/NS5f5QaEWnUeFfc5/qX+GPgxu4rhGUGGZCruXmZDNxa9RsN61bRTMm 2sDOpPqCevAildeME92+ahHxga9KFDjXDDjb72M/CE87Mzw+HkG8YgBIjmsiVf3ucejy 5VqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:reply-to; bh=kOt25K0Y8Zcoor5VJBQb8Vcf9gvNWfNXUiwlVEpOCs4=; b=fQ9E6ZPFhl6g6rvV4f520nBX6jZl4OBKRfIP0dTdRLt98zTbRb2d/UT9ELqckrCS43 3f9yOug/+3v3GRdkAJgRhokSCTMB58uOf/AHGyDmAO7SEyZPGnrvJ34EdjBST19z4OzD 21RQbag+9IogMS+5oMfxyTvHVWwhQpWncYkldFPEQgjjOrQo7hU/6Pa+M0cXGuOINeW+ 5HT1mqs9jLdAY4Fwwvh2A0CLnmEuBfcflafi1i/epLL+ehwWLzERBjTqLje5cxgjyW0O X3ymQk7vYKL25LfZH5fvfJFMLiMdrEgtnqks0GS7YdpLniYn8/dVx6iSDAxCnHPDaph/ bNqw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si680888eds.85.2021.03.17.21.53.32; Wed, 17 Mar 2021 21:53:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbhCREw0 (ORCPT + 99 others); Thu, 18 Mar 2021 00:52:26 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:55190 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbhCREwW (ORCPT ); Thu, 18 Mar 2021 00:52:22 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0USNEbJb_1616043135; Received: from xunleideMacBook-Pro.local(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0USNEbJb_1616043135) by smtp.aliyun-inc.com(127.0.0.1); Thu, 18 Mar 2021 12:52:16 +0800 Reply-To: xlpang@linux.alibaba.com Subject: Re: [PATCH v4 1/3] mm/slub: Introduce two counters for partial objects To: Vlastimil Babka , Xunlei Pang , Christoph Lameter , Christoph Lameter , Pekka Enberg , Roman Gushchin , Konstantin Khlebnikov , David Rientjes , Matthew Wilcox , Shu Ming , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Wen Yang , James Wang References: <1615967692-80524-1-git-send-email-xlpang@linux.alibaba.com> <1615967692-80524-2-git-send-email-xlpang@linux.alibaba.com> <322e2b18-e529-3004-c19a-8c4a3b97c532@suse.cz> From: Xunlei Pang Message-ID: <9594c2c0-b6ef-2064-b8c0-72f67032cde8@linux.alibaba.com> Date: Thu, 18 Mar 2021 12:52:15 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <322e2b18-e529-3004-c19a-8c4a3b97c532@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/18/21 2:45 AM, Vlastimil Babka wrote: > On 3/17/21 8:54 AM, Xunlei Pang wrote: >> The node list_lock in count_partial() spends long time iterating >> in case of large amount of partial page lists, which can cause >> thunder herd effect to the list_lock contention. >> >> We have HSF RT(High-speed Service Framework Response-Time) monitors, >> the RT figures fluctuated randomly, then we deployed a tool detecting >> "irq off" and "preempt off" to dump the culprit's calltrace, capturing >> the list_lock cost nearly 100ms with irq off issued by "ss", this also >> caused network timeouts. >> >> This patch introduces two counters to maintain the actual number >> of partial objects dynamically instead of iterating the partial >> page lists with list_lock held. >> >> New counters of kmem_cache_node: partial_free_objs, partial_total_objs. >> The main operations are under list_lock in slow path, its performance >> impact is expected to be minimal except the __slab_free() path. >> >> The only concern of introducing partial counter is that partial_free_objs >> may cause cacheline contention and false sharing issues in case of same >> SLUB concurrent __slab_free(), so define it to be a percpu counter and >> places it carefully. > > Hm I wonder, is it possible that this will eventually overflow/underflow the > counter on some CPU? (I guess practially only on 32bit). Maybe the operations > that are already done under n->list_lock should flush the percpu counter to a > shared counter? You are right, thanks a lot for noticing this. > > ... > >> @@ -3039,6 +3066,13 @@ static void __slab_free(struct kmem_cache *s, struct page *page, >> head, new.counters, >> "__slab_free")); >> >> + if (!was_frozen && prior) { >> + if (n) >> + __update_partial_free(n, cnt); >> + else >> + __update_partial_free(get_node(s, page_to_nid(page)), cnt); >> + } > > I would guess this is the part that makes your measurements notice that > (although tiny) difference. We didn't need to obtain the node pointer before and > now we do. And that is really done just for the per-node breakdown in "objects" > and "objects_partial" files under /sys/kernel/slab - distinguishing nodes is not > needed for /proc/slabinfo. So that kinda justifies putting this under a new > CONFIG as you did. Although perhaps somebody interested in these kind of stats > would enable CONFIG_SLUB_STATS anyway, so that's still an option to use instead > of introducing a new oddly specific CONFIG? At least until somebody comes up and > presents an use case where they want the per-node breakdowns in /sys but cannot > afford CONFIG_SLUB_STATS. > > But I'm also still thinking about simply counting all free objects (for the > purposes of accurate in /proc/slabinfo) as a percpu variable in > struct kmem_cache itself. That would basically put this_cpu_add() in all the > fast paths, but AFAICS thanks to the segment register it doesn't mean disabling > interrupts nor a LOCK operation, so maybe it wouldn't be that bad? And it > shouldn't need to deal with these node pointers. So maybe that would be > acceptable for CONFIG_SLUB_DEBUG? Guess I'll have to try... > The percpu operation itself should be fine, it looks to be cacheline pingpong issue due to extra percpu counter access, so making it cacheline aligned improves a little according to my tests.