linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Dao <dqminh@cloudflare.com>
To: Shakeel Butt <shakeelb@google.com>
Cc: "Ivan Babrou" <ivan@cloudflare.com>,
	kernel-team <kernel-team@cloudflare.com>,
	"Linux MM" <linux-mm@kvack.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Roman Gushchin" <guro@fb.com>, "Feng Tang" <feng.tang@intel.com>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Hillf Danton" <hdanton@sina.com>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Linus Torvalds" <torvalds@linux-foundation.org>
Subject: Re: Regression in workingset_refault latency on 5.15
Date: Fri, 25 Feb 2022 10:23:20 +0000	[thread overview]
Message-ID: <CA+wXwBRqGwSR+FYGfvxcpJD+bbh4GA7aCz9J1z213cQ_5k181g@mail.gmail.com> (raw)
In-Reply-To: <20220224185236.qgzm3jpoz2orjfcw@google.com>

On Thu, Feb 24, 2022 at 6:52 PM Shakeel Butt <shakeelb@google.com> 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 <dqminh@cloudflare.com> 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


  reply	other threads:[~2022-02-25 10:23 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 13:51 Daniel Dao
2022-02-23 15:57 ` Shakeel Butt
2022-02-23 16:00   ` Shakeel Butt
2022-02-23 17:07     ` Daniel Dao
2022-02-23 17:36       ` Shakeel Butt
2022-02-23 19:28         ` Ivan Babrou
2022-02-23 20:28           ` Shakeel Butt
2022-02-23 21:16             ` Ivan Babrou
2022-02-24 14:46               ` Daniel Dao
2022-02-24 16:58                 ` Shakeel Butt
2022-02-24 17:34                   ` Daniel Dao
2022-02-24 18:00                     ` Shakeel Butt
2022-02-24 18:52                       ` Shakeel Butt
2022-02-25 10:23                         ` Daniel Dao [this message]
2022-02-25 17:08                           ` Ivan Babrou
2022-02-25 17:22                             ` Shakeel Butt
2022-02-25 18:03                             ` Michal Koutný
2022-02-25 18:08                               ` Ivan Babrou
2022-02-28 23:09                                 ` Shakeel Butt
2022-02-28 23:34                                   ` Ivan Babrou
2022-02-28 23:43                                     ` Shakeel Butt
2022-03-02  0:48                                     ` Ivan Babrou
2022-03-02  2:50                                       ` Shakeel Butt
2022-03-02  3:40                                         ` Ivan Babrou
2022-03-02 22:33                                           ` Ivan Babrou
2022-03-03  2:32                                             ` Shakeel Butt
2022-03-03  2:35                                             ` Shakeel Butt
2022-03-04  0:21                                               ` Ivan Babrou
2022-03-04  1:05                                                 ` Shakeel Butt
2022-03-04  1:12                                                   ` Ivan Babrou
2022-03-02 11:49                                         ` Frank Hofmann
2022-03-02 15:52                                           ` Shakeel Butt
2022-03-02 10:08                                       ` Michal Koutný
2022-03-02 15:53                                         ` Shakeel Butt
2022-03-02 17:28                                           ` Ivan Babrou
2022-02-24  9:22 ` Thorsten Leemhuis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+wXwBRqGwSR+FYGfvxcpJD+bbh4GA7aCz9J1z213cQ_5k181g@mail.gmail.com \
    --to=dqminh@cloudflare.com \
    --cc=akpm@linux-foundation.org \
    --cc=feng.tang@intel.com \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=hdanton@sina.com \
    --cc=ivan@cloudflare.com \
    --cc=kernel-team@cloudflare.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=shakeelb@google.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox