lkml.org 
[lkml]   [2020]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2] mm/memcontrol: make the slab calculation consistent
    Date
    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. Simplify the code here.

    Signed-off-by: Muchun Song <songmuchun@bytedance.com>
    Acked-by: Roman Gushchin <guro@fb.com>
    ---
    Changes in v2:
    - Add a comment in the memory_stat_format() suggested by Roman.

    mm/memcontrol.c | 26 +++++++++++++++++++++-----
    1 file changed, 21 insertions(+), 5 deletions(-)

    diff --git a/mm/memcontrol.c b/mm/memcontrol.c
    index 9922f1510956..75df129b7a52 100644
    --- a/mm/memcontrol.c
    +++ b/mm/memcontrol.c
    @@ -1545,12 +1545,22 @@ static int __init memory_stats_init(void)
    int i;

    for (i = 0; i < ARRAY_SIZE(memory_stats); i++) {
    + switch (memory_stats[i].idx) {
    #ifdef CONFIG_TRANSPARENT_HUGEPAGE
    - if (memory_stats[i].idx == NR_ANON_THPS ||
    - memory_stats[i].idx == NR_FILE_THPS ||
    - memory_stats[i].idx == NR_SHMEM_THPS)
    + case NR_ANON_THPS:
    + case NR_FILE_THPS:
    + case NR_SHMEM_THPS:
    memory_stats[i].ratio = HPAGE_PMD_SIZE;
    + break;
    #endif
    + case NR_SLAB_UNRECLAIMABLE_B:
    + VM_BUG_ON(i < 1);
    + VM_BUG_ON(memory_stats[i - 1].idx != NR_SLAB_RECLAIMABLE_B);
    + break;
    + default:
    + break;
    + }
    +
    VM_BUG_ON(!memory_stats[i].ratio);
    VM_BUG_ON(memory_stats[i].idx >= MEMCG_NR_STAT);
    }
    @@ -1586,9 +1596,15 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
    size *= memory_stats[i].ratio;
    seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size);

    + /*
    + * We are printing reclaimable, unreclaimable of the slab
    + * and the sum of both.
    + */
    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);
    + int idx = i - 1;
    +
    + size += memcg_page_state(memcg, memory_stats[idx].idx) *
    + memory_stats[idx].ratio;
    seq_buf_printf(&s, "slab %llu\n", size);
    }
    }
    --
    2.11.0
    \
     
     \ /
      Last update: 2020-12-03 04:16    [W:4.460 / U:0.120 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site