* Re: [PATCH v3] cgroup/dmem: introduce a peak file
From: Michal Koutný @ 2026-05-29 13:01 UTC (permalink / raw)
To: Maarten Lankhorst
Cc: Thadeu Lima de Souza Cascardo, Tejun Heo, Johannes Weiner,
Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song,
Andrew Morton, Jonathan Corbet, Shuah Khan, Maxime Ripard,
Natalie Vock, Tvrtko Ursulin, cgroups, linux-kernel, linux-mm,
linux-doc, dri-devel, kernel-dev
In-Reply-To: <89901220-0a43-4668-9d20-aaecc72c58dd@lankhorst.se>
[-- Attachment #1: Type: text/plain, Size: 282 bytes --]
On Fri, May 29, 2026 at 09:34:28AM +0200, Maarten Lankhorst <dev@lankhorst.se> wrote:
> > Reviewed-by: Michal Koutný <mkoutny@suse.com>
> Reviewed-by: Maarten Lankhorst <dev@lankhorst.se>
>
> With your r-b it's ok to push it to the dmemcg tree?
Please go for it.
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]
^ permalink raw reply
* Re: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
From: kernel test robot @ 2026-05-29 12:47 UTC (permalink / raw)
To: Yury Norov, Andrew Morton, David Hildenbrand, Zi Yan,
Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park,
Gregory Price, Ying Huang, Alistair Popple, linux-kernel
Cc: oe-kbuild-all, Linux Memory Management List, Yury Norov,
Farhad Alemi, Waiman Long, Rasmus Villemoes, cgroups
In-Reply-To: <20260528190337.878027-1-ynorov@nvidia.com>
Hi Yury,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/mm-don-t-allow-empty-relative-nodemask-in-mpol_relative_nodemask/20260529-030835
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20260528190337.878027-1-ynorov%40nvidia.com
patch subject: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
config: sparc64-randconfig-002-20260529 (https://download.01.org/0day-ci/archive/20260529/202605292049.eaIv99hr-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260529/202605292049.eaIv99hr-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605292049.eaIv99hr-lkp@intel.com/
All warnings (new ones prefixed by >>):
mm/mempolicy.c: In function 'mpol_relative_nodemask':
>> mm/mempolicy.c:377:10: warning: 'return' with a value, in function returning void
return -EINVAL;
^
mm/mempolicy.c:370:13: note: declared here
static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
^~~~~~~~~~~~~~~~~~~~~~
vim +/return +377 mm/mempolicy.c
369
370 static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
371 const nodemask_t *rel)
372 {
373 unsigned int w = nodes_weight(*rel);
374 nodemask_t tmp;
375
376 if (w == 0)
> 377 return -EINVAL;
378
379 nodes_fold(tmp, *orig, w);
380 nodes_onto(*ret, tmp, *rel);
381 }
382
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
From: kernel test robot @ 2026-05-29 12:45 UTC (permalink / raw)
To: Yury Norov, Andrew Morton, David Hildenbrand, Zi Yan,
Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park,
Gregory Price, Ying Huang, Alistair Popple, linux-kernel
Cc: llvm, oe-kbuild-all, Linux Memory Management List, Yury Norov,
Farhad Alemi, Waiman Long, Rasmus Villemoes, cgroups
In-Reply-To: <20260528190337.878027-1-ynorov@nvidia.com>
Hi Yury,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/mm-don-t-allow-empty-relative-nodemask-in-mpol_relative_nodemask/20260529-030835
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20260528190337.878027-1-ynorov%40nvidia.com
patch subject: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260529/202605291432.MbAf9EG6-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260529/202605291432.MbAf9EG6-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605291432.MbAf9EG6-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> mm/mempolicy.c:377:3: warning: void function 'mpol_relative_nodemask' should not return a value [-Wreturn-mismatch]
377 | return -EINVAL;
| ^ ~~~~~~~
1 warning generated.
vim +/mpol_relative_nodemask +377 mm/mempolicy.c
369
370 static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
371 const nodemask_t *rel)
372 {
373 unsigned int w = nodes_weight(*rel);
374 nodemask_t tmp;
375
376 if (w == 0)
> 377 return -EINVAL;
378
379 nodes_fold(tmp, *orig, w);
380 nodes_onto(*ret, tmp, *rel);
381 }
382
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH rdma-next v2 0/3] cgroup/rdma: add MR memory size resource tracking
From: Michal Koutný @ 2026-05-29 12:46 UTC (permalink / raw)
To: Tao Cui; +Cc: tj, hannes, leon, jgg, linux-rdma, cgroups, Tao Cui
In-Reply-To: <20260529090733.2242822-1-cui.tao@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]
Hi.
On Fri, May 29, 2026 at 05:07:30PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
> The real scarce resource in multi-tenant
> deployments is pinned memory: how much physical memory gets registered
> through MRs.
> ...
> 3. Overlap with memory cgroup: mr_mem does not count process memory
> usage; it represents a per-device DMA registration budget: the
> amount of memory this cgroup may register through a given HCA.
> This is a different dimension from what memory cgroup tracks. An
> administrator might set mr_mem limits differently per device, which
> memory cgroup cannot express.
>
> In particular, mr_mem tracks the registered memory range associated
> with the MR rather than exact dynamically pinned pages (e.g. for
> ODP MRs). This is a stable, policy-oriented approximation of
> registration footprint, not an attempt at precise physical page
> accounting.
IIUC the pinned memory is regular RAM, i.e. it could be controlled with
memcg as needed. Or is there "physical" limit of what can be assigned to
a single device?
BTW, have a look at [1], it'd be good to converge to similar approach
(the current proposal allows distinguishing whether charging should
include or exempt memcg counting). Also it seems, that the dmem
controller could be a one-stop solution for all DMA charges. Please tell
me if there are any distinguishing factors between RDMA devices' memory
and these dmem memory regions.
Thanks,
Michal
[1] https://lore.kernel.org/r/20260519-cgroup-dmem-memcg-double-charge-v2-0-db4d1407062b@redhat.com/
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]
^ permalink raw reply
* [RFC PATCH v2 4/9] mm: admit large swapin by backend range in swapin_sync()
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
A large swapin can only read one folio when the whole range has compatible
backing. Mixed zswap/disk ranges must not reach large-folio IO, and zswap
range probes are only snapshots.
Filter the orders passed to swap_cache_alloc_folio() in swapin_sync().
Uniform zeromap ranges and all-disk ranges keep the existing large swapin
path. Fully zswap-backed ranges may be tried. Mixed zswap/disk ranges fall
back before allocation.
After a large swapcache folio is installed, recheck the zswap range and
drop the fresh folio if it became mixed. Also consume -EAGAIN from
swap_read_folio() the same way. Both cases retry order-0, where each slot
can resolve its current backend independently.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/memcontrol-v1.c | 8 ++-
mm/memory.c | 31 ++++++++-
mm/swap_state.c | 169 ++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 194 insertions(+), 14 deletions(-)
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 765069211567..5b11b8055c66 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -682,8 +682,8 @@ void __memcg1_swapout(struct folio *folio, struct swap_cluster_info *ci)
* memcg1_swapin - uncharge swap slot on swapin
* @folio: folio being swapped in
*
- * Call this function after successfully adding the charged
- * folio to swapcache.
+ * Call this after the charged folio has been added to swapcache and the caller
+ * is no longer going to drop it back to swapped-out state.
*
* Context: The folio has to be in swap cache and locked.
*/
@@ -721,7 +721,9 @@ void memcg1_swapin(struct folio *folio)
id = __swap_cgroup_clear(ci, swp_cluster_offset(folio->swap),
nr_pages);
swap_cluster_unlock(ci);
- mem_cgroup_uncharge_swap(id, nr_pages);
+
+ if (id)
+ mem_cgroup_uncharge_swap(id, nr_pages);
}
#endif
diff --git a/mm/memory.c b/mm/memory.c
index 5a365492a9a2..d73a19692dea 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4538,6 +4538,24 @@ static inline bool should_try_to_free_swap(struct swap_info_struct *si,
folio_ref_count(folio) == (extra_refs + folio_nr_pages(folio));
}
+static void memcg1_swapin_retry_folio(struct folio *folio,
+ struct vm_fault *vmf)
+{
+ if (!folio_test_large(folio) || !folio_test_swapcache(folio))
+ return;
+
+ if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) {
+ if (!folio_trylock(folio))
+ return;
+ } else {
+ folio_lock(folio);
+ }
+
+ if (folio_test_large(folio) && folio_test_swapcache(folio))
+ memcg1_swapin(folio);
+ folio_unlock(folio);
+}
+
static vm_fault_t pte_marker_clear(struct vm_fault *vmf)
{
vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, vmf->pmd,
@@ -4857,8 +4875,10 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
swapcache = folio;
ret |= folio_lock_or_retry(folio, vmf);
- if (ret & VM_FAULT_RETRY)
+ if (ret & VM_FAULT_RETRY) {
+ memcg1_swapin_retry_folio(folio, vmf);
goto out_release;
+ }
page = folio_file_page(folio, swp_offset(entry));
/*
@@ -5067,6 +5087,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (unlikely(folio != swapcache)) {
folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE);
folio_add_lru_vma(folio, vma);
+ if (folio_test_large(swapcache))
+ memcg1_swapin(swapcache);
folio_put_swap(swapcache, NULL);
} else if (!folio_test_anon(folio)) {
/*
@@ -5076,6 +5098,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
VM_WARN_ON_ONCE_FOLIO(folio_nr_pages(folio) != nr_pages, folio);
VM_WARN_ON_ONCE_FOLIO(folio_mapped(folio), folio);
folio_add_new_anon_rmap(folio, vma, address, rmap_flags);
+ if (folio_test_large(folio))
+ memcg1_swapin(folio);
folio_put_swap(folio, NULL);
} else {
VM_WARN_ON_ONCE(nr_pages != 1 && nr_pages != folio_nr_pages(folio));
@@ -5132,8 +5156,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (vmf->pte)
pte_unmap_unlock(vmf->pte, vmf->ptl);
out_page:
- if (folio_test_swapcache(folio))
+ if (folio_test_swapcache(folio)) {
+ if (folio_test_large(folio))
+ memcg1_swapin(folio);
folio_free_swap(folio);
+ }
folio_unlock(folio);
out_release:
folio_put(folio);
diff --git a/mm/swap_state.c b/mm/swap_state.c
index d37097913b30..f03ad4832f16 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -21,6 +21,7 @@
#include <linux/migrate.h>
#include <linux/vmalloc.h>
#include <linux/huge_mm.h>
+#include <linux/zswap.h>
#include <linux/shmem_fs.h>
#include "internal.h"
#include "swap_table.h"
@@ -403,7 +404,8 @@ void __swap_cache_replace_folio(struct swap_cluster_info *ci,
static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
swp_entry_t targ_entry, gfp_t gfp,
unsigned int order, struct vm_fault *vmf,
- struct mempolicy *mpol, pgoff_t ilx)
+ struct mempolicy *mpol, pgoff_t ilx,
+ bool defer_memcg1_swapin)
{
int err;
swp_entry_t entry;
@@ -466,7 +468,8 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
}
/* memsw uncharges swap when folio is added to swap cache */
- memcg1_swapin(folio);
+ if (!defer_memcg1_swapin || !order)
+ memcg1_swapin(folio);
if (shadow)
workingset_refault(folio, shadow);
@@ -495,9 +498,12 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
* Return: Returns the folio if allocation succeeded and folio is in the swap
* cache. Returns error code if failed due to race, OOM or invalid arguments.
*/
-struct folio *swap_cache_alloc_folio(swp_entry_t targ_entry, gfp_t gfp,
- unsigned long orders, struct vm_fault *vmf,
- struct mempolicy *mpol, pgoff_t ilx)
+static struct folio *__swap_cache_alloc_folio(swp_entry_t targ_entry,
+ gfp_t gfp, unsigned long orders,
+ struct vm_fault *vmf,
+ struct mempolicy *mpol,
+ pgoff_t ilx,
+ bool defer_memcg1_swapin)
{
int order, err;
struct folio *ret;
@@ -512,7 +518,8 @@ struct folio *swap_cache_alloc_folio(swp_entry_t targ_entry, gfp_t gfp,
do {
ret = __swap_cache_alloc(ci, targ_entry, gfp, order,
- vmf, mpol, ilx);
+ vmf, mpol, ilx,
+ defer_memcg1_swapin);
if (!IS_ERR(ret))
break;
err = PTR_ERR(ret);
@@ -525,6 +532,124 @@ struct folio *swap_cache_alloc_folio(swp_entry_t targ_entry, gfp_t gfp,
return ret;
}
+struct folio *swap_cache_alloc_folio(swp_entry_t targ_entry, gfp_t gfp,
+ unsigned long orders, struct vm_fault *vmf,
+ struct mempolicy *mpol, pgoff_t ilx)
+{
+ return __swap_cache_alloc_folio(targ_entry, gfp, orders, vmf,
+ mpol, ilx, false);
+}
+
+static struct folio *swap_cache_alloc_speculative_folio(swp_entry_t targ_entry,
+ gfp_t gfp,
+ unsigned long orders,
+ struct vm_fault *vmf,
+ struct mempolicy *mpol,
+ pgoff_t ilx)
+{
+ /*
+ * Speculative large swapin may drop this fresh swapcache folio and
+ * retry order-0 after backend or page-table revalidation. Keep the
+ * cgroup v1 memsw swap owner until the caller commits the folio.
+ */
+ return __swap_cache_alloc_folio(targ_entry, gfp, orders, vmf,
+ mpol, ilx, true);
+}
+
+static bool swapin_zeromap_same(swp_entry_t entry, unsigned int nr_pages)
+{
+ unsigned int ci_start = swp_cluster_offset(entry);
+ struct swap_cluster_info *ci = __swap_entry_to_cluster(entry);
+ bool is_zero;
+ unsigned int i;
+
+ if (ci_start + nr_pages > SWAPFILE_CLUSTER) {
+ VM_WARN_ON_ONCE(1);
+ return false;
+ }
+
+ rcu_read_lock();
+ if (!rcu_dereference(ci->table)) {
+ rcu_read_unlock();
+ return true;
+ }
+
+ is_zero = __swap_table_test_zero(ci, ci_start);
+ for (i = 1; i < nr_pages; i++) {
+ if (is_zero != __swap_table_test_zero(ci, ci_start + i)) {
+ rcu_read_unlock();
+ return false;
+ }
+ }
+ rcu_read_unlock();
+
+ return true;
+}
+
+static unsigned long swapin_admit_orders(swp_entry_t entry,
+ unsigned long orders)
+{
+ unsigned long candidates = orders & ~BIT(0);
+ unsigned long admitted = orders & BIT(0);
+ int order;
+
+ if (!candidates)
+ return orders;
+
+ while (candidates) {
+ enum zswap_range_state state;
+ unsigned int nr_pages;
+ swp_entry_t range_entry;
+ bool admit = false;
+
+ order = fls_long(candidates) - 1;
+ if (order > MAX_PAGE_ORDER) {
+ candidates &= ~BIT(order);
+ continue;
+ }
+
+ nr_pages = 1U << order;
+ range_entry = swp_entry(swp_type(entry),
+ round_down(swp_offset(entry), nr_pages));
+ if (!swapin_zeromap_same(range_entry, nr_pages))
+ goto next;
+
+ state = zswap_probe_range(range_entry, nr_pages);
+ switch (state) {
+ case ZSWAP_RANGE_MIXED:
+ break;
+ case ZSWAP_RANGE_ALL_ZSWAP:
+ case ZSWAP_RANGE_NEVER_ENABLED:
+ case ZSWAP_RANGE_NO_ZSWAP:
+ admit = true;
+ break;
+ }
+
+next:
+ if (admit)
+ admitted |= BIT(order);
+ else
+ count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK);
+ candidates &= ~BIT(order);
+ }
+
+ return admitted ? admitted : BIT(0);
+}
+
+static bool zswap_needs_order0_retry(struct folio *folio)
+{
+ if (!folio_test_large(folio))
+ return false;
+
+ /*
+ * Admission sees only an advisory zswap snapshot. Recheck after the
+ * large swapcache folio is installed; if the range became mixed, drop
+ * the fresh folio before IO and let order-0 handle each slot.
+ */
+ return zswap_probe_range(folio->swap, folio_nr_pages(folio)) ==
+ ZSWAP_RANGE_MIXED;
+}
+
/*
* If we are the only user, then try to free up the swap cache.
*
@@ -634,7 +759,8 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
folio = swap_cache_get_folio(entry);
if (folio)
return folio;
- folio = swap_cache_alloc_folio(entry, gfp, BIT(0), NULL, mpol, ilx);
+ folio = swap_cache_alloc_folio(entry, gfp, BIT(0), NULL,
+ mpol, ilx);
} while (PTR_ERR(folio) == -EEXIST);
if (IS_ERR_OR_NULL(folio))
@@ -677,18 +803,43 @@ struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp, unsigned long orders,
struct folio *folio;
int ret;
+ orders = swapin_admit_orders(entry, orders);
+again:
do {
folio = swap_cache_get_folio(entry);
if (folio)
return folio;
- folio = swap_cache_alloc_folio(entry, gfp, orders, vmf, mpol, ilx);
+ folio = swap_cache_alloc_speculative_folio(entry, gfp, orders,
+ vmf, mpol, ilx);
} while (PTR_ERR(folio) == -EEXIST);
if (IS_ERR(folio))
return folio;
+ if (zswap_needs_order0_retry(folio)) {
+ count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN_FALLBACK);
+ /*
+ * The folio is newly allocated, locked, clean and not uptodate;
+ * no data has been read into it. Removing it only restores the
+ * swap table entries so order-0 swapin can resolve a backend
+ * race without attempting speculative large-folio zswapin.
+ */
+ swap_cache_del_folio(folio);
+ folio_unlock(folio);
+ folio_put(folio);
+ orders = BIT(0);
+ goto again;
+ }
+
ret = swap_read_folio(folio, NULL);
- VM_WARN_ON_ONCE(ret == -EAGAIN);
+ if (ret == -EAGAIN) {
+ count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN_FALLBACK);
+ swap_cache_del_folio(folio);
+ folio_unlock(folio);
+ folio_put(folio);
+ orders = BIT(0);
+ goto again;
+ }
return folio;
}
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 9/9] docs: mm: update THP swapin counter descriptions
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
The THP swapin counter descriptions still describe large swapin as
coming only from non-zswap swap devices. Update them now that
zswap-backed large folio swapin can also increment swpin.
Also describe policy and backend rejection as swpin_fallback cases,
since speculative zswap large swapin can intentionally fall back before
doing large IO.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
Documentation/admin-guide/mm/transhuge.rst | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
index 23f8d13c2629..59b7a0d09243 100644
--- a/Documentation/admin-guide/mm/transhuge.rst
+++ b/Documentation/admin-guide/mm/transhuge.rst
@@ -667,13 +667,14 @@ zswpout
piece without splitting.
swpin
- is incremented every time a huge page is swapped in from a non-zswap
- swap device in one piece.
+ is incremented every time a huge page is swapped in from swap or
+ zswap in one piece.
swpin_fallback
- is incremented if swapin fails to allocate or charge a huge page
- and instead falls back to using huge pages with lower orders or
- small pages.
+ is incremented if swapin cannot use a huge page and instead falls
+ back to using huge pages with lower orders or small pages. This can
+ happen because allocation or charging fails, or because policy or
+ backend state rejects a speculative large swapin.
swpin_fallback_charge
is incremented if swapin fails to charge a huge page and instead
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 8/9] mm: try all-zswap large swapin within swap readahead windows
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
The non-synchronous swap fault path already computes either a VMA-based
or cluster-based readahead window. Use that existing window as locality
evidence for zswap-backed large swapin instead of mixing it with the
synchronous anon/shmem evidence.
The path first prepares the normal readahead window. If the faulting
aligned range is fully covered by that window and is still all-zswap, it
may be loaded as one large folio. If the large attempt fails or a backend
race is detected, the precomputed order-0 readahead window is used
without updating readahead state again.
Mixed zswap/disk ranges remain order-0 only. Disk-backed large swapin is
not added by this change.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/memory.c | 6 +-
mm/swap.h | 4 +-
mm/swap_state.c | 434 +++++++++++++++++++++++++++++++++++++++---------
mm/swapfile.c | 2 +-
4 files changed, 360 insertions(+), 86 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 7bbb89632000..451375090d83 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5027,13 +5027,14 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (folio)
swap_update_readahead(folio, vma, vmf->address);
if (!folio) {
+ unsigned long swapin_orders = thp_swapin_suitable_orders(vmf);
+
/*
* Swapin bypasses readahead for SWP_SYNCHRONOUS_IO devices.
* The swap device is pinned while checking the flag, matching
* the existing fault path.
*/
if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
- unsigned long swapin_orders = thp_swapin_suitable_orders(vmf);
unsigned long locality_orders =
swapin_anon_locality_orders(vmf, swapin_orders);
@@ -5041,7 +5042,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
swapin_orders | BIT(0),
locality_orders, vmf, NULL, 0);
} else {
- folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf);
+ folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
+ swapin_orders, vmf);
}
if (IS_ERR_OR_NULL(folio)) {
diff --git a/mm/swap.h b/mm/swap.h
index 5d1c81ab49b9..0e1bf9218b5e 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -323,7 +323,7 @@ struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
struct mempolicy *mpol, pgoff_t ilx);
struct folio *swapin_readahead(swp_entry_t entry, gfp_t flag,
- struct vm_fault *vmf);
+ unsigned long orders, struct vm_fault *vmf);
struct folio *swapin_sync(swp_entry_t entry, gfp_t flag, unsigned long orders,
unsigned long locality_orders, struct vm_fault *vmf,
struct mempolicy *mpol, pgoff_t ilx);
@@ -413,7 +413,7 @@ static inline struct folio *swap_cluster_readahead(swp_entry_t entry,
}
static inline struct folio *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
- struct vm_fault *vmf)
+ unsigned long orders, struct vm_fault *vmf)
{
return NULL;
}
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 80dff6a1ee65..4f1eb0a7f9f5 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -678,20 +678,24 @@ static bool swapin_zswap_admit(swp_entry_t entry,
static unsigned long swapin_admit_orders(swp_entry_t entry,
unsigned long orders,
struct vm_fault *vmf,
- unsigned long locality_orders)
+ unsigned long locality_orders,
+ bool zswap_only)
{
unsigned long candidates = orders & ~BIT(0);
- unsigned long admitted = orders & BIT(0);
+ unsigned long admitted = zswap_only ? 0 : orders & BIT(0);
+ enum zswap_range_state fault_zswap_state = ZSWAP_RANGE_NEVER_ENABLED;
struct zswap_admit_ctx zswap_ctx = {};
+ bool fault_zswap_checked = false;
int order;
if (!candidates)
- return orders;
+ return zswap_only ? 0 : orders;
while (candidates) {
enum zswap_range_state state;
unsigned int nr_pages;
swp_entry_t range_entry;
+ bool zswap_locality;
bool admit = false;
order = fls_long(candidates) - 1;
@@ -703,6 +707,29 @@ static unsigned long swapin_admit_orders(swp_entry_t entry,
nr_pages = 1U << order;
range_entry = swp_entry(swp_type(entry),
round_down(swp_offset(entry), nr_pages));
+ zswap_locality = order <= SWAPIN_ZSWAP_MAX_ORDER &&
+ swapin_zswap_locality(vmf, order,
+ locality_orders);
+ /*
+ * If the faulting slot is already in zswap but this order has
+ * no zswap locality evidence, a larger range covering the fault
+ * cannot be admitted: it is either all-zswap or mixed, and both
+ * require zswap locality. Avoid scanning the whole range on
+ * sparse/random zswap refaults. If the faulting slot is not in
+ * zswap, keep the full classification so all-disk large swapin
+ * can follow the existing policy.
+ */
+ if (!zswap_locality) {
+ if (zswap_only)
+ goto next;
+ if (!fault_zswap_checked) {
+ fault_zswap_state = zswap_probe_range(entry, 1);
+ fault_zswap_checked = true;
+ }
+ if (fault_zswap_state == ZSWAP_RANGE_ALL_ZSWAP)
+ goto next;
+ }
+
if (!swapin_zeromap_same(range_entry, nr_pages))
goto next;
@@ -718,7 +745,7 @@ static unsigned long swapin_admit_orders(swp_entry_t entry,
break;
case ZSWAP_RANGE_NEVER_ENABLED:
case ZSWAP_RANGE_NO_ZSWAP:
- admit = true;
+ admit = !zswap_only;
break;
}
@@ -730,21 +757,32 @@ static unsigned long swapin_admit_orders(swp_entry_t entry,
candidates &= ~BIT(order);
}
- return admitted ? admitted : BIT(0);
+ return admitted ? admitted : (zswap_only ? 0 : BIT(0));
}
-static bool zswap_needs_order0_retry(struct folio *folio)
+static bool zswap_folio_all_zswap(struct folio *folio)
{
+ return zswap_probe_range(folio->swap, folio_nr_pages(folio)) ==
+ ZSWAP_RANGE_ALL_ZSWAP;
+}
+
+static bool zswap_needs_fallback(struct folio *folio, bool zswap_only)
+{
+ enum zswap_range_state state;
+
if (!folio_test_large(folio))
return false;
+ state = zswap_probe_range(folio->swap, folio_nr_pages(folio));
+ if (zswap_only)
+ return state != ZSWAP_RANGE_ALL_ZSWAP;
+
/*
* Admission sees only an advisory zswap snapshot. Recheck after the
* large swapcache folio is installed; if the range became mixed, drop
* the fresh folio before IO and let order-0 handle each slot.
*/
- return zswap_probe_range(folio->swap, folio_nr_pages(folio)) ==
- ZSWAP_RANGE_MIXED;
+ return state == ZSWAP_RANGE_MIXED;
}
/*
@@ -758,8 +796,7 @@ bool swapin_fault_only_young(struct folio *folio)
if (!folio_test_large(folio) || !folio_test_swapcache(folio))
return false;
- return zswap_probe_range(folio->swap, folio_nr_pages(folio)) ==
- ZSWAP_RANGE_ALL_ZSWAP;
+ return zswap_folio_all_zswap(folio);
}
/*
@@ -893,34 +930,15 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
return folio;
}
-/**
- * swapin_sync - swap-in one or multiple entries skipping readahead.
- * @entry: swap entry indicating the target slot
- * @gfp: memory allocation flags
- * @orders: allocation orders
- * @locality_orders: orders with caller-provided locality evidence
- * @vmf: fault information
- * @mpol: NUMA memory allocation policy to be applied
- * @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
- *
- * This allocates a folio suitable for given @orders, or returns the
- * existing folio in the swap cache for @entry. This initiates the IO, too,
- * if needed. @entry is rounded down if @orders allow large allocation.
- *
- * Context: Caller must ensure @entry is valid and pin the swap device with
- * refcount.
- * Return: Returns the folio on success, error code if failed.
- */
-struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp,
- unsigned long orders,
- unsigned long locality_orders,
- struct vm_fault *vmf, struct mempolicy *mpol,
- pgoff_t ilx)
+static struct folio *swapin_alloc_read(swp_entry_t entry, gfp_t gfp,
+ unsigned long orders,
+ struct vm_fault *vmf,
+ struct mempolicy *mpol, pgoff_t ilx,
+ bool retry_order0, bool zswap_only)
{
struct folio *folio;
int ret;
- orders = swapin_admit_orders(entry, orders, vmf, locality_orders);
again:
do {
folio = swap_cache_get_folio(entry);
@@ -931,19 +949,21 @@ struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp,
} while (PTR_ERR(folio) == -EEXIST);
if (IS_ERR(folio))
- return folio;
+ return retry_order0 ? folio : NULL;
- if (zswap_needs_order0_retry(folio)) {
+ if (zswap_needs_fallback(folio, zswap_only)) {
count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN_FALLBACK);
/*
* The folio is newly allocated, locked, clean and not uptodate;
* no data has been read into it. Removing it only restores the
- * swap table entries so order-0 swapin can resolve a backend
+ * swap table entries so the fallback path can resolve a backend
* race without attempting speculative large-folio zswapin.
*/
swap_cache_del_folio(folio);
folio_unlock(folio);
folio_put(folio);
+ if (!retry_order0)
+ return NULL;
orders = BIT(0);
goto again;
}
@@ -954,12 +974,62 @@ struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp,
swap_cache_del_folio(folio);
folio_unlock(folio);
folio_put(folio);
+ if (!retry_order0)
+ return NULL;
orders = BIT(0);
goto again;
}
return folio;
}
+/**
+ * swapin_sync - swap-in one or multiple entries skipping readahead.
+ * @entry: swap entry indicating the target slot
+ * @gfp: memory allocation flags
+ * @orders: allocation orders
+ * @locality_orders: orders with caller-provided locality evidence
+ * @vmf: fault information
+ * @mpol: NUMA memory allocation policy to be applied
+ * @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
+ *
+ * This allocates a folio suitable for given @orders, or returns the
+ * existing folio in the swap cache for @entry. This initiates the IO, too,
+ * if needed. @entry is rounded down if @orders allow large allocation.
+ *
+ * Context: Caller must ensure @entry is valid and pin the swap device with
+ * refcount.
+ * Return: Returns the folio on success, error code if failed.
+ */
+struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp,
+ unsigned long orders,
+ unsigned long locality_orders,
+ struct vm_fault *vmf, struct mempolicy *mpol,
+ pgoff_t ilx)
+{
+ orders = swapin_admit_orders(entry, orders, vmf,
+ locality_orders, false);
+ return swapin_alloc_read(entry, gfp, orders, vmf, mpol, ilx,
+ true, false);
+}
+
+static struct folio *swapin_zswap_large(swp_entry_t entry, gfp_t gfp,
+ unsigned long orders,
+ unsigned long locality_orders,
+ struct vm_fault *vmf,
+ struct mempolicy *mpol, pgoff_t ilx)
+{
+ if (READ_ONCE(page_cluster) <= 0)
+ return NULL;
+
+ orders = swapin_admit_orders(entry, orders, vmf,
+ locality_orders, true);
+ if (!orders)
+ return NULL;
+
+ return swapin_alloc_read(entry, gfp, orders, vmf, mpol, ilx,
+ false, true);
+}
+
/*
* Locate a page of swap in physical memory, reserving swap cache space
* and reading the disk if it is not already cached.
@@ -1048,12 +1118,88 @@ static unsigned long swapin_nr_pages(unsigned long offset)
return pages;
}
+struct swap_cluster_ra {
+ unsigned long start_offset;
+ unsigned long end_offset;
+ bool readahead;
+};
+
+static void swap_cluster_ra_prepare(swp_entry_t entry,
+ struct swap_cluster_ra *ra)
+{
+ struct swap_info_struct *si = __swap_entry_to_info(entry);
+ unsigned long entry_offset = swp_offset(entry);
+ unsigned long mask;
+
+ mask = swapin_nr_pages(entry_offset) - 1;
+ ra->readahead = !!mask;
+ ra->start_offset = entry_offset;
+ ra->end_offset = entry_offset;
+ if (!mask)
+ return;
+
+ /* Read a page_cluster sized and aligned cluster around offset. */
+ ra->start_offset = entry_offset & ~mask;
+ ra->end_offset = entry_offset | mask;
+ if (!ra->start_offset) /* First page is swap header. */
+ ra->start_offset++;
+ if (ra->end_offset >= si->max)
+ ra->end_offset = si->max - 1;
+}
+
+static unsigned long swap_cluster_ra_orders(swp_entry_t entry,
+ unsigned long orders,
+ const struct swap_cluster_ra *ra)
+{
+ unsigned long admitted = 0;
+ unsigned long candidates = orders & ~BIT(0);
+ unsigned long entry_offset = swp_offset(entry);
+ int order;
+
+ if (!ra->readahead)
+ return 0;
+
+ while (candidates) {
+ unsigned long nr_pages;
+ unsigned long start_offset;
+ unsigned long end_offset;
+
+ order = fls_long(candidates) - 1;
+ if (order > MAX_PAGE_ORDER) {
+ candidates &= ~BIT(order);
+ continue;
+ }
+
+ nr_pages = 1UL << order;
+ start_offset = round_down(entry_offset, nr_pages);
+ end_offset = start_offset + nr_pages - 1;
+ if (start_offset >= ra->start_offset &&
+ end_offset <= ra->end_offset)
+ admitted |= BIT(order);
+ candidates &= ~BIT(order);
+ }
+
+ return admitted;
+}
+
+static bool swapin_readahead_skip(unsigned long index,
+ unsigned long skip_start,
+ unsigned long skip_end)
+{
+ return skip_start < skip_end &&
+ index >= skip_start && index < skip_end;
+}
+
/**
- * swap_cluster_readahead - swap in pages in hope we need them soon
+ * swap_cluster_readahead_win - swap in pages from a prepared swap window
* @entry: swap entry of this memory
* @gfp_mask: memory allocation flags
* @mpol: NUMA memory allocation policy to be applied
* @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
+ * @ra: readahead window prepared by swap_cluster_ra_prepare()
+ * @skip_start: first offset already covered by @target_folio
+ * @skip_end: offset after the already covered range
+ * @target_folio: target folio to return after queueing the rest of the window
*
* Returns the struct folio for entry and addr, after queueing swapin.
*
@@ -1066,33 +1212,38 @@ static unsigned long swapin_nr_pages(unsigned long offset)
* are used for every page of the readahead: neighbouring pages on swap
* are fairly likely to have been swapped out from the same node.
*/
-struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
- struct mempolicy *mpol, pgoff_t ilx)
+static struct folio *swap_cluster_readahead_win(swp_entry_t entry,
+ gfp_t gfp_mask,
+ struct mempolicy *mpol,
+ pgoff_t ilx,
+ const struct swap_cluster_ra *ra,
+ unsigned long skip_start,
+ unsigned long skip_end,
+ struct folio *target_folio)
{
struct folio *folio;
unsigned long entry_offset = swp_offset(entry);
- unsigned long offset = entry_offset;
- unsigned long start_offset, end_offset;
- unsigned long mask;
- struct swap_info_struct *si = __swap_entry_to_info(entry);
+ unsigned long offset;
struct blk_plug plug;
struct swap_iocb *splug = NULL;
swp_entry_t ra_entry;
- mask = swapin_nr_pages(offset) - 1;
- if (!mask)
+ if (!ra->readahead)
goto skip;
- /* Read a page_cluster sized and aligned cluster around offset. */
- start_offset = offset & ~mask;
- end_offset = offset | mask;
- if (!start_offset) /* First page is swap header. */
- start_offset++;
- if (end_offset >= si->max)
- end_offset = si->max - 1;
+ if (target_folio &&
+ skip_start <= ra->start_offset && skip_end > ra->end_offset)
+ goto skip;
blk_start_plug(&plug);
- for (offset = start_offset; offset <= end_offset ; offset++) {
+ for (offset = ra->start_offset; offset <= ra->end_offset; offset++) {
+ if (swapin_readahead_skip(offset, skip_start, skip_end)) {
+ if (skip_end > ra->end_offset)
+ break;
+ offset = skip_end - 1;
+ continue;
+ }
+
/* Ok, do the async read-ahead now */
ra_entry = swp_entry(swp_type(entry), offset);
folio = swap_cache_read_folio(ra_entry, gfp_mask, mpol, ilx,
@@ -1105,10 +1256,29 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
swap_read_unplug(splug);
lru_add_drain(); /* Push any new pages onto the LRU now */
skip:
+ if (target_folio)
+ return target_folio;
+
/* The page was likely read above, so no need for plugging here */
return swap_cache_read_folio(entry, gfp_mask, mpol, ilx, NULL, false);
}
+struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
+ struct mempolicy *mpol, pgoff_t ilx)
+{
+ struct swap_cluster_ra ra;
+
+ swap_cluster_ra_prepare(entry, &ra);
+ return swap_cluster_readahead_win(entry, gfp_mask, mpol, ilx, &ra,
+ 0, 0, NULL);
+}
+
+struct swap_vma_ra {
+ unsigned long start;
+ unsigned long end;
+ int win;
+};
+
static int swap_vma_ra_win(struct vm_fault *vmf, unsigned long *start,
unsigned long *end)
{
@@ -1147,35 +1317,69 @@ static int swap_vma_ra_win(struct vm_fault *vmf, unsigned long *start,
return win;
}
-/**
- * swap_vma_readahead - swap in pages in hope we need them soon
- * @targ_entry: swap entry of the targeted memory
- * @gfp_mask: memory allocation flags
- * @mpol: NUMA memory allocation policy to be applied
- * @targ_ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
- * @vmf: fault information
- *
- * Returns the struct folio for entry and addr, after queueing swapin.
- *
- * Primitive swap readahead code. We simply read in a few pages whose
- * virtual addresses are around the fault address in the same vma.
- *
- * Caller must hold read mmap_lock if vmf->vma is not NULL.
- *
+static unsigned long swap_vma_ra_orders(struct vm_fault *vmf,
+ unsigned long orders,
+ const struct swap_vma_ra *ra)
+{
+ unsigned long admitted = 0;
+ unsigned long candidates = orders & ~BIT(0);
+ int order;
+
+ if (ra->win <= 1)
+ return 0;
+
+ while (candidates) {
+ unsigned long size;
+ unsigned long start;
+ unsigned long end;
+
+ order = fls_long(candidates) - 1;
+ if (order > MAX_PAGE_ORDER) {
+ candidates &= ~BIT(order);
+ continue;
+ }
+
+ size = PAGE_SIZE << order;
+ start = ALIGN_DOWN(vmf->address, size);
+ end = start + size;
+ if (start >= ra->start && end <= ra->end)
+ admitted |= BIT(order);
+ candidates &= ~BIT(order);
+ }
+
+ return admitted;
+}
+
+/*
+ * Queue swapin for a precomputed VMA readahead window. The window has already
+ * been accounted in vma->swap_readahead_info, so fallback after a failed
+ * zswap-large attempt does not update readahead state a second time. If
+ * @target_folio is already populated, queue only the part of the window outside
+ * [@skip_start, @skip_end) and return @target_folio.
*/
-static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,
- struct mempolicy *mpol, pgoff_t targ_ilx, struct vm_fault *vmf)
+static struct folio *swap_vma_readahead_win(swp_entry_t targ_entry,
+ gfp_t gfp_mask,
+ struct mempolicy *mpol,
+ pgoff_t targ_ilx,
+ struct vm_fault *vmf,
+ const struct swap_vma_ra *ra,
+ unsigned long skip_start,
+ unsigned long skip_end,
+ struct folio *target_folio)
{
struct blk_plug plug;
struct swap_iocb *splug = NULL;
struct folio *folio;
pte_t *pte = NULL, pentry;
- int win;
unsigned long start, end, addr;
pgoff_t ilx = targ_ilx;
- win = swap_vma_ra_win(vmf, &start, &end);
- if (win == 1)
+ if (ra->win <= 1)
+ goto skip;
+
+ start = ra->start;
+ end = ra->end;
+ if (target_folio && skip_start <= start && skip_end >= end)
goto skip;
ilx = targ_ilx - PFN_DOWN(vmf->address - start);
@@ -1185,6 +1389,18 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,
struct swap_info_struct *si = NULL;
softleaf_t entry;
+ if (swapin_readahead_skip(addr, skip_start, skip_end)) {
+ unsigned long next = min(skip_end, end);
+
+ if (pte) {
+ pte_unmap(pte);
+ pte = NULL;
+ }
+ ilx += PFN_DOWN(next - addr) - 1;
+ addr = next - PAGE_SIZE;
+ continue;
+ }
+
if (!pte++) {
pte = pte_offset_map(vmf->pmd, addr);
if (!pte)
@@ -1220,6 +1436,9 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,
swap_read_unplug(splug);
lru_add_drain();
skip:
+ if (target_folio)
+ return target_folio;
+
/* The folio was likely read above, so no need for plugging here */
folio = swap_cache_read_folio(targ_entry, gfp_mask, mpol, targ_ilx,
NULL, false);
@@ -1230,25 +1449,78 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,
* swapin_readahead - swap in pages in hope we need them soon
* @entry: swap entry of this memory
* @gfp_mask: memory allocation flags
+ * @orders: large folio orders suitable for the faulting entry
* @vmf: fault information
*
* Returns the struct folio for entry and addr, after queueing swapin.
*
- * It's a main entry function for swap readahead. By the configuration,
- * it will read ahead blocks by cluster-based(ie, physical disk based)
- * or vma-based(ie, virtual address based on faulty address) readahead.
+ * This first computes the normal VMA or cluster readahead window. If the
+ * window fully covers an aligned all-zswap range containing the fault, that
+ * range may be swapped in as one large folio. The remaining window is still
+ * queued through the original order-0 readahead path, skipping the already
+ * covered target range and without updating readahead state a second time.
*/
struct folio *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask,
- struct vm_fault *vmf)
+ unsigned long orders, struct vm_fault *vmf)
{
struct mempolicy *mpol;
pgoff_t ilx;
struct folio *folio;
+ unsigned long ra_orders;
+ bool vma_ra;
mpol = get_vma_policy(vmf->vma, vmf->address, 0, &ilx);
- folio = swap_use_vma_readahead() ?
- swap_vma_readahead(entry, gfp_mask, mpol, ilx, vmf) :
- swap_cluster_readahead(entry, gfp_mask, mpol, ilx);
+ vma_ra = swap_use_vma_readahead();
+ if (vma_ra) {
+ struct swap_vma_ra ra = {};
+ unsigned long skip_start = 0;
+ unsigned long skip_end = 0;
+
+ ra.win = swap_vma_ra_win(vmf, &ra.start, &ra.end);
+ ra_orders = swap_vma_ra_orders(vmf, orders, &ra);
+ if (ra_orders) {
+ folio = swapin_zswap_large(entry, gfp_mask, ra_orders,
+ ra_orders, vmf, mpol, ilx);
+ if (folio) {
+ skip_start = ALIGN_DOWN(vmf->address,
+ folio_size(folio));
+ skip_end = skip_start + folio_size(folio);
+ folio = swap_vma_readahead_win(entry, gfp_mask,
+ mpol, ilx, vmf,
+ &ra, skip_start,
+ skip_end, folio);
+ goto out;
+ }
+ }
+ folio = swap_vma_readahead_win(entry, gfp_mask, mpol, ilx,
+ vmf, &ra, 0, 0, NULL);
+ } else {
+ struct swap_cluster_ra ra;
+ unsigned long skip_start = 0;
+ unsigned long skip_end = 0;
+
+ swap_cluster_ra_prepare(entry, &ra);
+ ra_orders = swap_cluster_ra_orders(entry, orders, &ra);
+ if (ra_orders) {
+ folio = swapin_zswap_large(entry, gfp_mask, ra_orders,
+ ra_orders, vmf, mpol, ilx);
+ if (folio) {
+ skip_start = swp_offset(folio->swap);
+ skip_end = skip_start + folio_nr_pages(folio);
+ folio = swap_cluster_readahead_win(entry,
+ gfp_mask,
+ mpol, ilx,
+ &ra,
+ skip_start,
+ skip_end,
+ folio);
+ goto out;
+ }
+ }
+ folio = swap_cluster_readahead_win(entry, gfp_mask, mpol, ilx,
+ &ra, 0, 0, NULL);
+ }
+out:
mpol_cond_put(mpol);
return folio;
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 615d90867111..3b7e7d8ae89d 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2452,7 +2452,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
};
folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE,
- &vmf);
+ 0, &vmf);
}
if (!folio) {
swp_tb = swap_table_get(__swap_entry_to_cluster(entry),
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 7/9] mm/shmem: provide VMA-hint locality for zswap large swapin
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
Let the shmem swap fault path pass locality evidence into the common
zswap large-swapin policy. Shmem does not have anon PTE-young density
evidence, so this first step only treats explicit VM_SEQ_READ as
positive evidence and VM_RAND_READ as a veto.
The non-fault shmem readahead path remains unchanged. This keeps large
zswap swapin limited to synchronous shmem faults where the caller
supplies a VMA and the common policy can still fall back to order-0.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/shmem.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index fa99b48ed62b..a5ac35ac85fb 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -30,6 +30,7 @@
#include <linux/fileattr.h>
#include <linux/filelock.h>
#include <linux/mm.h>
+#include <linux/memcontrol.h>
#include <linux/random.h>
#include <linux/sched/signal.h>
#include <linux/export.h>
@@ -1791,6 +1792,29 @@ static struct folio *shmem_swapin_cluster(swp_entry_t swap, gfp_t gfp,
return folio;
}
+static unsigned long shmem_swapin_locality_orders(struct vm_fault *vmf,
+ unsigned long orders)
+{
+ struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
+ unsigned long candidates = orders & ~BIT(0);
+
+ /*
+ * Shmem does not have anon-style PTE young density evidence. Start with
+ * explicit VMA access hints; future shmem/page-cache readahead evidence
+ * can be folded into this producer without changing common swapin policy.
+ */
+ if (!vma)
+ return 0;
+
+ if (vma->vm_flags & VM_RAND_READ)
+ return 0;
+
+ if (vma->vm_flags & VM_SEQ_READ)
+ return candidates;
+
+ return 0;
+}
+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
bool shmem_hpage_pmd_enabled(void)
{
@@ -2020,18 +2044,22 @@ static struct folio *shmem_swap_alloc_folio(struct inode *inode,
struct vm_fault *vmf, pgoff_t index,
swp_entry_t entry, int order, gfp_t gfp)
{
+ unsigned long locality_orders;
+ unsigned long orders;
pgoff_t ilx;
struct folio *folio;
struct mempolicy *mpol;
struct shmem_inode_info *info = SHMEM_I(inode);
- if ((vmf && unlikely(userfaultfd_armed(vmf->vma))) ||
- !zswap_never_enabled())
+ if (vmf && unlikely(userfaultfd_armed(vmf->vma)))
order = 0;
again:
+ orders = BIT(order);
+ locality_orders = shmem_swapin_locality_orders(vmf, orders);
mpol = shmem_get_pgoff_policy(info, index, order, &ilx);
- folio = swapin_sync(entry, gfp, BIT(order), 0, vmf, mpol, ilx);
+ folio = swapin_sync(entry, gfp, orders, locality_orders, vmf, mpol,
+ ilx);
mpol_cond_put(mpol);
if (!IS_ERR(folio))
@@ -2339,7 +2367,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
if (!folio_matches_swap_entry(folio, swap) ||
shmem_confirm_swap(mapping, index, swap) < 0) {
error = -EEXIST;
- goto unlock;
+ goto failed_swapcache;
}
if (!folio_test_uptodate(folio)) {
error = -EIO;
@@ -2369,6 +2397,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
if (sgp == SGP_WRITE)
folio_mark_accessed(folio);
+ if (folio_test_large(folio))
+ memcg1_swapin(folio);
folio_put_swap(folio, NULL);
swap_cache_del_folio(folio);
folio_mark_dirty(folio);
@@ -2379,9 +2409,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
failed:
if (shmem_confirm_swap(mapping, index, swap) < 0)
error = -EEXIST;
+failed_swapcache:
+ if (folio && folio_test_large(folio) && folio_test_swapcache(folio))
+ memcg1_swapin(folio);
if (error == -EIO)
shmem_set_folio_swapin_error(inode, index, folio, swap);
-unlock:
if (folio)
folio_unlock(folio);
failed_nolock:
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 6/9] mm: provide anon locality evidence for zswap large swapin
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
The common zswap large-swapin policy needs locality evidence from
callers before it can admit a large folio. For anonymous faults, provide
that evidence from existing VMA hints and from the PTE young state left
by earlier zswap-backed large swapins.
Keep non-faulting PTEs old when mapping a speculative all-zswap large
folio. A later fault can then require a dense young previous range before
admitting another large swapin without adding VMA state.
This also removes the old zswap-enabled guard from the THP swapin
candidate scan. The common swapin path now classifies the backend range
and falls back to order-0 for mixed zswap/disk ranges or races.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/memory.c | 234 +++++++++++++++++++++++++++++++++++++++++++-----
mm/swap.h | 6 ++
mm/swap_state.c | 15 ++++
3 files changed, 235 insertions(+), 20 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 92a82008d583..7bbb89632000 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4556,6 +4556,35 @@ static void memcg1_swapin_retry_folio(struct folio *folio,
folio_unlock(folio);
}
+static void set_swapin_ptes(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep, pte_t pte,
+ unsigned int nr_pages, unsigned int fault_pte_idx,
+ bool fault_only_young)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ pte_t old_pte;
+
+ if (!fault_only_young || nr_pages == 1) {
+ set_ptes(mm, address, ptep, pte, nr_pages);
+ return;
+ }
+
+ old_pte = pte_mkold(pte);
+ if (fault_pte_idx)
+ set_ptes(mm, address, ptep, old_pte, fault_pte_idx);
+
+ set_pte_at(mm, address + fault_pte_idx * PAGE_SIZE,
+ ptep + fault_pte_idx,
+ pte_mkyoung(pte_advance_pfn(pte, fault_pte_idx)));
+
+ fault_pte_idx++;
+ if (fault_pte_idx < nr_pages)
+ set_ptes(mm, address + fault_pte_idx * PAGE_SIZE,
+ ptep + fault_pte_idx,
+ pte_advance_pfn(old_pte, fault_pte_idx),
+ nr_pages - fault_pte_idx);
+}
+
static vm_fault_t pte_marker_clear(struct vm_fault *vmf)
{
vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, vmf->pmd,
@@ -4628,6 +4657,157 @@ static vm_fault_t handle_pte_marker(struct vm_fault *vmf)
}
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#define SWAPIN_ANON_YOUNG_MIN_PERCENT 75
+#define SWAPIN_ANON_MAX_FAULT_SKIP_SHIFT 2
+
+static bool swapin_anon_prev_young_dense(struct vm_fault *vmf,
+ unsigned int order)
+{
+ struct vm_area_struct *vma;
+ unsigned int nr_pages;
+ unsigned int threshold;
+ unsigned long size;
+ unsigned long base, prev, addr;
+ struct folio *first = NULL;
+ unsigned int present = 0;
+ unsigned int young = 0;
+ pmd_t *pmd;
+ pmd_t pmdval;
+ spinlock_t *ptl; /* protects the previous PTE range */
+ pte_t *ptep;
+ unsigned int i;
+
+ if (!IS_ENABLED(CONFIG_MMU) || !arch_has_hw_pte_young() || !vmf ||
+ !vmf->vma || !vmf->pmd || !order || order > MAX_PAGE_ORDER)
+ return false;
+
+ nr_pages = 1U << order;
+ threshold = DIV_ROUND_UP(nr_pages *
+ SWAPIN_ANON_YOUNG_MIN_PERCENT, 100);
+ size = PAGE_SIZE << order;
+
+ vma = vmf->vma;
+ base = ALIGN_DOWN(vmf->address, size);
+ if (base < size)
+ return false;
+
+ prev = base - size;
+ if (prev < vma->vm_start || prev + size > vma->vm_end)
+ return false;
+
+ pmd = vmf->pmd;
+ if ((prev & PMD_MASK) != (base & PMD_MASK)) {
+ pmd = mm_find_pmd(vma->vm_mm, prev);
+ if (!pmd)
+ return false;
+ }
+
+ pmdval = pmdp_get_lockless(pmd);
+ if (!pmd_present(pmdval) || pmd_leaf(pmdval))
+ return false;
+
+ ptep = pte_offset_map_lock(vma->vm_mm, pmd, prev, &ptl);
+ if (!ptep)
+ return false;
+
+ for (i = 0, addr = prev; i < nr_pages; i++, addr += PAGE_SIZE) {
+ struct folio *folio;
+ pte_t pte = ptep_get(ptep + i);
+
+ if (!pte_present(pte))
+ break;
+
+ folio = vm_normal_folio(vma, addr, pte);
+ if (!folio || folio_order(folio) != order)
+ break;
+ if (!first)
+ first = folio;
+ else if (folio != first)
+ break;
+
+ present++;
+ if (pte_young(pte))
+ young++;
+ }
+
+ pte_unmap_unlock(ptep, ptl);
+ if (present != nr_pages)
+ return false;
+
+ return young >= threshold;
+}
+
+static bool swapin_anon_accessed_neighbour(struct vm_fault *vmf,
+ unsigned int order)
+{
+ unsigned long size;
+ unsigned long base;
+ unsigned long fault_idx;
+ unsigned long max_skip;
+
+ if (!vmf || !vmf->vma || !order || order > MAX_PAGE_ORDER)
+ return false;
+
+ size = PAGE_SIZE << order;
+ base = ALIGN_DOWN(vmf->address, size);
+
+ /*
+ * Without a sequential hint, require prior young-density evidence and
+ * only allow faults near the start of the candidate range.
+ */
+ fault_idx = (vmf->address - base) >> PAGE_SHIFT;
+ max_skip = (1UL << order) >> SWAPIN_ANON_MAX_FAULT_SKIP_SHIFT;
+ if (fault_idx > max_skip)
+ return false;
+
+ return swapin_anon_prev_young_dense(vmf, order);
+}
+
+static bool swapin_anon_fault_starts_range(struct vm_fault *vmf,
+ unsigned int order)
+{
+ struct vm_area_struct *vma;
+ unsigned long size;
+ unsigned long base;
+ unsigned long first;
+
+ if (!vmf || !vmf->vma || !order || order > MAX_PAGE_ORDER)
+ return false;
+
+ vma = vmf->vma;
+ size = PAGE_SIZE << order;
+ base = ALIGN_DOWN(vmf->address, size);
+ first = ALIGN(vma->vm_start, size);
+
+ return base == first && vmf->address == base &&
+ base + size <= vma->vm_end;
+}
+
+static unsigned long swapin_anon_locality_orders(struct vm_fault *vmf,
+ unsigned long orders)
+{
+ struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
+ unsigned long locality_orders = 0;
+ unsigned long candidates = orders & ~BIT(0);
+ int order;
+
+ if (vma && (vma->vm_flags & VM_RAND_READ))
+ return 0;
+
+ if (vma && (vma->vm_flags & VM_SEQ_READ))
+ return candidates;
+
+ while (candidates) {
+ order = fls_long(candidates) - 1;
+ if (swapin_anon_fault_starts_range(vmf, order) ||
+ swapin_anon_accessed_neighbour(vmf, order))
+ locality_orders |= BIT(order);
+ candidates &= ~BIT(order);
+ }
+
+ return locality_orders;
+}
+
/*
* Check if the PTEs within a range are contiguous swap entries.
*/
@@ -4644,9 +4824,9 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)
if (!pte_same(pte, pte_move_swp_offset(vmf->orig_pte, -idx)))
return false;
/*
- * swap_read_folio() can't handle the case a large folio is hybridly
- * from different backends. And they are likely corner cases. Similar
- * things might be added once zswap support large folios.
+ * swap_read_folio() can't do mixed-backend large folio IO. The common
+ * synchronous swapin path will recheck backend state and fall back to
+ * order-0 if a zswap/disk race makes the range mixed.
*/
if (swap_pte_batch(ptep, nr_pages, pte) != nr_pages)
return false;
@@ -4693,14 +4873,6 @@ static unsigned long thp_swapin_suitable_orders(struct vm_fault *vmf)
if (unlikely(userfaultfd_armed(vma)))
return 0;
- /*
- * A large swapped out folio could be partially or fully in zswap. We
- * lack handling for such cases, so fallback to swapping in order-0
- * folio.
- */
- if (!zswap_never_enabled())
- return 0;
-
entry = softleaf_from_pte(vmf->orig_pte);
/*
* Get a list of all the (large) orders below PMD_ORDER that are enabled
@@ -4708,10 +4880,13 @@ static unsigned long thp_swapin_suitable_orders(struct vm_fault *vmf)
*/
orders = thp_vma_allowable_orders(vma, vma->vm_flags, TVA_PAGEFAULT,
BIT(PMD_ORDER) - 1);
+ if (!orders)
+ return 0;
orders = thp_vma_suitable_orders(vma, vmf->address, orders);
+ if (!orders)
+ return 0;
orders = thp_swap_suitable_orders(swp_offset(entry),
vmf->address, orders);
-
if (!orders)
return 0;
@@ -4741,6 +4916,12 @@ static unsigned long thp_swapin_suitable_orders(struct vm_fault *vmf)
{
return 0;
}
+
+static unsigned long swapin_anon_locality_orders(struct vm_fault *vmf,
+ unsigned long orders)
+{
+ return 0;
+}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
/* Sanity check that a folio is fully exclusive */
@@ -4777,6 +4958,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
unsigned long page_idx;
unsigned long address;
pte_t *ptep;
+ bool fault_only_young = false;
if (!pte_unmap_same(vmf))
goto out;
@@ -4845,13 +5027,22 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (folio)
swap_update_readahead(folio, vma, vmf->address);
if (!folio) {
- /* Swapin bypasses readahead for SWP_SYNCHRONOUS_IO devices */
- if (data_race(si->flags & SWP_SYNCHRONOUS_IO))
+ /*
+ * Swapin bypasses readahead for SWP_SYNCHRONOUS_IO devices.
+ * The swap device is pinned while checking the flag, matching
+ * the existing fault path.
+ */
+ if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
+ unsigned long swapin_orders = thp_swapin_suitable_orders(vmf);
+ unsigned long locality_orders =
+ swapin_anon_locality_orders(vmf, swapin_orders);
+
folio = swapin_sync(entry, GFP_HIGHUSER_MOVABLE,
- thp_swapin_suitable_orders(vmf) | BIT(0),
- 0, vmf, NULL, 0);
- else
+ swapin_orders | BIT(0),
+ locality_orders, vmf, NULL, 0);
+ } else {
folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf);
+ }
if (IS_ERR_OR_NULL(folio)) {
/*
@@ -5110,9 +5301,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
VM_BUG_ON(!folio_test_anon(folio) ||
(pte_write(pte) && !PageAnonExclusive(page)));
- set_ptes(vma->vm_mm, address, ptep, pte, nr_pages);
- arch_do_swap_page_nr(vma->vm_mm, vma, address,
- pte, pte, nr_pages);
+ if (folio == swapcache && nr_pages == folio_nr_pages(folio) &&
+ arch_has_hw_pte_young())
+ fault_only_young = swapin_fault_only_young(folio);
+ set_swapin_ptes(vma, address, ptep, pte, nr_pages, page_idx,
+ fault_only_young);
+ arch_do_swap_page_nr(vma->vm_mm, vma, address, pte, pte, nr_pages);
/*
* Remove the swap entry and conditionally try to free up the swapcache.
diff --git a/mm/swap.h b/mm/swap.h
index dd35a310d06d..5d1c81ab49b9 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -327,6 +327,7 @@ struct folio *swapin_readahead(swp_entry_t entry, gfp_t flag,
struct folio *swapin_sync(swp_entry_t entry, gfp_t flag, unsigned long orders,
unsigned long locality_orders, struct vm_fault *vmf,
struct mempolicy *mpol, pgoff_t ilx);
+bool swapin_fault_only_young(struct folio *folio);
void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma,
unsigned long addr);
@@ -430,6 +431,11 @@ static inline void swap_update_readahead(struct folio *folio,
{
}
+static inline bool swapin_fault_only_young(struct folio *folio)
+{
+ return false;
+}
+
static inline int swap_writeout(struct folio *folio,
struct swap_iocb **swap_plug)
{
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 5a4ca289009a..80dff6a1ee65 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -747,6 +747,21 @@ static bool zswap_needs_order0_retry(struct folio *folio)
ZSWAP_RANGE_MIXED;
}
+/*
+ * A speculative large swapin may install PTEs for pages that did not fault.
+ * Keep those non-faulting PTEs old so a later anon fault can report
+ * PTE-young density as caller-provided locality evidence without storing
+ * state in the VMA.
+ */
+bool swapin_fault_only_young(struct folio *folio)
+{
+ if (!folio_test_large(folio) || !folio_test_swapcache(folio))
+ return false;
+
+ return zswap_probe_range(folio->swap, folio_nr_pages(folio)) ==
+ ZSWAP_RANGE_ALL_ZSWAP;
+}
+
/*
* If we are the only user, then try to free up the swap cache.
*
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 3/9] mm/zswap: support fully zswap-backed large folio loads
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
zswap currently refuses large swapcache folios. That is correct for mixed
backend ranges, but it also prevents the common swapin path from loading a
range that is still fully backed by zswap.
Teach zswap_load() to fill a locked large swapcache folio by decompressing
each base-page entry into the matching folio offset, then flushing the
folio once. A missing entry after zswap data has been seen is reported as
-EAGAIN so the caller can drop the speculative large folio and retry
order-0.
The large load keeps the zswap entries in place. It is a clean speculative
fill: until the swap slots are freed, zswap remains the backing copy if
reclaim drops the large folio before PTEs are installed.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/zswap.c | 105 ++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 87 insertions(+), 18 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index da5297f7bd69..94ba112a2982 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -15,6 +15,8 @@
#include <linux/module.h>
#include <linux/cpu.h>
+#include <linux/mm.h>
+#include <linux/huge_mm.h>
#include <linux/highmem.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -934,7 +936,8 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
return comp_ret == 0 && alloc_ret == 0;
}
-static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio)
+static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio,
+ unsigned int page_idx, bool flush_dcache)
{
struct zswap_pool *pool = entry->pool;
struct scatterlist input[2]; /* zsmalloc returns an SG list 1-2 entries */
@@ -952,14 +955,15 @@ static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio)
WARN_ON_ONCE(input->length != PAGE_SIZE);
- dst = kmap_local_folio(folio, 0);
+ dst = kmap_local_folio(folio, page_idx * PAGE_SIZE);
memcpy_from_sglist(dst, input, 0, PAGE_SIZE);
dlen = PAGE_SIZE;
kunmap_local(dst);
- flush_dcache_folio(folio);
+ if (flush_dcache)
+ flush_dcache_folio(folio);
} else {
sg_init_table(&output, 1);
- sg_set_folio(&output, folio, PAGE_SIZE, 0);
+ sg_set_folio(&output, folio, PAGE_SIZE, page_idx * PAGE_SIZE);
acomp_request_set_params(acomp_ctx->req, input, &output,
entry->length, PAGE_SIZE);
ret = crypto_acomp_decompress(acomp_ctx->req);
@@ -1042,7 +1046,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry,
goto out;
}
- if (!zswap_decompress(entry, folio)) {
+ if (!zswap_decompress(entry, folio, 0, true)) {
ret = -EIO;
goto out;
}
@@ -1615,10 +1619,9 @@ enum zswap_range_state zswap_probe_range(swp_entry_t swp,
* NOT marked up-to-date, so that an IO error is emitted (e.g. do_swap_page()
* will SIGBUS).
*
- * -EINVAL: if the swapped out content was in zswap, but the page belongs
- * to a large folio, which is not supported by zswap. The folio is unlocked,
- * but NOT marked up-to-date, so that an IO error is emitted (e.g.
- * do_swap_page() will SIGBUS).
+ * -EAGAIN: if the swapped out content belongs to a large folio, but the
+ * range is mixed or raced with writeback. The folio remains locked so the
+ * caller can drop the large swapcache folio and retry order-0.
*
* -ENOENT: if the swapped out content was not in zswap. The folio remains
* locked on return.
@@ -1626,9 +1629,12 @@ enum zswap_range_state zswap_probe_range(swp_entry_t swp,
int zswap_load(struct folio *folio)
{
swp_entry_t swp = folio->swap;
+ unsigned int nr_pages = folio_nr_pages(folio);
+ unsigned int type = swp_type(swp);
pgoff_t offset = swp_offset(swp);
- struct xarray *tree = swap_zswap_tree(swp);
+ struct xarray *tree;
struct zswap_entry *entry;
+ unsigned int i;
VM_WARN_ON_ONCE(!folio_test_locked(folio));
VM_WARN_ON_ONCE(!folio_test_swapcache(folio));
@@ -1636,21 +1642,84 @@ int zswap_load(struct folio *folio)
if (zswap_never_enabled())
return -ENOENT;
- /*
- * Large folios should not be swapped in while zswap is being used, as
- * they are not properly handled. Zswap does not properly load large
- * folios, and a large folio may only be partially in zswap.
- */
- if (WARN_ON_ONCE(folio_test_large(folio))) {
+ if (folio_test_large(folio)) {
+ struct obj_cgroup *first_objcg = NULL;
+ bool same_objcg = true;
+ bool saw_zswap = false;
+ bool saw_non_zswap = false;
+
+ /*
+ * The locked large swapcache folio now covers the range and
+ * conflicts with zswap writeback's order-0 swapcache allocation.
+ * If the range is mixed or an entry disappears, retry order-0.
+ */
+ for (i = 0; i < nr_pages; i++) {
+ tree = swap_zswap_tree(swp_entry(type, offset + i));
+ entry = xa_load(tree, offset + i);
+ if (!entry) {
+ if (saw_zswap)
+ return -EAGAIN;
+ saw_non_zswap = true;
+ continue;
+ }
+ if (saw_non_zswap)
+ return -EAGAIN;
+
+ if (!saw_zswap)
+ first_objcg = entry->objcg;
+ else if (entry->objcg != first_objcg)
+ same_objcg = false;
+ saw_zswap = true;
+ }
+ if (!saw_zswap)
+ return -ENOENT;
+
+ for (i = 0; i < nr_pages; i++) {
+ tree = swap_zswap_tree(swp_entry(type, offset + i));
+ entry = xa_load(tree, offset + i);
+ if (!entry)
+ return -EAGAIN;
+
+ if (!zswap_decompress(entry, folio, i, false)) {
+ folio_unlock(folio);
+ return -EIO;
+ }
+ }
+
+ flush_dcache_folio(folio);
+ /*
+ * Keep zswap entries until swap slots are freed. This is a clean
+ * speculative fill; zswap remains the backing copy if reclaim
+ * drops the large folio before PTEs are installed.
+ */
+ folio_mark_uptodate(folio);
+ count_vm_events(ZSWPIN, nr_pages);
+ count_mthp_stat(folio_order(folio), MTHP_STAT_SWPIN);
+
+ if (same_objcg) {
+ if (first_objcg)
+ count_objcg_events(first_objcg, ZSWPIN, nr_pages);
+ } else {
+ for (i = 0; i < nr_pages; i++) {
+ tree = swap_zswap_tree(swp_entry(type, offset + i));
+ entry = xa_load(tree, offset + i);
+ if (WARN_ON_ONCE(!entry))
+ continue;
+ if (entry->objcg)
+ count_objcg_events(entry->objcg, ZSWPIN, 1);
+ }
+ }
+
folio_unlock(folio);
- return -EINVAL;
+ return 0;
}
+ tree = swap_zswap_tree(swp);
entry = xa_load(tree, offset);
if (!entry)
return -ENOENT;
- if (!zswap_decompress(entry, folio)) {
+ if (!zswap_decompress(entry, folio, 0, true)) {
folio_unlock(folio);
return -EIO;
}
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 5/9] mm: add common locality admission for zswap large swapin
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
Fully zswap-backed ranges are safe to load as a large folio only when
the caller has a reason to expect the neighbouring slots to be useful.
Otherwise a sparse refault can turn one 4K demand fault into a 64K
decompression and swapcache fill.
Add a common admission gate for zswap-backed large swapin. The common
layer keeps backend checks, the 64K cap, recent-refault rejection, and
zswap reclaim-pressure rejection. It consumes a caller-provided locality
order mask instead of looking at anon or shmem state directly.
Callers pass no locality evidence for now, so this patch only installs
the common policy hook. Later patches add anon and shmem producers.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/memory.c | 2 +-
mm/shmem.c | 2 +-
mm/swap.h | 8 ++--
mm/swap_state.c | 118 ++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 117 insertions(+), 13 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index d73a19692dea..92a82008d583 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4849,7 +4849,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (data_race(si->flags & SWP_SYNCHRONOUS_IO))
folio = swapin_sync(entry, GFP_HIGHUSER_MOVABLE,
thp_swapin_suitable_orders(vmf) | BIT(0),
- vmf, NULL, 0);
+ 0, vmf, NULL, 0);
else
folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf);
diff --git a/mm/shmem.c b/mm/shmem.c
index 56c23a7b15c7..fa99b48ed62b 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2031,7 +2031,7 @@ static struct folio *shmem_swap_alloc_folio(struct inode *inode,
again:
mpol = shmem_get_pgoff_policy(info, index, order, &ilx);
- folio = swapin_sync(entry, gfp, BIT(order), vmf, mpol, ilx);
+ folio = swapin_sync(entry, gfp, BIT(order), 0, vmf, mpol, ilx);
mpol_cond_put(mpol);
if (!IS_ERR(folio))
diff --git a/mm/swap.h b/mm/swap.h
index ea7e1f3c4410..dd35a310d06d 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -323,9 +323,10 @@ struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
struct mempolicy *mpol, pgoff_t ilx);
struct folio *swapin_readahead(swp_entry_t entry, gfp_t flag,
- struct vm_fault *vmf);
+ struct vm_fault *vmf);
struct folio *swapin_sync(swp_entry_t entry, gfp_t flag, unsigned long orders,
- struct vm_fault *vmf, struct mempolicy *mpol, pgoff_t ilx);
+ unsigned long locality_orders, struct vm_fault *vmf,
+ struct mempolicy *mpol, pgoff_t ilx);
void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma,
unsigned long addr);
@@ -418,7 +419,8 @@ static inline struct folio *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
static inline struct folio *swapin_sync(
swp_entry_t entry, gfp_t flag, unsigned long orders,
- struct vm_fault *vmf, struct mempolicy *mpol, pgoff_t ilx)
+ unsigned long locality_orders, struct vm_fault *vmf,
+ struct mempolicy *mpol, pgoff_t ilx)
{
return NULL;
}
diff --git a/mm/swap_state.c b/mm/swap_state.c
index f03ad4832f16..5a4ca289009a 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -21,6 +21,7 @@
#include <linux/migrate.h>
#include <linux/vmalloc.h>
#include <linux/huge_mm.h>
+#include <linux/sizes.h>
#include <linux/zswap.h>
#include <linux/shmem_fs.h>
#include "internal.h"
@@ -556,6 +557,24 @@ static struct folio *swap_cache_alloc_speculative_folio(swp_entry_t targ_entry,
mpol, ilx, true);
}
+/*
+ * Initial conservative cap for speculative zswap large swapin. Locality
+ * evidence is supplied by the caller or by generic VMA hints; the common
+ * swapin layer keeps backend safety and pressure decisions here.
+ */
+#define SWAPIN_ZSWAP_MAX_SIZE SZ_64K
+#if PAGE_SIZE < SWAPIN_ZSWAP_MAX_SIZE
+#define SWAPIN_ZSWAP_MAX_ORDER \
+ ilog2(SWAPIN_ZSWAP_MAX_SIZE / PAGE_SIZE)
+#else
+#define SWAPIN_ZSWAP_MAX_ORDER 0
+#endif
+
+struct zswap_admit_ctx {
+ bool pressure_checked;
+ bool reclaim_pressure;
+};
+
static bool swapin_zeromap_same(swp_entry_t entry, unsigned int nr_pages)
{
unsigned int ci_start = swp_cluster_offset(entry);
@@ -586,11 +605,84 @@ static bool swapin_zeromap_same(swp_entry_t entry, unsigned int nr_pages)
return true;
}
+static bool swapin_zswap_locality(struct vm_fault *vmf, unsigned int order,
+ unsigned long locality_orders)
+{
+ struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
+
+ if (!order || order > MAX_PAGE_ORDER)
+ return false;
+
+ if (vma && (vma->vm_flags & VM_RAND_READ))
+ return false;
+
+ return locality_orders & BIT(order);
+}
+
+static bool swapin_zswap_refaulted(swp_entry_t entry, unsigned int nr_pages)
+{
+ unsigned int type = swp_type(entry);
+ pgoff_t offset = swp_offset(entry);
+ unsigned int i;
+
+ for (i = 0; i < nr_pages; i++) {
+ bool workingset;
+ void *shadow;
+
+ shadow = swap_cache_get_shadow(swp_entry(type, offset + i));
+ if (!shadow)
+ continue;
+ if (workingset_test_recent(shadow, false, &workingset, false) &&
+ workingset)
+ return true;
+ }
+
+ return false;
+}
+
+static bool swapin_zswap_admit(swp_entry_t entry,
+ unsigned int order, unsigned int nr_pages,
+ struct vm_fault *vmf,
+ unsigned long locality_orders,
+ struct zswap_admit_ctx *ctx)
+{
+ if (order > SWAPIN_ZSWAP_MAX_ORDER)
+ return false;
+
+ /*
+ * Treat zswap-backed large swapin as speculative. The common layer
+ * consumes caller-provided locality orders, but does not inspect
+ * anon-specific PTE state or shmem-specific mapping state directly.
+ */
+ if (!swapin_zswap_locality(vmf, order, locality_orders))
+ return false;
+
+ /*
+ * A recent workingset refault shadow in the target range means reclaim
+ * already saw churn there. Keep the refault path narrow instead of
+ * speculatively decompressing neighbouring slots.
+ */
+ if (swapin_zswap_refaulted(entry, nr_pages))
+ return false;
+
+ if (!ctx->pressure_checked) {
+ ctx->reclaim_pressure = zswap_pool_reclaim_pressure();
+ ctx->pressure_checked = true;
+ }
+ if (ctx->reclaim_pressure)
+ return false;
+
+ return true;
+}
+
static unsigned long swapin_admit_orders(swp_entry_t entry,
- unsigned long orders)
+ unsigned long orders,
+ struct vm_fault *vmf,
+ unsigned long locality_orders)
{
unsigned long candidates = orders & ~BIT(0);
unsigned long admitted = orders & BIT(0);
+ struct zswap_admit_ctx zswap_ctx = {};
int order;
if (!candidates)
@@ -616,9 +708,14 @@ static unsigned long swapin_admit_orders(swp_entry_t entry,
state = zswap_probe_range(range_entry, nr_pages);
switch (state) {
+ case ZSWAP_RANGE_ALL_ZSWAP:
+ admit = swapin_zswap_admit(range_entry, order,
+ nr_pages, vmf,
+ locality_orders,
+ &zswap_ctx);
+ break;
case ZSWAP_RANGE_MIXED:
break;
- case ZSWAP_RANGE_ALL_ZSWAP:
case ZSWAP_RANGE_NEVER_ENABLED:
case ZSWAP_RANGE_NO_ZSWAP:
admit = true;
@@ -769,8 +866,8 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
ret = swap_read_folio(folio, plug);
/*
* Swap readahead allocates order-0 folios. -EAGAIN is reserved for
- * retryable large zswap backend races and must be handled by the
- * synchronous common swapin path.
+ * retryable large zswap backend races and should never escape to this
+ * order-0 path.
*/
VM_WARN_ON_ONCE(ret == -EAGAIN);
if (readahead) {
@@ -786,6 +883,7 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
* @entry: swap entry indicating the target slot
* @gfp: memory allocation flags
* @orders: allocation orders
+ * @locality_orders: orders with caller-provided locality evidence
* @vmf: fault information
* @mpol: NUMA memory allocation policy to be applied
* @ilx: NUMA interleave index, for use only when MPOL_INTERLEAVE
@@ -794,16 +892,20 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
* existing folio in the swap cache for @entry. This initiates the IO, too,
* if needed. @entry is rounded down if @orders allow large allocation.
*
- * Context: Caller must ensure @entry is valid and pin the swap device with refcount.
+ * Context: Caller must ensure @entry is valid and pin the swap device with
+ * refcount.
* Return: Returns the folio on success, error code if failed.
*/
-struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp, unsigned long orders,
- struct vm_fault *vmf, struct mempolicy *mpol, pgoff_t ilx)
+struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp,
+ unsigned long orders,
+ unsigned long locality_orders,
+ struct vm_fault *vmf, struct mempolicy *mpol,
+ pgoff_t ilx)
{
struct folio *folio;
int ret;
- orders = swapin_admit_orders(entry, orders);
+ orders = swapin_admit_orders(entry, orders, vmf, locality_orders);
again:
do {
folio = swap_cache_get_folio(entry);
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 2/9] mm: let swap_read_folio() report retryable zswap races
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
Large zswap loads need a way to ask the caller to drop a speculative large
swapcache folio and retry order-0. A void swap_read_folio() cannot express
that without turning a backend race into an IO failure.
Return int from swap_read_folio() and reserve -EAGAIN for retryable large
zswap races. Existing order-0 paths keep treating the read as before; the
synchronous swapin path only warns for now. A later patch will consume
-EAGAIN and retry order-0.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
mm/page_io.c | 19 +++++++++++++++++--
mm/swap.h | 5 +++--
mm/swap_state.c | 13 +++++++++++--
3 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index f2d8fe7fd057..16724bdfb400 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -653,13 +653,21 @@ static void swap_read_folio_bdev_async(struct folio *folio,
submit_bio(bio);
}
-void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
+/*
+ * Return -EAGAIN only when a locked large swapcache folio hit a retryable
+ * zswap backend race. The caller owns that still-locked folio and must drop or
+ * retry it. Other zswap errors are still reported through the usual folio
+ * state: the folio is unlocked without PG_uptodate and the fault path will
+ * turn that into an I/O error.
+ */
+int swap_read_folio(struct folio *folio, struct swap_iocb **plug)
{
struct swap_info_struct *sis = __swap_entry_to_info(folio->swap);
bool synchronous = sis->flags & SWP_SYNCHRONOUS_IO;
bool workingset = folio_test_workingset(folio);
unsigned long pflags;
bool in_thrashing;
+ int ret = 0;
VM_BUG_ON_FOLIO(!folio_test_swapcache(folio) && !synchronous, folio);
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
@@ -681,8 +689,14 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
goto finish;
}
- if (zswap_load(folio) != -ENOENT)
+ ret = zswap_load(folio);
+ if (ret == -EAGAIN) {
+ VM_WARN_ON_ONCE_FOLIO(!folio_test_large(folio), folio);
goto finish;
+ }
+ if (ret != -ENOENT)
+ goto finish;
+ ret = 0;
/* We have to read from slower devices. Increase zswap protection. */
zswap_folio_swapin(folio);
@@ -701,6 +715,7 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
psi_memstall_leave(&pflags);
}
delayacct_swapin_end();
+ return ret;
}
void __swap_read_unplug(struct swap_iocb *sio)
diff --git a/mm/swap.h b/mm/swap.h
index 77d2d14eda42..ea7e1f3c4410 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -241,7 +241,7 @@ extern void __swap_cluster_free_entries(struct swap_info_struct *si,
/* linux/mm/page_io.c */
int sio_pool_init(void);
struct swap_iocb;
-void swap_read_folio(struct folio *folio, struct swap_iocb **plug);
+int swap_read_folio(struct folio *folio, struct swap_iocb **plug);
void __swap_read_unplug(struct swap_iocb *plug);
static inline void swap_read_unplug(struct swap_iocb *plug)
{
@@ -381,8 +381,9 @@ static inline void folio_put_swap(struct folio *folio, struct page *page)
{
}
-static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
+static inline int swap_read_folio(struct folio *folio, struct swap_iocb **plug)
{
+ return 0;
}
static inline void swap_write_unplug(struct swap_iocb *sio)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 04f5ce992401..d37097913b30 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -628,6 +628,7 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
struct swap_iocb **plug, bool readahead)
{
struct folio *folio;
+ int ret;
do {
folio = swap_cache_get_folio(entry);
@@ -639,7 +640,13 @@ static struct folio *swap_cache_read_folio(swp_entry_t entry, gfp_t gfp,
if (IS_ERR_OR_NULL(folio))
return NULL;
- swap_read_folio(folio, plug);
+ ret = swap_read_folio(folio, plug);
+ /*
+ * Swap readahead allocates order-0 folios. -EAGAIN is reserved for
+ * retryable large zswap backend races and must be handled by the
+ * synchronous common swapin path.
+ */
+ VM_WARN_ON_ONCE(ret == -EAGAIN);
if (readahead) {
folio_set_readahead(folio);
count_vm_event(SWAP_RA);
@@ -668,6 +675,7 @@ struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp, unsigned long orders,
struct vm_fault *vmf, struct mempolicy *mpol, pgoff_t ilx)
{
struct folio *folio;
+ int ret;
do {
folio = swap_cache_get_folio(entry);
@@ -679,7 +687,8 @@ struct folio *swapin_sync(swp_entry_t entry, gfp_t gfp, unsigned long orders,
if (IS_ERR(folio))
return folio;
- swap_read_folio(folio, NULL);
+ ret = swap_read_folio(folio, NULL);
+ VM_WARN_ON_ONCE(ret == -EAGAIN);
return folio;
}
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 1/9] mm/zswap: expose range state for swapin policy
From: fujunjie @ 2026-05-29 12:19 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
In-Reply-To: <tencent_98CD9F78E48D08DC005A6471A13CFF28B60A@qq.com>
Large folio swapin needs to know whether a candidate swap range is fully
backed by zswap before it can choose an order. That decision should stay
in common swapin code, not inside zswap.
Export two zswap facts for that caller: a lockless range occupancy snapshot
and the current zswap reclaim-pressure state. The range state is
advisory only. Writeback or invalidation can change the backend after the
snapshot, so users must recheck before issuing large-folio IO.
Signed-off-by: fujunjie <fujunjie1@qq.com>
---
include/linux/zswap.h | 26 +++++++++++++++++++++++++
mm/zswap.c | 44 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/include/linux/zswap.h b/include/linux/zswap.h
index 30c193a1207e..8f9aee97517c 100644
--- a/include/linux/zswap.h
+++ b/include/linux/zswap.h
@@ -9,6 +9,18 @@ struct lruvec;
extern atomic_long_t zswap_stored_pages;
+/*
+ * Advisory zswap occupancy snapshot for a swap range. This is not a complete
+ * backend classifier; callers must recheck before depending on ALL_ZSWAP for
+ * large-folio IO.
+ */
+enum zswap_range_state {
+ ZSWAP_RANGE_NEVER_ENABLED,
+ ZSWAP_RANGE_NO_ZSWAP,
+ ZSWAP_RANGE_ALL_ZSWAP,
+ ZSWAP_RANGE_MIXED,
+};
+
#ifdef CONFIG_ZSWAP
struct zswap_lruvec_state {
@@ -27,6 +39,9 @@ struct zswap_lruvec_state {
unsigned long zswap_total_pages(void);
bool zswap_store(struct folio *folio);
int zswap_load(struct folio *folio);
+enum zswap_range_state zswap_probe_range(swp_entry_t swp,
+ unsigned int nr_pages);
+bool zswap_pool_reclaim_pressure(void);
void zswap_invalidate(swp_entry_t swp);
int zswap_swapon(int type, unsigned long nr_pages);
void zswap_swapoff(int type);
@@ -49,6 +64,17 @@ static inline int zswap_load(struct folio *folio)
return -ENOENT;
}
+static inline enum zswap_range_state zswap_probe_range(swp_entry_t swp,
+ unsigned int nr_pages)
+{
+ return ZSWAP_RANGE_NEVER_ENABLED;
+}
+
+static inline bool zswap_pool_reclaim_pressure(void)
+{
+ return false;
+}
+
static inline void zswap_invalidate(swp_entry_t swp) {}
static inline int zswap_swapon(int type, unsigned long nr_pages)
{
diff --git a/mm/zswap.c b/mm/zswap.c
index 761cd699e0a3..da5297f7bd69 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -506,6 +506,19 @@ unsigned long zswap_total_pages(void)
return total;
}
+/*
+ * Expose whether zswap reclaim pressure is active. This is a backend fact:
+ * zswap_check_limits() sets the state once the pool reaches the hard limit and
+ * keeps it set until the pool falls below the accept threshold.
+ */
+bool zswap_pool_reclaim_pressure(void)
+{
+ if (zswap_never_enabled())
+ return false;
+
+ return READ_ONCE(zswap_pool_reached_full);
+}
+
static bool zswap_check_limits(void)
{
unsigned long cur_pages = zswap_total_pages();
@@ -1559,6 +1572,37 @@ bool zswap_store(struct folio *folio)
return ret;
}
+enum zswap_range_state zswap_probe_range(swp_entry_t swp,
+ unsigned int nr_pages)
+{
+ unsigned int type = swp_type(swp);
+ pgoff_t offset = swp_offset(swp);
+ bool present = false, missing = false;
+ unsigned int i;
+
+ /*
+ * This is an advisory, lockless snapshot for common swapin admission.
+ * Callers must recheck before depending on an all-zswap range for IO:
+ * concurrent writeback or invalidation can change the backend state.
+ */
+ if (zswap_never_enabled())
+ return ZSWAP_RANGE_NEVER_ENABLED;
+
+ for (i = 0; i < nr_pages; i++) {
+ struct xarray *tree = swap_zswap_tree(swp_entry(type, offset + i));
+
+ if (xa_load(tree, offset + i))
+ present = true;
+ else
+ missing = true;
+
+ if (present && missing)
+ return ZSWAP_RANGE_MIXED;
+ }
+
+ return present ? ZSWAP_RANGE_ALL_ZSWAP : ZSWAP_RANGE_NO_ZSWAP;
+}
+
/**
* zswap_load() - load a folio from zswap
* @folio: folio to load
--
2.34.1
^ permalink raw reply related
* [RFC PATCH v2 0/9] mm: support zswap-backed large folio swapin
From: fujunjie @ 2026-05-29 12:17 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Alexandre Ghiti, Kairui Song, Usama Arif
Cc: Chris Li, Johannes Weiner, Yosry Ahmed, Nhat Pham,
David Hildenbrand, Hugh Dickins, Roman Gushchin, Shakeel Butt,
linux-kernel, cgroups
Hi,
This RFC explores large-folio swapin for ranges that are still fully backed
by zswap.
Large swapin is currently disabled once zswap is in the picture. Anonymous
faults stop considering large orders after zswap has ever been enabled,
shmem does the same, and zswap_load() refuses large swapcache folios. That
keeps mixed zswap/disk cases safe, but it also loses the dense case where
every slot in an aligned 64K range is still resident in zswap.
The series keeps the policy in common swapin code:
- zswap reports backend facts and provides the large-folio load helper.
- swapin_sync() filters candidate orders by backend range.
- all-disk and zeromap ranges keep the existing Kairui large-swapin path.
- mixed zswap/disk ranges stay order-0.
- all-zswap ranges may use a 64K folio after locality admission.
- anon provides locality evidence from VMA hints and PTE young density.
- shmem starts with explicit VMA-hint evidence only.
- swap readahead uses its existing VMA/cluster window as locality
evidence; it does not also run the anon PTE-young rule.
The backend range probe is only a snapshot. If the backend changes after a
fresh large swapcache folio is allocated, the common path drops that folio
and falls back to order-0. zswap_load() can also return -EAGAIN for the
same retry path. If a late fault retry keeps the large folio in swapcache
instead of deleting it, the cgroup v1 memsw swap owner is committed before
returning.
This is mTHP/large-folio swapin. The mappings installed by do_swap_page()
are still PTE mappings, not PMD mappings. The expected win is fewer faults,
batched PTE/rmap work, and preserving the large folio across zswapin
instead of rebuilding the working set as order-0 pages.
Prior art: Usama Arif posted a related RFC on 2024-10-18:
mm: zswap: add support for zswapin of large folios
https://lore.kernel.org/linux-mm/20241018105026.2521366-1-usamaarif642@gmail.com/
This RFC keeps the same broad goal, but moves admission into common swapin
code. zswap does not decide the policy. Mixed zswap/disk ranges are
rejected before large IO, and the first cap is 64K.
This is a rewrite of the RFC posted on 2026-05-08:
[RFC PATCH 0/5] mm: support zswap-backed anonymous large folio swapin
https://lore.kernel.org/linux-mm/tencent_8B437BE4F586C162950BF71954316C1EDB05@qq.com/
The v1 series was anonymous-only and kept too much of the policy near the
anon fault and zswap paths. This version is rebuilt on top of Kairui Song's
common swapin infrastructure. It keeps admission in common swapin code,
rejects mixed zswap/disk large ranges, and adds separate locality producers
for anon, shmem and swap readahead.
Performance and behavior
========================
The A/B tables are 10-run measurements. Elapsed values are seconds,
shown as mean +/- sample standard deviation. "phase" or "refault" is the
measured refault subphase. "zswpin" counts zswap loads. "pswpin" counts
swap-ins from the real swap device; pswpin=0 means the refaults were served
by zswap even when a disk swap device was configured. "RFC 64K" is the mean
number of successful 64K swapins.
The numbers below show where the large path is used and where it is
rejected.
zram-backed zswap microbench, 64K mTHP, 8G guest:
+-----------------+----------------+----------------+--------+--------+--------+----------+
| workload | base elapsed | RFC elapsed | delta | phase | zswpin | RFC 64K |
+-----------------+----------------+----------------+--------+--------+--------+----------+
| usama_1g | 11.260+/-0.235 | 10.301+/-0.140 | -8.5% | -22.2% | 1.000x | 16381.1 |
| nohint_seq64 | 4.398+/-0.085 | 4.025+/-0.022 | -8.5% | -21.1% | 1.000x | 6221.1 |
| seqhint_seq64 | 4.283+/-0.060 | 3.948+/-0.062 | -7.8% | -20.6% | 1.000x | 6223.5 |
| stride64_sparse | 3.095+/-0.051 | 3.086+/-0.025 | -0.3% | +5.8% | 1.002x | 1.0 |
| random64_sparse | 3.095+/-0.046 | 3.076+/-0.016 | -0.6% | +0.7% | 1.001x | 0.0 |
| random64_full | 4.423+/-0.067 | 4.405+/-0.018 | -0.4% | +0.1% | 1.000x | 0.0 |
+-----------------+----------------+----------------+--------+--------+--------+----------+
The usama_1g row follows the shape of the 2024 RFC benchmark: allocate 1G,
fill it with compressible per-page data, reclaim it through memory.reclaim,
then time the full integrity-check refault. The seq64 rows use a 512M
target and 768M of pressure. "sparse" touches one 4K page per 64K region, while
"full" touches every 4K page. "seqhint" uses MADV_SEQUENTIAL; "nohint" does
not.
Virtio-block swap device present, zswap enabled:
+-----------------+---------------+---------------+--------+---------+--------+--------+---------+
| workload | base elapsed | RFC elapsed | delta | refault | pswpin | zswpin | RFC 64K |
+-----------------+---------------+---------------+--------+---------+--------+--------+---------+
| seq64 | 4.399+/-0.100 | 4.279+/-0.216 | -2.7% | -10.5% | 0 | 1.000x | 3110.7 |
| stride64_sparse | 3.103+/-0.047 | 3.119+/-0.086 | +0.5% | +6.2% | 0 | 0.999x | 0.0 |
| random64_sparse | 3.142+/-0.112 | 3.097+/-0.030 | -1.4% | -2.2% | 0 | 0.999x | 0.1 |
| random64_full | 4.473+/-0.147 | 4.445+/-0.088 | -0.6% | +0.9% | 0 | 1.000x | 0.4 |
+-----------------+---------------+---------------+--------+---------+--------+--------+---------+
This run uses a real block swap device, but the refaulted data stayed in
zswap. It covers the all-zswap hit path with disk swap configured, not disk
read IO.
Virtio-block pressure/mixed run, zswap max_pool_percent=1,
low-compressibility full fill:
+-------------------------------+---------------+---------------+--------+---------+----------------+------------+---------+----------+
| workload | base elapsed | RFC elapsed | delta | refault | pswpin base/RFC | RFC zswpin | RFC 64K | fallback |
+-------------------------------+---------------+---------------+--------+---------+----------------+------------+---------+----------+
| seq64_full_pressure | 5.908+/-0.195 | 5.790+/-0.235 | -2.0% | +3.0% | 90258/99038 | 20327 | 0.0 | 3730 |
| random64_sparse_full_pressure | 5.104+/-0.069 | 5.068+/-0.090 | -0.7% | -9.1% | 6201/6196 | 1297 | 0.0 | 0 |
+-------------------------------+---------------+---------------+--------+---------+----------------+------------+---------+----------+
This run reaches the disk-backed path: pswpin is non-zero in both base and
RFC. It is mainly fallback coverage. The RFC does not install 64K folios
for these disk/mixed-heavy ranges.
Policy matrix, virtio-block swap device present:
+------------------------------+----+------+--------+--------+-------+----------+
| case | pc | hint | pswpin | zswpin | zswpwb| 64K in |
+------------------------------+----+------+--------+--------+-------+----------+
| pc0_seq | 0 | none | 0 | 99559 | 0 | 0 |
| pc3_seq | 3 | none | 0 | 99498 | 0 | 0 |
| pc4_seq | 4 | none | 0 | 99512 | 0 | 3109 |
| pc5_seq | 5 | none | 0 | 99657 | 0 | 3113 |
| hint_none_random_sparse | 5 | none | 0 | 6265 | 0 | 0 |
| hint_random_seq | 5 | rand | 0 | 99488 | 0 | 0 |
| mixed_seq_full | 5 | none | 97725 | 20147 | 84 | 569 |
| mixed_random_sparse_full | 5 | none | 6230 | 1302 | 0 | 0 |
+------------------------------+----+------+--------+--------+-------+----------+
The pc rows show the readahead-window gate. The hint_random_seq row shows
the explicit random hint veto. The mixed rows use a small zswap pool to
force disk/zswap split backing; most mixed ranges are rejected, while any
remaining 64K successes were all-zswap at the time of the fault.
Kbuild pressure, zram swap, 384M memcg:
+----------------------+----------+----------+--------+--------+----------+
| setup | base | RFC | delta | zswpin | RFC 64K |
+----------------------+----------+----------+--------+--------+----------+
| zram swap, 384M memcg| 2060.323 | 2047.516 | -0.6% | 0.991x | 2797 |
+----------------------+----------+----------+--------+--------+----------+
This is a single-run zram pressure smoke. It did not show Kbuild
regression, and the RFC run installed 64K zswap-backed folios. The result
should not be read as a tuned-performance claim.
Kbuild pressure, virtio-block swap device, 512M memcg:
+-------------------------+----------+----------+--------+--------+----------+
| setup | base | RFC | delta | pswpin | RFC 64K |
+-------------------------+----------+----------+--------+--------+----------+
| disk swap, 512M memcg | 1420.671 | 1409.263 | -0.8% | 0 | 7497 |
+-------------------------+----------+----------+--------+--------+----------+
This is a single-run pressure smoke. The disk-swap Kbuild run also stayed
on the all-zswap hit path, so it is pressure coverage with a disk swap device
present rather than proof of disk-read large swapin.
Shmem smoke, tmpfs huge=always, 64K shmem mTHP:
+----------------------------+---------------+---------+-------------+----------+
| case | refault hint | touched | 64K shmem | 64K in |
+----------------------------+---------------+---------+-------------+----------+
| nohint_seq | none | 65536 | 4096 | 0 |
| seq_refault_hint | sequential | 65536 | 4096 | 4096 |
| random_refault_hint_sparse | random | 4096 | 4096 | 0 |
+----------------------------+---------------+---------+-------------+----------+
That matches the current shmem producer: explicit sequential refault hints
allow large zswap swapin; no hint and random hints do not.
What this RFC does not establish
================================
The 64K cap is deliberate, but it is not tuned. The anon PTE-young rule is
only anon evidence. Shmem has the framework and explicit VMA hints in this
RFC, not a page-cache locality producer. For larger orders, the anon
producer should probably use bounded sampling instead of walking every PTE
in a 1M or larger candidate range. The mixed-backend tests cover fallback
behavior, but this series does not add mixed zswap/disk large IO.
Changes since RFC v1:
- rebuilt the series on Kairui Song's common swapin/swap-table work;
- moved large-swapin admission into common swapin code;
- made zswap provide range facts and fully-zswap-backed folio loads;
- rejected mixed zswap/disk large ranges before large IO;
- capped zswap-backed swapin at 64K for this RFC;
- added locality producers for anon, shmem hints and swap readahead;
- covered cgroup v1 memsw accounting in speculative large-swapcache
fallback paths;
- added 10-run microbench data, mixed-backend pressure tests, shmem
smoke tests, and zram/disk Kbuild pressure data.
fujunjie (9):
mm/zswap: expose range state for swapin policy
mm: let swap_read_folio() report retryable zswap races
mm/zswap: support fully zswap-backed large folio loads
mm: admit large swapin by backend range in swapin_sync()
mm: add common locality admission for zswap large swapin
mm: provide anon locality evidence for zswap large swapin
mm/shmem: provide VMA-hint locality for zswap large swapin
mm: try all-zswap large swapin within swap readahead windows
docs: mm: update THP swapin counter descriptions
Documentation/admin-guide/mm/transhuge.rst | 11 +-
include/linux/zswap.h | 26 +
mm/memcontrol-v1.c | 8 +-
mm/memory.c | 269 +++++++-
mm/page_io.c | 19 +-
mm/shmem.c | 42 +-
mm/swap.h | 21 +-
mm/swap_state.c | 681 +++++++++++++++++++--
mm/swapfile.c | 2 +-
mm/zswap.c | 149 ++++-
10 files changed, 1099 insertions(+), 129 deletions(-)
base-commit: 404fb4f38e8f38469dfff4df0205c9d18eeb1f57
--
2.34.1
^ permalink raw reply
* Re: [PATCH v5 5/9] mm: list_lru: deduplicate lock_list_lru()
From: Wei Yang @ 2026-05-29 9:56 UTC (permalink / raw)
To: Johannes Weiner
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes, Shakeel Butt,
Michal Hocko, Dave Chinner, Roman Gushchin, Muchun Song, Qi Zheng,
Yosry Ahmed, Zi Yan, Liam R . Howlett, Usama Arif,
Kiryl Shutsemau, Vlastimil Babka, Kairui Song, Mikhail Zaslonko,
Vasily Gorbik, Baolin Wang, Barry Song, Dev Jain, Lance Yang,
Nico Pache, Ryan Roberts, cgroups, linux-mm, linux-kernel
In-Reply-To: <20260527204757.2544958-6-hannes@cmpxchg.org>
On Wed, May 27, 2026 at 04:45:12PM -0400, Johannes Weiner wrote:
>The MEMCG and !MEMCG paths have the same pattern. Share the code.
>
>Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
>Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
>Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
>Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
>Reviewed-by: Liam R. Howlett (Oracle) <liam@infradead.org>
>---
> mm/list_lru.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
>diff --git a/mm/list_lru.c b/mm/list_lru.c
>index 7d0523e44010..fdb3fe2ea64f 100644
>--- a/mm/list_lru.c
>+++ b/mm/list_lru.c
>@@ -15,6 +15,14 @@
> #include "slab.h"
> #include "internal.h"
Hi, Johannes
One very tiny nit below.
>
>+static inline void lock_list_lru(struct list_lru_one *l, bool irq)
Here we use @irq.
>+{
>+ if (irq)
>+ spin_lock_irq(&l->lock);
>+ else
>+ spin_lock(&l->lock);
>+}
>+
> static inline void unlock_list_lru(struct list_lru_one *l, bool irq_off)
Here we use @irq_off.
Do you think it would be nicer to unify the parameter name?
Also the name in callsite and the argument annotation. Would it be cleaner
readers?
--
Wei Yang
Help you, Help me
^ permalink raw reply
* [PATCH rdma-next v2 0/3] cgroup/rdma: add MR memory size resource tracking
From: Tao Cui @ 2026-05-29 9:07 UTC (permalink / raw)
To: tj, hannes, mkoutny, leon, jgg; +Cc: linux-rdma, cgroups, Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
Currently the RDMA cgroup only tracks two aggregate counters:
hca_handle and hca_object. The real scarce resource in multi-tenant
deployments is pinned memory: how much physical memory gets registered
through MRs. The existing hca_object counter is too coarse to capture
this.
This series adds a single new resource type:
- mr_mem - Cumulative MR memory size in bytes
The per-object-type counters (qp, mr) from RFC v1 have been removed
per review feedback [1]: modern NICs pool objects from the same memory
pool so the distinction between QP count and MR count is not
meaningful for resource limiting. hca_object remains sufficient for
coarse object accounting.
After this series, an administrator can set limits like:
echo "mlx5_0 mr_mem=1073741824" > rdma.max
Design
~~~~~~
mr_mem is not page-level ownership tracking; it is object-based
accounting tied to the MR lifetime:
- charged at MR registration time
- uncharged at MR destruction time
- the charge is pinned to the cgroup that created the MR for the
entire lifetime of the MR object
This model intentionally defines accounting semantics around MR
object lifetime rather than page ownership:
1. fork(): fork() does not duplicate MR objects. Even though the
child inherits the uverbs fd and can access the parent's ucontext,
the MR remains a single kernel object. The charge is tied to the
MR object, not to the number of processes that can reach it, so
no splitting or re-accounting is needed.
2. Cgroup migration: mr_mem follows the same semantics as the existing
hca_object; charge at creation time against the invoking task's
cgroup, uncharge at destruction time. The RDMA cgroup does not
implement can_attach/attach callbacks today, so charges do not
migrate with the task. This is a known limitation that applies
equally to hca_handle and hca_object. mr_mem does not introduce
any new complication here.
3. Overlap with memory cgroup: mr_mem does not count process memory
usage; it represents a per-device DMA registration budget: the
amount of memory this cgroup may register through a given HCA.
This is a different dimension from what memory cgroup tracks. An
administrator might set mr_mem limits differently per device, which
memory cgroup cannot express.
In particular, mr_mem tracks the registered memory range associated
with the MR rather than exact dynamically pinned pages (e.g. for
ODP MRs). This is a stable, policy-oriented approximation of
registration footprint, not an attempt at precise physical page
accounting.
Tao Cui (3):
cgroup/rdma: extend charge/uncharge API with s64 amount parameter
cgroup/rdma: add MR memory size resource tracking
cgroup/rdma: update cgroup resource list for MR_MEM
Documentation/admin-guide/cgroup-v2.rst | 21 ++--
drivers/infiniband/core/cgroup.c | 10 +-
drivers/infiniband/core/core_priv.h | 12 +-
drivers/infiniband/core/rdma_core.c | 20 +++-
drivers/infiniband/core/uverbs_cmd.c | 61 +++++++++-
drivers/infiniband/core/uverbs_std_types_mr.c | 37 ++++++
include/linux/cgroup_rdma.h | 8 +-
include/rdma/ib_verbs.h | 1 +
kernel/cgroup/rdma.c | 108 +++++++++++++-----
9 files changed, 219 insertions(+), 59 deletions(-)
---
Changes from RFC v1:
- Removed RDMACG_RESOURCE_QP and RDMACG_RESOURCE_MR per-type
counters following review feedback from Jason Gunthorpe [1].
- Retained only RDMACG_RESOURCE_MR_MEM as the sole new resource.
- Added detailed semantic notes to the commit messages addressing
fork(), cgroup migration, and overlap with memory cgroup [2].
- Renamed patches to reflect the narrower scope.
[1] https://lore.kernel.org/all/20260525134314.GI7702@ziepe.ca/
[2] https://lore.kernel.org/all/20260528075537.2170697-1-cuitao@kylinos.cn/
--
2.43.0
^ permalink raw reply
* [PATCH rdma-next v2 3/3] cgroup/rdma: update cgroup resource list for MR_MEM
From: Tao Cui @ 2026-05-29 9:07 UTC (permalink / raw)
To: tj, hannes, mkoutny, leon, jgg; +Cc: linux-rdma, cgroups, Tao Cui
In-Reply-To: <20260529090733.2242822-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
The RDMA cgroup now supports MR memory size tracking via the new
mr_mem resource. Update the cgroup-v2 documentation to describe
the new resource and revise the usage examples accordingly.
The mr_mem resource tracks the cumulative size of memory registered
through Memory Regions per device per cgroup, providing a DMA
registration budget that is orthogonal to the existing hca_object
counter.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
Documentation/admin-guide/cgroup-v2.rst | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index 993446ab66d0..08d80e6f79ec 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -2766,15 +2766,16 @@ RDMA Interface Files
The following nested keys are defined.
- ========== =============================
+ ========== ================================================
hca_handle Maximum number of HCA Handles
hca_object Maximum number of HCA Objects
- ========== =============================
+ mr_mem Maximum cumulative MR memory size in bytes
+ ========== ================================================
An example for mlx4 and ocrdma device follows::
- mlx4_0 hca_handle=2 hca_object=2000
- ocrdma1 hca_handle=3 hca_object=max
+ mlx4_0 hca_handle=2 hca_object=2000 mr_mem=1073741824
+ ocrdma1 hca_handle=3 hca_object=max mr_mem=max
rdma.current
A read-only file that describes current resource usage.
@@ -2782,8 +2783,8 @@ RDMA Interface Files
An example for mlx4 and ocrdma device follows::
- mlx4_0 hca_handle=1 hca_object=20
- ocrdma1 hca_handle=1 hca_object=23
+ mlx4_0 hca_handle=1 hca_object=20 mr_mem=1048576
+ ocrdma1 hca_handle=1 hca_object=23 mr_mem=0
rdma.peak
A read-only nested-keyed file that exists for all the cgroups
@@ -2792,8 +2793,8 @@ RDMA Interface Files
An example for mlx4 and ocrdma device follows::
- mlx4_0 hca_handle=1 hca_object=20
- ocrdma1 hca_handle=0 hca_object=23
+ mlx4_0 hca_handle=1 hca_object=20 mr_mem=1048576
+ ocrdma1 hca_handle=0 hca_object=23 mr_mem=0
rdma.events
A read-only nested-keyed file which exists on non-root
@@ -2815,7 +2816,7 @@ RDMA Interface Files
An example for mlx4 device follows::
- mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=3 hca_object.max=0 hca_object.alloc_fail=0
+ mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=3 hca_object.max=0 hca_object.alloc_fail=0 mr_mem.max=0 mr_mem.alloc_fail=0
rdma.events.local
Similar to rdma.events but the fields in the file are local
@@ -2836,7 +2837,7 @@ RDMA Interface Files
An example for mlx4 device follows::
- mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=0 hca_object.max=0 hca_object.alloc_fail=0
+ mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=0 hca_object.max=0 hca_object.alloc_fail=0 mr_mem.max=0 mr_mem.alloc_fail=0
DMEM
----
--
2.43.0
^ permalink raw reply related
* [PATCH rdma-next v2 2/3] cgroup/rdma: add MR memory size resource tracking
From: Tao Cui @ 2026-05-29 9:07 UTC (permalink / raw)
To: tj, hannes, mkoutny, leon, jgg; +Cc: linux-rdma, cgroups, Tao Cui
In-Reply-To: <20260529090733.2242822-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
Add RDMACG_RESOURCE_MR_MEM so that the cumulative memory size of
registered Memory Regions can be tracked and limited independently
from the aggregate hca_object counter.
Unlike count-based resources (hca_handle, hca_object) which are
charged in the generic IDR allocation path, MR_MEM is byte-based
and must be charged after the MR length is known. Charge in the
uverbs MR registration handlers (ioctl and legacy), and uncharge
in the generic destroy paths (alloc_abort_idr_uobject,
destroy_hw_idr_uobject).
Store the charged byte count in uobj->rdmacg_mr_mem_bytes so that
the destroy path knows how much to uncharge.
Semantic notes
~~~~~~~~~~~~~~
mr_mem is not page-level ownership tracking - it is object-based
accounting tied to the MR lifetime:
- charged at MR registration time
- uncharged at MR destruction time
- the charge lives with the MR's creating cgroup for the entire
lifetime of the MR object
This model intentionally defines accounting semantics around MR
object lifetime rather than page ownership:
1. fork(): fork() does not duplicate MR objects. Even though the
child inherits the uverbs fd and can access the parent's ucontext,
the MR remains a single kernel object. The charge is tied to the
MR object, not to the number of processes that can reach it, so
no splitting or re-accounting is needed.
2. Cgroup migration: mr_mem follows the same semantics as the existing
hca_object - charge at creation time against the invoking task's
cgroup, uncharge at destruction time. The RDMA cgroup does not
implement can_attach/attach callbacks today, so charges do not
migrate with the task. This is a known limitation that applies
equally to hca_handle and hca_object. mr_mem does not introduce
any new complication here.
3. Overlap with memory cgroup: mr_mem does not count process memory
usage - it represents a per-device DMA registration budget: how
much memory can this cgroup register through a given HCA. This is
a different dimension from what memory cgroup tracks. An
administrator might set mr_mem limits differently per device, which
memory cgroup cannot express.
In particular, mr_mem tracks the registered memory range associated
with the MR rather than exact dynamically pinned pages (e.g. for
ODP MRs). This is a stable, policy-oriented approximation of
registration footprint - not an attempt at precise physical page
accounting.
Guard against u64-to-s64 overflow by rejecting MR lengths that
exceed S64_MAX at each registration site.
Handle MR reregistration (IB_USER_VERBS_CMD_REREG_MR with
IB_MR_REREG_TRANS) by computing the delta between old and new
lengths and charging or uncharging the difference. When the driver
creates a new HW object (new_mr != NULL), the full new length is
charged to the new uobj and the old uobj's mr_mem is released
through the existing rdma_assign_uobject -> destroy_hw_idr_uobject
-> rdmacg_uncharge_uobj path.
Enable MR memory limits:
echo "mlx5_0 mr_mem=1073741824" > rdma.max
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
drivers/infiniband/core/rdma_core.c | 14 ++++-
drivers/infiniband/core/uverbs_cmd.c | 57 +++++++++++++++++++
drivers/infiniband/core/uverbs_std_types_mr.c | 37 ++++++++++++
include/linux/cgroup_rdma.h | 1 +
include/rdma/ib_verbs.h | 1 +
kernel/cgroup/rdma.c | 21 ++++++-
6 files changed, 126 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 3268285b5478..a540cef6bb67 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -523,10 +523,19 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
return ret;
}
-static void alloc_abort_idr_uobject(struct ib_uobject *uobj)
+static void rdmacg_uncharge_uobj(struct ib_uobject *uobj)
{
ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
RDMACG_RESOURCE_HCA_OBJECT, 1);
+ if (uobj->rdmacg_mr_mem_bytes)
+ ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM,
+ uobj->rdmacg_mr_mem_bytes);
+}
+
+static void alloc_abort_idr_uobject(struct ib_uobject *uobj)
+{
+ rdmacg_uncharge_uobj(uobj);
xa_erase(&uobj->ufile->idr, uobj->id);
}
@@ -546,8 +555,7 @@ static int __must_check destroy_hw_idr_uobject(struct ib_uobject *uobj,
if (why == RDMA_REMOVE_ABORT)
return 0;
- ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
- RDMACG_RESOURCE_HCA_OBJECT, 1);
+ rdmacg_uncharge_uobj(uobj);
return 0;
}
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 9540ac180711..901de117c808 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -752,6 +752,17 @@ static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
uobj->object = mr;
uobj_put_obj_read(pd);
+
+ if (cmd.length > S64_MAX)
+ goto err_free;
+ if (cmd.length) {
+ ret = ib_rdmacg_try_charge(&uobj->cg_obj, uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM, cmd.length);
+ if (ret)
+ goto err_dereg;
+ uobj->rdmacg_mr_mem_bytes = cmd.length;
+ }
+
uobj_finalize_uobj_create(uobj, attrs);
resp.lkey = mr->lkey;
@@ -759,6 +770,8 @@ static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
resp.mr_handle = uobj->id;
return uverbs_response(attrs, &resp, sizeof(resp));
+err_dereg:
+ ib_dereg_mr_user(mr, &attrs->driver_udata);
err_put:
uobj_put_obj_read(pd);
err_free:
@@ -854,6 +867,20 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
rdma_restrack_set_name(&new_mr->res, NULL);
rdma_restrack_add(&new_mr->res);
+ if ((cmd.flags & IB_MR_REREG_TRANS) && cmd.length) {
+ if (cmd.length > S64_MAX) {
+ ret = -EINVAL;
+ goto err_rereg_new_mr;
+ }
+ ret = ib_rdmacg_try_charge(&new_uobj->cg_obj,
+ new_uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM,
+ cmd.length);
+ if (ret)
+ goto err_rereg_new_mr;
+ new_uobj->rdmacg_mr_mem_bytes = cmd.length;
+ }
+
/*
* The new uobj for the new HW object is put into the same spot
* in the IDR and the old uobj & HW object is deleted.
@@ -871,6 +898,31 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
atomic_inc(&new_pd->usecnt);
}
if (cmd.flags & IB_MR_REREG_TRANS) {
+ s64 delta;
+
+ if (cmd.length > S64_MAX) {
+ ret = -EINVAL;
+ goto put_new_uobj;
+ }
+ delta = (s64)cmd.length -
+ (s64)uobj->rdmacg_mr_mem_bytes;
+
+ if (delta > 0) {
+ ret = ib_rdmacg_try_charge(
+ &uobj->cg_obj,
+ uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM,
+ delta);
+ if (ret)
+ goto put_new_uobj;
+ } else if (delta < 0) {
+ ib_rdmacg_uncharge(
+ &uobj->cg_obj,
+ uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM,
+ -delta);
+ }
+ uobj->rdmacg_mr_mem_bytes = cmd.length;
mr->iova = cmd.hca_va;
mr->length = cmd.length;
}
@@ -887,6 +939,11 @@ static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
put_new_uobj:
if (new_uobj)
uobj_alloc_abort(new_uobj, attrs);
+err_rereg_new_mr:
+ if (new_uobj) {
+ rdma_alloc_abort_uobject(new_uobj, attrs, true);
+ new_uobj = NULL;
+ }
put_uobj_pd:
if (cmd.flags & IB_MR_REREG_PD)
uobj_put_obj_read(new_pd);
diff --git a/drivers/infiniband/core/uverbs_std_types_mr.c b/drivers/infiniband/core/uverbs_std_types_mr.c
index 570b9656801d..3989ff2d282b 100644
--- a/drivers/infiniband/core/uverbs_std_types_mr.c
+++ b/drivers/infiniband/core/uverbs_std_types_mr.c
@@ -32,6 +32,7 @@
*/
#include "rdma_core.h"
+#include "core_priv.h"
#include "uverbs.h"
#include <rdma/uverbs_std_types.h>
#include "restrack.h"
@@ -140,6 +141,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
rdma_restrack_set_name(&mr->res, NULL);
rdma_restrack_add(&mr->res);
uobj->object = mr;
+ if (attr.length > S64_MAX)
+ return -EINVAL;
+
+ if (attr.length) {
+ ret = ib_rdmacg_try_charge(&uobj->cg_obj, uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM, attr.length);
+ if (ret) {
+ ib_dereg_mr_user(mr, &attrs->driver_udata);
+ return ret;
+ }
+ uobj->rdmacg_mr_mem_bytes = attr.length;
+ }
uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_REG_DM_MR_HANDLE);
@@ -254,6 +267,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_DMABUF_MR)(
rdma_restrack_add(&mr->res);
uobj->object = mr;
+ if (length > S64_MAX)
+ return -EINVAL;
+ if (length) {
+ ret = ib_rdmacg_try_charge(&uobj->cg_obj, uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM, length);
+ if (ret) {
+ ib_dereg_mr_user(mr, &attrs->driver_udata);
+ return ret;
+ }
+ uobj->rdmacg_mr_mem_bytes = length;
+ }
+
uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_REG_DMABUF_MR_HANDLE);
ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_DMABUF_MR_RESP_LKEY,
@@ -383,6 +408,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_MR)(
rdma_restrack_add(&mr->res);
uobj->object = mr;
+ if (length > S64_MAX)
+ return -EINVAL;
+ if (length) {
+ ret = ib_rdmacg_try_charge(&uobj->cg_obj, uobj->context->device,
+ RDMACG_RESOURCE_MR_MEM, length);
+ if (ret) {
+ ib_dereg_mr_user(mr, &attrs->driver_udata);
+ return ret;
+ }
+ uobj->rdmacg_mr_mem_bytes = length;
+ }
+
uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_REG_MR_HANDLE);
ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_MR_RESP_LKEY,
diff --git a/include/linux/cgroup_rdma.h b/include/linux/cgroup_rdma.h
index 7146cefa95a6..2c8fb1ebb1a9 100644
--- a/include/linux/cgroup_rdma.h
+++ b/include/linux/cgroup_rdma.h
@@ -12,6 +12,7 @@
enum rdmacg_resource_type {
RDMACG_RESOURCE_HCA_HANDLE,
RDMACG_RESOURCE_HCA_OBJECT,
+ RDMACG_RESOURCE_MR_MEM,
RDMACG_RESOURCE_MAX,
};
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 9dd76f489a0b..c7dcd5d085fb 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1569,6 +1569,7 @@ struct ib_uobject {
void *object; /* containing object */
struct list_head list; /* link to context's list */
struct ib_rdmacg_object cg_obj; /* rdmacg object */
+ s64 rdmacg_mr_mem_bytes; /* charged MR memory size */
int id; /* index into kernel idr */
struct kref ref;
atomic_t usecnt; /* protects exclusive access */
diff --git a/kernel/cgroup/rdma.c b/kernel/cgroup/rdma.c
index 519f7f537223..ebfc5721c098 100644
--- a/kernel/cgroup/rdma.c
+++ b/kernel/cgroup/rdma.c
@@ -23,14 +23,18 @@ enum rdmacg_limit_tokens {
RDMACG_HCA_HANDLE_MAX,
RDMACG_HCA_OBJECT_VAL,
RDMACG_HCA_OBJECT_MAX,
+ RDMACG_MR_MEM_VAL,
+ RDMACG_MR_MEM_MAX,
NR_RDMACG_LIMIT_TOKENS,
};
static const match_table_t rdmacg_limit_tokens = {
- { RDMACG_HCA_HANDLE_VAL, "hca_handle=%d" },
+ { RDMACG_HCA_HANDLE_VAL, "hca_handle=%d" },
{ RDMACG_HCA_HANDLE_MAX, "hca_handle=max" },
- { RDMACG_HCA_OBJECT_VAL, "hca_object=%d" },
+ { RDMACG_HCA_OBJECT_VAL, "hca_object=%d" },
{ RDMACG_HCA_OBJECT_MAX, "hca_object=max" },
+ { RDMACG_MR_MEM_VAL, "mr_mem=%d" },
+ { RDMACG_MR_MEM_MAX, "mr_mem=max" },
{ NR_RDMACG_LIMIT_TOKENS, NULL },
};
@@ -55,6 +59,7 @@ enum rdmacg_file_type {
static char const *rdmacg_resource_names[] = {
[RDMACG_RESOURCE_HCA_HANDLE] = "hca_handle",
[RDMACG_RESOURCE_HCA_OBJECT] = "hca_object",
+ [RDMACG_RESOURCE_MR_MEM] = "mr_mem",
};
/* resource tracker for each resource of rdma cgroup */
@@ -566,6 +571,18 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
new_limits[RDMACG_RESOURCE_HCA_OBJECT] = S64_MAX;
enables |= BIT(RDMACG_RESOURCE_HCA_OBJECT);
break;
+ case RDMACG_MR_MEM_VAL:
+ if (match_s64(&args[0], &intval)) {
+ ret = -EINVAL;
+ goto parse_err;
+ }
+ new_limits[RDMACG_RESOURCE_MR_MEM] = intval;
+ enables |= BIT(RDMACG_RESOURCE_MR_MEM);
+ break;
+ case RDMACG_MR_MEM_MAX:
+ new_limits[RDMACG_RESOURCE_MR_MEM] = S64_MAX;
+ enables |= BIT(RDMACG_RESOURCE_MR_MEM);
+ break;
default:
ret = -EINVAL;
goto parse_err;
--
2.43.0
^ permalink raw reply related
* [PATCH rdma-next v2 1/3] cgroup/rdma: extend charge/uncharge API with s64 amount parameter
From: Tao Cui @ 2026-05-29 9:07 UTC (permalink / raw)
To: tj, hannes, mkoutny, leon, jgg; +Cc: linux-rdma, cgroups, Tao Cui
In-Reply-To: <20260529090733.2242822-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
Change struct rdmacg_resource fields (max, usage, peak) and all
charge/uncharge function signatures from int to s64 to prepare for
byte-sized resource tracking such as MR memory.
Replace match_int with a match_s64 helper that uses kstrtoll so the
user-space limit tokens accept 64-bit values. All existing callers
pass amount=1 (count-based), so the change is transparent for
existing count-based resources.
The rpool->usage_sum counter continues to track the number of active
charge operations (not the sum of charged amounts); this is correct
because it governs rpool lifetime - a pool is releasable only when
all charges, regardless of amount, have been released.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
drivers/infiniband/core/cgroup.c | 10 ++--
drivers/infiniband/core/core_priv.h | 12 ++--
drivers/infiniband/core/rdma_core.c | 8 +--
drivers/infiniband/core/uverbs_cmd.c | 4 +-
include/linux/cgroup_rdma.h | 7 ++-
kernel/cgroup/rdma.c | 87 ++++++++++++++++++----------
6 files changed, 83 insertions(+), 45 deletions(-)
diff --git a/drivers/infiniband/core/cgroup.c b/drivers/infiniband/core/cgroup.c
index 1f037fe01450..81e24de72392 100644
--- a/drivers/infiniband/core/cgroup.c
+++ b/drivers/infiniband/core/cgroup.c
@@ -36,18 +36,20 @@ void ib_device_unregister_rdmacg(struct ib_device *device)
int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index)
+ enum rdmacg_resource_type resource_index,
+ s64 amount)
{
return rdmacg_try_charge(&cg_obj->cg, &device->cg_device,
- resource_index);
+ resource_index, amount);
}
EXPORT_SYMBOL(ib_rdmacg_try_charge);
void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index)
+ enum rdmacg_resource_type resource_index,
+ s64 amount)
{
rdmacg_uncharge(cg_obj->cg, &device->cg_device,
- resource_index);
+ resource_index, amount);
}
EXPORT_SYMBOL(ib_rdmacg_uncharge);
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h
index a2c36666e6fc..345356d1e504 100644
--- a/drivers/infiniband/core/core_priv.h
+++ b/drivers/infiniband/core/core_priv.h
@@ -159,11 +159,13 @@ void ib_device_unregister_rdmacg(struct ib_device *device);
int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index);
+ enum rdmacg_resource_type resource_index,
+ s64 amount);
void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index);
+ enum rdmacg_resource_type resource_index,
+ s64 amount);
#else
static inline void ib_device_register_rdmacg(struct ib_device *device)
{
@@ -175,14 +177,16 @@ static inline void ib_device_unregister_rdmacg(struct ib_device *device)
static inline int ib_rdmacg_try_charge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index)
+ enum rdmacg_resource_type resource_index,
+ s64 amount)
{
return 0;
}
static inline void ib_rdmacg_uncharge(struct ib_rdmacg_object *cg_obj,
struct ib_device *device,
- enum rdmacg_resource_type resource_index)
+ enum rdmacg_resource_type resource_index,
+ s64 amount)
{
}
#endif
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 5018ec837056..3268285b5478 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -437,7 +437,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
goto uobj_put;
ret = ib_rdmacg_try_charge(&uobj->cg_obj, uobj->context->device,
- RDMACG_RESOURCE_HCA_OBJECT);
+ RDMACG_RESOURCE_HCA_OBJECT, 1);
if (ret)
goto remove;
@@ -526,7 +526,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,
static void alloc_abort_idr_uobject(struct ib_uobject *uobj)
{
ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
- RDMACG_RESOURCE_HCA_OBJECT);
+ RDMACG_RESOURCE_HCA_OBJECT, 1);
xa_erase(&uobj->ufile->idr, uobj->id);
}
@@ -547,7 +547,7 @@ static int __must_check destroy_hw_idr_uobject(struct ib_uobject *uobj,
return 0;
ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
- RDMACG_RESOURCE_HCA_OBJECT);
+ RDMACG_RESOURCE_HCA_OBJECT, 1);
return 0;
}
@@ -878,7 +878,7 @@ static void ufile_destroy_ucontext(struct ib_uverbs_file *ufile,
}
ib_rdmacg_uncharge(&ucontext->cg_obj, ib_dev,
- RDMACG_RESOURCE_HCA_HANDLE);
+ RDMACG_RESOURCE_HCA_HANDLE, 1);
rdma_restrack_del(&ucontext->res);
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 91a62d2ade4d..9540ac180711 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -234,7 +234,7 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
}
ret = ib_rdmacg_try_charge(&ucontext->cg_obj, ucontext->device,
- RDMACG_RESOURCE_HCA_HANDLE);
+ RDMACG_RESOURCE_HCA_HANDLE, 1);
if (ret)
goto err;
@@ -273,7 +273,7 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
err_uncharge:
ib_rdmacg_uncharge(&ucontext->cg_obj, ucontext->device,
- RDMACG_RESOURCE_HCA_HANDLE);
+ RDMACG_RESOURCE_HCA_HANDLE, 1);
err:
mutex_unlock(&file->ucontext_lock);
up_read(&file->hw_destroy_rwsem);
diff --git a/include/linux/cgroup_rdma.h b/include/linux/cgroup_rdma.h
index 404e746552ca..7146cefa95a6 100644
--- a/include/linux/cgroup_rdma.h
+++ b/include/linux/cgroup_rdma.h
@@ -7,6 +7,7 @@
#define _CGROUP_RDMA_H
#include <linux/cgroup.h>
+#include <linux/types.h>
enum rdmacg_resource_type {
RDMACG_RESOURCE_HCA_HANDLE,
@@ -46,9 +47,11 @@ void rdmacg_unregister_device(struct rdmacg_device *device);
/* APIs for RDMA/IB stack to charge/uncharge pool specific resources */
int rdmacg_try_charge(struct rdma_cgroup **rdmacg,
struct rdmacg_device *device,
- enum rdmacg_resource_type index);
+ enum rdmacg_resource_type index,
+ s64 amount);
void rdmacg_uncharge(struct rdma_cgroup *cg,
struct rdmacg_device *device,
- enum rdmacg_resource_type index);
+ enum rdmacg_resource_type index,
+ s64 amount);
#endif /* CONFIG_CGROUP_RDMA */
#endif /* _CGROUP_RDMA_H */
diff --git a/kernel/cgroup/rdma.c b/kernel/cgroup/rdma.c
index 5e82a03b3270..519f7f537223 100644
--- a/kernel/cgroup/rdma.c
+++ b/kernel/cgroup/rdma.c
@@ -59,9 +59,9 @@ static char const *rdmacg_resource_names[] = {
/* resource tracker for each resource of rdma cgroup */
struct rdmacg_resource {
- int max;
- int usage;
- int peak;
+ s64 max;
+ s64 usage;
+ s64 peak;
};
/*
@@ -105,13 +105,13 @@ static inline struct rdma_cgroup *get_current_rdmacg(void)
}
static void set_resource_limit(struct rdmacg_resource_pool *rpool,
- int index, int new_max)
+ int index, s64 new_max)
{
- if (new_max == S32_MAX) {
- if (rpool->resources[index].max != S32_MAX)
+ if (new_max == S64_MAX) {
+ if (rpool->resources[index].max != S64_MAX)
rpool->num_max_cnt++;
} else {
- if (rpool->resources[index].max == S32_MAX)
+ if (rpool->resources[index].max == S64_MAX)
rpool->num_max_cnt--;
}
rpool->resources[index].max = new_max;
@@ -122,7 +122,7 @@ static void set_all_resource_max_limit(struct rdmacg_resource_pool *rpool)
int i;
for (i = 0; i < RDMACG_RESOURCE_MAX; i++)
- set_resource_limit(rpool, i, S32_MAX);
+ set_resource_limit(rpool, i, S64_MAX);
}
static void free_cg_rpool_locked(struct rdmacg_resource_pool *rpool)
@@ -206,7 +206,8 @@ get_cg_rpool_locked(struct rdma_cgroup *cg, struct rdmacg_device *device)
static void
uncharge_cg_locked(struct rdma_cgroup *cg,
struct rdmacg_device *device,
- enum rdmacg_resource_type index)
+ enum rdmacg_resource_type index,
+ s64 amount)
{
struct rdmacg_resource_pool *rpool;
@@ -222,7 +223,7 @@ uncharge_cg_locked(struct rdma_cgroup *cg,
return;
}
- rpool->resources[index].usage--;
+ rpool->resources[index].usage -= amount;
/*
* A negative count (or overflow) is invalid,
@@ -307,14 +308,15 @@ static void rdmacg_event_locked(struct rdma_cgroup *cg,
static void rdmacg_uncharge_hierarchy(struct rdma_cgroup *cg,
struct rdmacg_device *device,
struct rdma_cgroup *stop_cg,
- enum rdmacg_resource_type index)
+ enum rdmacg_resource_type index,
+ s64 amount)
{
struct rdma_cgroup *p;
mutex_lock(&rdmacg_mutex);
for (p = cg; p != stop_cg; p = parent_rdmacg(p))
- uncharge_cg_locked(p, device, index);
+ uncharge_cg_locked(p, device, index, amount);
mutex_unlock(&rdmacg_mutex);
@@ -329,12 +331,13 @@ static void rdmacg_uncharge_hierarchy(struct rdma_cgroup *cg,
*/
void rdmacg_uncharge(struct rdma_cgroup *cg,
struct rdmacg_device *device,
- enum rdmacg_resource_type index)
+ enum rdmacg_resource_type index,
+ s64 amount)
{
if (index >= RDMACG_RESOURCE_MAX)
return;
- rdmacg_uncharge_hierarchy(cg, device, NULL, index);
+ rdmacg_uncharge_hierarchy(cg, device, NULL, index, amount);
}
EXPORT_SYMBOL(rdmacg_uncharge);
@@ -343,6 +346,7 @@ EXPORT_SYMBOL(rdmacg_uncharge);
* @rdmacg: pointer to rdma cgroup which will own this resource
* @device: pointer to rdmacg device
* @index: index of the resource to charge in cgroup (resource pool)
+ * @amount: amount to charge
*
* This function follows charging resource in hierarchical way.
* It will fail if the charge would cause the new value to exceed the
@@ -361,7 +365,8 @@ EXPORT_SYMBOL(rdmacg_uncharge);
*/
int rdmacg_try_charge(struct rdma_cgroup **rdmacg,
struct rdmacg_device *device,
- enum rdmacg_resource_type index)
+ enum rdmacg_resource_type index,
+ s64 amount)
{
struct rdma_cgroup *cg, *p;
struct rdmacg_resource_pool *rpool;
@@ -371,6 +376,9 @@ int rdmacg_try_charge(struct rdma_cgroup **rdmacg,
if (index >= RDMACG_RESOURCE_MAX)
return -EINVAL;
+ if (amount <= 0)
+ return -EINVAL;
+
/*
* hold on to css, as cgroup can be removed but resource
* accounting happens on css.
@@ -384,8 +392,9 @@ int rdmacg_try_charge(struct rdma_cgroup **rdmacg,
ret = PTR_ERR(rpool);
goto err;
} else {
- new = (s64)rpool->resources[index].usage + 1;
- if (new > rpool->resources[index].max) {
+ new = rpool->resources[index].usage + amount;
+ if (new < rpool->resources[index].usage ||
+ new > rpool->resources[index].max) {
ret = -EAGAIN;
goto err;
} else {
@@ -409,7 +418,7 @@ int rdmacg_try_charge(struct rdma_cgroup **rdmacg,
if (ret == -EAGAIN)
rdmacg_event_locked(cg, p, device, index);
mutex_unlock(&rdmacg_mutex);
- rdmacg_uncharge_hierarchy(cg, device, p, index);
+ rdmacg_uncharge_hierarchy(cg, device, p, index, amount);
return ret;
}
EXPORT_SYMBOL(rdmacg_try_charge);
@@ -477,6 +486,25 @@ static struct rdmacg_device *rdmacg_get_device_locked(const char *name)
return NULL;
}
+static int match_s64(substring_t *s, s64 *result)
+{
+ char *buf;
+ int ret;
+ s64 val;
+
+ buf = kmemdup_nul(s->from, s->to - s->from, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ ret = kstrtoll(buf, 0, &val);
+ kfree(buf);
+ if (ret)
+ return ret;
+ if (val < 0)
+ return -EINVAL;
+ *result = val;
+ return 0;
+}
+
static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
@@ -486,7 +514,7 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
struct rdmacg_device *device;
char *options = strstrip(buf);
char *p;
- int *new_limits;
+ s64 *new_limits;
unsigned long enables = 0;
int i = 0, ret = 0;
@@ -497,7 +525,7 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
goto err;
}
- new_limits = kzalloc_objs(int, RDMACG_RESOURCE_MAX);
+ new_limits = kcalloc(RDMACG_RESOURCE_MAX, sizeof(s64), GFP_KERNEL);
if (!new_limits) {
ret = -ENOMEM;
goto err;
@@ -506,7 +534,8 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
/* parse resource limit tokens */
while ((p = strsep(&options, " \t\n"))) {
substring_t args[MAX_OPT_ARGS];
- int tok, intval;
+ int tok;
+ s64 intval;
if (!*p)
continue;
@@ -514,7 +543,7 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
tok = match_token(p, rdmacg_limit_tokens, args);
switch (tok) {
case RDMACG_HCA_HANDLE_VAL:
- if (match_int(&args[0], &intval) || intval < 0) {
+ if (match_s64(&args[0], &intval)) {
ret = -EINVAL;
goto parse_err;
}
@@ -522,11 +551,11 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
enables |= BIT(RDMACG_RESOURCE_HCA_HANDLE);
break;
case RDMACG_HCA_HANDLE_MAX:
- new_limits[RDMACG_RESOURCE_HCA_HANDLE] = S32_MAX;
+ new_limits[RDMACG_RESOURCE_HCA_HANDLE] = S64_MAX;
enables |= BIT(RDMACG_RESOURCE_HCA_HANDLE);
break;
case RDMACG_HCA_OBJECT_VAL:
- if (match_int(&args[0], &intval) || intval < 0) {
+ if (match_s64(&args[0], &intval)) {
ret = -EINVAL;
goto parse_err;
}
@@ -534,7 +563,7 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of,
enables |= BIT(RDMACG_RESOURCE_HCA_OBJECT);
break;
case RDMACG_HCA_OBJECT_MAX:
- new_limits[RDMACG_RESOURCE_HCA_OBJECT] = S32_MAX;
+ new_limits[RDMACG_RESOURCE_HCA_OBJECT] = S64_MAX;
enables |= BIT(RDMACG_RESOURCE_HCA_OBJECT);
break;
default:
@@ -588,7 +617,7 @@ static void print_rpool_values(struct seq_file *sf,
{
enum rdmacg_file_type sf_type;
int i;
- u32 value;
+ s64 value;
sf_type = seq_cft(sf)->private;
@@ -599,7 +628,7 @@ static void print_rpool_values(struct seq_file *sf,
if (rpool)
value = rpool->resources[i].max;
else
- value = S32_MAX;
+ value = S64_MAX;
} else if (sf_type == RDMACG_RESOURCE_TYPE_PEAK) {
value = rpool ? rpool->resources[i].peak : 0;
} else {
@@ -609,10 +638,10 @@ static void print_rpool_values(struct seq_file *sf,
value = 0;
}
- if (value == S32_MAX)
+ if (value == S64_MAX)
seq_puts(sf, RDMACG_MAX_STR);
else
- seq_printf(sf, "%d", value);
+ seq_printf(sf, "%lld", value);
seq_putc(sf, ' ');
}
}
--
2.43.0
^ permalink raw reply related
* Re: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
From: kernel test robot @ 2026-05-29 8:58 UTC (permalink / raw)
To: Yury Norov, Andrew Morton, David Hildenbrand, Zi Yan,
Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park,
Gregory Price, Ying Huang, Alistair Popple, linux-kernel
Cc: llvm, oe-kbuild-all, Linux Memory Management List, Yury Norov,
Farhad Alemi, Waiman Long, Rasmus Villemoes, cgroups
In-Reply-To: <20260528190337.878027-1-ynorov@nvidia.com>
Hi Yury,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/mm-don-t-allow-empty-relative-nodemask-in-mpol_relative_nodemask/20260529-030835
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20260528190337.878027-1-ynorov%40nvidia.com
patch subject: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260529/202605291609.AR5UEvmT-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260529/202605291609.AR5UEvmT-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605291609.AR5UEvmT-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> mm/mempolicy.c:377:3: warning: void function 'mpol_relative_nodemask' should not return a value [-Wreturn-mismatch]
377 | return -EINVAL;
| ^ ~~~~~~~
1 warning generated.
vim +/mpol_relative_nodemask +377 mm/mempolicy.c
369
370 static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
371 const nodemask_t *rel)
372 {
373 unsigned int w = nodes_weight(*rel);
374 nodemask_t tmp;
375
376 if (w == 0)
> 377 return -EINVAL;
378
379 nodes_fold(tmp, *orig, w);
380 nodes_onto(*ret, tmp, *rel);
381 }
382
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
From: kernel test robot @ 2026-05-29 8:47 UTC (permalink / raw)
To: Yury Norov, Andrew Morton, David Hildenbrand, Zi Yan,
Matthew Brost, Joshua Hahn, Rakie Kim, Byungchul Park,
Gregory Price, Ying Huang, Alistair Popple, linux-kernel
Cc: oe-kbuild-all, Linux Memory Management List, Yury Norov,
Farhad Alemi, Waiman Long, Rasmus Villemoes, cgroups
In-Reply-To: <20260528190337.878027-1-ynorov@nvidia.com>
Hi Yury,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/mm-don-t-allow-empty-relative-nodemask-in-mpol_relative_nodemask/20260529-030835
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20260528190337.878027-1-ynorov%40nvidia.com
patch subject: [PATCH] mm: don't allow empty relative nodemask in mpol_relative_nodemask()
config: x86_64-buildonly-randconfig-003-20260529 (https://download.01.org/0day-ci/archive/20260529/202605291631.6MATSv6v-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260529/202605291631.6MATSv6v-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605291631.6MATSv6v-lkp@intel.com/
All errors (new ones prefixed by >>):
mm/mempolicy.c: In function 'mpol_relative_nodemask':
>> mm/mempolicy.c:377:24: error: 'return' with a value, in function returning void [-Wreturn-mismatch]
377 | return -EINVAL;
| ^
mm/mempolicy.c:370:13: note: declared here
370 | static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
| ^~~~~~~~~~~~~~~~~~~~~~
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MFD_STMFX
Depends on [n]: HAS_IOMEM [=y] && I2C [=y] && OF [=n]
Selected by [y]:
- PINCTRL_STMFX [=y] && PINCTRL [=y] && I2C [=y] && HAS_IOMEM [=y]
vim +/return +377 mm/mempolicy.c
369
370 static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
371 const nodemask_t *rel)
372 {
373 unsigned int w = nodes_weight(*rel);
374 nodemask_t tmp;
375
376 if (w == 0)
> 377 return -EINVAL;
378
379 nodes_fold(tmp, *orig, w);
380 nodes_onto(*ret, tmp, *rel);
381 }
382
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH v3] cgroup/dmem: introduce a peak file
From: Maarten Lankhorst @ 2026-05-29 7:34 UTC (permalink / raw)
To: Michal Koutný, Thadeu Lima de Souza Cascardo
Cc: Tejun Heo, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Andrew Morton, Jonathan Corbet,
Shuah Khan, Maxime Ripard, Natalie Vock, Tvrtko Ursulin, cgroups,
linux-kernel, linux-mm, linux-doc, dri-devel, kernel-dev
In-Reply-To: <ahCISfTlN10gD8e6@localhost.localdomain>
Den 2026-05-22 kl. 18:48, skrev Michal Koutný:
> On Thu, May 14, 2026 at 02:36:08PM -0300, Thadeu Lima de Souza Cascardo <cascardo@igalia.com> wrote:
>> Just like we have memory.peak, introduce a dmem.peak, which uses the
>> page_counter support for that.
>>
>> For now, make it read-only.
>>
>> This allows for memory usage monitoring without polling dmem.current when
>> the information needed is the maximum device memory used. That can be used
>> for capacity planning, such that dmem.max can be properly setup for a given
>> workload. It can also be used for debugging to determine whether a given
>> workload would have caused eviction or system memory use.
>>
>> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
>> ---
>> Changes in v3:
>> - EDITME: describe what is new in this series revision.
>> - EDITME: use bulletpoints and terse descriptions.
>> - Link to v2: https://patch.msgid.link/20260513-dmem_peak-v2-1-dac06999db9e@igalia.com
>>
>> Changes in v2:
>> - Make it read-only for now and adjust documentation accordingly.
>> - Link to v1: https://patch.msgid.link/20260506-dmem_peak-v1-0-8d803eb3449c@igalia.com
>> ---
>> Documentation/admin-guide/cgroup-v2.rst | 6 ++++++
>> kernel/cgroup/dmem.c | 15 +++++++++++++++
>> 2 files changed, 21 insertions(+)
>>
>> diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
>> index 6efd0095ed99..d103623b2be4 100644
>> --- a/Documentation/admin-guide/cgroup-v2.rst
>> +++ b/Documentation/admin-guide/cgroup-v2.rst
>> @@ -2808,6 +2808,12 @@ DMEM Interface Files
>> The semantics are the same as for the memory cgroup controller, and are
>> calculated in the same way.
>>
>> + dmem.peak
>> + A read-only nested-keyed file that exists on non-root cgroups.
>
> s/nested-keyed/flat-keyed/
>
>
> With that
>
> Reviewed-by: Michal Koutný <mkoutny@suse.com>
Reviewed-by: Maarten Lankhorst <dev@lankhorst.se>
With your r-b it's ok to push it to the dmemcg tree?
Kind regards,
~Maarten Lankhorst
^ permalink raw reply
* [linux-next:master] BUILD REGRESSION f7af91adc230aa99e23330ecf85bc9badd9780ad
From: kernel test robot @ 2026-05-29 6:48 UTC (permalink / raw)
To: Andrew Morton
Cc: Linux Memory Management List, cgroups, netdev, rust-for-linux,
Mark Brown
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
branch HEAD: f7af91adc230aa99e23330ecf85bc9badd9780ad Add linux-next specific files for 20260528
Error/Warning (recently discovered and may have been fixed):
https://lore.kernel.org/oe-kbuild-all/202605290432.Pyzd4kuW-lkp@intel.com
https://lore.kernel.org/oe-kbuild-all/202605291041.seNEWvLQ-lkp@intel.com
https://lore.kernel.org/oe-kbuild-all/202605291334.abNeADbG-lkp@intel.com
drivers/net/arcnet/com20020-pci.c:225:52: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
mm/memcontrol-v1.c:651:31: error: implicit declaration of function 'swp_cluster_offset' [-Wimplicit-function-declaration]
samples/rust/rust_driver_auxiliary.o: warning: objtool: _RINvXs5_NtNtCshc5sK6KjdJJ_6kernel5alloc4kboxINtB6_3BoxINtNtNtCsbsbRiabPlh9_4core3mem12maybe_uninit11MaybeUninitINtNtBa_9auxiliary16RegistrationDataNtCseULRbgTYaTO_21rust_driver_auxiliary4DataEENtNtB8_9allocator7KmallocEINtCs57PXBekmiam_8pin_init12InPlaceWriteB1L_E14write_pin_initNtNtBa_5error5ErrorINtNtB3y_10___internal11InitClosureNCINvYIBH_B1L_B35_EINtNtBa_4init11InPlaceInitB1L_E8pin_initB4u_IB4O_NCINvMsc_B1O_INtB1O_12RegistrationB2l_E3newNtNtBX_7convert10InfallibleB2l_Es_0B1L_B4u_EE0B1L_B4u_EEB2n_: symbol name too long, can't create __pfx_ symbol
Unverified Error/Warning (likely false positive, kindly check if interested):
block/partitions/ldm.c:1487:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/base/bus.c:801:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/dpll/dpll_core.c:238:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/hwtracing/intel_th/msu.c:1277:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/infiniband/hw/mthca/mthca_memfree.c:220:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/media/common/siano/smscoreapi.c:744:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/misc/eeprom/at25.c:466:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/pinctrl/core.c:2168:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/regulator/core.c:6262:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/staging/greybus/uart.c:917:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
drivers/usb/core/../misc/onboard_usb_dev_pdevs.c:124:1: internal compiler error: in final_scan_insn_1, at final.c:3073
drivers/usb/dwc3/gadget.c:3474:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
fs/jfs/jfs_logmgr.c:1417:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
fs/notify/fanotify/fanotify_user.c:1746:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
fs/ntfs/super.c:2537:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
net/rxrpc/sendmsg.c:497:1: internal compiler error: in final_scan_insn_1, at final.cc:2813
Error/Warning ids grouped by kconfigs:
recent_errors
|-- alpha-randconfig-r072-20260529
| `-- drivers-net-arcnet-com20020-pci.c:warning:snprintf-output-may-be-truncated-before-the-last-format-character
|-- csky-randconfig-001-20260529
| |-- drivers-base-bus.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-misc-eeprom-at25.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-pinctrl-core.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-regulator-core.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-staging-greybus-uart.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-usb-dwc3-gadget.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- fs-jfs-jfs_logmgr.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| `-- fs-notify-fanotify-fanotify_user.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
|-- csky-randconfig-002
| `-- drivers-usb-core-..-misc-onboard_usb_dev_pdevs.c:internal-compiler-error:in-final_scan_insn_1-at-final.c
|-- csky-randconfig-r112-20260528
| |-- block-partitions-ldm.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-dpll-dpll_core.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-media-common-siano-smscoreapi.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| `-- fs-ntfs-super.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
|-- csky-randconfig-r122-20260528
| |-- drivers-hwtracing-intel_th-msu.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| |-- drivers-infiniband-hw-mthca-mthca_memfree.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
| `-- net-rxrpc-sendmsg.c:internal-compiler-error:in-final_scan_insn_1-at-final.cc
|-- sh-allyesconfig
| `-- mm-memcontrol-v1.c:error:implicit-declaration-of-function-swp_cluster_offset
`-- x86_64-randconfig-004-20260529
`-- samples-rust-rust_driver_auxiliary.o:warning:objtool:_RINvXs5_NtNtCshc5sK6KjdJJ_6kernel5alloc4kboxINtB6_3BoxINtNtNtCsbsbRiabPlh9_4core3mem12maybe_uninit11MaybeUninitINtNtBa_9auxiliary16RegistrationDat
elapsed time: 753m
configs tested: 178
configs skipped: 2
tested configs:
alpha allnoconfig gcc-15.2.0
alpha allyesconfig gcc-15.2.0
alpha defconfig gcc-15.2.0
arc allmodconfig gcc-15.2.0
arc allnoconfig gcc-15.2.0
arc allyesconfig gcc-15.2.0
arc defconfig gcc-15.2.0
arc randconfig-001-20260529 gcc-14.3.0
arc randconfig-002-20260529 gcc-10.5.0
arm allnoconfig clang-23
arm allyesconfig gcc-15.2.0
arm defconfig clang-23
arm defconfig gcc-15.2.0
arm randconfig-001-20260529 gcc-14.3.0
arm randconfig-002-20260529 gcc-8.5.0
arm randconfig-003-20260529 gcc-13.4.0
arm randconfig-004-20260529 clang-23
arm64 allmodconfig clang-19
arm64 allnoconfig gcc-15.2.0
arm64 defconfig gcc-15.2.0
arm64 randconfig-001-20260529 gcc-8.5.0
arm64 randconfig-002-20260529 clang-23
arm64 randconfig-003-20260529 clang-23
arm64 randconfig-004-20260529 gcc-15.2.0
csky allmodconfig gcc-15.2.0
csky allnoconfig gcc-15.2.0
csky defconfig gcc-15.2.0
csky randconfig-001-20260529 gcc-15.2.0
csky randconfig-002-20260529 gcc-15.2.0
hexagon allmodconfig clang-17
hexagon allnoconfig clang-23
hexagon defconfig clang-23
hexagon defconfig gcc-15.2.0
hexagon randconfig-001-20260529 clang-23
hexagon randconfig-002-20260529 clang-23
i386 allmodconfig gcc-14
i386 allnoconfig gcc-14
i386 allyesconfig gcc-14
i386 buildonly-randconfig-001-20260529 gcc-12
i386 buildonly-randconfig-002-20260529 clang-20
i386 buildonly-randconfig-003-20260529 gcc-12
i386 buildonly-randconfig-004-20260529 gcc-14
i386 buildonly-randconfig-005-20260529 gcc-14
i386 buildonly-randconfig-006-20260529 gcc-14
i386 defconfig clang-20
i386 defconfig gcc-15.2.0
i386 randconfig-001-20260529 gcc-14
i386 randconfig-002-20260529 gcc-12
i386 randconfig-003-20260529 clang-20
i386 randconfig-004-20260529 clang-20
i386 randconfig-005-20260529 gcc-14
i386 randconfig-006-20260529 clang-20
i386 randconfig-007-20260529 gcc-12
i386 randconfig-011-20260529 clang-20
i386 randconfig-012-20260529 clang-20
i386 randconfig-013-20260529 clang-20
i386 randconfig-014-20260529 clang-20
i386 randconfig-015-20260529 gcc-14
i386 randconfig-016-20260529 clang-20
i386 randconfig-017-20260529 gcc-13
loongarch allmodconfig clang-19
loongarch allnoconfig clang-23
loongarch defconfig clang-19
loongarch randconfig-001-20260529 gcc-15.2.0
loongarch randconfig-002-20260529 gcc-15.2.0
m68k allmodconfig gcc-15.2.0
m68k allnoconfig gcc-15.2.0
m68k allyesconfig gcc-15.2.0
m68k defconfig gcc-15.2.0
microblaze allnoconfig gcc-15.2.0
microblaze allyesconfig gcc-15.2.0
microblaze defconfig gcc-15.2.0
mips allmodconfig gcc-15.2.0
mips allnoconfig gcc-15.2.0
mips allyesconfig gcc-15.2.0
nios2 allmodconfig gcc-11.5.0
nios2 allnoconfig gcc-11.5.0
nios2 defconfig gcc-11.5.0
nios2 randconfig-001-20260529 gcc-8.5.0
nios2 randconfig-002-20260529 gcc-8.5.0
openrisc allmodconfig gcc-15.2.0
openrisc allnoconfig gcc-15.2.0
openrisc defconfig gcc-15.2.0
openrisc or1klitex_defconfig gcc-15.2.0
parisc allmodconfig gcc-15.2.0
parisc allnoconfig gcc-15.2.0
parisc allyesconfig gcc-15.2.0
parisc defconfig gcc-15.2.0
parisc randconfig-001-20260529 gcc-8.5.0
parisc randconfig-002-20260529 gcc-8.5.0
parisc64 defconfig gcc-15.2.0
powerpc allmodconfig gcc-15.2.0
powerpc allnoconfig gcc-15.2.0
powerpc randconfig-001-20260529 gcc-12.5.0
powerpc randconfig-002-20260529 clang-19
powerpc64 randconfig-001-20260529 gcc-15.2.0
powerpc64 randconfig-002-20260529 clang-19
riscv allmodconfig clang-23
riscv allnoconfig gcc-15.2.0
riscv allyesconfig clang-16
riscv defconfig clang-23
riscv defconfig gcc-15.2.0
riscv randconfig-001-20260529 gcc-8.5.0
riscv randconfig-002-20260529 gcc-9.5.0
s390 allmodconfig clang-18
s390 allnoconfig clang-23
s390 allyesconfig gcc-15.2.0
s390 defconfig clang-23
s390 defconfig gcc-15.2.0
s390 randconfig-001-20260529 gcc-8.5.0
s390 randconfig-002-20260529 clang-23
sh allmodconfig gcc-15.2.0
sh allnoconfig gcc-15.2.0
sh allyesconfig gcc-15.2.0
sh defconfig gcc-15.2.0
sh randconfig-001-20260529 gcc-15.2.0
sh randconfig-002-20260529 gcc-15.2.0
sparc allnoconfig gcc-15.2.0
sparc defconfig gcc-15.2.0
sparc randconfig-001-20260529 gcc-8.5.0
sparc randconfig-002-20260529 gcc-15.2.0
sparc64 allmodconfig clang-23
sparc64 defconfig clang-20
sparc64 randconfig-001-20260529 gcc-11.5.0
sparc64 randconfig-002-20260529 gcc-8.5.0
um allmodconfig clang-19
um allnoconfig clang-23
um allyesconfig gcc-14
um defconfig clang-23
um i386_defconfig gcc-14
um randconfig-001-20260529 gcc-14
um randconfig-002-20260529 gcc-14
um x86_64_defconfig clang-23
x86_64 allmodconfig clang-20
x86_64 allnoconfig clang-20
x86_64 allyesconfig clang-20
x86_64 buildonly-randconfig-001-20260529 gcc-14
x86_64 buildonly-randconfig-002-20260529 gcc-14
x86_64 buildonly-randconfig-003-20260529 gcc-14
x86_64 buildonly-randconfig-004-20260529 clang-20
x86_64 buildonly-randconfig-004-20260529 gcc-14
x86_64 buildonly-randconfig-005-20260529 clang-20
x86_64 buildonly-randconfig-005-20260529 gcc-14
x86_64 buildonly-randconfig-006-20260529 gcc-14
x86_64 defconfig gcc-14
x86_64 kexec clang-20
x86_64 randconfig-001-20260529 gcc-14
x86_64 randconfig-002-20260529 clang-20
x86_64 randconfig-003-20260529 gcc-14
x86_64 randconfig-004-20260529 clang-20
x86_64 randconfig-005-20260529 clang-20
x86_64 randconfig-006-20260529 clang-20
x86_64 randconfig-011-20260529 gcc-14
x86_64 randconfig-012-20260529 gcc-14
x86_64 randconfig-013-20260529 clang-20
x86_64 randconfig-014-20260529 clang-20
x86_64 randconfig-015-20260529 gcc-14
x86_64 randconfig-016-20260529 clang-20
x86_64 randconfig-071-20260529 gcc-14
x86_64 randconfig-072-20260529 clang-20
x86_64 randconfig-073-20260529 clang-20
x86_64 randconfig-074-20260529 gcc-14
x86_64 randconfig-075-20260529 gcc-14
x86_64 randconfig-076-20260529 gcc-14
x86_64 rhel-9.4 clang-20
x86_64 rhel-9.4 gcc-14
x86_64 rhel-9.4-bpf gcc-14
x86_64 rhel-9.4-func clang-20
x86_64 rhel-9.4-func gcc-14
x86_64 rhel-9.4-kselftests clang-20
x86_64 rhel-9.4-kselftests gcc-14
x86_64 rhel-9.4-kunit gcc-14
x86_64 rhel-9.4-ltp gcc-14
x86_64 rhel-9.4-rust clang-20
xtensa allnoconfig gcc-15.2.0
xtensa allyesconfig gcc-15.2.0
xtensa randconfig-001-20260529 gcc-11.5.0
xtensa randconfig-002-20260529 gcc-8.5.0
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH-next v3 5/5] cgroup/cpuset: Support multiple source/destination cpusets for cpuset_*attach()
From: Guopeng Zhang @ 2026-05-29 2:26 UTC (permalink / raw)
To: Waiman Long, Chen Ridong, Tejun Heo, Johannes Weiner,
Michal Koutný, Ingo Molnar, Peter Zijlstra
Cc: cgroups, linux-kernel, Aaron Tomlin
In-Reply-To: <20260527153800.1557449-6-longman@redhat.com>
在 2026/5/27 23:38, Waiman Long 写道:
> With cgroup v2, the cgroup_taskset structure passed into the cgroup
> can_attach() and attach() methods can contain task migration data with
> multiple destination or source cpusets when the cpuset controller is
> enabled or disabled respectively.
...
> -/* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
> +/*
> + * Called by cgroups to determine if a cpuset is usable; cpuset_mutex held.
> + *
> + * With cgroup v2, enabling of cpuset controller in a cgroup subtree can
> + * cause @tset to contain task migration data from one parent cpuset to multiple
> + * child cpusets. Not much is needed to be done here other than tracking the
> + * number of DL tasks in each cpuset as the CPUs and memory nodes of the child
> + * cpusets are exactly the same as the parent.
> + *
> + * Conversely, disabling of cpuset controller can cause @tset to contain task
> + * migration data from multiple child cpusets to one parent cpuset. Here, the
> + * CPUs and memory nodes of the child cpusets may be different from the parent,
> + * but must be a subset of its parent.
> + *
> + * Another possible many-to-one migration is the moving of the whole
> + * multithreaded process with threads in different cpusets to another cpuset.
> + *
> + * For all other use cases, @tset task migration data should be from one source
> + * cpuset to one destination cpuset.
> + */
> static int cpuset_can_attach(struct cgroup_taskset *tset)
> {
> struct cgroup_subsys_state *css;
> @@ -3079,6 +3172,16 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
> goto out_unlock;
>
> cgroup_taskset_for_each(task, css, tset) {
> + struct cpuset *newcs = css_cs(css);
> + struct cpuset *new_oldcs = task_cs(task);
> +
> + if ((newcs != cs) || (new_oldcs != oldcs)) {
> + cs = newcs;
> + oldcs = new_oldcs;
> + ret = cpuset_can_attach_check(cs, oldcs, &setsched_check);
> + if (ret)
> + goto out_unlock;
> + }
Just a minor nit while running checkpatch --strict on this patch:
checkpatch reports unnecessary parentheses here:
if ((newcs != cs) || (new_oldcs != oldcs)) {
Perhaps this can be simplified to:
if (newcs != cs || new_oldcs != oldcs) {
> ret = task_can_attach(task);
> if (ret)
...
> /*
> * In the default hierarchy, enabling cpuset in the child cgroups
> - * will trigger a number of cpuset_attach() calls with no change
> - * in effective cpus and mems. In that case, we can optimize out
> - * by skipping the task iteration and update.
> + * will trigger a cpuset_attach() call with no change in effective cpus
> + * and mems. In that case, we can optimize out by skipping the task
> + * iteration and update, but the destination cpuset list is iterated to
> + * set old_mems_sllowed.
> */
I also noticed one small typo in the added comment:
s/old_mems_sllowed/old_mems_allowed/
Best,
Guopeng
^ permalink raw reply
* Re: [PATCH-next v3 4/5] cgroup/cpuset: Move mpol_rebind_mm/cpuset_migrate_mm() calls inside cpuset_attach_task()
From: Guopeng Zhang @ 2026-05-29 2:21 UTC (permalink / raw)
To: Waiman Long, Chen Ridong, Tejun Heo, Johannes Weiner,
Michal Koutný, Ingo Molnar, Peter Zijlstra
Cc: cgroups, linux-kernel, Aaron Tomlin
In-Reply-To: <20260527153800.1557449-5-longman@redhat.com>
在 2026/5/27 23:37, Waiman Long 写道:
> The cpuset_attach_task() was introduced in commit 42a11bf5c543
> ("cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly")
> to enable the CLONE_INTO_CGROUP flag of clone(2) to behave more like
> moving a task from one cpuset into another one. That commits didn't
> move the mpol_rebind_mm() and cpuset_migrate_mm() calls for group leader
> into cpuset_attach_task().
>
> When the CLONE_INTO_CGROUP flag is used without CLONE_THREAD, the new
> task is its own group leader. So it is still not equivalent to moving
> task between cpusets in this case. Make CLONE_INTO_CGROUP behaves
> more close to cpuset_attach() by moving the mpol_rebind_mm() and
> cpuset_migrate_mm() calls inside cpuset_attach_task(). As a result,
> cpuset_attach_old_cs, attach_cpus_updated and attach_mems_updated will
> also need to be updated in cpuset_fork().
>
> Besides, the original code use cpuset_attach_nodemask_to for
> both nodemask returned by guarantee_online_mems() used only by
> cpuset_change_task_nodemask() and cs->effective_mems in all other cases.
> Such dual use is now impractical by merging the two task iteration loops
> into one. So keep cpuset_attach_nodemask_to for the nodemask returned
> by guarantee_online_mems() and reference cs->effective_mems directly
> in all the other cases.
>
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> kernel/cgroup/cpuset.c | 90 ++++++++++++++++++++++--------------------
> 1 file changed, 47 insertions(+), 43 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index b233a71f9b7c..7100575927f6 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3149,9 +3149,12 @@ static void cpuset_cancel_attach(struct cgroup_taskset *tset)
> */
> static cpumask_var_t cpus_attach;
> static nodemask_t cpuset_attach_nodemask_to;
> +static bool queue_task_work;
...
> @@ -3686,7 +3685,12 @@ static void cpuset_fork(struct task_struct *task)
> /* CLONE_INTO_CGROUP */
> mutex_lock(&cpuset_mutex);
> guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
> + /* Assume CPUs and memory nodes are updated */
> + attach_cpus_updated = attach_mems_updated = true;
> + cpuset_attach_old_cs = oldcs;
> + oldcs->old_mems_allowed = oldcs->effective_mems;
> cpuset_attach_task(cs, task);
> + attach_cpus_updated = attach_mems_updated = false;
>
> dec_attach_in_progress_locked(cs);
> mutex_unlock(&cpuset_mutex);
Just a minor nit while running checkpatch --strict on this patch:
checkpatch reports:
CHECK: multiple assignments should be avoided
Perhaps the multiple assignments can be split to keep the patch
checkpatch-clean?
attach_cpus_updated = true;
attach_mems_updated = true;
and later:
attach_cpus_updated = false;
attach_mems_updated = false;
Just a style nit.
Best,
Guopeng
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox