Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7826139rwl; Thu, 23 Mar 2023 09:06:40 -0700 (PDT) X-Google-Smtp-Source: AK7set9ANZqjshMKti/odZw+yNw0ybuN8jcYq1Dm1BEyIHGr37ZKJ2gZmjgN3SFkT9DzLqyWcGWn X-Received: by 2002:aa7:8f33:0:b0:627:ecd4:84a5 with SMTP id y19-20020aa78f33000000b00627ecd484a5mr7190245pfr.14.1679587600077; Thu, 23 Mar 2023 09:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679587600; cv=none; d=google.com; s=arc-20160816; b=d9ug87wStvCd3lmBI3tTQFR/F39I91MoKCxo2vEQ0+rJCa8fXnvMhiu6vdZ+M8DIwy aK+bX1RTmGssOJjlpQ3ckwmwDVF+B7HF6y8IjI6QOmy689uwi31+gk4Coiww4wn9kiGw lDiYsdDWALRl4HejgnlePmUTZqV6Bnx/w7/4YEZqjOlfBNI4B+Gx2Jrijvjg4+/dxIZW eusFppqaC+pTsCxU69t6Xo5OJabYv2oAxtvHuRVuUm5cEIjXcd20Cc6bwfxxeJ/U64vW KkVpqwDuPBWU0YFvLbm57BtE9xDxAysrH8aQ2kjxwOjVJp5go21tllZLloXy4MEOPJGD uWtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xQQYR3tgoTZGjn44UlqD2Q/Bi/7ZZ0L1D2F+tNyu+vY=; b=yVtz+WMoBHXIVzGW8rfGyYIFvIPjKUCqTLTegxRTCjsLzqmCbjzOvttvRwpstpSh6W w+t4KbsyMrIl+N1qb3zdkcD/o0PZIrNm11oPLWOkNFjQ9iNP6JPKaLaXjzuQN5mmC+Ry ynyVK3FmF4lOkvYiJrUImcz+S6n94KOpbRRkG/v8NC0ecqIkLaDq/o4B25yTkLknMf7y KaNfAhGj+sIqQ6mt157RFK/GFEXQQdxzlEGiSnVderhCllRm7QOZxC58ShAFUCxlou5R 8BZYp5TduQPXRe58rJou0jNrcc0BUJVz/P5w1YNHCrBNX2ZUJd8hzWNnJ9llt7PS+XA8 cEAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=JUSYGg90; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a63e715000000b00503015b772asi16532948pgi.743.2023.03.23.09.06.21; Thu, 23 Mar 2023 09:06:40 -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=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=JUSYGg90; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232242AbjCWQAl (ORCPT + 99 others); Thu, 23 Mar 2023 12:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbjCWQAh (ORCPT ); Thu, 23 Mar 2023 12:00:37 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A167325941 for ; Thu, 23 Mar 2023 09:00:32 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id g19so1962418qts.9 for ; Thu, 23 Mar 2023 09:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; t=1679587231; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xQQYR3tgoTZGjn44UlqD2Q/Bi/7ZZ0L1D2F+tNyu+vY=; b=JUSYGg90JZTT6Yd13pjG6DLnrb2PDfmyEiLktcz2+MNdTX1qhs8SEmuA54OaIlpPJb DxtqFpASEbLE1v0MWbPxSyp5iJvz/cWT8oHdtMYHkFXPLcVCi5GYkPZurEN1bWPwQDzC weuJE2NJS7RteJovT2yARUM6DjWrj4KVVFVUPsqLMqvDhc6sSQI6Mvr+an7mCsZje+Ma HzcrGuLfySAPmUsyXVd3Jh0ih8mkd/t0KaiLpkyblfIp5tKl5BXeCDVIuYG91jK7wKEU fOndc7BtP6DmMZ+/1A5temMFZBDYv1b7xByaHD0exVuhFbacP6Sn5JBtcOlh09PvP/Ah bUrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679587231; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xQQYR3tgoTZGjn44UlqD2Q/Bi/7ZZ0L1D2F+tNyu+vY=; b=fcAXgwEO46r6jKvksuDyfpKnED43gIXEi3hAFCiAYWXm+JK2agT6i11d6DtcB+qduu ThEwT9eOMFKlvxNVJmMxwzPgO1a9tMn3ucJIjBsEShZne4Gx2OEIjTG4+enTFivvSY0W cMmbf8dqeb6EBgr8e3Mkhf6IEI+uq4Y96/nWI+IiZIeaeRsIi4H0W9NE66XBeohC6B0n G03aJdxzXmyfmC0x3Tfk5w381wAyLF3HmKqaC41BC/NUi1XkahHrNj8cH9TWkNFfMsfl qKAohkz8WUr3ZMA2s0wE8nhL2pmZw9IJlZXgF0ZT//UAAqh4VPk5mrjw+dcYVDNm8Z7o RecA== X-Gm-Message-State: AO0yUKW6VDgcN5QwrEFXykz8dzw/t4PGVFOH7/J5qvGHHqrv7xe1mjqx jXnfTfzmzp4y24lFjfQyNRgw1Q== X-Received: by 2002:a05:622a:182a:b0:3e3:90fa:c5d9 with SMTP id t42-20020a05622a182a00b003e390fac5d9mr5230973qtc.40.1679587231698; Thu, 23 Mar 2023 09:00:31 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:62db]) by smtp.gmail.com with ESMTPSA id j23-20020ac86657000000b003e0c29112b6sm7802610qtp.7.2023.03.23.09.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 09:00:31 -0700 (PDT) Date: Thu, 23 Mar 2023 12:00:30 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Vasily Averin , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org Subject: Re: [RFC PATCH 6/7] workingset: memcg: sleep when flushing stats in workingset_refault() Message-ID: <20230323160030.GD739026@cmpxchg.org> References: <20230323040037.2389095-1-yosryahmed@google.com> <20230323040037.2389095-7-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230323040037.2389095-7-yosryahmed@google.com> X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > > 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()