• Muchun Song's avatar
    mm: memcontrol: make the slab calculation consistent · fff66b79
    Muchun Song authored
    Although the ratio of the slab is one, we also should read the ratio from
    the related memory_stats instead of hard-coding.  And the local variable
    of size is already the value of slab_unreclaimable.  So we do not need to
    read again.
    
    To do this we need some code like below:
    
    if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) {
    -	size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) +
    -	       memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B);
    +       VM_BUG_ON(i < 1);
    +       VM_BUG_ON(memory_stats[i - 1].idx != NR_SLAB_RECLAIMABLE_B);
    +	size += memcg_page_state(memcg, memory_stats[i - 1].idx) *
    +		memory_stats[i - 1].ratio;
    
    It requires a series of VM_BUG_ONs or comments to ensure these two items
    are actually adjacent and in the right order.  So it would probably be
    easier to implement this using a wrapper that has a big switch() for unit
    conversion.
    
    More details about this discussion can refer to:
    
        https://lore.kernel.org/patchwork/patch/1348611/
    
    This would fix the ratio inconsistency and get rid of the order
    guarantee.
    
    Link: https://lkml.kernel.org/r/20201228164110.2838-8-songmuchun@bytedance.comSigned-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Cc: Feng Tang <feng.tang@intel.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: Michal Hocko <mhocko@suse.com>
    Cc: NeilBrown <neilb@suse.de>
    Cc: Pankaj Gupta <pankaj.gupta@cloud.ionos.com>
    Cc: Rafael. J. Wysocki <rafael@kernel.org>
    Cc: Randy Dunlap <rdunlap@infradead.org>
    Cc: Roman Gushchin <guro@fb.com>
    Cc: Sami Tolvanen <samitolvanen@google.com>
    Cc: Shakeel Butt <shakeelb@google.com>
    Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    fff66b79
memcontrol.c 191 KB