Re: [PATCH] mm/page_alloc: fix documentation error and remove magic numbers

From: Rafael Aquini
Date: Wed Jun 24 2020 - 10:26:38 EST


On Wed, Jun 24, 2020 at 03:09:58PM +0100, Matthew Wilcox wrote:
> On Wed, Jun 24, 2020 at 10:07:27AM -0400, Rafael Aquini wrote:
> > On Wed, Jun 24, 2020 at 12:12:55PM +0100, Matthew Wilcox wrote:
> > > On Tue, Jun 23, 2020 at 11:27:12PM -0400, Joel Savitz wrote:
> > > > In addition, this patch replaces the magic number bounds with symbolic
> > > > constants to clarify the logic.
> > >
> > > Why do people think this kind of thing makes the code easier to read?
> > > It actually makes it harder. Unless the constants are used in more
> > > than one place, just leave the numbers where they are.
> > >
> > > > @@ -7852,6 +7852,9 @@ void setup_per_zone_wmarks(void)
> > > > * 8192MB: 11584k
> > > > * 16384MB: 16384k
> > > > */
> > > > +static const int MIN_FREE_KBYTES_LOWER_BOUND = 1 << 7;
> > > > +static const int MIN_FREE_KBYTES_UPPER_BOUND = 1 << 18;
> > > > +
> >
> > I think these constants would look better if declared as an enum.
>
> Why does having to look in two different places make the code clearer?
>

It might not make it clearer in this particular case, because it was
easy to take the meaning from the code, but it also doesn't make it
harder to read, so I don't have any strong opinion on this case.

Joel's approach, however, makes sense if you consider it's generally a
good practice to get rid of the unnamed magic numbers anti-pattern.

Cheers,
-- Rafael