]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
zsmalloc: allow only one active pool compaction context
authorSergey Senozhatsky <senozhatsky@chromium.org>
Tue, 18 Apr 2023 07:46:39 +0000 (16:46 +0900)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 30 Oct 2023 11:00:20 +0000 (12:00 +0100)
commitdb9c89e26409a21344d723e96e9dd65a82fc95cf
tree08acf1c54a592effb04abe776c5f8de0202a7c13
parent593a799a08c7ec7a2e0a33ef0c0fd76fd0258656
zsmalloc: allow only one active pool compaction context

BugLink: https://bugs.launchpad.net/bugs/2039110
commit d2658f2052c7db6ec0a79977205f8cf1cb9effc2 upstream.

zsmalloc pool can be compacted concurrently by many contexts,
e.g.

 cc1 handle_mm_fault()
      do_anonymous_page()
       __alloc_pages_slowpath()
        try_to_free_pages()
         do_try_to_free_pages(
          lru_gen_shrink_node()
           shrink_slab()
            do_shrink_slab()
             zs_shrinker_scan()
              zs_compact()

Pool compaction is currently (basically) single-threaded as
it is performed under pool->lock. Having multiple compaction
threads results in unnecessary contention, as each thread
competes for pool->lock. This, in turn, affects all zsmalloc
operations such as zs_malloc(), zs_map_object(), zs_free(), etc.

Introduce the pool->compaction_in_progress atomic variable,
which ensures that only one compaction context can run at a
time. This reduces overall pool->lock contention in (corner)
cases when many contexts attempt to shrink zspool simultaneously.

Link: https://lkml.kernel.org/r/20230418074639.1903197-1-senozhatsky@chromium.org
Fixes: c0547d0b6a4b ("zsmalloc: consolidate zs_pool's migrate_lock and size_class's locks")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
mm/zsmalloc.c