Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2275805pxm; Fri, 4 Mar 2022 12:55:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo8VoOA2MwUbkcmb9i58G33L5pELLcrkbHQTH1+ZkqYcPd7zrd61+tIstTgngR/8kRaIm4 X-Received: by 2002:a05:6a00:1950:b0:4f6:369b:4c4d with SMTP id s16-20020a056a00195000b004f6369b4c4dmr256500pfk.79.1646427305407; Fri, 04 Mar 2022 12:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646427305; cv=none; d=google.com; s=arc-20160816; b=i630l5x/iNj8zb69ISJ0/RCi6LB9m9ACv9rbD+E8k2YKGWt+xA8wXNvDD0t2qznaS6 B1ykX1p1ddLuFfTB84TeTSsZQBg6zH/RAIk6JxAKezoBPUS2HoeeKGtw68Yz3dTSyIh6 kZJoyVDR3FelqbbqFtjJ38pQxkoHMCq9J9FGtmmh5cBD4YClchJjjc1lkKUSuv/DoyLF vXBKF9WbVXTwdDsBAWh168pDj9w+4j68qNm1NjSPc94SqhtHNdixTQ+JT3NwzQWN5IuT G6tkkr8h2OzmzuBF7/RiFBsUMDycSI59TmooO8cSsRB/Os3Q9wA8UvWmeioJo6NyZcZh ssTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=bEOxM9dCTwOgx3v/sybpuLomdOANvZM0pQSflYOHu1w=; b=ot1grodlvmnHmUQIRgb9vtEG94ex1ofahOb8f4r1a/mY1yhI+hSlEXJur3/GESFjN5 hkYgnxgFO2Pla65FDLQdwHHyenmNxTcgSu+Tnvs+CJ1ingVz2zP4ISM0k1QtZm26cFNj cnVM95pZrvA2v77UHgc22XjBvUEpShh791HgP/yCc+MJpANQNFVltbwuX7AuadkFHIhd VAr/Vwi4VapltKGNOLxW8+kcUuVy8YDCtlm+9H9C/l5ULK2qAIJgTX8c20W1nyS5qfnw uPipN1J5WgEPXSJYJGJWANcOWArjb9QecTCCU4aSfczcQRq66lOGQc5aveb/fx6No5ph DxtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=i652L4F2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h7-20020a056a001a4700b004e1bb6519e7si6032922pfv.76.2022.03.04.12.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:55:05 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=i652L4F2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2CF2527D113; Fri, 4 Mar 2022 11:49:10 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241878AbiCDSyX (ORCPT + 99 others); Fri, 4 Mar 2022 13:54:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbiCDSyU (ORCPT ); Fri, 4 Mar 2022 13:54:20 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D1D1BD04D for ; Fri, 4 Mar 2022 10:53:32 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id z30so5827642ybi.2 for ; Fri, 04 Mar 2022 10:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bEOxM9dCTwOgx3v/sybpuLomdOANvZM0pQSflYOHu1w=; b=i652L4F2GnSj5foPdKPemlgr6xx94ua5Ic9XEX8NWr98rE/J8kp3lucWhLtM4AOES3 T9r1sjUabt2iScIDVpUdwI7AvcDZFK6NUnb+i966anXeK79MKuuIqPU7cQfPEN83otOC mKwkhFqmQ0lI9vTrYAN1FaKXTRwQdjLTY1yTk= 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=bEOxM9dCTwOgx3v/sybpuLomdOANvZM0pQSflYOHu1w=; b=uFBaPYnCScUil39kAQ2FL0jZSXpYUn0vnQg3iI+LoIaaB0B2e5jFu93ootydc3i7hA c1oY7z5pK10+Cfy/T6N2Qw7aFYLfUyUGcpc5t6Mnn6Iv/Ee7NQE4uIlRWfuKu3YqJLtR QyItwilzIEd8njWkxNlu11tqJqkAE37yb2Sgv728gBIPAKBrfuFwfIzOdXOUg9DSgDNw PMX/sHmXYMzmvoOuaF86Od9QjbqlSIL6k6I7kuApJtLjBaXYSwWticH4ZSELUK4B34YT ih5Lady4cuyLGGLcw5uGhiX7IB0Da3MfscaP65bXvNuWkARgCk42WbKtHY2+wg0nH7RL S9/A== X-Gm-Message-State: AOAM530NiYQTYv2FiaFPeuohB/v8ZyJD5hlBalkZrY9+jbVitY+KEPp2 7YGrUeW1iwC/Oac0wg9pcmCCH5MDddG9tedRjTYeqQ== X-Received: by 2002:a25:bc8:0:b0:628:80d9:526c with SMTP id 191-20020a250bc8000000b0062880d9526cmr17661448ybl.115.1646420011206; Fri, 04 Mar 2022 10:53:31 -0800 (PST) MIME-Version: 1.0 References: <20220304184040.1304781-1-shakeelb@google.com> In-Reply-To: <20220304184040.1304781-1-shakeelb@google.com> From: Ivan Babrou Date: Fri, 4 Mar 2022 10:53:20 -0800 Message-ID: Subject: Re: [PATCH] memcg: sync flush only if periodic flush is delayed To: Shakeel Butt Cc: =?UTF-8?Q?Michal_Koutn=C3=BD?= , Johannes Weiner , Michal Hocko , Roman Gushchin , Frank Hofmann , Andrew Morton , cgroups@vger.kernel.org, Linux MM , linux-kernel , Daniel Dao , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Fri, Mar 4, 2022 at 10:40 AM 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. > > Link: https://lore.kernel.org/all/CA+wXwBSyO87ZX5PVwdHm-=dBjZYECGmfnydUicUyrQqndgX2MQ@mail.gmail.com [1] > Fixes: 1f828223b799 ("memcg: flush lruvec stats in the refault") > Signed-off-by: Shakeel Butt > Reported-by: Daniel Dao > Cc: > --- See my testing results here: https://lore.kernel.org/linux-mm/CABWYdi2usrWOnOnmKYYvuFpE=yJmgtq4a7u6FiGJGJkskv+eVQ@mail.gmail.com/ Tested-by: Ivan Babrou