On Mon, Feb 26, 2024 at 04:05:37PM -0800, Paul E. McKenney wrote: > On Mon, Feb 26, 2024 at 06:29:43PM -0500, Kent Overstreet wrote: > > Well, we won't want it getting hammered on continuously - we should be > > able to tune reclaim so that doesn't happen. > > > > I think getting numbers on the amount of memory stranded waiting for RCU > > is probably first order of business - minor tweak to kfree_rcu() et all > > for that; there's APIs they can query to maintain that counter. > > We can easily tell you the number of blocks of memory waiting to be freed. > But RCU does not know their size. Yes, we could ferret this on each > call to kmem_free_rcu(), but that might not be great for performance. > We could traverse the lists at runtime, but such traversal must be done > with interrupts disabled, which is also not great. > > > then, we can add a heuristic threshhold somewhere, something like > > > > if (rcu_stranded * multiplier > reclaimable_memory) > > kick_rcu() > > If it is a heuristic anyway, it sounds best to base the heuristic on > the number of objects rather than their aggregate size. I don't think that'll really work given that object size can very from < 100 bytes all the way up to 2MB hugepages. The shrinker API works that way and I positively hate it; it's really helpful for introspection and debugability later to give good human understandable units to this stuff. And __ksize() is pretty cheap, and I think there might be room in struct slab to stick the object size there instead of getting it from the slab cache - and folio_size() is cheaper still.