• Vladimir Davydov's avatar
    radix-tree: account radix_tree_node to memory cgroup · 58e698af
    Vladimir Davydov authored
    Allocation of radix_tree_node objects can be easily triggered from
    userspace, so we should account them to memory cgroup.  Besides, we need
    them accounted for making shadow node shrinker per memcg (see
    mm/workingset.c).
    
    A tricky thing about accounting radix_tree_node objects is that they are
    mostly allocated through radix_tree_preload(), so we can't just set
    SLAB_ACCOUNT for radix_tree_node_cachep - that would likely result in a
    lot of unrelated cgroups using objects from each other's caches.
    
    One way to overcome this would be making radix tree preloads per memcg,
    but that would probably look cumbersome and overcomplicated.
    
    Instead, we make radix_tree_node_alloc() first try to allocate from the
    cache with __GFP_ACCOUNT, no matter if the caller has preloaded or not,
    and only if it fails fall back on using per cpu preloads.  This should
    make most allocations accounted.
    Signed-off-by: default avatarVladimir Davydov <vdavydov@virtuozzo.com>
    Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
    Cc: Michal Hocko <mhocko@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    58e698af
radix-tree.c 39.9 KB