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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 1A372C432BE for ; Tue, 31 Aug 2021 12:58:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA00D60F92 for ; Tue, 31 Aug 2021 12:58:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BA00D60F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chrisdown.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 55B196B0072; Tue, 31 Aug 2021 08:58:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E67A6B0073; Tue, 31 Aug 2021 08:58:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ABDF6B0074; Tue, 31 Aug 2021 08:58:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 2C0EC6B0072 for ; Tue, 31 Aug 2021 08:58:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DE1A1180366E8 for ; Tue, 31 Aug 2021 12:58:24 +0000 (UTC) X-FDA: 78535379328.13.E4D4284 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf27.hostedemail.com (Postfix) with ESMTP id 959057000091 for ; Tue, 31 Aug 2021 12:58:24 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id q14so27565389wrp.3 for ; Tue, 31 Aug 2021 05:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RlSDoTBJbwZ1+/0ecNtGprCwalpFdAzDsfxdMM/e3GM=; b=l6S/pUeAfrJSprNCOKEOYd0+Fgv9a+ujQ0HxDPG00/VLHsmDx1l+WWWaPEfcR6hOvm vcCJB/kZxW0s+dCeUdJryWsSUpt3N7YnGoU3xfWpBQ8BBRKp2XPW4v5C54TW6+mGqpa6 FgTQX4vh4vrH2Uxa2zZRNnyyZu8u+Hm+JDdoc= 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:user-agent; bh=RlSDoTBJbwZ1+/0ecNtGprCwalpFdAzDsfxdMM/e3GM=; b=gWvZtclYQmUjLCLCqFLJLYokMnfHV6jgQJebHHbrPyqbzt/y1sTaQ/ly4r3iHubKzb TgNS6ayRsPo39UZ4yzi4eSIkEAmwGFTiANjGMMCj7p1lIsNRoHIzpwPdLPvh+lwakupO PZp2jEWxq9IsGhFJV22t4A4irK6QCDmlpt22uBLzi5mIVpnOZse1ZXxfkId+RsAnWD30 guDgFRECHqoVCK3hFVvUj7oS8mpIYXiuEHFFBLND2thCVEOHtCszIC3bzFm7033b2LqO dzHwqtsGw5DIdq/2bDGJpO4rir3+Ope78pIZrNbPG7xcDORSowJMEvd4lS8GMv0Cw65i 9x/A== X-Gm-Message-State: AOAM533u3siE+8KPphRi/TUdRah2eoGMYy9egR/SoszwkOrUVIDA5Wkb EfndBC++MESZdzw5jdxpyPcqhw== X-Google-Smtp-Source: ABdhPJyMvnQ+99yRM6iY3/8/7Ati9ZYYEYbENFZ+LfxvFcbOSPr25fVfv9Cxv1kXbG2Hy0eQbccQfA== X-Received: by 2002:adf:b743:: with SMTP id n3mr31397338wre.243.1630414702960; Tue, 31 Aug 2021 05:58:22 -0700 (PDT) Received: from localhost ([2620:10d:c093:400::5:bdb8]) by smtp.gmail.com with ESMTPSA id m1sm2590293wmq.10.2021.08.31.05.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 05:58:22 -0700 (PDT) Date: Tue, 31 Aug 2021 13:58:21 +0100 From: Chris Down To: Rik van Riel Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, stable@kernel.org, Michal Hocko , Johannes Weiner Subject: Re: [PATCH] mm,vmscan: fix divide by zero in get_scan_count Message-ID: References: <20210826220149.058089c6@imladris.surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210826220149.058089c6@imladris.surriel.com> User-Agent: Mutt/2.1.1 (e2a89abc) (2021-07-12) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=chrisdown.name header.s=google header.b="l6S/pUeA"; dmarc=pass (policy=none) header.from=chrisdown.name; spf=pass (imf27.hostedemail.com: domain of chris@chrisdown.name designates 209.85.221.41 as permitted sender) smtp.mailfrom=chris@chrisdown.name X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 959057000091 X-Stat-Signature: mmthpipojjq1wpxfy8n7eyfc9gxfbhs6 X-HE-Tag: 1630414704-216231 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: Rik van Riel writes: >Changeset f56ce412a59d ("mm: memcontrol: fix occasional OOMs due to >proportional memory.low reclaim") introduced a divide by zero corner >case when oomd is being used in combination with cgroup memory.low >protection. > >When oomd decides to kill a cgroup, it will force the cgroup memory >to be reclaimed after killing the tasks, by writing to the memory.max >file for that cgroup, forcing the remaining page cache and reclaimable >slab to be reclaimed down to zero. > >Previously, on cgroups with some memory.low protection that would result >in the memory being reclaimed down to the memory.low limit, or likely not >at all, having the page cache reclaimed asynchronously later. > >With f56ce412a59d the oomd write to memory.max tries to reclaim all the >way down to zero, which may race with another reclaimer, to the point of >ending up with the divide by zero below. > >This patch implements the obvious fix. > >Fixes: f56ce412a59d ("mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim") >Signed-off-by: Rik van Riel Thanks, good catch. No strong preference on this vs. max3(), so feel free to keep my ack either way. Acked-by: Chris Down > >diff --git a/mm/vmscan.c b/mm/vmscan.c >index eeae2f6bc532..f1782b816c98 100644 >--- a/mm/vmscan.c >+++ b/mm/vmscan.c >@@ -2592,7 +2592,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > cgroup_size = max(cgroup_size, protection); > > scan = lruvec_size - lruvec_size * protection / >- cgroup_size; >+ (cgroup_size + 1); > > /* > * Minimally target SWAP_CLUSTER_MAX pages to keep > >