Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4350067pxb; Tue, 31 Aug 2021 03:03:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzioogO72IXe+JCl2b3XmleDrLc52/vGooB7ldyQCQwepLIo6N5NMqLHQ/cyAJwBSu71T+Z X-Received: by 2002:a17:907:98ce:: with SMTP id kd14mr30364501ejc.440.1630404186070; Tue, 31 Aug 2021 03:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630404186; cv=none; d=google.com; s=arc-20160816; b=X1w4/URiVrFvrvW+7u3N96ZGjgvfm0xvaygFbhhLwfclAB8IN5KQwW0SyS1RtAGojI xE5PPtKJBHZhbrseS+KnRJ+UuOth5vcWpBPU+vvnTbpsqKi/IRckxMX3mVjAALfrKBR7 u2IttVAoDzrvADi1kko9VESkSmfxMb0e1bM3R1ISSRDO5GNwks6N/YkJU2d5CMU8p4b7 K6pxowblxpeTmjTzsJKpwrN1CD2LE3ezBCRIyvHysJx9x9SMTDdmD3jbnC30WSeX3hN/ 66Ibae7L9MHeKXR8XSMuEiLFnpogZVQqNWI4EnfPESLQoVC8rcAWhdUXHrtAtb6GFNfF 1jHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WiP8R2FARUsYFRgyybzZXk+qgD0ErxdUL7/x1nn4EHc=; b=kLFxfJ0CSu0ObtxA3kxJA1JjZHj+fxWvu+/muni12z6YUjh4CtUsZ8PmOcjKNIIaOK 3DwvPfoodMIETa+mXbHre5lrpEZ5KhJzekKUky0Ixdb5Y82Ra4K/TxYdmMNze0hoIgub GoLyhOfjzrAiw8jMF36z4ik8j5xYbaGfj1CnTjLKI1kdiYC9z5HInlANwKuPqMJTd90X FMUyilH+I5iO32W1BgSeydER39wAdYGrNKFNRdovyePCbhZAqE3LfeHEGFDI4nAtUJ7R MmNe+pXngWzWUaK5TodQdEnWPGlWMMd/DXze3GC79ZwRB6CXJUy1hQikIp2lCRdSeW5m +wNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=jGmRKaHj; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n25si17717483ejg.73.2021.08.31.03.02.09; Tue, 31 Aug 2021 03:03:06 -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=@suse.com header.s=susede1 header.b=jGmRKaHj; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240813AbhHaKAG (ORCPT + 99 others); Tue, 31 Aug 2021 06:00:06 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:53658 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240576AbhHaKAF (ORCPT ); Tue, 31 Aug 2021 06:00:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0AC6C221D5; Tue, 31 Aug 2021 09:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1630403950; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WiP8R2FARUsYFRgyybzZXk+qgD0ErxdUL7/x1nn4EHc=; b=jGmRKaHjiB0LJjuSUiCQxNuc0IQU6ggQnRYlQc5lU2gNvcToeTo/ZDpq3fDTJFmiy61YsT fd/IuOQXQx5ZTYzw/1yiGDfqlhwZcClL4HqECu10DBBA/ljjUOk8Wk0ByScFt0RA5WFzBy EBlts6L764k93fDF645Tw7QRW/j4dFk= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E91A4A3B95; Tue, 31 Aug 2021 09:59:08 +0000 (UTC) Date: Tue, 31 Aug 2021 11:59:05 +0200 From: Michal Hocko To: Johannes Weiner Cc: Rik van Riel , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, stable@kernel.org, Chris Down Subject: Re: [PATCH] mm,vmscan: fix divide by zero in get_scan_count Message-ID: References: <20210826220149.058089c6@imladris.surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 30-08-21 16:48:03, Johannes Weiner wrote: > On Thu, Aug 26, 2021 at 10:01:49PM -0400, Rik van Riel wrote: [...] > > 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); > > I have no overly strong preferences, but if Michal prefers max(), how about: > > cgroup_size = max3(cgroup_size, protection, 1); Yes this is better. > Or go back to not taking the branch in the first place when there is > no protection in effect... > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 6247f6f4469a..9c200bb3ae51 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2547,7 +2547,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > mem_cgroup_protection(sc->target_mem_cgroup, memcg, > &min, &low); > > - if (min || low) { > + if (min || (!sc->memcg_low_reclaim && low)) { > /* > * Scale a cgroup's reclaim pressure by proportioning > * its current usage to its memory.low or memory.min This is slightly more complex to read but it is also better than +1 trick. Either of the two work for me. -- Michal Hocko SUSE Labs