Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2350146pxb; Mon, 20 Sep 2021 19:44:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhJIHcAhJfe+SUcXCSn11Y/g+2HSqJnMnSoZQM5SudxcKeePuKhncBXftCGQb4f2QCt7p6 X-Received: by 2002:a17:906:24c1:: with SMTP id f1mr32643999ejb.314.1632192293230; Mon, 20 Sep 2021 19:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192293; cv=none; d=google.com; s=arc-20160816; b=AEsv/VMeMlnq/kElO/OR5GuESsgNKXX7ZERDTnPC8l6z5S52VnV9AgxpOXw9UqonVq xOjrUP7mQqIT/S9mHbaefrcjCmLsegpQP1IPD7ekq4GChwUZu7fFRMKZUI+qhKiQGnsn xMBPGKxxH/jZDHij7MmZYslwIeEh7MEFk70QxZBI8TL+ITBgnbjVf2zkZV6YN1w6Bt76 cBcs17nHjf+4tP0kYwrj3qDwDnjlvV3DZH4wcwb/Og5dzqypFIIOKhAl26hIs2CIy9ER +wvTpsru4qza6yRlqftMoLhQj6rNNLwhU7lViAK3cNGOYnBbBgPLQHYDcKjuu7YOhNzx yxFw== 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=c70QY+BPE7zFAc09MF0Cq8WZ/Zv/Rdy1hYTlEysqBmg=; b=x9H2MZzl7PifogZg7v/i3v2QdxMKkMgtk4/sfUKAh/wTElgrl53+aAO5UnjdsJHg1g knS8VKLLdkBrqMJP59V8SN1h5taHhyhF3DnR3eFaycUqoFOwjRf1Vaqi39hrgTKFCDFZ ZTtoEEWJP30VaFPyRB3rsZRSFAEEgexupT9a7hreEyHbln5NDY5NK4JNiYKewOOZFZMR DaPyKehabgarYD+txYwQlWz22vmMziJlp4HL06mOhyqf8jvfYRMSNnr5RL2RNrsc4d0e Pj99Ka+TkRLYvMDGcXWQGJrBCy6S7YHibOpaisBQCpa3slDuZxT4JlU8hERUDhUqh5eE hL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rjxZ0/mw"; 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 cc9si13182012edb.38.2021.09.20.19.44.30; Mon, 20 Sep 2021 19:44:53 -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="rjxZ0/mw"; 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 S1377969AbhITSWS (ORCPT + 99 others); Mon, 20 Sep 2021 14:22:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:35786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376728AbhITSOW (ORCPT ); Mon, 20 Sep 2021 14:14:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B930D60EB2; Mon, 20 Sep 2021 17:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158497; bh=YcGaJkAlIlcC2i4SObD2N6Q3x/v2GSFf6fGkp3Z1bPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjxZ0/mwRb0vgMHHkurcyiBZBZLmz5tk2tmzh0ejpyOTlonJmeKHDxTRbMUFB2JM9 23uR5pqhBIJPtGEDrg+npginaD/U5e9w447DR2eAahfc3thynZeYlMd7pYAM8J+1H1 7xUaz7/PaZkKcvJT8VcGnt3DVjwjc+o7g6ozjK8s= 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.4 182/260] mm,vmscan: fix divide by zero in get_scan_count Date: Mon, 20 Sep 2021 18:43:20 +0200 Message-Id: <20210920163937.302237520@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 @@ -2513,7 +2513,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