Re: [PATCH] mm,vmscan: fix divide by zero in get_scan_count

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux