Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2424164rwi; Tue, 11 Oct 2022 08:36:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wNvo/FhtNEWgVtWxo71o/MZkns2VJw0knAn1gje0LgbNl8TuvgU40dZUZV6QJ7nWc9gte X-Received: by 2002:a17:903:2490:b0:17f:bf7e:c521 with SMTP id p16-20020a170903249000b0017fbf7ec521mr23868772plw.161.1665502551404; Tue, 11 Oct 2022 08:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665502551; cv=none; d=google.com; s=arc-20160816; b=zWQiRzHZ2ZJuMomCrXwW1Laui5JEQWu9wk3F2a7riByPk6XugnIDo0JEw8SD+d9NHP NHeBXEqA42WCcdRdAv9bhMOtJwP8eiN3OXUPRZT5IJ1o77D1GFiZwqWg2c1HRmhI/MRg ZkK95jqr/BXpGzFx5ahvtKonwC+ztNFLs5qkn7AkEH5cBdN33nvMiAWWwKEy+rrYMABj zCYw96tgCp98lnfoX/qaW4OBB4UorT+Vgu0tGKEJCqVjK44BwY1WuPertGEYcAIDPWdF XQCh3BOElos9plBmr04NZ0NCLsX29rwt5tXu7fmFQVsND5iBOWX2XJDor0lvyXsktsFA VLpw== 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=4/tx5Hg2EBXygF2G8xfjAkH7UAOIXn21J5RskYrkmds=; b=AFijq6vJKEgQWdHnONJBBaxJ0Itl2UJ75TKeqxzokfw9rBFbRlrg//WRlBHsrZuhcp xux2TL8ZcvpmuraCwyCrIgjE3FCmCyH5xRUh7J4PPiQsShP5ZKyi0IsCMeF3AHBO24Es sJqNl6YfOmDkJMNRbxaUDVoM+dNtQDx8wzb8m5EdFzL8v6hqs+i6BYqK3Qv+LmjjPJFQ T2WqiaKejluvis8T+qV780W3c0p7VpUcn8HegSuAntuB37reWMir5aHvMW9c/yC30LgI 4P9g0iLQyMyRZHVPS1wDwimKMgyiTbDGQ/uKMNp2r1f2v5n+3KjzZp/qs1lbzKgfxxjb bnsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OsVCvCDw; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22-20020a621a16000000b00562f45512fasi12154804pfa.322.2022.10.11.08.35.38; Tue, 11 Oct 2022 08:35:51 -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=@redhat.com header.s=mimecast20190719 header.b=OsVCvCDw; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiJKObE (ORCPT + 99 others); Tue, 11 Oct 2022 10:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiJKObA (ORCPT ); Tue, 11 Oct 2022 10:31:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8CB62929 for ; Tue, 11 Oct 2022 07:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665498657; 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=4/tx5Hg2EBXygF2G8xfjAkH7UAOIXn21J5RskYrkmds=; b=OsVCvCDw7SlsXQpLxEG3pciT3m1hOPS4l8PRDTCXiIoIBXHiV52OBYPR5ZhpyxyMFT6sZR QNW2AFSUB1+jv6S4tj7q748aGLVDHowW+a7lcc+gKpyRwcxlUUkojlNH4Q0OUhYEaBPZzE UUA19GcwUnWb4vDFru06/x39e8Z959M= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-275-SvpcsVCvNv6sGp-hOHfwnQ-1; Tue, 11 Oct 2022 10:30:55 -0400 X-MC-Unique: SvpcsVCvNv6sGp-hOHfwnQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0657B382ECCD; Tue, 11 Oct 2022 14:30:55 +0000 (UTC) Received: from llong.com (unknown [10.22.17.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EA0040E9920; Tue, 11 Oct 2022 14:30:54 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Tejun Heo , Chris Down , Waiman Long Subject: [PATCH] mm/memcontrol: Don't increase effective low/min if no protection needed Date: Tue, 11 Oct 2022 10:30:15 -0400 Message-Id: <20221011143015.1152968-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 Since commit bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations"), the effective low/min protections can be non-zero even if the corresponding memory.low/min values are 0. That can surprise users to see MEMCG_LOW events even when the memory.low value is not set. One example is the LTP's memcontrol04 test which fails because it detects some MEMCG_LOW events for a cgroup with a memory.min value of 0. Fix this by updating effective_protection() to not returning a non-zero low/min protection values if the corresponding memory.low/min values or those of its parent are 0. Fixes: bc50bcc6e00b ("mm: memcontrol: clean up and document effective low/min calculations") Signed-off-by: Waiman Long --- mm/memcontrol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b69979c9ced5..893d4d5e518a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6660,6 +6660,9 @@ static unsigned long effective_protection(unsigned long usage, unsigned long protected; unsigned long ep; + if (!setting || !parent_effective) + return 0UL; /* No protection is needed */ + protected = min(usage, setting); /* * If all cgroups at this level combined claim and use more -- 2.31.1