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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFB1DC433F5 for ; Fri, 25 Feb 2022 10:23:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AAF18D0002; Fri, 25 Feb 2022 05:23:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 458558D0001; Fri, 25 Feb 2022 05:23:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 347168D0002; Fri, 25 Feb 2022 05:23:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 247938D0001 for ; Fri, 25 Feb 2022 05:23:33 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id E4FD08096A for ; Fri, 25 Feb 2022 10:23:32 +0000 (UTC) X-FDA: 79180915464.01.A96FB70 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf30.hostedemail.com (Postfix) with ESMTP id 67F0E80006 for ; Fri, 25 Feb 2022 10:23:32 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id c1so4247399pgk.11 for ; Fri, 25 Feb 2022 02:23:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Dh20ZIUFbwXMcnXNMENbopqsfZbRAKd3wHIsqvGQ1PM=; b=o4aHzjzPWBGMpi6ZcbUrSr91TaBiLaSE7N72ZRybvk4VJTtbzDKOQmwlcxLUvbR/Vf IBBg7Xg9V3t8/MO8wiHSzpSzDly0SwQ6N9aIV4/7gL8WDbfn0q7ZNCIBzAQRK5j1IIhc 4iRQaptUOiYpU4MQVJ5UXfm53HnNRE14jmpLM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Dh20ZIUFbwXMcnXNMENbopqsfZbRAKd3wHIsqvGQ1PM=; b=cXgOH1Eij/1U584FkNiJ6aW3l1bf7bLz2MrzeTobf1bDER5Fx8im+8AXTIea45Shd7 UK4gKGSMAy4j7VEKjcKZJrloSZmPZvT+FBNu6LRgLALzZVNx7AUsXFo5DBMah02cw4XY sqR+yEHQPGgEYiQ+TUjN0QSpGezPPq8iRKpPWtr/QV8KrEqGFCxcV7pSPimRr0/xD00a ssrzRJNA4fz21HKhcAEC6GLhwyQk01qEbWlKrpYtIb9/1kaYSMcz0VH2LViaaeSX/4gD ArUz4RXe/YIA9pl2/z+Uub2M501naNQFSOV47A8Hs2pMZI3EUksgSfJraIfSF9OR0UpQ ruaw== X-Gm-Message-State: AOAM532dZF+lboYV7zoChYk7yhzYpm10apuOTU1mO99FsvM1eC/g/Zd2 ePeBs0fseLHapNQro2uvSUFk1e1HozNWbcs0DEXErQ== X-Google-Smtp-Source: ABdhPJw0Jtit+scTuVAIYuG5kmpLAKXu/sVYhPEiIqagxYxLeMsMRmWOKFvhAPJEPLdUugAyd4yOdnbe3xuTLkFjFXs= X-Received: by 2002:a63:110a:0:b0:34b:f642:c00b with SMTP id g10-20020a63110a000000b0034bf642c00bmr5701305pgl.333.1645784611171; Fri, 25 Feb 2022 02:23:31 -0800 (PST) MIME-Version: 1.0 References: <20220224165838.oir5clpkkqpstpx3@google.com> <20220224185236.qgzm3jpoz2orjfcw@google.com> In-Reply-To: <20220224185236.qgzm3jpoz2orjfcw@google.com> From: Daniel Dao Date: Fri, 25 Feb 2022 10:23:20 +0000 Message-ID: Subject: Re: Regression in workingset_refault latency on 5.15 To: Shakeel Butt Cc: Ivan Babrou , kernel-team , Linux MM , Johannes Weiner , Roman Gushchin , Feng Tang , Michal Hocko , Hillf Danton , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Andrew Morton , Linus Torvalds Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 67F0E80006 X-Stat-Signature: i8378gc5tshi7s48xnzwcn4qpm8cwyfq Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=cloudflare.com header.s=google header.b=o4aHzjzP; spf=none (imf30.hostedemail.com: domain of dqminh@cloudflare.com has no SPF policy when checking 209.85.215.180) smtp.mailfrom=dqminh@cloudflare.com; dmarc=pass (policy=reject) header.from=cloudflare.com X-HE-Tag: 1645784612-909739 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000026, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Feb 24, 2022 at 6:52 PM Shakeel Butt wrote: > > On Thu, Feb 24, 2022 at 10:00:55AM -0800, Shakeel Butt wrote: > > On Thu, Feb 24, 2022 at 9:34 AM Daniel Dao wrote: > [...] > > Anyways I am thinking of introducing mem_cgroup_flush_stats_asyn() > > which will schedule flush_memcg_stats_dwork() without delay. Let me > > prepare the patch based on 5.15-stable for you to test. > > > Can you please try the following patch and let me the results? > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index d9b8df5ef212..cd732d7e00ca 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -1002,6 +1002,7 @@ static inline unsigned long > lruvec_page_state_local(struct lruvec *lruvec, > } > > void mem_cgroup_flush_stats(void); > +void mem_cgroup_flush_stats_async(void); > > void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item > idx, > int val); > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 32ba963ebf2e..0f298cbd4763 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -682,6 +682,14 @@ void mem_cgroup_flush_stats(void) > __mem_cgroup_flush_stats(); > } > > +void mem_cgroup_flush_stats_aync(void) > +{ > + if (atomic_read(&stats_flush_threshold) > num_online_cpus()) { > + mod_delayed_work(system_unbound_wq, &stats_flush_dwork, 0); > + atomic_set(&stats_flush_threshold, 0); > + } > +} > + > static void flush_memcg_stats_dwork(struct work_struct *w) > { > __mem_cgroup_flush_stats(); > diff --git a/mm/workingset.c b/mm/workingset.c > index d5b81e4f4cbe..86d43bfc5c63 100644 > --- a/mm/workingset.c > +++ b/mm/workingset.c > @@ -352,7 +352,7 @@ void workingset_refault(struct page *page, void *shadow) > > inc_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file); > > - mem_cgroup_flush_stats(); > + mem_cgroup_flush_stats_async(); > /* > * Compare the distance to the existing workingset size. We > * don't activate pages that couldn't stay resident even if I think this looks good so far. Some stats: 1) More time spent in flush_memcg_stats_dwork $ sudo /usr/share/bcc/tools/funclatency -d 60 flush_memcg_stats_dwork Tracing 1 functions for "flush_memcg_stats_dwork"... Hit Ctrl-C to end. nsecs : count distribution 0 -> 1 : 0 | | 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 0 | | 256 -> 511 : 21 | | 512 -> 1023 : 115 | | 1024 -> 2047 : 47 | | 2048 -> 4095 : 86 | | 4096 -> 8191 : 48 | | 8192 -> 16383 : 2 | | 16384 -> 32767 : 2 | | 32768 -> 65535 : 1 | | 65536 -> 131071 : 52 | | 131072 -> 262143 : 400 |** | 262144 -> 524287 : 2172 |**************** | 524288 -> 1048575 : 4193 |******************************* | 1048576 -> 2097151 : 5357 |****************************************| 2097152 -> 4194303 : 1834 |************* | 4194304 -> 8388607 : 485 |*** | 8388608 -> 16777215 : 3 | | avg = 1346983 nsecs, total: 19959597708 nsecs, count: 14818 2) Less time spent in workingset_refault ~$ sudo /usr/share/bcc/tools/funclatency -d 60 workingset_refault Tracing 1 functions for "workingset_refault"... Hit Ctrl-C to end. nsecs : count distribution 0 -> 1 : 0 | | 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 0 | | 256 -> 511 : 10318 |****************************************| 512 -> 1023 : 2877 |*********** | 1024 -> 2047 : 1089 |**** | 2048 -> 4095 : 4785 |****************** | 4096 -> 8191 : 4528 |***************** | 8192 -> 16383 : 1270 |**** | 16384 -> 32767 : 82 | | 32768 -> 65535 : 80 | | 65536 -> 131071 : 20 | | 131072 -> 262143 : 2 | | 262144 -> 524287 : 0 | | 524288 -> 1048575 : 1 | | avg = 2705 nsecs, total: 67782139 nsecs, count: 25052