Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4868007rwl; Tue, 28 Mar 2023 12:30:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7AQNSxhhvWyhHs9B2ZoCuHIYWCT6pPPwdPIfYIo5n6XBd8SRRQ9jgCMWcyRfYFfZB0Yr0 X-Received: by 2002:a17:902:ea0c:b0:19f:36b1:c35 with SMTP id s12-20020a170902ea0c00b0019f36b10c35mr20520682plg.64.1680031802449; Tue, 28 Mar 2023 12:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680031802; cv=none; d=google.com; s=arc-20160816; b=yiCsm9KeEE5RFuIGuiclWxeBCEYxaKufUpE2ckSgy0DH2k4YdKkeRNtokBNJMv8z3l sSrJ91OPNOlIXfBSVRvDw6nPeaPal42qizZwsRGzogxEpDnRFjgvf7t1JxwOHG3FjQ7F Akc6Fg7yJ3GDQizk5QtgOApYBeXbc1B+SmtBDUiRsx8oTXbFuaHDnQP2BxJzICekzdN/ 4XeVv9hUemSkte4YsOfdRlCLMXFPP/kwI7aIgoVzZRtNjA84Ozie0ltjCY0t/N785NJY Dk9lj+2VfObiVbkF8D7SNJY7l+arHEqbPpaYvUnpBnRMVaFZekaQ8bMUUKp05s1PpUVL Sy0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=mXQXsZqlBT+IvrC1SlejLvJwmsFqvbFWj1xTrESNOYw=; b=YvPkvaKSF60xhFpI3EXQYyaCpmSsV4Oj9M/gZrB4rcsdronHT+7Wnlyuw2tUfxcSmj e0V0mTABt+rsHAi0Vg0/YlVORNGn9UIBMYA7ElGVxq6uxodOeUlvBHMMmE/dQYQzzyBb 3lAqkEWODa6+oEqA3ly7c9cGMdNGQcjDVKrWOQs4lV8Q++VOC9+uB1EOxwDCFYKwGjZw ecaAubSKdApQf2IudkFyD1RVR/kkEG1rb7qynXpwsURSqFnjtrj4/ojdkL3tb3c3ydBE Mvf+AR70DVjx3IUIyRiWDXpWQElnFGVpJAvbgV7jXz7TleYnxZoNaqVntwMx9SSSTBbZ 3Uow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CknRXyRU; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l185-20020a6388c2000000b0050f1157c4e3si26853340pgd.867.2023.03.28.12.29.51; Tue, 28 Mar 2023 12:30:02 -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=CknRXyRU; 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 S229708AbjC1T0m (ORCPT + 99 others); Tue, 28 Mar 2023 15:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjC1T0k (ORCPT ); Tue, 28 Mar 2023 15:26:40 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C7C30F1 for ; Tue, 28 Mar 2023 12:26:38 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id eh3so53986610edb.11 for ; Tue, 28 Mar 2023 12:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680031597; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mXQXsZqlBT+IvrC1SlejLvJwmsFqvbFWj1xTrESNOYw=; b=CknRXyRUtdGTwn5BeQWmVKT7SMD2819Xs8pLx5U4MGjre+MnImaICr8wSz9TGbOWC9 mVV1DZsNNCBwQc7YRWY/4N5hWGHjFAG4IBa2FO35XMRs2SQWu406qZl/OOAMaxMO3pqF UvlmTwbzzKtXz4FgENrQqQ1zWe3cDhXwJOwPFHqAfE1Vk2R9GD+1j3doH0DabaJ8EwPs kEMdmTlfozsQAlMhCy8ia1T3+1fUt8rGhUogVpJR+7XhEyMrvUiyCF3WtjzuSe3DyYnx IEBXT1pgM8v+EXEXYeb2OBk7LR1PCsjNlNs5qRde5KW9n23G6cBqdlRh0qNxHsDqBnGd cFLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680031597; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mXQXsZqlBT+IvrC1SlejLvJwmsFqvbFWj1xTrESNOYw=; b=m9XZnQC4vOEjtUCMyZkVWh0byZonvWdA02NvWnJ9e3DGynB1KyXgBUapBHxakU4729 CU5VzGdTJipBKgxfl1QOvgSlJuc9PXnkHNHxJNxoDtna4yIXRR+N5cvcg8RvTM0frPqE 80OZ6RssOlsnCxiZV/ovZl8mNRl1c+JSfjPjE/DzoPTbH6pXvTJcv5QCD9uH1Efh9FAy eCreEOCxuvw3ShWGrLu1h0+uKVk8HcZ4uf61n4y7onb1sz2CdstTs1nSzb6RVbmS8267 zjwYvxK2oVcZujFLMpmWJlrojUHRrJSyaASr1T98cwzs/YOKYBDy6wK4z3BY1uJzv/FZ D2ew== X-Gm-Message-State: AAQBX9dYTeoRvnLon3lZgtvr+AAugoNx0phScGQUlLaIPcYtpS68oAmx RHt4bsJ104BYsxvv8sfeV2s3Yfwokyy/AiXrFFixJw== X-Received: by 2002:a17:907:1c09:b0:92f:b329:cb75 with SMTP id nc9-20020a1709071c0900b0092fb329cb75mr10558404ejc.5.1680031597358; Tue, 28 Mar 2023 12:26:37 -0700 (PDT) MIME-Version: 1.0 References: <20230328061638.203420-1-yosryahmed@google.com> <20230328061638.203420-7-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 28 Mar 2023 12:26:01 -0700 Message-ID: Subject: Re: [PATCH v1 6/9] memcg: sleep during flushing stats in safe contexts To: Johannes Weiner Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Vasily Averin , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 28, 2023 at 12:06=E2=80=AFPM Johannes Weiner wrote: > > On Tue, Mar 28, 2023 at 11:45:19AM -0700, Yosry Ahmed wrote: > > On Tue, Mar 28, 2023 at 11:35=E2=80=AFAM Johannes Weiner wrote: > > > On Tue, Mar 28, 2023 at 06:16:35AM +0000, Yosry Ahmed wrote: > > > > void mem_cgroup_flush_stats_ratelimited(void) > > > > { > > > > if (time_after64(jiffies_64, READ_ONCE(flush_next_time))) > > > > - mem_cgroup_flush_stats(); > > > > + mem_cgroup_flush_stats_atomic(); > > > > +} > > > > > > This should probably be mem_cgroup_flush_stats_atomic_ratelimited(). > > > > > > (Whee, kinda long, but that's alright. Very specialized caller...) > > > > It should, but the following patch makes it non-atomic anyway, so I > > thought I wouldn't clutter the diff by renaming it here and then > > reverting it back in the next patch. > > > > There is an argument for maintaining a clean history tho in case the > > next patch is reverted separately (which is the reason I put it in a > > separate patch to begin with) -- so perhaps I should rename it here to > > mem_cgroup_flush_stats_atomic_ratelimited () and back to > > mem_cgroup_flush_stats_ratelimited() in the next patch, just for > > consistency? > > Sounds good to me. It's pretty minor churn. Ack. Will do so for v2. Thanks! > > > > Btw, can you guys think of a reason against moving the threshold chec= k > > > into the common function? It would then apply to the time-limited > > > flushes as well, but that shouldn't hurt anything. This would make th= e > > > code even simpler: > > > > I think the point of having the threshold check outside the common > > function is that the periodic flusher always flushes, regardless of > > the threshold, to keep rstat flushing from critical contexts as cheap > > as possible. > > Good point. Yeah, let's keep it separate then. Agreed. > > > > > @@ -2845,7 +2845,7 @@ static void prepare_scan_count(pg_data_t *pgd= at, struct scan_control *sc) > > > > * Flush the memory cgroup stats, so that we read accurate pe= r-memcg > > > > * lruvec stats for heuristics. > > > > */ > > > > - mem_cgroup_flush_stats(); > > > > + mem_cgroup_flush_stats_atomic(); > > > > > > I'm thinking this one could be non-atomic as well. It's called fairly > > > high up in reclaim without any locks held. > > > > A later patch does exactly that. I put making the reclaim and refault > > paths non-atomic in separate patches to easily revert them if we see a > > regression. Let me know if this is too defensive and if you'd rather > > have them squashed. > > No, good call. I should have just looked ahead first :-)