From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DA15C3600C for ; Fri, 4 Apr 2025 01:25:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89D406B0024; Thu, 3 Apr 2025 21:25:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8441E6B0026; Thu, 3 Apr 2025 21:25:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F0A06B0025; Thu, 3 Apr 2025 21:25:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4E57E6B0022 for ; Thu, 3 Apr 2025 21:25:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 358EC1619D8 for ; Fri, 4 Apr 2025 01:25:10 +0000 (UTC) X-FDA: 83294617980.04.7478AB6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 59EBA4000A for ; Fri, 4 Apr 2025 01:25:08 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="aK4VrS/P"; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743729908; a=rsa-sha256; cv=none; b=0xAh7iCRprXzH5HcVkwYsXve2rHtjmN2WyMzaMJ3T1gTvBLS35lLQjUf3gpVJhYcgS+5oD rGFKmyrJ6PD98YpzriRpRXFXv9N/XFlCHmzhyBQ1Uz8vkZvofNxBeZchPlBvsCvjWK8W8K ooOnfpNT6sBIgIpKNEydFTRCKyKFk4M= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="aK4VrS/P"; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743729908; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=eeDF4dFIWOS0DFmcqcZYB3wJsohtT8Hr0IIadggs/8c=; b=MPSG4kBPpNrZux2mzegWnvES2Z7ZeE3yBLVGUD7ILON6mSKOwJow63ZXgCg6PvvRtiTgxX W62BqTatq2Tbmp1qW74/Vqee42O2pDTND//5molAcLcjlGSa6zKqxuBRah4U+rfotZ8qHH UjisdSGqgc/0en4rcidJbBCaF450eM4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743729907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=eeDF4dFIWOS0DFmcqcZYB3wJsohtT8Hr0IIadggs/8c=; b=aK4VrS/Pu73xwESGR6IYpRb0OZAjxcO8LXJsazfhrSRiiIjU10DUH+phWyzux5VHzlBxoa EjwtgbQRCAaULOfAuOQ5ZVw/ONu38+6FasdGn2oD18PvxZBk/fD889nA8jRQRqlJP4GxPg 55mGyPBYB169SHEbaCNMUDbB2RujMn8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-qnvY40IQO2C4Esh2un-iuA-1; Thu, 03 Apr 2025 21:25:00 -0400 X-MC-Unique: qnvY40IQO2C4Esh2un-iuA-1 X-Mimecast-MFC-AGG-ID: qnvY40IQO2C4Esh2un-iuA_1743729898 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCD5C1956089; Fri, 4 Apr 2025 01:24:57 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.89.4]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B1B3180B489; Fri, 4 Apr 2025 01:24:54 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Tejun Heo , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Waiman Long Subject: [PATCH v2 1/2] memcg: Don't generate low/min events if either low/min or elow/emin is 0 Date: Thu, 3 Apr 2025 21:24:34 -0400 Message-ID: <20250404012435.656045-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 59EBA4000A X-Stat-Signature: oje7dny4y79zh5cweeij4ra7p5u4hek9 X-Rspam-User: X-HE-Tag: 1743729908-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laQB3YXJJ4Sx/HYhLP2zL8xT56hNVdCOgZHOY/GFGuBnTv7Kctna5cJ6LPtWlqyj6EX2VGStXeczz1WN2WN3GtNjBTEmoohhUOW33MwfgbkSSIHsMtl0NnC31J9ZJ9906IrLeY5B6lggNhalAaFN99JPeQIrcBE/FyHshOeH4tnXL9UFAtT69d3QPWWPvmmSOn80H8FbonvqhSdF4aR9V3TTfoRfg33JrMRYIrpxBsuKYAN9wEQZ0LSHHE8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The test_memcontrol selftest consistently fails its test_memcg_low sub-test due to the fact that two of its test child cgroups which have a memmory.low of 0 or an effective memory.low of 0 still have low events generated for them since mem_cgroup_below_low() use the ">=" operator when comparing to elow. The two failed use cases are as follows: 1) memory.low is set to 0, but low events can still be triggered and so the cgroup may have a non-zero low event count. I doubt users are looking for that as they didn't set memory.low at all. 2) memory.low is set to a non-zero value but the cgroup has no task in it so that it has an effective low value of 0. Again it may have a non-zero low event count if memory reclaim happens. This is probably not a result expected by the users and it is really doubtful that users will check an empty cgroup with no task in it and expecting some non-zero event counts. The simple and naive fix of changing the operator to ">", however, changes the memory reclaim behavior which can lead to other failures as low events are needed to facilitate memory reclaim. So we can't do that without some relatively riskier changes in memory reclaim. Another simpler alternative is to avoid reporting below_low failure if either memory.low or its effective equivalent is 0 which is done by this patch specifically for the two failed use cases above. With this patch applied, the test_memcg_low sub-test finishes successfully without failure in most cases. Though both test_memcg_low and test_memcg_min sub-tests may still fail occasionally if the memory.current values fall outside of the expected ranges. To be consistent, similar change is appled to mem_cgroup_below_min() as to avoid the two failed use cases above with low replaced by min. Signed-off-by: Waiman Long --- include/linux/memcontrol.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 53364526d877..4d4a1f159eaa 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -601,21 +601,31 @@ static inline bool mem_cgroup_unprotected(struct mem_cgroup *target, static inline bool mem_cgroup_below_low(struct mem_cgroup *target, struct mem_cgroup *memcg) { + unsigned long elow; + if (mem_cgroup_unprotected(target, memcg)) return false; - return READ_ONCE(memcg->memory.elow) >= - page_counter_read(&memcg->memory); + elow = READ_ONCE(memcg->memory.elow); + if (!elow || !READ_ONCE(memcg->memory.low)) + return false; + + return page_counter_read(&memcg->memory) <= elow; } static inline bool mem_cgroup_below_min(struct mem_cgroup *target, struct mem_cgroup *memcg) { + unsigned long emin; + if (mem_cgroup_unprotected(target, memcg)) return false; - return READ_ONCE(memcg->memory.emin) >= - page_counter_read(&memcg->memory); + emin = READ_ONCE(memcg->memory.emin); + if (!emin || !READ_ONCE(memcg->memory.min)) + return false; + + return page_counter_read(&memcg->memory) <= emin; } int __mem_cgroup_charge(struct folio *folio, struct mm_struct *mm, gfp_t gfp); -- 2.48.1