Message ID | 20230323040037.2389095-7-yosryahmed@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2714098wrt; Wed, 22 Mar 2023 21:27:10 -0700 (PDT) X-Google-Smtp-Source: AK7set9oO15uXnDVEWjKpVDzEUZIIG+Kn+++kwAbw4vzOokmIwdvOSXRPxy9u8sVsLHSf7PNhh4x X-Received: by 2002:a17:906:80c2:b0:870:58ae:842e with SMTP id a2-20020a17090680c200b0087058ae842emr9165377ejx.24.1679545630327; Wed, 22 Mar 2023 21:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679545630; cv=none; d=google.com; s=arc-20160816; b=JjcVegaf5336Y4H5Vg+8lazM860HmmwrijwrCpuM0oNueJ+Bs8OOdSX7bpMChOwlTp A+vRjhvo8EsdbSUk4Zi5Xd+VG0pvJP3k7j4283I1mxJYR/eWdsIg81pJyL0wbFE6fiqm l1SzmmMcTaSMhw0JGehLeH0jQzUAdx2kKETiDb+vFbLtG20lQ/EMt/NO5LeebBCQKdS+ fZBT42C0eqaEYhlnorsf2ol0/aRKB1Q8rgK0U6DuWNuY0ao2/qtpnXNaOPV6gGWgE/gs hbxgbBAu0M6LP2mX3dig9vXwNgEBpNAOlj4tFSNb7dBCw3vI5UzBRwjhztwAA4uN5W5J Kkjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=DvW6z05yP1RDyGP7nq/4lgL3U4dF4JocmqCHP8QmZFKq2FhR/T/yeddYU2r/VmI2UE yB9mkpkctZg/D4zVYipwb4+Hia05pDdGIfuFfRAPd8LQWZkKQMXLEim+rIEejh0LOhDq cAsxuMdCDD2SsGNMQGLwIq8Bv2gtosyJs5yzqZNNSb7quxpxPqPRmYqE8Gm2wm0Z/PnW fKMW8M/LV01WLvgMGZIsX1knxnsgqbPBxdmn6CQF3HGi+ZYAaH8oKk0w94ZB+C1QRAy/ 3hHY/gPTms1U8iWEc1XB5tHXxBCeh8qP+cmVWXujQ9FeaNuDhhuqI0G69eltgRHyTIwx KzCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CYUJafqL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a170906795400b00933f92e9917si10665830ejo.371.2023.03.22.21.26.47; Wed, 22 Mar 2023 21:27:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CYUJafqL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbjCWEBS (ORCPT <rfc822;ezelljr.billy@gmail.com> + 99 others); Thu, 23 Mar 2023 00:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjCWEAy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 23 Mar 2023 00:00:54 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72F32CFD6 for <linux-kernel@vger.kernel.org>; Wed, 22 Mar 2023 21:00:52 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id b1-20020a17090a8c8100b002400db03706so332087pjo.0 for <linux-kernel@vger.kernel.org>; Wed, 22 Mar 2023 21:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679544052; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=CYUJafqLeSTzFoXixoXxJfg+d8a1R4JvCUerDh64ifDjpdaxbdbWqowybN/gvJ19LK Og473fSzkkpOeMA58DC64BMRm6M0MCGDM/VGSfHLkAlVcw8rDdEYpMTrVbzG7kCaO9yo XEy99SSbQbOpczsL5Zy04pgal2f5dv+k8luu/GDpUWQB1RZl9qYQhWpR8p3p3vD98PGc ce78QmYoavhlvFbHk6YMCQ65CM/lnXEYztj/xUq2pBOa3UnU3uBgApeimhahme8eLkyC CQZkL9MM7bPQMzx+6ozclKMKwr8T8qPF+ZR71Vewcxu4v3esM5hXIWD8hj0gOLxV+qOY L9ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679544052; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=0OdWIZXWG69ojLsWv+qKYE58VdO4AsnmylmhUc76hqlo4lef2r99wxipnYsAHgUIJ3 dNBWbhj9k8CVdi/VnOSX+hgIcnOHIdBpyY4L4VKuPF0+B+LBuFH2WTO3DqKw8TwnMSWo suAeGCz7YyQ9czuZBuPihOv07OEguyBSV2S93fuihiK9fr6rBjcJMNcNPpl74wlxH4WE 5PhtaU3CBBVtyoX8SaYARsKhwBcTgiXTKsflvXRRsAKOfWCwuIm3UaDucGqdbtFsxg9x I1kOWUcSdnqwTVS/YPU0M3LygLghuwHMUBvIGJ5MCz7+So2U1VgvurASD/A4Fjp8+oF7 rXKQ== X-Gm-Message-State: AO0yUKWVDqqVpuRBhtZB40AeZg3kZLCsZCxzFk1F30HVAMvpLqlWHl0H W4xBl1rK3tUA/mQ2gNxtmXiJOxtETXu9EOYl X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:ce11:b0:23f:d473:dd44 with SMTP id f17-20020a17090ace1100b0023fd473dd44mr1881490pju.3.1679544052257; Wed, 22 Mar 2023 21:00:52 -0700 (PDT) Date: Thu, 23 Mar 2023 04:00:36 +0000 In-Reply-To: <20230323040037.2389095-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230323040037.2389095-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230323040037.2389095-7-yosryahmed@google.com> Subject: [RFC PATCH 6/7] workingset: memcg: sleep when flushing stats in workingset_refault() From: Yosry Ahmed <yosryahmed@google.com> To: Tejun Heo <tj@kernel.org>, Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>, Zefan Li <lizefan.x@bytedance.com>, Johannes Weiner <hannes@cmpxchg.org>, Michal Hocko <mhocko@kernel.org>, Roman Gushchin <roman.gushchin@linux.dev>, Shakeel Butt <shakeelb@google.com>, Muchun Song <muchun.song@linux.dev>, Andrew Morton <akpm@linux-foundation.org> Cc: Vasily Averin <vasily.averin@linux.dev>, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, Yosry Ahmed <yosryahmed@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761131238755469835?= X-GMAIL-MSGID: =?utf-8?q?1761131238755469835?= |
Series |
Make rstat flushing IRQ and sleep friendly
|
|
Commit Message
Yosry Ahmed
March 23, 2023, 4 a.m. UTC
In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to
flush stats within an RCU read section and with sleeping disallowed.
Move the call to mem_cgroup_flush_stats_delayed() above the RCU read
section and allow sleeping to avoid unnecessarily performing a lot of
work without sleeping.
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
A lot of code paths call into workingset_refault(), so I am not
generally sure at all whether it's okay to sleep in all contexts or not.
Feedback here would be very helpful.
---
mm/workingset.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Comments
On Thu, Mar 23, 2023 at 04:00:36AM +0000, Yosry Ahmed wrote: > In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to > flush stats within an RCU read section and with sleeping disallowed. > Move the call to mem_cgroup_flush_stats_delayed() above the RCU read > section and allow sleeping to avoid unnecessarily performing a lot of > work without sleeping. > > Signed-off-by: Yosry Ahmed <yosryahmed@google.com> > --- > > A lot of code paths call into workingset_refault(), so I am not > generally sure at all whether it's okay to sleep in all contexts or not. > Feedback here would be very helpful. Yes, it's safe.
On Thu, Mar 23, 2023 at 04:00:36AM +0000, Yosry Ahmed wrote: > In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to > flush stats within an RCU read section and with sleeping disallowed. > Move the call to mem_cgroup_flush_stats_delayed() above the RCU read > section and allow sleeping to avoid unnecessarily performing a lot of > work without sleeping. > > Signed-off-by: Yosry Ahmed <yosryahmed@google.com> > --- > > A lot of code paths call into workingset_refault(), so I am not > generally sure at all whether it's okay to sleep in all contexts or not. > Feedback here would be very helpful. > > --- > mm/workingset.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/mm/workingset.c b/mm/workingset.c > index 042eabbb43f6..410bc6684ea7 100644 > --- a/mm/workingset.c > +++ b/mm/workingset.c > @@ -406,6 +406,8 @@ void workingset_refault(struct folio *folio, void *shadow) > unpack_shadow(shadow, &memcgid, &pgdat, &eviction, &workingset); > eviction <<= bucket_order; > > + /* Flush stats (and potentially sleep) before holding RCU read lock */ > + mem_cgroup_flush_stats_delayed(true); Btw, it might be a good time to rename this while you're in the area. delayed suggests this is using a delayed_work, but this is actually sometimes flushing directly from the callsite. What it's doing is ratelimited calls. A better name would be: mem_cgroup_flush_stats_ratelimited()
On Thu, Mar 23, 2023 at 8:50 AM Johannes Weiner <hannes@cmpxchg.org> wrote: > > On Thu, Mar 23, 2023 at 04:00:36AM +0000, Yosry Ahmed wrote: > > In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to > > flush stats within an RCU read section and with sleeping disallowed. > > Move the call to mem_cgroup_flush_stats_delayed() above the RCU read > > section and allow sleeping to avoid unnecessarily performing a lot of > > work without sleeping. > > > > Signed-off-by: Yosry Ahmed <yosryahmed@google.com> > > --- > > > > A lot of code paths call into workingset_refault(), so I am not > > generally sure at all whether it's okay to sleep in all contexts or not. > > Feedback here would be very helpful. > > Yes, it's safe. Thanks! That's very helpful!
On Thu, Mar 23, 2023 at 9:00 AM Johannes Weiner <hannes@cmpxchg.org> wrote: > > On Thu, Mar 23, 2023 at 04:00:36AM +0000, Yosry Ahmed wrote: > > In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to > > flush stats within an RCU read section and with sleeping disallowed. > > Move the call to mem_cgroup_flush_stats_delayed() above the RCU read > > section and allow sleeping to avoid unnecessarily performing a lot of > > work without sleeping. > > > > Signed-off-by: Yosry Ahmed <yosryahmed@google.com> > > --- > > > > A lot of code paths call into workingset_refault(), so I am not > > generally sure at all whether it's okay to sleep in all contexts or not. > > Feedback here would be very helpful. > > > > --- > > mm/workingset.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/mm/workingset.c b/mm/workingset.c > > index 042eabbb43f6..410bc6684ea7 100644 > > --- a/mm/workingset.c > > +++ b/mm/workingset.c > > @@ -406,6 +406,8 @@ void workingset_refault(struct folio *folio, void *shadow) > > unpack_shadow(shadow, &memcgid, &pgdat, &eviction, &workingset); > > eviction <<= bucket_order; > > > > + /* Flush stats (and potentially sleep) before holding RCU read lock */ > > + mem_cgroup_flush_stats_delayed(true); > > Btw, it might be a good time to rename this while you're in the > area. delayed suggests this is using a delayed_work, but this is > actually sometimes flushing directly from the callsite. > > What it's doing is ratelimited calls. A better name would be: > > mem_cgroup_flush_stats_ratelimited() Agreed. Will do in the next version.
diff --git a/mm/workingset.c b/mm/workingset.c index 042eabbb43f6..410bc6684ea7 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -406,6 +406,8 @@ void workingset_refault(struct folio *folio, void *shadow) unpack_shadow(shadow, &memcgid, &pgdat, &eviction, &workingset); eviction <<= bucket_order; + /* Flush stats (and potentially sleep) before holding RCU read lock */ + mem_cgroup_flush_stats_delayed(true); rcu_read_lock(); /* * Look up the memcg associated with the stored ID. It might @@ -461,9 +463,6 @@ void workingset_refault(struct folio *folio, void *shadow) lruvec = mem_cgroup_lruvec(memcg, pgdat); mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file, nr); - - /* Do not sleep with RCU lock held */ - mem_cgroup_flush_stats_delayed(false); /* * Compare the distance to the existing workingset size. We * don't activate pages that couldn't stay resident even if