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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham 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 8B0AEC4361B for ; Tue, 8 Dec 2020 18:20:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06F5923B46 for ; Tue, 8 Dec 2020 18:20:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06F5923B46 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58F556B005D; Tue, 8 Dec 2020 13:20:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 543D66B0068; Tue, 8 Dec 2020 13:20:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42E876B006C; Tue, 8 Dec 2020 13:20:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id 2CAB26B005D for ; Tue, 8 Dec 2020 13:20:39 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E50291EE6 for ; Tue, 8 Dec 2020 18:20:38 +0000 (UTC) X-FDA: 77570930556.14.brush33_2316c94273e9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id C4A9B1822987A for ; Tue, 8 Dec 2020 18:20:38 +0000 (UTC) X-HE-Tag: brush33_2316c94273e9 X-Filterd-Recvd-Size: 6433 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 18:20:38 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id t22so21126514ljk.0 for ; Tue, 08 Dec 2020 10:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KtsL6yyTsdRfL58pMrd/cVVqUWZ3Qpi4P1xbGQ497SA=; b=VfSb6i7CO6ruLDo2yDHAEhRj3tkB7pO3suizcEQKb0xPFlkwllIbDZyW7RhQ2aHIXL FqhSKoj+RwzE27HoBNjxdTU1dOo/wAQj7siOo+Y/ntWjoy6QLYQKBWOeNygpzbQteutN fZEnylSc/DaG6VqYLY/J9G8QyAnXOutvRYZc+CKHbPktW/vRLVM7V8LzwdHzH17j8FZy +xpZeE6qCWRnmjpkjPsgi3YvVLcG3w0mUm7KYzQJ7juXJWwfXBnPatgmtyNVQkUI0iTs ToO+3bSGVHkKXYjceu0ANnh30hjqfInU2RExCqJh4nSu3wGSyut5MmtTujBveXeXzIoj rh+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KtsL6yyTsdRfL58pMrd/cVVqUWZ3Qpi4P1xbGQ497SA=; b=kxjP0S8xTl+TMxencArEqUeE85dnmKH6OfQ/61lsSbb/oeZTTZIaCCdwT7EAFHXAc+ a9A83dlLjAgAQPKEl3vG263EA0IuwxNI/9x/DijsTVWYlcBs36969di3gfxOIhW1nsVO f/Ii+Ev6UzRuMt+wCXdrHPtySmHyELOsoXwaRc0O+QIQ/JB3O6TYu4hlaYWsjGQKdkJK An6xYyRG8qrbGdCsRM5JYIqq3y8kNcjd9LyrXT4Z0oA1m6Nn5zjR7W3sgGmfnGso4411 W6yBhpaR+8VCnsttH5UunacBvt/yIskjdOhj1bOlz96knUUJgQyXQ7u3/IOPKTwUGAz8 TRPA== X-Gm-Message-State: AOAM532mCubqCCDEqfxFe3QlSl6GFQwln5rHkYH6RNg+tmhL5XUrqyU+ knsgkK8iglo599K1mbaynMZEotx0rULfkhsV5JRzBA== X-Google-Smtp-Source: ABdhPJyWaxVyzu/eCzLpxSL+BGt4RdiR3UrrzgqIuDxvzKnwDQHOd8dkCSuOJ8JoJW3sLaUTpeXKNzNTKof/w5DUcC4= X-Received: by 2002:a05:651c:234:: with SMTP id z20mr1321110ljn.456.1607451634599; Tue, 08 Dec 2020 10:20:34 -0800 (PST) MIME-Version: 1.0 References: <20201208095132.79383-1-songmuchun@bytedance.com> In-Reply-To: <20201208095132.79383-1-songmuchun@bytedance.com> From: Shakeel Butt Date: Tue, 8 Dec 2020 10:20:23 -0800 Message-ID: Subject: Re: [PATCH v2] mm: memcontrol: optimize per-lruvec stats counter memory usage To: Muchun Song Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Roman Gushchin , Stephen Rothwell , Chris Down , Yafang Shao , Wei Yang , LKML , Cgroups , Linux MM Content-Type: text/plain; charset="UTF-8" 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 Tue, Dec 8, 2020 at 1:53 AM Muchun Song wrote: > > The vmstat threshold is 32 (MEMCG_CHARGE_BATCH), so the type of s32 > of lruvec_stat_cpu is enough. And introduce struct per_cpu_lruvec_stat > to optimize memory usage. > > The size of struct lruvec_stat is 304 bytes on 64 bits system. As it > is a per-cpu structure. So with this patch, we can save 304 / 2 * ncpu > bytes per-memcg per-node where ncpu is the number of the possible CPU. > If there are c memory cgroup (include dying cgroup) and n NUMA node in > the system. Finally, we can save (152 * ncpu * c * n) bytes. > > Signed-off-by: Muchun Song Few nits below: Reviewed-by: Shakeel Butt > --- > Changes in v1 -> v2: > - Update the commit log to point out how many bytes that we can save. > > include/linux/memcontrol.h | 6 +++++- > mm/memcontrol.c | 10 +++++++++- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 3febf64d1b80..290d6ec8535a 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -92,6 +92,10 @@ struct lruvec_stat { > long count[NR_VM_NODE_STAT_ITEMS]; > }; > > +struct per_cpu_lruvec_stat { lruvec_stat is also per-cpu, so the name per_cpu_lruvec_stat does not really tell why it is different from lruvec. Maybe name is batched_lruvec_stat or something else. > + s32 count[NR_VM_NODE_STAT_ITEMS]; > +}; > + > /* > * Bitmap of shrinker::id corresponding to memcg-aware shrinkers, > * which have elements charged to this memcg. > @@ -111,7 +115,7 @@ struct mem_cgroup_per_node { > struct lruvec_stat __percpu *lruvec_stat_local; A comment for the above why it still needs to be lruvec_stat. > > /* Subtree VM stats (batched updates) */ > - struct lruvec_stat __percpu *lruvec_stat_cpu; > + struct per_cpu_lruvec_stat __percpu *lruvec_stat_cpu; > atomic_long_t lruvec_stat[NR_VM_NODE_STAT_ITEMS]; > > unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS]; > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index eec44918d373..da6dc6ca388d 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5198,7 +5198,7 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) > return 1; > } > > - pn->lruvec_stat_cpu = alloc_percpu_gfp(struct lruvec_stat, > + pn->lruvec_stat_cpu = alloc_percpu_gfp(struct per_cpu_lruvec_stat, > GFP_KERNEL_ACCOUNT); > if (!pn->lruvec_stat_cpu) { > free_percpu(pn->lruvec_stat_local); > @@ -7089,6 +7089,14 @@ static int __init mem_cgroup_init(void) > { > int cpu, node; > > + /* > + * Currently s32 type (can refer to struct per_cpu_lruvec_stat) is > + * used for per-memcg-per-cpu caching of per-node statistics. In order > + * to work fine, we should make sure that the overfill threshold can't > + * exceed S32_MAX / PAGE_SIZE. > + */ > + BUILD_BUG_ON(MEMCG_CHARGE_BATCH > S32_MAX / PAGE_SIZE); > + > cpuhp_setup_state_nocalls(CPUHP_MM_MEMCQ_DEAD, "mm/memctrl:dead", NULL, > memcg_hotplug_cpu_dead); > > -- > 2.11.0 >