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 9FA0DC433FE for ; Mon, 7 Mar 2022 03:06:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 091E58D0002; Sun, 6 Mar 2022 22:06:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 042048D0001; Sun, 6 Mar 2022 22:06:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4BAE8D0002; Sun, 6 Mar 2022 22:06:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id D5F098D0001 for ; Sun, 6 Mar 2022 22:06:50 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A7D9122FD7 for ; Mon, 7 Mar 2022 03:06:50 +0000 (UTC) X-FDA: 79216102980.11.35BCDA9 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf19.hostedemail.com (Postfix) with ESMTP id 2B58A1A000B for ; Mon, 7 Mar 2022 03:06:50 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id z12-20020a17090ad78c00b001bf022b69d6so11762497pju.2 for ; Sun, 06 Mar 2022 19:06:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6ey8cLWo1tz1DNUd2Nc6hiH1KedMMgMlODqQQD3VlCY=; b=Qgt1K3fEyPBstauNxxmncR1jrHD3gM7mvcJt6hygrWjZtJ2/1ZSN/u3TE8NNG5RBx8 517BVk5U/KnYi/qULMblsVXoXv6URbi6qN/2VfdqHbiZf/fudYvnGqmJ/gdAe3U6M707 VXEdd5QoT7oF4cMDfmF+E/yaiGsOXtMzfD3+AdHFS61S3OGqaWg6creqk8G3EmqnZasD v9u6tFSwNiJSn6S3aIew0NTPkbvCZpOlGx+QmVJmflNmyknitM57bkNSkqkKHLWNr9ba elJx5NozxzqnDMTy/Us3/cwJ2ZAEYjgcRUuPogVF6SKXZt3PAge1AGeaxdcYor6Y+GuF Hjng== 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=6ey8cLWo1tz1DNUd2Nc6hiH1KedMMgMlODqQQD3VlCY=; b=QEzau7MWzDe19oapbf7jTaLCcrljGE04DHcQLrviGE9/77HJq8wdI80uA8c/ZgQ5ot eyngrPxSDocz8FLc/2Zk0zBtRYawXRaHDDe1dHMPrPPmzN+/5EMmZDrt+OWArhWuI5tl 6yeGv36y9VNgsa9cbLAsnl4QkZSJw1lHFBpNKrCfm1dA11/vL+6nU4y1buV57rmYWd2y q6hiDFkZIpxkWBPaPSD/flgrdzCbKy6zp+TLcB5d/sHYqZKs729nDUO7SeX1rDsWWuvz 98oOlb6hKKkkOi2aJQ0e1zYQBJLzuuHA3anUpZOuShwxQ4HCvpI6pr/JIq2uZ1LccZME JjPw== X-Gm-Message-State: AOAM533rvHFSa4nyRX0jjNndHK+8MzKyPX9k9SI1ljylQx8CV7cQnh/s NPKO7C/+4dSgk780Bce/D4bAp4MJPgMr2OmU9N3Eyw== X-Google-Smtp-Source: ABdhPJxRokqzFjtZhzZrl2YEdzw7kIjEpxRXVztns9i9QlzriHGNyrKZnBcLga6GFIe22xMSyT7ICvA5lpmsSH5UwtY= X-Received: by 2002:a17:902:e745:b0:151:5474:d3ed with SMTP id p5-20020a170902e74500b001515474d3edmr9762847plf.106.1646622408818; Sun, 06 Mar 2022 19:06:48 -0800 (PST) MIME-Version: 1.0 References: <20220304184040.1304781-1-shakeelb@google.com> <20220306184404.049447f8447d288fde34cabe@linux-foundation.org> In-Reply-To: <20220306184404.049447f8447d288fde34cabe@linux-foundation.org> From: Shakeel Butt Date: Sun, 6 Mar 2022 19:06:37 -0800 Message-ID: Subject: Re: [PATCH] memcg: sync flush only if periodic flush is delayed To: Andrew Morton Cc: =?UTF-8?Q?Michal_Koutn=C3=BD?= , Johannes Weiner , Michal Hocko , Roman Gushchin , Ivan Babrou , Frank Hofmann , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Daniel Dao , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2B58A1A000B X-Stat-Signature: q84ftjqex7cn7eg5osd1ehkhysau57et Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Qgt1K3fE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of shakeelb@google.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=shakeelb@google.com X-HE-Tag: 1646622410-334354 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Mar 6, 2022 at 6:44 PM Andrew Morton wrote: > > On Fri, 4 Mar 2022 18:40:40 +0000 Shakeel Butt wrote: > > > Daniel Dao has reported [1] a regression on workloads that may trigger > > a lot of refaults (anon and file). The underlying issue is that flushing > > rstat is expensive. Although rstat flush are batched with (nr_cpus * > > MEMCG_BATCH) stat updates, it seems like there are workloads which > > genuinely do stat updates larger than batch value within short amount of > > time. Since the rstat flush can happen in the performance critical > > codepaths like page faults, such workload can suffer greatly. > > > > This patch fixes this regression by making the rstat flushing > > conditional in the performance critical codepaths. More specifically, > > the kernel relies on the async periodic rstat flusher to flush the stats > > and only if the periodic flusher is delayed by more than twice the > > amount of its normal time window then the kernel allows rstat flushing > > from the performance critical codepaths. > > > > Now the question: what are the side-effects of this change? The worst > > that can happen is the refault codepath will see 4sec old lruvec stats > > and may cause false (or missed) activations of the refaulted page which > > may under-or-overestimate the workingset size. Though that is not very > > concerning as the kernel can already miss or do false activations. > > > > There are two more codepaths whose flushing behavior is not changed by > > this patch and we may need to come to them in future. One is the > > writeback stats used by dirty throttling and second is the deactivation > > heuristic in the reclaim. For now keeping an eye on them and if there is > > report of regression due to these codepaths, we will reevaluate then. > > > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > > > ... > > > > @@ -648,10 +652,16 @@ void mem_cgroup_flush_stats(void) > > __mem_cgroup_flush_stats(); > > } > > > > +void mem_cgroup_flush_stats_delayed(void) > > +{ > > + if (rstat_flush_time && time_after64(jiffies_64, flush_next_time)) > > rstat_flush_time isn't defined for me and my googling indicates this is > the first time the symbol has been used in the history of the world. > I'm stumped. > Oh sorry about that. I thought I renamed all instances of "rstat_flush_time" to "flush_next_time" before sending out the email. Please just remove "rstat_flush_time &&" from the if-condition. thanks, Shakeel