Re: [PATCH] mm: do not call add_nr_deferred() with zero deferred

Dave Chinner
2022-04-22T01:19:15Z

On Tue, Apr 19, 2022 at 09:42:30AM -0700, Roman Gushchin wrote:
> On Tue, Apr 19, 2022 at 02:56:06PM +0200, David Hildenbrand wrote:
> > On 16.04.22 02:41, Roman Gushchin wrote:
> > > add_nr_deferred() is often called with next_deferred equal to 0.
> > > For instance, it's happening under low memory pressure for any
> > > shrinkers with a low number of cached objects. A corresponding trace
> > > looks like:
> > > <...>-619914 [005] .... 467456.345160: mm_shrink_slab_end: \
> > > super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 \
> > > unused scan count 0 new scan count 0 total_scan 0 \
> > > last shrinker return val 0
> > >
> > > <...>-619914 [005] .... 467456.345371: mm_shrink_slab_end: \
> > > super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 \
> > > unused scan count 0 new scan count 0 total_scan 0 \
> > > last shrinker return val 0
> > >
> > > <...>-619914 [005] .... 467456.345380: mm_shrink_slab_end: \
> > > super_cache_scan+0x0/0x1a0 0000000087027f06: nid: 1 unused \
> > > scan count 0 new scan count 0 total_scan 0 \
> > > last shrinker return val 0
> > >
> > > This lead to unnecessary checks and atomic operations, which can be
> > > avoided by checking next_deferred for not being zero before calling
> > > add_nr_deferred(). In this case the mm_shrink_slab_end trace point
> > > will get a potentially slightly outdated "new scan count" value, but
> > > it's totally fine.
> >
> > Sufficient improvement to justify added complexity for anybody reading
> > that code?
>
> I don't have any numbers and really doubt the difference is significant,

Never been able to measure it myself.

HwoeverI'd much prefer the tracepoint output stays accurate - I've had to
post-process and/or graph the shrinker progress as reported by the
start/end tracpoints to find problems in the algorithms in the past.
That's why there is the additional complexity in the code to make
sure the coutners are accurate in the first place.

> however the added complexity is also small: one "if" statement.

Yeah, complexity is not the problem here - it's that accuracy of the
tracepoints has actually mattered to me in the past...

Cheers,

DAve.
--
Dave Chinner
dchinner@redhat.com