Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp362807pxb; Wed, 23 Mar 2022 20:41:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmWyB+LVOLGpJIqRqAVar8SrXEfHjvxxkcbkimJHOcaT5NCVzIDiN5dLqlhzDnaqYB9847 X-Received: by 2002:a17:903:40c4:b0:154:a24b:d1e7 with SMTP id t4-20020a17090340c400b00154a24bd1e7mr3604875pld.27.1648093288282; Wed, 23 Mar 2022 20:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648093288; cv=none; d=google.com; s=arc-20160816; b=Kr8KEbeQplgvjHWLw+vswlfVtP/rxPSy5lFj1SUDqf/vxWbxyXN0E8CsCHymoIvK+2 TsjZQLfDuzhLzmZ4XoUmWLx+NHe1uXHmYyHak+YDEPWwA9O7gHiJOSzQFGr9tPccm/Qh v/a88v2LqAdLYmqgPmjU+JFoPNapxT1b7czIlS+zxQdBfP1ijnuk1pDnpYPJw0AOGMEW GXgFyzDMQHpB/31EMXNf+hu9Vfk8S8I21yjj1BOF2UTzudKBJnhS8n0/LSFZ40C4vUgr 5Avt9u9FjWmDtvZwVciXGrl7C9H6cZHEN7Q+wkEEJ56Cp67UeJjkyfRraV1yU+2AWSbn dDXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=jKxuo3tSnTqh2UAPL1+VAIp6n+IcAR/qJqwZEPA/Ep0=; b=qYzznuTlZeXJYGV2JOq20GSTNN8LBc+O/myQ7cb8OMJqbiBqd2sOaSpg49PRyDUyFJ rDPmxCgYnAs4Xa854eUil0YCLEOMslKTBQofXEO0po1e1P/6d0PO6+n7eXPXxnWjTiZL t6ip6C6biHqO7IiTDJcLOifClb2iSCWxjW5A2hp/x+6+JlpFDAubpAoQ4PmH2h0UuuCo Hv4iXa3AoRtMWcHB79NTVh+BIFAqUg7dZbKZ8f5MYnZ2bQ07/WmOpMNCtITuHUIQoMhB UPOAKazOcz1TK7GjLyqOY/ADzyaBALfXK7SLoTNLSKYRo1mgWoQNCjQ1sUIfuLuBcOTk Xu5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pejEAflb; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a056a00072d00b004fa3a8e0001si15192226pfm.184.2022.03.23.20.40.52; Wed, 23 Mar 2022 20:41:28 -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=@suse.com header.s=susede1 header.b=pejEAflb; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240298AbiCVSY5 (ORCPT + 99 others); Tue, 22 Mar 2022 14:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240281AbiCVSYz (ORCPT ); Tue, 22 Mar 2022 14:24:55 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184CC1E3F2; Tue, 22 Mar 2022 11:23:13 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A8818210E9; Tue, 22 Mar 2022 18:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1647973391; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jKxuo3tSnTqh2UAPL1+VAIp6n+IcAR/qJqwZEPA/Ep0=; b=pejEAflbD21zArvB8wKtKlgVaGQeoKrHBbjaNQ+yMhdLHxpcZ5nSjgpEPiuPF3IwpPCuTN kdOtpj5t1Kj+d0NpiDAtZwrchSIQpMrEws2qmz681mePvSYG9jyO1PXoABxfa1eApIX/gQ v3p8YpFlcSdFbFKNVSoUFV6FpkRp080= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0AF82133B6; Tue, 22 Mar 2022 18:23:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sIFvAQ8UOmLwGwAAMHmgww (envelope-from ); Tue, 22 Mar 2022 18:23:11 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Richard Palethorpe , Andrew Morton , Shakeel Butt , Roman Gushchin , Michal Hocko , Vlastimil Babka , "Matthew Wilcox (Oracle)" , Muchun Song , Johannes Weiner , Yang Shi , Suren Baghdasaryan , Tejun Heo , Chris Down Subject: [RFC PATCH] mm: memcg: Do not count memory.low reclaim if it does not happen Date: Tue, 22 Mar 2022 19:22:48 +0100 Message-Id: <20220322182248.29121-1-mkoutny@suse.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 This was observed with memcontrol selftest/new LTP test but can be also reproduced in simplified setup of two siblings: `parent .low=50M ` s1 .low=50M .current=50M+ε ` s2 .low=0M .current=50M The expectation is that s2/memory.events:low will be zero under outer reclaimer since no protection should be given to cgroup s2 (even with memory_recursiveprot). However, this does not happen. The apparent reason is that when s1 is considered for (proportional) reclaim the scanned proportion is rounded up to SWAP_CLUSTER_MAX and slightly over-proportional amount is reclaimed. Consequently, when the effective low value of s2 is calculated, it observes unclaimed parent's protection from s1 (ε-SWAP_CLUSTER_MAX in theory) and effectively appropriates it. The effect is slightly regularized protection (workload dependent) between siblings and misreported MEMCG_LOW event when reclaiming s2 with this protection. Fix the behavior by not reporting breached memory.low in such situations. (This affects also setups where all siblings have memory.low=0, parent's memory.events:low will still be non-zero when parent's memory.low is breached but it will be reduced by the events originated in children.) Fixes: 8a931f801340 ("mm: memcontrol: recursive memory.low protection") Reported-by: Richard Palethorpe Link: https://lore.kernel.org/all/20220321101429.3703-1-rpalethorpe@suse.com/ Signed-off-by: Michal Koutný --- include/linux/memcontrol.h | 8 ++++---- mm/vmscan.c | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) Why is this RFC? 1) It changes number of events observed on parent/memory.events:low (especially for truly recursive configs where all children specify memory.low=0). IIUC past discussions about equality of all-zeros and all-infinities, those eagerly reported MEMCG_LOW events (in latter case) were deemed skewing the stats [1]. 2) The observed behavior slightly impacts distribution of parent's memory.low. Constructed example is a passive protected workload in s1 and active in s2 (active ~ counteracts the reclaim with allocations). It could strip protection from s1 one by one (one:=SWAP_CLUSTER_MAX/2^sc.priority). That may be considered both wrong (s1 should have been more protected) or correct s2 deserves protection due to its activity. I don't have (didn't collect) data for this, so I think just masking the false events is sufficient (or independent). [1] https://lore.kernel.org/r/20200221185839.GB70967@cmpxchg.org diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 0abbd685703b..99ac72e00bff 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -626,13 +626,13 @@ static inline bool mem_cgroup_supports_protection(struct mem_cgroup *memcg) } -static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) +static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg, bool effective) { if (!mem_cgroup_supports_protection(memcg)) return false; - return READ_ONCE(memcg->memory.elow) >= - page_counter_read(&memcg->memory); + return page_counter_read(&memcg->memory) <= (effective ? + READ_ONCE(memcg->memory.elow) : READ_ONCE(memcg->memory.low)); } static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg) @@ -1177,7 +1177,7 @@ static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root, { } -static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) +static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg, bool effective) { return false; } diff --git a/mm/vmscan.c b/mm/vmscan.c index 59b14e0d696c..3bdb35d6bee6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3152,7 +3152,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) * If there is no reclaimable memory, OOM. */ continue; - } else if (mem_cgroup_below_low(memcg)) { + } else if (mem_cgroup_below_low(memcg, true)) { /* * Soft protection. * Respect the protection only as long as @@ -3163,7 +3163,8 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) sc->memcg_low_skipped = 1; continue; } - memcg_memory_event(memcg, MEMCG_LOW); + if (mem_cgroup_below_low(memcg, false)) + memcg_memory_event(memcg, MEMCG_LOW); } reclaimed = sc->nr_reclaimed; -- 2.35.1