Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2386922ybg; Thu, 30 Jul 2020 19:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy80rqMh1vJ0zTlVWLbJs9SqQCpiuXmUHp93Ls3xUbtWaLojKIae70gVG+Iwq+xpdg6qlkA X-Received: by 2002:a05:6402:1a26:: with SMTP id be6mr1884370edb.162.1596164008590; Thu, 30 Jul 2020 19:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596164008; cv=none; d=google.com; s=arc-20160816; b=YOit8n1gwaepIozbXIdL1MZdZd/b8SagmX5xhsL/URuM0Xm1MrNxktz1PgMIsjqo2k Pli3pwd2WUeQeqGhM6JxdrmoI0elfhHWG/NvnEpezThRNBkF18rOJfn0Yq4GKktcRXrj vO+E7MInXW970CDN7e/5U9CipoTsHKOYVVUFYFgQlQ6MLkE7OAFjVloDdsTI5I2CcmP+ i1fjQgK0HFThILFYJBnGJJlv/4Ib+UP4eowYyVLt+7m0m3D5RYHatoP8u+QTMDp12CD2 9noA4Lh6+nzQs+nuf3pshMgSmjDIVnFrmBvekjl6wQ5/9MZG4S01DsjaEluki3MzKPKd rj9Q== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:reply-to; bh=41wopv+mzMX91KOSijyfmJkAU11mCxdF7eo+QfwEtu4=; b=XPtuEFUCqpuI0DqBXwTmpQhfISKwZou5k3ZmEt9rzPa/CTLEGK+mDvR6ZMTtd/T+L7 aQsAV7b2tlfBxeDYC08WP3XMNApOfk/RxR1rRQo4KOkWyPfNGTI24S501WEbRCojQzkU qU44gCgcw9Hgkfj1nW1hdyuTBxaaLV6b3aWW/estjSTmF3ex7HFJCvzBPWqk3Awl+Hbh 8J5Jp2H5/f3zFZXiHjL9W+5w2dXI/QdRGUHTXsfYhLM+HFcxcfNexC34oo9ZjkA3RQIp 8Hf3GKZm0wALZePNc6MLFd9eTGzGGK5e9XdkNRdHwgVLY53mMt/fO9qc4T8yJzxfTCEj PH/w== 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 qk16si4169076ejb.532.2020.07.30.19.53.05; Thu, 30 Jul 2020 19:53:28 -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 S1731222AbgGaCwS (ORCPT + 99 others); Thu, 30 Jul 2020 22:52:18 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:51926 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731124AbgGaCwS (ORCPT ); Thu, 30 Jul 2020 22:52:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U4Gz0ZT_1596163932; Received: from xunleideMacBook-Pro.local(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0U4Gz0ZT_1596163932) by smtp.aliyun-inc.com(127.0.0.1); Fri, 31 Jul 2020 10:52:13 +0800 Reply-To: xlpang@linux.alibaba.com Subject: Re: [PATCH 1/2] mm/slub: Introduce two counters for the partial objects To: Christopher Lameter Cc: Andrew Morton , Wen Yang , Yang Shi , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1593678728-128358-1-git-send-email-xlpang@linux.alibaba.com> From: xunlei Message-ID: Date: Fri, 31 Jul 2020 10:52:14 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/7/7 ????2:59, Christopher Lameter wrote: > On Thu, 2 Jul 2020, Xunlei Pang wrote: > >> 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 are: pfree_objects, ptotal_objects. >> The main operations are under list_lock in slow path, its performance >> impact is minimal. > > > If at all then these counters need to be under CONFIG_SLUB_DEBUG. > >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -616,6 +616,8 @@ struct kmem_cache_node { >> #ifdef CONFIG_SLUB >> unsigned long nr_partial; >> struct list_head partial; >> + atomic_long_t pfree_objects; /* partial free objects */ >> + atomic_long_t ptotal_objects; /* partial total objects */ > > Please in the CONFIG_SLUB_DEBUG. Without CONFIG_SLUB_DEBUG we need to > build with minimal memory footprint. Thanks for the comments. show_slab_objects() also calls it with CONFIG_SYSFS: if (flags & SO_PARTIAL) { struct kmem_cache_node *n; for_each_kmem_cache_node(s, node, n) { if (flags & SO_TOTAL) x = count_partial(n, count_total); else if (flags & SO_OBJECTS) x = count_partial(n, count_inuse); else x = n->nr_partial; total += x; nodes[node] += x; } } I'm not sure if it's due to some historical reason, it works without CONFIG_SLUB_DEBUG. > >> #ifdef CONFIG_SLUB_DEBUG >> atomic_long_t nr_slabs; >> atomic_long_t total_objects; >> diff --git a/mm/slub.c b/mm/slub.c > > > > Also this looks to be quite heavy on the cache and on execution time. Note > that the list_lock could be taken frequently in the performance sensitive > case of freeing an object that is not in the partial lists. > Yes, the concurrent __slab_free() has potential lock/atomic contention, how about using percpu variable for partial free like below? static inline void __update_partial_free(struct kmem_cache_node *n, long delta) { atomic_long_add(delta, this_cpu_ptr(n->partial_free_objs)); } -Xunlei