lkml.org 
[lkml]   [2021]   [Jul]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v13 010/137] mm: Add folio flag manipulation functions
On Tue, 13 Jul 2021 11:55:04 -0400 Johannes Weiner <hannes@cmpxchg.org> wrote:

> On Tue, Jul 13, 2021 at 11:15:33AM +0200, Peter Zijlstra wrote:
> > On Tue, Jul 13, 2021 at 03:15:10AM +0100, Matthew Wilcox wrote:
> > > On Mon, Jul 12, 2021 at 08:24:09PM -0400, Johannes Weiner wrote:
> > > > On Mon, Jul 12, 2021 at 04:04:54AM +0100, Matthew Wilcox (Oracle) wrote:
> > > > > +/* Whether there are one or multiple pages in a folio */
> > > > > +static inline bool folio_single(struct folio *folio)
> > > > > +{
> > > > > + return !folio_head(folio);
> > > > > +}
> > > >
> > > > Reading more converted code in the series, I keep tripping over the
> > > > new non-camelcased flag testers.
> > >
> > > Added PeterZ as he asked for it.
> > >
> > > https://lore.kernel.org/linux-mm/20210419135528.GC2531743@casper.infradead.org/
> >
> > Aye; I hate me some Camels with a passion. And Linux Coding style
> > explicitly not having Camels these things were always a sore spot. I'm
> > very glad to see them go.
> >
> > > > It's not an issue when it's adjectives: folio_uptodate(),
> > > > folio_referenced(), folio_locked() etc. - those are obvious. But nouns
> > > > and words that overlap with struct member names can easily be confused
> > > > with non-bool accessors and lookups. Pop quiz: flag test or accessor?
> > > >
> > > > folio_private()
> > > > folio_lru()
> > > > folio_nid()
> > > > folio_head()
> > > > folio_mapping()
> > > > folio_slab()
> > > > folio_waiters()
> > >
> > > I know the answers to each of those, but your point is valid. So what's
> > > your preferred alternative? folio_is_lru(), folio_is_uptodate(),
> > > folio_is_slab(), etc? I've seen suggestions for folio_test_lru(),
> > > folio_test_uptodate(), and I don't much care for that alternative.
> >
> > Either _is_ or _test_ works for me, with a slight preference to _is_ on
> > account it of being shorter.

Useful discussion, and quite important. Thanks for bringing it up.

> I agree that _is_ reads nicer by itself, but paired with other ops
> such as testset, _test_ might be better.
>
> For example, in __set_page_dirty_no_writeback()
>
> if (folio_is_dirty())
> return !folio_testset_dirty()
>
> is less clear about what's going on than would be:
>
> if (folio_test_dirty())
> return !folio_testset_dirty()

I like folio_is_foo(). As long as it is used consistently, we'll get
used to it quickly.

Some GNU tools are careful about appending "_p" to
functions-which-test-something (stands for "predicate"). Having spent
a lot of time a long time ago with my nose in this stuff, I found the
convention to be very useful. I think foo_is_bar() is as good as
foo_bar_p() in this regard.

>
> folio_test_foo()
> folio_set_foo()
> folio_clear_foo()
> folio_testset_foo()
> folio_testclear_foo()

Agree with everyone else about prefixing every symbol with "folio_".
Although at times there will be heartache over which subsystem the
function actually belongs to. For example, a hypothetical function
which writes back a folio to disk could be writeback_folio() or
folio_writeback(). Really it's a part of writeback so should be
writeback_folio(). Plus folio isn't really a subsystem. But then,
neither is spin_lock much, and that naming works OK.


And sure, the CaMeLcAsE is fugly, but it sure is useful.
set_page_dirty() is very different from SetPageDirty() and boy that
visual differentiation is a relief.

\
 
 \ /
  Last update: 2021-07-14 03:57    [W:0.194 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site