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=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 DEF62C4320A for ; Mon, 30 Aug 2021 13:24:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53B9260FE8 for ; Mon, 30 Aug 2021 13:24:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 53B9260FE8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A300E8D0001; Mon, 30 Aug 2021 09:24:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DFE06B0072; Mon, 30 Aug 2021 09:24:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A8268D0001; Mon, 30 Aug 2021 09:24:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 78C616B0071 for ; Mon, 30 Aug 2021 09:24:30 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 27A2F18085CEB for ; Mon, 30 Aug 2021 13:24:30 +0000 (UTC) X-FDA: 78531816300.39.CE1B4C5 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf22.hostedemail.com (Postfix) with ESMTP id B704C1902 for ; Mon, 30 Aug 2021 13:24:29 +0000 (UTC) Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mKhGx-0008HT-Gs; Mon, 30 Aug 2021 09:24:23 -0400 Message-ID: Subject: Re: [PATCH] mm,vmscan: fix divide by zero in get_scan_count From: Rik van Riel To: Michal Hocko Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, stable@kernel.org, Chris Down , Johannes Weiner Date: Mon, 30 Aug 2021 09:24:22 -0400 In-Reply-To: References: <20210826220149.058089c6@imladris.surriel.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-/uvygdDFQnPrPTOwi7qF" User-Agent: Evolution 3.40.3 (3.40.3-1.fc34) MIME-Version: 1.0 Authentication-Results: imf22.hostedemail.com; dkim=none; spf=none (imf22.hostedemail.com: domain of riel@shelob.surriel.com has no SPF policy when checking 96.67.55.147) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B704C1902 X-Stat-Signature: ecb97ppas9pwexrok84a6ri6hxbje483 X-HE-Tag: 1630329869-161647 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: --=-/uvygdDFQnPrPTOwi7qF Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 2021-08-30 at 13:33 +0200, Michal Hocko wrote: > On Thu 26-08-21 22:01:49, Rik van Riel wrote: > > 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. > >=20 > > 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. > >=20 > > 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. > >=20 > > 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. > >=20 > > This patch implements the obvious fix. >=20 > I must be missing something but how can cgroup_size be ever 0 when it > is > max(cgroup_size, protection) and protection !=3D 0? Going into the condition we use if (low || min), where it is possible for low > 0 && min =3D=3D 0. Inside the conditional, we can end up testing against min. --=20 All Rights Reversed. --=-/uvygdDFQnPrPTOwi7qF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEKR73pCCtJ5Xj3yADznnekoTE3oMFAmEs3AYACgkQznnekoTE 3oOYSQf7BU32gfB5rnz9drsdzvYBU1XZwNk1uMzS34QeiiioQ9jj6l79Q7qWOOSX w9mThSCMrddEUO8t6HC1zQnp62OFMXx1wYfD7mSmNt3Kk4AL88Yjs9r+PbkwwCeA 2BXj92pvWmIrPjuLwbnfY56DrgBn4PfrrR2fGkWXUO3NT47zGD2K0MdWo9pKm0sl vGOMQKBhWFpfvgETJodL4BThuI66RivSNtWUAK39Ys2EvOxqIo0xngEl3QC7zwik 9ouW9cwA6cmTU9Wt559qtkui+ZHFpMJSlME5oxRdLmlj1vF0BQrBxAyP36Cp78x3 ReJbFnl3CIQintU/JFemhC/9UX/GRQ== =q6Bd -----END PGP SIGNATURE----- --=-/uvygdDFQnPrPTOwi7qF--