1. 04 Jan, 2024 1 commit
  2. 28 Dec, 2023 1 commit
    • Vlastimil Babka's avatar
      mm/slub: free KFENCE objects in slab_free_hook() · 782f8906
      Vlastimil Babka authored
      When freeing an object that was allocated from KFENCE, we do that in the
      slowpath __slab_free(), relying on the fact that KFENCE "slab" cannot be
      the cpu slab, so the fastpath has to fallback to the slowpath.
      
      This optimization doesn't help much though, because is_kfence_address()
      is checked earlier anyway during the free hook processing or detached
      freelist building. Thus we can simplify the code by making the
      slab_free_hook() free the KFENCE object immediately, similarly to KASAN
      quarantine.
      
      In slab_free_hook() we can place kfence_free() above init processing, as
      callers have been making sure to set init to false for KFENCE objects.
      This simplifies slab_free(). This places it also above kasan_slab_free()
      which is ok as that skips KFENCE objects anyway.
      
      While at it also determine the init value in slab_free_freelist_hook()
      outside of the loop.
      
      This change will also make introducing per cpu array caches easier.
      Tested-by: default avatarMarco Elver <elver@google.com>
      Reviewed-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      782f8906
  3. 07 Dec, 2023 3 commits
    • Vlastimil Babka's avatar
      mm/slub: handle bulk and single object freeing separately · 284f17ac
      Vlastimil Babka authored
      Currently we have a single function slab_free() handling both single
      object freeing and bulk freeing with necessary hooks, the latter case
      requiring slab_free_freelist_hook(). It should be however better to
      distinguish the two use cases for the following reasons:
      
      - code simpler to follow for the single object case
      
      - better code generation - although inlining should eliminate the
        slab_free_freelist_hook() for single object freeing in case no
        debugging options are enabled, it seems it's not perfect. When e.g.
        KASAN is enabled, we're imposing additional unnecessary overhead for
        single object freeing.
      
      - preparation to add percpu array caches in near future
      
      Therefore, simplify slab_free() for the single object case by dropping
      unnecessary parameters and calling only slab_free_hook() instead of
      slab_free_freelist_hook(). Rename the bulk variant to slab_free_bulk()
      and adjust callers accordingly.
      
      While at it, flip (and document) slab_free_hook() return value so that
      it returns true when the freeing can proceed, which matches the logic of
      slab_free_freelist_hook() and is not confusingly the opposite.
      
      Additionally we can simplify a bit by changing the tail parameter of
      do_slab_free() when freeing a single object - instead of NULL we can set
      it equal to head.
      
      bloat-o-meter shows small code reduction with a .config that has KASAN
      etc disabled:
      
      add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-118 (-118)
      Function                                     old     new   delta
      kmem_cache_alloc_bulk                       1203    1196      -7
      kmem_cache_free                              861     835     -26
      __kmem_cache_free                            741     704     -37
      kmem_cache_free_bulk                         911     863     -48
      Reviewed-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      284f17ac
    • Vlastimil Babka's avatar
      mm/slub: introduce __kmem_cache_free_bulk() without free hooks · 520a688a
      Vlastimil Babka authored
      Currently, when __kmem_cache_alloc_bulk() fails, it frees back the
      objects that were allocated before the failure, using
      kmem_cache_free_bulk(). Because kmem_cache_free_bulk() calls the free
      hooks (KASAN etc.) and those expect objects that were processed by the
      post alloc hooks, slab_post_alloc_hook() is called before
      kmem_cache_free_bulk().
      
      This is wasteful, although not a big concern in practice for the rare
      error path. But in order to efficiently handle percpu array batch refill
      and free in the near future, we will also need a variant of
      kmem_cache_free_bulk() that avoids the free hooks. So introduce it now
      and use it for the failure path.
      
      In case of failure we however still need to perform memcg uncharge so
      handle that in a new memcg_slab_alloc_error_hook(). Thanks to Chengming
      Zhou for noticing the missing uncharge.
      
      As a consequence, __kmem_cache_alloc_bulk() no longer needs the objcg
      parameter, remove it.
      Reviewed-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      520a688a
    • Vlastimil Babka's avatar
      mm/slub: fix bulk alloc and free stats · 6f3dd2c3
      Vlastimil Babka authored
      The SLUB sysfs stats enabled CONFIG_SLUB_STATS have two deficiencies
      identified wrt bulk alloc/free operations:
      
      - Bulk allocations from cpu freelist are not counted. Add the
        ALLOC_FASTPATH counter there.
      
      - Bulk fastpath freeing will count a list of multiple objects with a
        single FREE_FASTPATH inc. Add a stat_add() variant to count them all.
      Reviewed-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
      6f3dd2c3
  4. 06 Dec, 2023 13 commits
  5. 05 Dec, 2023 11 commits
  6. 04 Dec, 2023 3 commits
  7. 22 Nov, 2023 1 commit
  8. 13 Nov, 2023 3 commits
  9. 12 Nov, 2023 4 commits