• Waiman Long's avatar
    mm/memcg: optimize user context object stock access · 55927114
    Waiman Long authored
    Most kmem_cache_alloc() calls are from user context.  With instrumentation
    enabled, the measured amount of kmem_cache_alloc() calls from non-task
    context was about 0.01% of the total.
    
    The irq disable/enable sequence used in this case to access content from
    object stock is slow.  To optimize for user context access, there are now
    two sets of object stocks (in the new obj_stock structure) for task
    context and interrupt context access respectively.
    
    The task context object stock can be accessed after disabling preemption
    which is cheap in non-preempt kernel.  The interrupt context object stock
    can only be accessed after disabling interrupt.  User context code can
    access interrupt object stock, but not vice versa.
    
    The downside of this change is that there are more data stored in local
    object stocks and not reflected in the charge counter and the vmstat
    arrays.  However, this is a small price to pay for better performance.
    
    [longman@redhat.com: fix potential uninitialized variable warning]
      Link: https://lkml.kernel.org/r/20210526193602.8742-1-longman@redhat.com
    [akpm@linux-foundation.org: coding style fixes]
    
    Link: https://lkml.kernel.org/r/20210506150007.16288-5-longman@redhat.comSigned-off-by: default avatarWaiman Long <longman@redhat.com>
    Acked-by: default avatarRoman Gushchin <guro@fb.com>
    Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Pekka Enberg <penberg@kernel.org>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Roman Gushchin <guro@fb.com>
    Cc: Muchun Song <songmuchun@bytedance.com>
    Cc: Alex Shi <alex.shi@linux.alibaba.com>
    Cc: Chris Down <chris@chrisdown.name>
    Cc: Yafang Shao <laoar.shao@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Cc: Masayoshi Mizuma <msys.mizuma@gmail.com>
    Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    55927114
memcontrol.c 192 KB