Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3603408pxb; Mon, 30 Aug 2021 06:25:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFqV5MkGqBSth9EzdwnRxvhavpZfrGFFm883ZBrpnodUwfbUaxYw9JwBZfG8J+3wUhdbXN X-Received: by 2002:a02:cb0c:: with SMTP id j12mr4453624jap.83.1630329918048; Mon, 30 Aug 2021 06:25:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630329918; cv=none; d=google.com; s=arc-20160816; b=ZKctei8o33QVUeyovZwWfdUIqeBeSBH33Gv+PNta0oXOltNguz8PoUbgWD/Q8TUrf3 vUD/+qgRpJ17hVHGpPtaiNYgSGD1XTI3zxu2Q/qPIjs5OXEtSkuUkZhrn9dnfF0yBsNv mLh3RhWNoLPspFgWZn64muQ8MOxUsrLcYqubl8NbX+3xBhgPnF2SfuwnzzFg2gzudz8+ 3fUKyzOl6YKaEBBSu+9bXX0c3L2UhKjGlY0lgSG2xKGqgEdkOlrCST2Hi/wZgfYWItgT pLMfmGLty1ivgINXnwGQ0p0b8T6LRWk/Y6PaGOFmPs484irmtd4fpQCthaQUJMJQ1xQ0 MIdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=7q0DgCJWnuLqWjgiPngK8x+NULt4rfZBpyeD9M5wGkc=; b=IhJ+fTYWTQ6nTPv/GGikHbvNrX3z1H/rscmQjVtR4p0qstxUbWEwFz62dT3Wqu0MKe lsi6vf5AGTj0vuhiTKyulOX+vZmbjNaa8lhvKBOmp57TrPlv9HaWhRkJca33Wwlj/XCZ IPTJPCLsLqZJ1gXPeb9WDsUcJQPG0tbceYfF4wrKG3hbr4DNkxE4A6Q/mBUiPoGSHTqm nxJcRFj0yfKPqejZLC8NpdAfZvtHDpl1VS1W2PjhJxyLYzJCzuEl1s5kiE8qH/BPrH0l 14jZA/Uf+Z75koPuNsyXlGB8mllbeT3qVaG2DH3JzywaPZGPeC1gE2DJ/4b2kzRskc8j kwPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si13838288ilq.125.2021.08.30.06.25.06; Mon, 30 Aug 2021 06:25:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236537AbhH3NZV (ORCPT + 99 others); Mon, 30 Aug 2021 09:25:21 -0400 Received: from shelob.surriel.com ([96.67.55.147]:45798 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbhH3NZV (ORCPT ); Mon, 30 Aug 2021 09:25:21 -0400 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 Sender: riel@shelob.surriel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-/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--