mm: memcg: normalize the value passed into memcg_rstat_updated()
authorYosry Ahmed <yosryahmed@google.com>
Fri, 22 Sep 2023 17:57:40 +0000 (17:57 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 18 Oct 2023 21:34:12 +0000 (14:34 -0700)
commit7bd5bc3ce9632aefd0eed33a19212a2e55c0f873
tree2584a661fa5e51523ab5a2be43e1d8fa055fdfbd
parentff841a06c844b0556b434d67cfc43f4fda56ae7b
mm: memcg: normalize the value passed into memcg_rstat_updated()

memcg_rstat_updated() uses the value of the state update to keep track of
the magnitude of pending updates, so that we only do a stats flush when
it's worth the work.  Most values passed into memcg_rstat_updated() are in
pages, however, a few of them are actually in bytes or KBs.

To put this into perspective, a 512 byte slab allocation today would look
the same as allocating 512 pages.  This may result in premature flushes,
which means unnecessary work and latency.

Normalize all the state values passed into memcg_rstat_updated() to pages.
Round up non-zero sub-page to 1 page, because memcg_rstat_updated()
ignores 0 page updates.

Link: https://lkml.kernel.org/r/20230922175741.635002-3-yosryahmed@google.com
Fixes: 5b3be698a872 ("memcg: better bounds on the memcg stats updates")
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol.c