Re: + mm-rework-calculation-of-bdi_min_ratio-in-bdi_set_min_ratio.patch added to -mm tree

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

 



On Mon, 25 Apr 2022 10:37:23 +0200 Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> On Fri, Apr 22, 2022 at 01:54:13PM -0700, Andrew Morton wrote:
> 
> > From: Chen Wandun <chenwandun@xxxxxxxxxx>
> > Subject: mm: rework calculation of bdi_min_ratio in bdi_set_min_ratio
> > 
> > In function bdi_set_min_ratio, min_ratio is unsigned int, it will
> > result underflow when setting min_ratio below bdi->min_ratio, it
> > is confusing. Rework it, no functional change.
> > 
>
> ...
>
> > 
> > --- a/mm/page-writeback.c~mm-rework-calculation-of-bdi_min_ratio-in-bdi_set_min_ratio
> > +++ a/mm/page-writeback.c
> > @@ -650,18 +650,25 @@ static unsigned int bdi_min_ratio;
> >  
> >  int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
> >  {
> > +	unsigned int delta;
> >  	int ret = 0;
> >  
> >  	spin_lock_bh(&bdi_lock);
> >  	if (min_ratio > bdi->max_ratio) {
> >  		ret = -EINVAL;
> >  	} else {
> 
> > -		min_ratio -= bdi->min_ratio;
> > -		if (bdi_min_ratio + min_ratio < 100) {
> > -			bdi_min_ratio += min_ratio;
> > -			bdi->min_ratio += min_ratio;
> >  		} else {
> > -			ret = -EINVAL;
> 
> I really don't see the why we're doing this, code gets to be worse, for
> no actual gain.

Oh.  I found the resulting code to be considerably more understandable.
I mean, how does the old code work?  afaict it treats `unsigned
min_ratio' as a signed value(!) and relies upon an underflowed unsigned
to be a large number (> 100) when avoiding underflowing global
bdi_min_ratio.  Or something like that.  Also, modifying an incoming
arg's value is kinda rude.

And there's no change in the object file's .text size.

> > +		if (min_ratio < bdi->min_ratio) {
> > +			delta = bdi->min_ratio - min_ratio;
> > +			bdi_min_ratio -= delta;
> > +			bdi->min_ratio = min_ratio;
> >  		} else {
> > +			delta = min_ratio - bdi->min_ratio;
> > +			if (bdi_min_ratio + delta < 100) {
> > +				bdi_min_ratio += delta;
> > +				bdi->min_ratio = min_ratio;
> > +			} else {
> > +				ret = -EINVAL;
> > +			}
> >  		}
> 
> >  	}



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux