Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp923773pxb; Thu, 26 Aug 2021 19:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhlku5NxCJsTeJjUFWZDPdOd2Pi7y8A4u+zd7KA9KLYrdpG6kXZWaF+864THFToLxaBjYl X-Received: by 2002:a50:9b52:: with SMTP id a18mr7363568edj.165.1630029819724; Thu, 26 Aug 2021 19:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630029819; cv=none; d=google.com; s=arc-20160816; b=g6yJRS3v9fjkBQNHEo1vYoKNsJZQAtNIIaV4X7w8FaphlI8x95R4OKObKSpLj6NoEs /WBjekqJ6XaMGHcfxhZLv2U50nVSs364l4MSJ+BsvQu6AsbxTdHFivqy2zt44sgBNKuQ /VHehVFS9FbS0kNTVFZ1SZjS+b/dudmEgswW7F9Rvl7X/QViQfrlC2XdyAsRj8C58IrB i3ff1nP2NUirt8lou5Dx8PLC8rKnUqwxptmOyWBQ9CWQzhIdmJpKKY17q4vmfd+jzFcq kC2eYTXK1ioCmV+1vaBDfgtph/dDqNkxG5aSQEE7+4UpdSf+91T8SarC+JGjqHLojDzb q+7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=LPa5UsG0lqtigTIbA8Pneyr7aWVv+S+AkQsV8SQLdRg=; b=eSeY/QHNf1Z/qaBF6qS/b4CrZVhLPaTn+Y6YGARd+z8mm6UfGAjAsJgPHT6991mcCb SY9qwSQAz6ece6FvbiiTYBA8ZwEGOXYtB6x4efN62uxypyUolod7icQ/sLI93TTQDwkG z939EjaRrteYJ40qqVQg91I19dvNdhInr/3lMaya8RWYWjzmtUFU+CPXyiURFxnTPBWT L5KqjOZ2osfHY712cRG9xyvLgEbF9N7KKCXNWM3sGZ4lOAgydViC3kE4NpGVKjheilCP 3dyETi6mdiPgFaHejI6Ak7l9fVLu8M4P/QdmbNTg/x2VMHBlf+nnfJT185NCMFKLBhfL EkMg== 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 s10si5692127edd.150.2021.08.26.19.03.16; Thu, 26 Aug 2021 19:03:39 -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 S243959AbhH0CCs (ORCPT + 99 others); Thu, 26 Aug 2021 22:02:48 -0400 Received: from shelob.surriel.com ([96.67.55.147]:37610 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbhH0CCr (ORCPT ); Thu, 26 Aug 2021 22:02:47 -0400 Received: from [2603:3005:d05:2b00:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mJRBp-0005il-UE; Thu, 26 Aug 2021 22:01:53 -0400 Date: Thu, 26 Aug 2021 22:01:49 -0400 From: Rik van Riel To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, stable@kernel.org, Michal Hocko , Chris Down , Johannes Weiner Subject: [PATCH] mm,vmscan: fix divide by zero in get_scan_count Message-ID: <20210826220149.058089c6@imladris.surriel.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@shelob.surriel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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