1. Feb 23, 2024
    • Yosry Ahmed's avatar
      mm: swap: enforce updating inuse_pages at the end of swap_range_free() · 64cf264c
      Yosry Ahmed authored
      Patch series "mm: zswap: simplify zswap_swapoff()", v2.
      
      These patches aim to simplify zswap_swapoff() by removing the unnecessary
      trees cleanup code.  Patch 1 makes sure that the order of operations
      during swapoff is enforced correctly, making sure the simplification in
      patch 2 is correct in a future-proof manner.
      
      
      This patch (of 2):
      
      In swap_range_free(), we update inuse_pages then do some cleanups (arch
      invalidation, zswap invalidation, swap cache cleanups, etc).  During
      swapoff, try_to_unuse() checks that inuse_pages is 0 to make sure all swap
      entries are freed.  Make sure we only update inuse_pages after we are done
      with the cleanups in swap_range_free(), and use the proper memory barriers
      to enforce it.  This makes sure that code following try_to_unuse() can
      safely assume that swap_range_free() ran for all entries in thr swapfile
      (e.g.  swap cache cleanup, zswap_swapoff()).
      
      In practice, this currently isn't a problem because swap_range_free() is
      called with the swap info lock held, and the swapoff code happens to spin
      for that after try_to_unuse().  However, this seems fragile and
      unintentional, so make it more relable and future-proof.  This also
      facilitates a following simplification of zswap_swapoff().
      
      Link: https://lkml.kernel.org/r/20240124045113.415378-1-yosryahmed@google.com
      Link: https://lkml.kernel.org/r/20240124045113.415378-2-yosryahmed@google.com
      
      
      Signed-off-by: default avatarYosry Ahmed <yosryahmed@google.com>
      Reviewed-by: default avatar"Huang, Ying" <ying.huang@intel.com>
      Cc: Chengming Zhou <zhouchengming@bytedance.com>
      Cc: Chris Li <chrisl@kernel.org>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Nhat Pham <nphamcs@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      64cf264c
    • Chengming Zhou's avatar
      mm/zswap: split zswap rb-tree · 44c7c734
      Chengming Zhou authored
      Each swapfile has one rb-tree to search the mapping of swp_entry_t to
      zswap_entry, that use a spinlock to protect, which can cause heavy lock
      contention if multiple tasks zswap_store/load concurrently.
      
      Optimize the scalability problem by splitting the zswap rb-tree into
      multiple rb-trees, each corresponds to SWAP_ADDRESS_SPACE_PAGES (64M),
      just like we did in the swap cache address_space splitting.
      
      Although this method can't solve the spinlock contention completely, it
      can mitigate much of that contention.  Below is the results of kernel
      build in tmpfs with zswap shrinker enabled:
      
           linux-next  zswap-lock-optimize
      real 1m9.181s    1m3.820s
      user 17m44.036s  17m40.100s
      sys  7m37.297s   4m54.622s
      
      So there are clearly improvements.
      
      Link: https://lkml.kernel.org/r/20240117-b4-zswap-lock-optimize-v2-2-b5cc55479090@bytedance.com
      
      
      Signed-off-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Acked-by: default avatarNhat Pham <nphamcs@gmail.com>
      Acked-by: default avatarYosry Ahmed <yosryahmed@google.com>
      Cc: Chris Li <chriscli@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      44c7c734
    • Chengming Zhou's avatar
      mm/zswap: make sure each swapfile always have zswap rb-tree · bb29fd77
      Chengming Zhou authored
      Patch series "mm/zswap: optimize the scalability of zswap rb-tree", v2.
      
      When testing the zswap performance by using kernel build -j32 in a tmpfs
      directory, I found the scalability of zswap rb-tree is not good, which is
      protected by the only spinlock.  That would cause heavy lock contention if
      multiple tasks zswap_store/load concurrently.
      
      So a simple solution is to split the only one zswap rb-tree into multiple
      rb-trees, each corresponds to SWAP_ADDRESS_SPACE_PAGES (64M).  This idea
      is from the commit 4b3ef9da ("mm/swap: split swap cache into 64MB
      trunks").
      
      Although this method can't solve the spinlock contention completely, it
      can mitigate much of that contention.  Below is the results of kernel
      build in tmpfs with zswap shrinker enabled:
      
           linux-next  zswap-lock-optimize
      real 1m9.181s    1m3.820s
      user 17m44.036s  17m40.100s
      sys  7m37.297s   4m54.622s
      
      So there are clearly improvements.  And it's complementary with the
      ongoing zswap xarray conversion by Chris.  Anyway, I think we can also
      merge this first, it's complementary IMHO.  So I just refresh and resend
      this for further discussion.
      
      
      This patch (of 2):
      
      Not all zswap interfaces can handle the absence of the zswap rb-tree,
      actually only zswap_store() has handled it for now.
      
      To make things simple, we make sure each swapfile always have the zswap
      rb-tree prepared before being enabled and used.  The preparation is
      unlikely to fail in practice, this patch just make it explicit.
      
      Link: https://lkml.kernel.org/r/20240117-b4-zswap-lock-optimize-v2-0-b5cc55479090@bytedance.com
      Link: https://lkml.kernel.org/r/20240117-b4-zswap-lock-optimize-v2-1-b5cc55479090@bytedance.com
      
      
      Signed-off-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Acked-by: default avatarNhat Pham <nphamcs@gmail.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Acked-by: default avatarYosry Ahmed <yosryahmed@google.com>
      Cc: Chris Li <chriscli@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      bb29fd77
    • Lukas Bulwahn's avatar
      mempolicy: clean up minor dead code in queue_pages_test_walk() · 3efbe13e
      Lukas Bulwahn authored
      Commit 2cafb582 ("mempolicy: remove confusing MPOL_MF_LAZY dead code")
      removes MPOL_MF_LAZY handling in queue_pages_test_walk(), and with that,
      there is no effective use of the local variable endvma in that function
      remaining.
      
      Remove the local variable endvma and its dead code. No functional change.
      
      This issue was identified with clang-analyzer's dead stores analysis.
      
      Link: https://lkml.kernel.org/r/20240122092504.18377-1-lukas.bulwahn@gmail.com
      
      
      Signed-off-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
      Cc: Hugh Dickins <hughd@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      3efbe13e
    • Lukas Bulwahn's avatar
      maple_tree: avoid duplicate variable init in mast_spanning_rebalance() · 8689d750
      Lukas Bulwahn authored
      The local variables r_tmp and l_tmp in mast_spanning_rebalance() are
      already initialized at its declaration; there is no need to assign the
      value again.
      
      Remove the duplicate initialization of {r,l}_tmp.  No functional change. 
      Due to common compiler optimizations, also no change to object code.
      
      This issue was identified with clang-analyzer's dead stores analysis.
      
      Link: https://lkml.kernel.org/r/20240122102000.29558-1-lukas.bulwahn@gmail.com
      
      
      Signed-off-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
      Reviewed-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      8689d750
    • Nico Pache's avatar
      selftests: mm: perform some system cleanup before using hugepages · b433ffa8
      Nico Pache authored
      When running with CATEGORY= (thp | hugetlb) we see a large numbers of
      tests failing.  These failures are due to not being able to allocate a
      hugepage and normally occur on memory contrainted systems or when using
      large page sizes.
      
      drop_cache and compact_memory before the tests for a higher chance at a
      successful hugepage allocation.
      
      Link: https://lkml.kernel.org/r/20240117180037.15734-1-npache@redhat.com
      
      
      Signed-off-by: default avatarNico Pache <npache@redhat.com>
      Cc: Shuah Khan <shuah@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      b433ffa8
    • Lokesh Gidra's avatar
      userfaultfd: fix return error if mmap_changing is non-zero in MOVE ioctl · 6ca03f1b
      Lokesh Gidra authored
      To be consistent with other uffd ioctl's returning EAGAIN when
      mmap_changing is detected, we should change UFFDIO_MOVE to do the same.
      
      Link: https://lkml.kernel.org/r/20240117223922.1445327-1-lokeshgidra@google.com
      
      
      Signed-off-by: default avatarLokesh Gidra <lokeshgidra@google.com>
      Acked-by: default avatarSuren Baghdasaryan <surenb@google.com>
      Acked-by: default avatarMike Rapoport (IBM) <rppt@kernel.org>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Axel Rasmussen <axelrasmussen@google.com>
      Cc: Brian Geffon <bgeffon@google.com>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kalesh Singh <kaleshsingh@google.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Nicolas Geoffray <ngeoffray@google.com>
      Cc: Peter Xu <peterx@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      6ca03f1b
    • Greg Thelen's avatar
      selftests/memfd: delete unused declarations · a9117b4d
      Greg Thelen authored
      Commit 32d118ad ("selftests/memfd: add tests for F_SEAL_EXEC"):
      - added several unused 'nbytes' local variables
      
      Commit 6469b66e ("selftests: improve vm.memfd_noexec sysctl tests"):
      - orphaned 'newpid_thread_fn2()' forward declaration
      - orphaned 'join_newpid_thread()' forward declaration
      - added unused 'pid' local in sysctl_simple_child()
      - orphaned 'fd' local in sysctl_simple_child()
      - added unused 'fd' in sysctl_nested_child()
      
      Delete the unused locals and forward declarations.
      
      Link: https://lkml.kernel.org/r/20240118095057.677544-1-gthelen@google.com
      
      
      Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
      Cc: Aleksa Sarai <cyphar@cyphar.com>
      Cc: Daniel Verkamp <dverkamp@chromium.org>
      Cc: Jeff Xu <jeffxu@google.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Shuah Khan <shuah@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      a9117b4d
    • Shakeel Butt's avatar
      mm: writeback: ratelimit stat flush from mem_cgroup_wb_stats · d9b3ce87
      Shakeel Butt authored
      One of our workloads (Postgres 14) has regressed when migrated from 5.10
      to 6.1 upstream kernel.  The regression can be reproduced by sysbench's
      oltp_write_only benchmark.  It seems like the always on rstat flush in
      mem_cgroup_wb_stats() is causing the regression.  So, rate limit that
      specific rstat flush.  One potential consequence would be the dirty
      throttling might be decided on stale memcg stats.  However from our
      benchmarks and production traffic we have not observed any change in the
      dirty throttling behavior of the application.
      
      Link: https://lkml.kernel.org/r/20240118184235.618164-1-shakeelb@google.com
      Fixes: 2d146aa3
      
       ("mm: memcontrol: switch to rstat")
      Signed-off-by: default avatarShakeel Butt <shakeelb@google.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Acked-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Muchun Song <muchun.song@linux.dev>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      d9b3ce87
    • Kefeng Wang's avatar
      mm: memory: move mem_cgroup_charge() into alloc_anon_folio() · 085ff35e
      Kefeng Wang authored
      The GFP flags from vma_thp_gfp_mask() according to user configuration only
      used for large folio allocation but not for memory cgroup charge, and
      GFP_KERNEL is used for both order-0 and large order folio when memory
      cgroup charge at present.  However, mem_cgroup_charge() uses the GFP flags
      in a fairly sophisticated way.  In addition to checking
      gfpflags_allow_blocking(), it pays attention to __GFP_NORETRY and
      __GFP_RETRY_MAYFAIL to ensure that processes within this memcg do not
      exceed their quotas.
      
      So we'd better to move mem_cgroup_charge() into alloc_anon_folio(),
      
      1) it will make us to allocate as much as possible large order folio,
         because we could try the next order if mem_cgroup_charge() fails,
         although the memcg's memory usage is close to its limits.
      
      2) using same GFP flags for allocation and charge is to be consistent
         with PMD THP firstly, in addition, according to GFP flag returned from
         vma_thp_gfp_mask(), GFP_TRANSHUGE_LIGHT could make us skip direct
         reclaim, _GFP_NORETRY will make us skip mem_cgroup_oom() and won't
         trigger memory cgroup oom from large order(order <= COSTLY_ORDER) folio
         charging.
      
      Link: https://lkml.kernel.org/r/20240122011612.501029-1-wangkefeng.wang@huawei.com
      Link: https://lkml.kernel.org/r/20240117103954.2756050-1-wangkefeng.wang@huawei.com
      
      
      Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
      Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Roman Gushchin <roman.gushchin@linux.dev>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Shakeel Butt <shakeelb@google.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      085ff35e
    • Ryan Roberts's avatar
      tools/mm: add thpmaps script to dump THP usage info · 2444172c
      Ryan Roberts authored
      With the proliferation of large folios for file-backed memory, and more
      recently the introduction of multi-size THP for anonymous memory, it is
      becoming useful to be able to see exactly how large folios are mapped into
      processes.  For some architectures (e.g.  arm64), if most memory is mapped
      using contpte-sized and -aligned blocks, TLB usage can be optimized so
      it's useful to see where these requirements are and are not being met.
      
      thpmaps is a Python utility that reads /proc/<pid>/smaps,
      /proc/<pid>/pagemap and /proc/kpageflags to print information about how
      transparent huge pages (both file and anon) are mapped to a specified
      process or cgroup.  It aims to help users debug and optimize their
      workloads.  In future we may wish to introduce stats directly into the
      kernel (e.g.  smaps or similar), but for now this provides a short term
      solution without the need to introduce any new ABI.
      
      Run with help option for a full listing of the arguments:
      
          # ./thpmaps --help
      
      --8<--
      usage: thpmaps [-h] [--pid pid | --cgroup path] [--rollup]
                     [--cont size[KMG]] [--inc-smaps] [--inc-empty]
                     [--periodic sleep_ms]
      
      Prints information about how transparent huge pages are mapped, either
      system-wide, or for a specified process or cgroup.
      
      When run with --pid, the user explicitly specifies the set of pids to
      scan.  e.g.  "--pid 10 [--pid 134 ...]".  When run with --cgroup, the user
      passes either a v1 or v2 cgroup and all pids that belong to the cgroup
      subtree are scanned.  When run with neither --pid nor --cgroup, the full
      set of pids on the system is gathered from /proc and scanned as if the
      user had provided "--pid 1 --pid 2 ...".
      
      A default set of statistics is always generated for THP mappings. 
      However, it is also possible to generate additional statistics for
      "contiguous block mappings" where the block size is user-defined.
      
      Statistics are maintained independently for anonymous and file-backed
      (pagecache) memory and are shown both in kB and as a percentage of either
      total anonymous or total file-backed memory as appropriate.
      
      THP Statistics
      --------------
      
      Statistics are always generated for fully- and contiguously-mapped THPs
      whose mapping address is aligned to their size, for each <size> supported
      by the system.  Separate counters describe THPs mapped by PTE vs those
      mapped by PMD.  (Although note a THP can only be mapped by PMD if it is
      PMD-sized):
      
      - anon-thp-pte-aligned-<size>kB
      - file-thp-pte-aligned-<size>kB
      - anon-thp-pmd-aligned-<size>kB
      - file-thp-pmd-aligned-<size>kB
      
      Similarly, statistics are always generated for fully- and contiguously-
      mapped THPs whose mapping address is *not* aligned to their size, for each
      <size> supported by the system.  Due to the unaligned mapping, it is
      impossible to map by PMD, so there are only PTE counters for this case:
      
      - anon-thp-pte-unaligned-<size>kB
      - file-thp-pte-unaligned-<size>kB
      
      Statistics are also always generated for mapped pages that belong to a THP
      but where the is THP is *not* fully- and contiguously- mapped.  These
      "partial" mappings are all counted in the same counter regardless of the
      size of the THP that is partially mapped:
      
      - anon-thp-pte-partial
      - file-thp-pte-partial
      
      Contiguous Block Statistics
      ---------------------------
      
      An optional, additional set of statistics is generated for every
      contiguous block size specified with `--cont <size>`.  These statistics
      show how much memory is mapped in contiguous blocks of <size> and also
      aligned to <size>.  A given contiguous block must all belong to the same
      THP, but there is no requirement for it to be the *whole* THP.  Separate
      counters describe contiguous blocks mapped by PTE vs those mapped by PMD:
      
      - anon-cont-pte-aligned-<size>kB
      - file-cont-pte-aligned-<size>kB
      - anon-cont-pmd-aligned-<size>kB
      - file-cont-pmd-aligned-<size>kB
      
      As an example, if monitoring 64K contiguous blocks (--cont 64K), there are
      a number of sources that could provide such blocks: a fully- and
      contiguously-mapped 64K THP that is aligned to a 64K boundary would
      provide 1 block.  A fully- and contiguously-mapped 128K THP that is
      aligned to at least a 64K boundary would provide 2 blocks.  Or a 128K THP
      that maps its first 100K, but contiguously and starting at a 64K boundary
      would provide 1 block.  A fully- and contiguously-mapped 2M THP would
      provide 32 blocks.  There are many other possible permutations.
      
      options:
        -h, --help           show this help message and exit
        --pid pid            Process id of the target process. Maybe issued
                             multiple times to scan multiple processes. --pid
                             and --cgroup are mutually exclusive. If neither
                             are provided, all processes are scanned to
                             provide system-wide information.
        --cgroup path        Path to the target cgroup in sysfs. Iterates
                             over every pid in the cgroup and its children.
                             --pid and --cgroup are mutually exclusive. If
                             neither are provided, all processes are scanned
                             to provide system-wide information.
        --rollup             Sum the per-vma statistics to provide a summary
                             over the whole system, process or cgroup.
        --cont size[KMG]     Adds stats for memory that is mapped in
                             contiguous blocks of <size> and also aligned to
                             <size>. May be issued multiple times to track
                             multiple sized blocks. Useful to infer e.g.
                             arm64 contpte and hpa mappings. Size must be a
                             power-of-2 number of pages.
        --inc-smaps          Include all numerical, additive
                             /proc/<pid>/smaps stats in the output.
        --inc-empty          Show all statistics including those whose value
                             is 0.
        --periodic sleep_ms  Run in a loop, polling every sleep_ms
                             milliseconds.
      
      Requires root privilege to access pagemap and kpageflags.
      --8<--
      
      Example command to summarise fully and partially mapped THPs and 64K
      contiguous blocks over all VMAs in all processes in the system
      (--inc-empty forces printing stats that are 0):
      
          # ./thpmaps --cont 64K --rollup --inc-empty
      
      --8<--
      anon-thp-pmd-aligned-2048kB:      139264 kB ( 6%)
      file-thp-pmd-aligned-2048kB:           0 kB ( 0%)
      anon-thp-pte-aligned-16kB:             0 kB ( 0%)
      anon-thp-pte-aligned-32kB:             0 kB ( 0%)
      anon-thp-pte-aligned-64kB:         72256 kB ( 3%)
      anon-thp-pte-aligned-128kB:            0 kB ( 0%)
      anon-thp-pte-aligned-256kB:            0 kB ( 0%)
      anon-thp-pte-aligned-512kB:            0 kB ( 0%)
      anon-thp-pte-aligned-1024kB:           0 kB ( 0%)
      anon-thp-pte-aligned-2048kB:           0 kB ( 0%)
      anon-thp-pte-unaligned-16kB:           0 kB ( 0%)
      anon-thp-pte-unaligned-32kB:           0 kB ( 0%)
      anon-thp-pte-unaligned-64kB:           0 kB ( 0%)
      anon-thp-pte-unaligned-128kB:          0 kB ( 0%)
      anon-thp-pte-unaligned-256kB:          0 kB ( 0%)
      anon-thp-pte-unaligned-512kB:          0 kB ( 0%)
      anon-thp-pte-unaligned-1024kB:         0 kB ( 0%)
      anon-thp-pte-unaligned-2048kB:         0 kB ( 0%)
      anon-thp-pte-partial:              63232 kB ( 3%)
      file-thp-pte-aligned-16kB:        809024 kB (47%)
      file-thp-pte-aligned-32kB:         43168 kB ( 3%)
      file-thp-pte-aligned-64kB:         98496 kB ( 6%)
      file-thp-pte-aligned-128kB:        17536 kB ( 1%)
      file-thp-pte-aligned-256kB:            0 kB ( 0%)
      file-thp-pte-aligned-512kB:            0 kB ( 0%)
      file-thp-pte-aligned-1024kB:           0 kB ( 0%)
      file-thp-pte-aligned-2048kB:           0 kB ( 0%)
      file-thp-pte-unaligned-16kB:       21712 kB ( 1%)
      file-thp-pte-unaligned-32kB:         704 kB ( 0%)
      file-thp-pte-unaligned-64kB:         896 kB ( 0%)
      file-thp-pte-unaligned-128kB:      44928 kB ( 3%)
      file-thp-pte-unaligned-256kB:          0 kB ( 0%)
      file-thp-pte-unaligned-512kB:          0 kB ( 0%)
      file-thp-pte-unaligned-1024kB:         0 kB ( 0%)
      file-thp-pte-unaligned-2048kB:         0 kB ( 0%)
      file-thp-pte-partial:               9252 kB ( 1%)
      anon-cont-pmd-aligned-64kB:       139264 kB ( 6%)
      file-cont-pmd-aligned-64kB:            0 kB ( 0%)
      anon-cont-pte-aligned-64kB:       100672 kB ( 4%)
      file-cont-pte-aligned-64kB:       161856 kB ( 9%)
      --8<--
      
      Link: https://lkml.kernel.org/r/20240116141235.960842-1-ryan.roberts@arm.com
      
      
      Signed-off-by: default avatarRyan Roberts <ryan.roberts@arm.com>
      Tested-by: default avatarBarry Song <v-songbaohua@oppo.com>
      Cc: Alistair Popple <apopple@nvidia.com>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: William Kucharski <william.kucharski@oracle.com>
      Cc: Zenghui Yu <yuzenghui@huawei.com>
      Cc: Zi Yan <ziy@nvidia.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      2444172c
    • Ronald Monthero's avatar
      mm/zswap: improve with alloc_workqueue() call · 8409a385
      Ronald Monthero authored
      The core-api create_workqueue is deprecated, this patch replaces the
      create_workqueue with alloc_workqueue.  The previous implementation
      workqueue of zswap was a bounded workqueue, this patch uses
      alloc_workqueue() to create an unbounded workqueue.  The WQ_UNBOUND
      attribute is desirable making the workqueue not localized to a specific
      cpu so that the scheduler is free to exercise improvisations in any
      demanding scenarios for offloading cpu time slices for workqueues.  For
      example if any other workqueues of the same primary cpu had to be served
      which are WQ_HIGHPRI and WQ_CPU_INTENSIVE.  Also Unbound workqueue happens
      to be more efficient in a system during memory pressure scenarios in
      comparison to a bounded workqueue.
      
      shrink_wq = alloc_workqueue("zswap-shrink",
                           WQ_UNBOUND|WQ_MEM_RECLAIM, 1);
      
      Overall the change suggested in this patch should be seamless and does not
      alter the existing behavior, other than the improvisation to be an
      unbounded workqueue.
      
      Link: https://lkml.kernel.org/r/20240116133145.12454-1-debug.penguin32@gmail.com
      
      
      Signed-off-by: default avatarRonald Monthero <debug.penguin32@gmail.com>
      Acked-by: default avatarNhat Pham <nphamcs@gmail.com>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Chris Li <chrisl@kernel.org>
      Cc: Dan Streetman <ddstreet@ieee.org>
      Cc: Seth Jennings <sjenning@redhat.com>
      Cc: Vitaly Wool <vitaly.wool@konsulko.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      8409a385
    • Pankaj Raghav's avatar
      readahead: use ilog2 instead of a while loop in page_cache_ra_order() · e03c16fb
      Pankaj Raghav authored
      A while loop is used to adjust the new_order to be lower than the
      ra->size.  ilog2 could be used to do the same instead of using a loop.
      
      ilog2 typically resolves to a bit scan reverse instruction.  This is
      particularly useful when ra->size is smaller than the 2^new_order as it
      resolves in one instruction instead of looping to find the new_order.
      
      No functional changes.
      
      Link: https://lkml.kernel.org/r/20240115102523.2336742-1-kernel@pankajraghav.com
      
      
      Signed-off-by: default avatarPankaj Raghav <p.raghav@samsung.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      e03c16fb
  2. Feb 22, 2024