Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1542423pxb; Thu, 16 Sep 2021 09:34:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydir7pWSyOobeEFWRlHD3ASHOslJDBoPFvyo45A79Sbp8odbok/vGcqcqqLWTFciW9XhKi X-Received: by 2002:a50:a846:: with SMTP id j64mr7457285edc.21.1631810062094; Thu, 16 Sep 2021 09:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810062; cv=none; d=google.com; s=arc-20160816; b=R3QRCbsWVvMatHVWNs0fbjMQzkYfa34FS42YNoHuS4Q2q3JnDPM6i39ekWccYUAry6 sGf9PV4k0EwiC+yoogRgt6nIzQyH5EqxDrCjG5p1pDzhh2/jMR4NN3wdlQKKHotXykWD Yefz/UMxyM3yr7oL/pdIpCt7ew7uyfX8y8a0ZZVUu22a+woXRNGEhMorzQ49J2KRCi6v y965uf3VMLxsOySoKhC8wFLtbHAGC44RZ0HdN7fbsKqDW8+m0YD19DEoBWJ+MCxbMGQK XIC3ZPtc3GaFGqTwWLctKYy78CoXbIyB1gWFUhF5LCcfLC+6kERI90QABpntLEORLZ5b dKqA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=646TSVPYHt1feQEwW9VsHN8OSR/3DTIIaCq0izeyxLs=; b=X1b7/CqCei/L2Ge2Oy+owTs5YT1fM9yehtJjAPwAzrkLpCBQAwjgGHzVPXbuEes8ep hiCyQ2j51jaIkvpSFZmabf7AbDdELqEF4V97WYxZWj9vYTye99mjBqUS7R1lZ8fDkJ77 BpwjhkGvj3gGKhhoiP/TNwa1BBlD6k6V81/jJUW2eLGill7nRfivDSaCwZTMakkTNbAq perKM9g/YtayvnVsF8cvJSr8+FPEoUdzP1IOoW1X4fsYPFuSWJkugapSiLgz84Jforuq Sa2tB7g6Qx5Se8ROqsFDY+bvstUEnavxiGi44gPPSw7rVWkpDqykBcF3XrR3y6ae6eOJ AO4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tIP4sWHc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb10si2927554edb.16.2021.09.16.09.33.56; Thu, 16 Sep 2021 09:34:22 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tIP4sWHc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242938AbhIPQc1 (ORCPT + 99 others); Thu, 16 Sep 2021 12:32:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:59354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240858AbhIPQX4 (ORCPT ); Thu, 16 Sep 2021 12:23:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0B7B66044F; Thu, 16 Sep 2021 16:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808969; bh=0Oeb+OWEsJyxx2aPT1GIu7DFYl6hRQ7rEOChTfq71K8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tIP4sWHcOmlh6Oc/tVoiQ/x7Uk7WulJOuivkvpTMdN2vi4H/N5xo+MsUnNdrYiqS8 wMgO+Spf6yEIg1SOrzUQmw+lc34wDI32ni4tWW9wtU2Sxf9u0obE9r1i4Vx9yadakE jjoiaF+gyU84bnSWOePy43Ln+6DMHxLcurlov/cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rik van Riel , Roman Gushchin , Michal Hocko , Johannes Weiner , Chris Down , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 290/306] mm,vmscan: fix divide by zero in get_scan_count Date: Thu, 16 Sep 2021 18:00:35 +0200 Message-Id: <20210916155803.989969226@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rik van Riel commit 32d4f4b782bb8f0ceb78c6b5dc46eb577ae25bf7 upstream. Commit 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. Link: https://lkml.kernel.org/r/20210826220149.058089c6@imladris.surriel.com Fixes: f56ce412a59d ("mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim") Signed-off-by: Rik van Riel Acked-by: Roman Gushchin Acked-by: Michal Hocko Acked-by: Johannes Weiner Acked-by: Chris Down Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2378,7 +2378,7 @@ out: 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