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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56FEAC54FD0 for ; Fri, 24 Apr 2020 13:44:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 134BB20728 for ; Fri, 24 Apr 2020 13:44:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="reMptdcU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 134BB20728 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B5DF38E0006; Fri, 24 Apr 2020 09:44:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B34988E0003; Fri, 24 Apr 2020 09:44:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A725F8E0006; Fri, 24 Apr 2020 09:44:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id 8CF668E0003 for ; Fri, 24 Apr 2020 09:44:41 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4E0C08248068 for ; Fri, 24 Apr 2020 13:44:41 +0000 (UTC) X-FDA: 76742868762.01.pets82_8027eb1d69528 X-HE-Tag: pets82_8027eb1d69528 X-Filterd-Recvd-Size: 5366 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 13:44:40 +0000 (UTC) Received: by mail-qv1-f65.google.com with SMTP id p13so4619261qvt.12 for ; Fri, 24 Apr 2020 06:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GrqwkdFthEBqmV0EtTHQbF1VPg6uCI8XEJMKDMyh0as=; b=reMptdcUfkhPGshqy/6RnWXmeBSTBbug+imnrttfwdK9Hn4aguqliKLxiDTGrHrDQM cQjXw8N9UR8VQ/kwgXPM0DIoQlqb4sE3ECXBCSxfa2MpQEvK2HiAAHhxf3c8Jg135rS3 QyGI2hkWzBs8j7O9dy05RtAJjT3wkbVICBrT5vI+s9c1Yb0gDtmCeVgzfzwBSsu9uvfd qGGeWWNI920Qki5//bbxBkz8Zk3JUkBbHvOSzXlyl3CD18KpC7bSaGGoBgmZKXFoCwBw tNMzDsZxAsXbiZarNX6PBIyjdXdcRYiE/y87nnzXTpqeN11g2ZsHufdtgYK7tAIhKJoL 1yIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GrqwkdFthEBqmV0EtTHQbF1VPg6uCI8XEJMKDMyh0as=; b=fSoknaqA/xHQCP/zXOLf8o86r6zzxV8lpX6+mMncGvYrGMWLq7xVgo3sU05unTvPV3 4/wXciw5oF5La0D1bgzJPnRbVwMJmTg/hQrgj05UH8Mk3mBof08+oUZbEA3f9R4K9FEW Y0JChzG4ibKHpdz2hPyx+WpT387qw9bdcmXTENazVDafSh8dzmESh9fG7yDRIMN4Bcdc FWfDUrhQ4Ka6I9aesjff7CYpxv3IJzQcK96DVasobffaeo+oTrmnC8wi9psrMCuD0h7P EMAqhkuyuP2Yd5jeFP0C5xlnkHPrbsH38NXUTVtjaC4xBPlkkhE3mLpmhole+aJ6mRZm y1Hg== X-Gm-Message-State: AGi0PuYnQPXWrg7AE+RXaN63iIVAs7bO9/v6HEvHLSLFEtcaat2e8oUF 5HFeIqsga+6cigEv9tVX1DZCKw== X-Google-Smtp-Source: APiQypKcW62pt2L+mTN64ooWKizwU3N66xR0k/5MwAc1zgIPdIIOeJm2tvohmfg5gQrYhvktYABVxA== X-Received: by 2002:a0c:a68a:: with SMTP id t10mr9031292qva.133.1587735879325; Fri, 24 Apr 2020 06:44:39 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::921]) by smtp.gmail.com with ESMTPSA id k2sm4142562qta.39.2020.04.24.06.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 06:44:38 -0700 (PDT) Date: Fri, 24 Apr 2020 09:44:38 -0400 From: Johannes Weiner To: Yafang Shao Cc: akpm@linux-foundation.org, mhocko@kernel.org, vdavydov.dev@gmail.com, linux-mm@kvack.org, Chris Down , Roman Gushchin , stable@vger.kernel.org Subject: Re: [PATCH] mm, memcg: fix wrong mem cgroup protection Message-ID: <20200424134438.GA496852@cmpxchg.org> References: <20200423061629.24185-1-laoar.shao@gmail.com> <20200424131450.GA495720@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200424131450.GA495720@cmpxchg.org> 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: On Fri, Apr 24, 2020 at 09:14:52AM -0400, Johannes Weiner wrote: > However, mem_cgroup_protected() never expected anybody to look at the > effective protection values when it indicated that the cgroup is above > its protection. As a result, a query during limit reclaim may return > stale protection values that were calculated by a previous reclaim > cycle in which the cgroup did have siblings. Btw, I think there is opportunity to make this a bit less error prone. We have a mem_cgroup_protected() that returns yes or no, essentially, but protection isn't a binary state anymore. It's also been a bit iffy that it looks like a simple predicate function, but it indeed needs to run procedurally for each cgroup in order for the calculations throughout the tree to be correct. It might be better to have a mem_cgroup_calculate_protection() that runs for every cgroup we visit and sets up the internal state; then have more self-explanatory query functions on top of that: mem_cgroup_below_min() mem_cgroup_below_low() mem_cgroup_protection() What do you guys think? diff --git a/mm/vmscan.c b/mm/vmscan.c index e0f502b5fca6..dbd3f75d39b9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2615,14 +2615,15 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) unsigned long reclaimed; unsigned long scanned; - switch (mem_cgroup_protected(target_memcg, memcg)) { - case MEMCG_PROT_MIN: + mem_cgroup_calculate_protection(target_memcg, memcg); + + if (mem_cgroup_below_min(memcg)) { /* * Hard protection. * If there is no reclaimable memory, OOM. */ continue; - case MEMCG_PROT_LOW: + } else if (mem_cgroup_below_low(memcg)) { /* * Soft protection. * Respect the protection only as long as @@ -2634,16 +2635,6 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) continue; } memcg_memory_event(memcg, MEMCG_LOW); - break; - case MEMCG_PROT_NONE: - /* - * All protection thresholds breached. We may - * still choose to vary the scan pressure - * applied based on by how much the cgroup in - * question has exceeded its protection - * thresholds (see get_scan_count). - */ - break; } reclaimed = sc->nr_reclaimed;