mm/swap, memcg: Introduce swap tiers for cgroup based swap control
Subsystems (6)
Youngjun Park
reviewerv3 cover mm/swap, memcg: Introduce swap tiers for cgroup based swap control
This is the third version of the RFC for the "Swap Tiers" concept, incorporating LPC 2025 feedback and subsequent bug fixes.
Previous approach: https://lore.kernel.org/linux-mm/[email protected]/
RFC v2: https://lore.kernel.org/linux-mm/[email protected]/
RFC v1: https://lore.kernel.org/linux-mm/[email protected]/
v3 addresses bug fixes found during testing and adds clarifications to improve patch reviewability.
Overview (Recap)
================
Swap Tiers enable cgroup-based swap device assignment by grouping swap devices into named tiers. This allows faster devices (e.g., SSD) to be dedicated to latency-sensitive workloads while slower devices (e.g., HDD, network) serve background tasks. The concept was suggested by Chris Li.
Key Changes after LPC 2025(RFC v1)
==================================
The most significant change in v2 was adopting strict cgroup hierarchy semantics based on LPC 2025 feedback.
v1 allowed children to explicitly select tiers ("+tier") regardless of parent configuration, violating standard cgroup principles.
v2 enforces proper hierarchy: child configurations are always subsets of parent. Default is all tiers enabled; use "-tier" to exclude.
Example:
Global: SSD, HDD, NET
Parent: -HDD → uses SSD, NET
Child: -SSD → uses NET (intersection)
If SSD deleted: Child uses NET (exclusions reset) If NEW added: All cgroups use it by default
This ensures children cannot access resources denied by ancestors, matching standard cgroup behavior.
For detailed rationale, see v2 RFC and LPC presentation.
Changes in RFC v3
=================
- Fixed swap_alloc_fast() tier eligibility check
- Fixed tier_mask restoration on error paths
- Fixed priority -1 tier deletion bug
- Fixed !CONFIG_MEMCG build failures
- Improved commit messages
- Fix improper error handling
- Fixed coding style violations
- Fixed tier deletion propagation to cgroups
Changes in RFC v2
=================
- Strict cgroup hierarchy compliance (LPC 2025 feedback)
- Percpu swap device cache to preserve fastpath performance (Kairui Song, Baoquan He)
- Simplified tier structure (Chris Li)
- Removed explicit "+" selection; default is all tiers, use "-" to exclude (Chris Li)
- Removed CONFIG_SWAP_TIER; now base kernel feature (Chris Li)
- Effective tier calculation moved to configuration time (swap.tiers write)
- Mixed operation support for "+" and "-" in /sys/kernel/mm/swap/tiers (Chris Li)
- Commit reorganization for clarity (Chris Li)
- Added tier priority modification support
- Added documentation for swap tiers concept and usage (Chris Li)
Real-world Results
==================
App preloading on our internal platform using NBD as separate tier. (Our first real-world use case. We plan to refine and expand this usage.)
Without separate swap tier,
- Cannot selectively avoid default flash swap, unable to reduce flash wear and lifespan issues.
- Can't selectively assign NBD to specific apps that need it.
Result (cold launch vs. preloaded):
- Streaming App A: 13.17s → 4.18s (68% faster)
- Streaming App B: 5.60s → 1.12s (80% faster)
- E-commerce App C: 10.25s → 2.00s (80% faster)
Performance validation against baseline (no tiers configured) shows negligible overhead (<1%) in kernel build and vm-scalability benchmarks. Detailed results in v2 cover letter.
Any feedback welcome.
Youngjun Park
Youngjun Park (5):
mm: swap: introduce swap tier infrastructure
mm: swap: associate swap devices with tiers
mm: memcontrol: add interface for swap tier selection mm, swap: change back to use each swap device's percpu cluster mm, swap: introduce percpu swap device cache to avoid fragmentation
Documentation/admin-guide/cgroup-v2.rst | 27 ++ Documentation/mm/swap-tier.rst | 109 ++++++ MAINTAINERS | 2 + include/linux/memcontrol.h | 3 +- include/linux/swap.h | 17 +- mm/Makefile | 2 +- mm/memcontrol.c | 85 +++++ mm/swap.h | 4 + mm/swap_state.c | 72 ++++ mm/swap_tier.c | 469 ++++++++++++++++++++++++ mm/swap_tier.h | 84 +++++ mm/swapfile.c | 133 +++---- 12 files changed, 938 insertions(+), 69 deletions(-) create mode 100644 Documentation/mm/swap-tier.rst create mode 100644 mm/swap_tier.c create mode 100644 mm/swap_tier.h
base-commit: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2
Signature · 1 line
2.34.1
Youngjun Park
reviewerRFC PATCH v3 1/5 mm: swap: introduce swap tier infrastructure
This patch introduces the "Swap tier" concept, which serves as an abstraction layer for managing swap devices based on their performance characteristics (e.g., NVMe, HDD, Network swap).
Swap tiers are user-named groups representing priority ranges. These tiers collectively cover the entire priority space from -1 (DEF_SWAP_PRIO) to SHRT_MAX.
To configure tiers, a new sysfs interface is exposed at /sys/kernel/mm/swap/tiers. The input parser evaluates commands from left to right and supports batch input, allowing users to add, remove or modify multiple tiers in a single write operation.
Tier management enforces continuous priority ranges anchored by start priorities. Operations trigger range splitting or merging, but overwriting start priorities is forbidden. Merging expands lower tiers upwards to preserve configured start priorities, except when removing DEF_SWAP_PRIO, which merges downwards.
--- MAINTAINERS | 2 + mm/Makefile | 2 +- mm/swap.h | 4 + mm/swap_state.c | 70 +++++++++++ mm/swap_tier.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++++ mm/swap_tier.h | 38 ++++++ mm/swapfile.c | 7 +- 7 files changed, 423 insertions(+), 4 deletions(-) create mode 100644 mm/swap_tier.c create mode 100644 mm/swap_tier.h
MAINTAINERS +2 -0
@@ -16743,6 +16743,8 @@ F: mm/swap.c F: mm/swap.h F: mm/swap_table.h F: mm/swap_state.c +F: mm/swap_tier.c +F: mm/swap_tier.h F: mm/swapfile.c MEMORY MANAGEMENT - THP (TRANSPARENT HUGE PAGE)
mm/Makefile +1 -1
@@ -75,7 +75,7 @@ ifdef CONFIG_MMU obj-$(CONFIG_ADVISE_SYSCALLS) += madvise.o endif -obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o +obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o swap_tier.o obj-$(CONFIG_ZSWAP) += zswap.o obj-$(CONFIG_HAS_DMA) += dmapool.o obj-$(CONFIG_HUGETLBFS) += hugetlb.o hugetlb_sysfs.o hugetlb_sysctl.o
mm/swap.h +4 -0
@@ -16,6 +16,10 @@ extern int page_cluster;#define swap_entry_order (order) 0#endif +#define DEF_SWAP_PRIO -1 + +extern spinlock_t swap_lock; +extern struct plist_head swap_active_head;extern struct swap_info_struct *swap_info[];/*
mm/swap_state.c +70 -0
84 lines not on this page · raw message
mm/swap_tier.c new file +304 -0
304 lines not on this page · raw message
mm/swap_tier.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SWAP_TIER_H +#define _SWAP_TIER_H + +#include <linux/types.h> +#include <linux/spinlock.h> + +#define MAX_TIERNAME 16 + +/* Ensure MAX_SWAPTIER does not exceed MAX_SWAPFILES */ +#if 8 >MAX_SWAPFILES +#define MAX_SWAPTIER MAX_SWAPFILES +#else +#define MAX_SWAPTIER 8 +#endif + +extern spinlock_t swap_tier_lock; + +struct swap_tier_save_ctx { +char name[MAX_TIERNAME ]; +short prio; +}; + +#define DEFINE_SWAP_TIER_SAVE_CTX (_name) \ + struct swap_tier_save_ctx _name[MAX_SWAPTIER] = {0} + +/* Initialization and application */ +void swap_tiers_init (void ); +ssize_t swap_tiers_sysfs_show (char *buf); + +int swap_tiers_add (const char *name,int prio); +int swap_tiers_remove (const char *name); +int swap_tiers_modify (const char *name,int prio); + +void swap_tiers_save (struct swap_tier_save_ctx ctx[]); +void swap_tiers_restore (struct swap_tier_save_ctx ctx[]); +bool swap_tiers_validate (void ); +#endif /* _SWAP_TIER_H */
mm/swapfile.c +4 -3
@@ -50,6 +50,7 @@#include "internal.h" #include "swap_table.h" #include "swap.h" +#include "swap_tier.h" static bool swap_count_continued (struct swap_info_struct *,pgoff_t ,unsigned char );
@@ -65,7 +66,7 @@ static void move_cluster(struct swap_info_struct *si, struct swap_cluster_info *ci, struct list_head *list, enum swap_cluster_flags new_flags); -static DEFINE_SPINLOCK (swap_lock); +DEFINE_SPINLOCK (swap_lock);static unsigned int nr_swapfiles;atomic_long_t nr_swap_pages;/*
@@ -76,7 +77,6 @@ atomic_long_t nr_swap_pages;EXPORT_SYMBOL_GPL (nr_swap_pages);/* protected with swap_lock. reading in vm_swap_full() doesn't need lock */ long total_swap_pages; -#define DEF_SWAP_PRIO -1unsigned long swapfile_maximum_size;#ifdef CONFIG_MIGRATION bool swap_migration_ad_supported;
@@ -89,7 +89,7 @@ static const char Bad_offset[] = "Bad swap offset entry ";* all active swap_info_structs * protected with swap_lock, and ordered by priority. */ -static PLIST_HEAD (swap_active_head); +PLIST_HEAD (swap_active_head);/* * all available (active, not full) swap_info_structs
@@ -3977,6 +3977,7 @@ static int __init swapfile_init(void) swap_migration_ad_supported = true;#endif /* CONFIG_MIGRATION */ +swap_tiers_init ();return 0 ; }subsys_initcall (swapfile_init);
Signature · 1 line
2.34.1
kernel test robot
build botRe: [RFC PATCH v3 1/5] mm: swap: introduce swap tier infrastructure
kernel test robot noticed the following build warnings:
Hi Youngjun,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2]
url: https://github.com/intel-lab-lkp/linux/commits/Youngjun-Park/mm-swap-introduce-swap-tier-infrastructure/20260201-005914 base: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2 patch link: https://lore.kernel.org/r/20260131125454.3187546-2-youngjun.park%40lge.com patch subject: [RFC PATCH v3 1/5] mm: swap: introduce swap tier infrastructure config: i386-buildonly-randconfig-003-20260202 (https://download.01.org/0day-ci/archive/20260202/[email protected]/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/20260202/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> mm/swap_tier.c:95:10: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
93 | len += sysfs_emit_at(buf, len, "%-16s %-5ld %-11d %-11d\n",
| ~~~~~
| %-5d
94 | tier->name,
95 | TIER_IDX(tier),
| ^~~~~~~~~~~~~~
mm/swap_tier.c:30:24: note: expanded from macro 'TIER_IDX'
30 | #define TIER_IDX(tier) ((tier) - swap_tiers)
| ^~~~~~~~~~~~~~~~~~~~~1 warning generated.
vim +95 mm/swap_tier.c
82
83 ssize_t swap_tiers_sysfs_show(char *buf)
84 {
85 struct swap_tier *tier;
86 ssize_t len = 0;
87
88 len += sysfs_emit_at(buf, len, "%-16s %-5s %-11s %-11s\n",
89 "Name", "Idx", "PrioStart", "PrioEnd");
90
91 spin_lock(&swap_tier_lock);
92 for_each_active_tier(tier) {
93 len += sysfs_emit_at(buf, len, "%-16s %-5ld %-11d %-11d\n",
94 tier->name,
> 95 TIER_IDX(tier),
96 tier->prio,
97 TIER_END_PRIO(tier));
98 if (len >= PAGE_SIZE)
99 break; 100 }
101 spin_unlock(&swap_tier_lock);
102
103 return len;
104 }
105
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Youngjun Park
reviewerRFC PATCH v3 2/5 mm: swap: associate swap devices with tiers
In reply to Youngjun ParkThis patch connects swap devices to the swap tier infrastructure, ensuring that devices are correctly assigned to tiers based on their priority.
A tier_mask is added to identify the tier membership of swap devices. Although tier-based allocation logic is not yet implemented, this mapping is necessary to track which tier a device belongs to. Upon activation, the device is assigned to a tier by matching its priority against the configured tier ranges.
The infrastructure allows dynamic modification of tiers, such as splitting or merging ranges. These operations are permitted provided that the tier assignment of already configured swap devices remains unchanged.
This patch also adds the documentation for the swap tier feature, covering the core concepts, sysfs interface usage, and configuration details.
--- Documentation/mm/swap-tier.rst | 109 +++++++++++++++++++++++++++++++++ include/linux/swap.h | 1 + mm/swap_state.c | 2 +- mm/swap_tier.c | 100 +++++++++++++++++++++++++++--- mm/swap_tier.h | 13 +++- mm/swapfile.c | 2 + 6 files changed, 215 insertions(+), 12 deletions(-) create mode 100644 Documentation/mm/swap-tier.rst
Documentation/mm/swap-tier.rst new file +109 -0
@@ -0,0 +1,109 @@ +.. SPDX-License-Identifier: GPL-2.0 + +:Author: Chris Li <[email protected]> Youngjun Park <[email protected]> + +========== +Swap Tier +========== + +Swap tier is a collection of user-named groups classified by priority ranges. +It acts as a facilitation layer, allowing users to manage swap devices based +on their speeds. + +Users are encouraged to assign swap device priorities according to device +speed to fully utilize this feature. While the current implementation is +integrated with cgroups, the concept is designed to be extensible for other +subsystems in the future. + +Use case +------- + +Users can perform selective swapping by choosing a swap tier assigned according +to speed within a cgroup. + +For more information on cgroup v2, please refer to +``Documentation/admin-guide/cgroup-v2.rst``. + +Priority Range +-------------- + +The specified tiers must cover the entire priority range from -1 +(DEF_SWAP_PRIO) to SHRT_MAX. + +Consistency +----------- + +Tier consistency is guaranteed with a focus on maximizing flexibility. When a +swap device is activated within a tier range, a reference is held from the +start of the tier to the priority of that swap device. This ensures that the +tier of region containing the active swap device does not disappear. + +If a request to add a new tier with a priority higher than the current swap +device is received, the existing tier can be split. + +However, specifying a tier in a cgroup does not hold a reference to the tier. +Consequently, the corresponding tier can disappear at any time. + +Configuration Interface +----------------------- + +The swap tiers can be configured via the following interface: + +/sys/kernel/mm/swap/tiers + +Operations can be performed using the following syntax: + +* Add: ``+"<tiername>":"<start_priority>"`` +* Remove: ``-"<tiername>"`` +* Modify: ``"<tiername>":"<start_priority>"`` + +Multiple operations can be provided in a single write, separated by spaces (" ") +or commas (","). + +When configuring tiers, the specified value represents the **start priority** +of that tier. The end priority is automatically determined by the start +priority of the next higher tier. Consequently, adding or modifying a tier +automatically adjusts (splits or merges) the ranges of adjacent tiers to +ensure continuity. + +Examples +-------- + +**1. Initialization** + +A tier starting at -1 is mandatory to cover the entire priority range up to +SHRT_MAX. In this example, 'HDD' starts at 50, and 'NET' covers the remaining +lower range starting from -1. + +:: + + # echo "+HDD:50, +NET:-1" > /sys/kernel/mm/swap/tiers + # cat /sys/kernel/mm/swap/tiers + Name Idx PrioStart PrioEnd + HDD 0 50 32767 + NET 1 -1 49 + +**2. Modification and Splitting** + +Here, 'HDD' is moved to start at 80, and a new tier 'SSD' is added at 100. +Notice how the ranges are automatically recalculated: +* 'SSD' takes the top range. Split HDD Tier's range. (100 to SHRT_MAX). +* 'HDD' is adjusted to the range between 'NET' and 'SSD' (80 to 99). +* 'NET' automatically extends to fill the gap below 'HDD' (-1 to 79). + +:: + + # echo "HDD:80, +SSD:100" > /sys/kernel/mm/swap/tiers + # cat /sys/kernel/mm/swap/tiers + Name Idx PrioStart PrioEnd + SSD 2 100 32767 + HDD 0 80 99 + NET 1 -1 79 + +**3. Removal** + +Tiers can be removed using the '-' prefix. + +:: + + # echo "-SSD,-HDD,-NET" > /sys/kernel/mm/swap/tiers
include/linux/swap.h +1 -0
@@ -262,6 +262,7 @@ struct swap_info_struct {struct percpu_ref users;/* indicate and keep swap device valid. */ unsigned long flags;/* SWP_USED etc: see above */ signed short prio;/* swap priority of this type */ +int tier_mask;/* swap tier mask */ struct plist_node list;/* entry in swap_active_head */ signed char type;/* strange name for an index */ unsigned int max;/* extent of the swap_map */
mm/swap_state.c +1 -1
@@ -997,7 +997,7 @@ static ssize_t tiers_store(struct kobject *kobj, goto restore; } -if (!swap_tiers_validate ()) { +if (!swap_tiers_update ()) { ret = -EINVAL ; goto restore; }
mm/swap_tier.c +90 -10
179 lines not on this page · raw message
mm/swap_tier.h +12 -1
@@ -14,6 +14,9 @@#define MAX_SWAPTIER 8#endif +/* Forward declarations */ +struct swap_info_struct ; +extern spinlock_t swap_tier_lock;struct swap_tier_save_ctx {
@@ -24,6 +27,10 @@ struct swap_tier_save_ctx {#define DEFINE_SWAP_TIER_SAVE_CTX (_name) \ struct swap_tier_save_ctx _name[MAX_SWAPTIER] = {0} +#define TIER_ALL_MASK (~0) +#define TIER_DEFAULT_IDX (31) +#define TIER_DEFAULT_MASK (1 << TIER_DEFAULT_IDX) +/* Initialization and application */ void swap_tiers_init (void );ssize_t swap_tiers_sysfs_show (char *buf);
@@ -34,5 +41,9 @@ int swap_tiers_modify(const char *name, int prio);void swap_tiers_save (struct swap_tier_save_ctx ctx[]);void swap_tiers_restore (struct swap_tier_save_ctx ctx[]); -bool swap_tiers_validate (void ); +bool swap_tiers_update (void ); + +/* Tier assignment */ +void swap_tiers_assign_dev (struct swap_info_struct *swp); +#endif /* _SWAP_TIER_H */
mm/swapfile.c +2 -0
@@ -2672,6 +2672,8 @@ static void _enable_swap_info(struct swap_info_struct *si)/* Add back to available list */ add_to_avail_list (si, true); + +swap_tiers_assign_dev (si); } static void enable_swap_info(struct swap_info_struct *si, int prio,
Signature · 1 line
2.34.1
kernel test robot
build botRe: [RFC PATCH v3 2/5] mm: swap: associate swap devices with tiers
kernel test robot noticed the following build warnings:
Hi Youngjun,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2]
url: https://github.com/intel-lab-lkp/linux/commits/Youngjun-Park/mm-swap-introduce-swap-tier-infrastructure/20260201-005914 base: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2 patch link: https://lore.kernel.org/r/20260131125454.3187546-3-youngjun.park%40lge.com patch subject: [RFC PATCH v3 2/5] mm: swap: associate swap devices with tiers reproduce: (https://download.01.org/0day-ci/archive/20260201/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
WARNING: No kernel-doc for file ./include/linux/kho/abi/memfd.h
ERROR: Cannot find file ./include/linux/migrate.h
WARNING: No kernel-doc for file ./include/linux/migrate.h
ERROR: Cannot find file ./include/linux/mmap_lock.h
WARNING: No kernel-doc for file ./include/linux/mmap_lock.h
>> Documentation/mm/swap-tier.rst:19: WARNING: Title underline too short.
--
ERROR: Cannot find file ./include/linux/mutex.h
ERROR: Cannot find file ./include/linux/mutex.h
WARNING: No kernel-doc for file ./include/linux/mutex.h
ERROR: Cannot find file ./include/linux/fwctl.h
WARNING: No kernel-doc for file ./include/linux/fwctl.h
>> Documentation/mm/swap-tier.rst: WARNING: document isn't included in any toctree [toc.not_included]
vim +19 Documentation/mm/swap-tier.rst
17
18 Use case
> 19 -------
20 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Youngjun Park
reviewerRFC PATCH v3 3/5 mm: memcontrol: add interface for swap tier selection
In reply to Youngjun ParkThis patch integrates the swap tier infrastructure with cgroup, enabling the selection of specific swap devices per cgroup by configuring allowed swap tiers.
The new memory.swap.tiers interface controls allowed swap tiers via a mask. By default, the mask is set to include all tiers, allowing specific tiers to be excluded or restored. Note that effective tiers are calculated separately using a dedicated mask to respect the cgroup hierarchy. Consequently, configured tiers may differ from effective ones, as they must be a subset of the parent's.
Note that cgroups do not pin swap tiers. This is similar to the cpuset controller, which does not prevent CPU hotplug. This approach ensures flexibility by allowing tier configuration changes regardless of cgroup usage.
--- Documentation/admin-guide/cgroup-v2.rst | 27 ++++++++ include/linux/memcontrol.h | 3 +- mm/memcontrol.c | 85 +++++++++++++++++++++++ mm/swap_state.c | 6 +- mm/swap_tier.c | 89 ++++++++++++++++++++++++- mm/swap_tier.h | 39 ++++++++++- mm/swapfile.c | 4 ++ 7 files changed, 246 insertions(+), 7 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +27 -0
@@ -1848,6 +1848,33 @@ The following nested keys are defined. Swap usage hard limit. If a cgroup's swap usage reaches this limit, anonymous memory of the cgroup will not be swapped out. + memory.swap.tiers + A read-write nested-keyed file which exists on non-root + cgroups. The default is to enable all tiers. + + This interface allows selecting which swap tiers a cgroup can + use for swapping out memory. + + The effective tiers are inherited from the parent. Only tiers + effective in the parent can be effective in the child. However, + the child can explicitly disable tiers allowed by the parent. + + When read, the file shows two lines: + - The first line shows the operation string that was + written to this file. + - The second line shows the effective operation after + merging with parent settings. + + When writing, the format is: + (+/-)(TIER_NAME) (+/-)(TIER_NAME) ... + + Valid tier names are those configured in + /sys/kernel/mm/swap/tiers. + + Each tier can be prefixed with: + + Enable this tier + - Disable this tier + memory.swap.events A read-only flat-keyed file which exists on non-root cgroups. The following entries are defined. Unless specified
include/linux/memcontrol.h +2 -1
@@ -283,7 +283,8 @@ struct mem_cgroup {/* per-memcg mm_struct list */ struct lru_gen_mm_list mm_list;#endif - +int tier_mask; +int tier_effective_mask;#ifdef CONFIG_MEMCG_V1 /* Legacy consumer-oriented counters */ struct page_counter kmem;/* v1 only */
mm/memcontrol.c +85 -0
115 lines not on this page · raw message
mm/swap_state.c +4 -2
@@ -961,6 +961,8 @@ static ssize_t tiers_store(struct kobject *kobj,char *p, *token, *name, *tmp;int ret =0 ;short prio; +int mask =0 ; +DEFINE_SWAP_TIER_SAVE_CTX (ctx); tmp =kstrdup (buf,GFP_KERNEL );
@@ -978,7 +980,7 @@ static ssize_t tiers_store(struct kobject *kobj,continue ;if (token[0 ] =='-' ) { - ret =swap_tiers_remove (token +1 ); + ret =swap_tiers_remove (token +1 , &mask); }else { name =strsep (&token,":" );
@@ -997,7 +999,7 @@ static ssize_t tiers_store(struct kobject *kobj, goto restore; } -if (!swap_tiers_update ()) { +if (!swap_tiers_update (mask)) { ret = -EINVAL ; goto restore; }
mm/swap_tier.c +87 -2
113 lines not on this page · raw message
mm/swap_tier.h +37 -2
@@ -31,19 +31,54 @@ struct swap_tier_save_ctx {#define TIER_DEFAULT_IDX (31)#define TIER_DEFAULT_MASK (1 << TIER_DEFAULT_IDX) +#ifdef CONFIG_MEMCG +static inline int folio_tier_effective_mask (struct folio *folio) +{ +struct mem_cgroup *memcg =folio_memcg (folio); + +return memcg ? memcg->tier_effective_mask :TIER_ALL_MASK ; +} +#else +static inline int folio_tier_effective_mask (struct folio *folio) +{ +return TIER_ALL_MASK ; +} +#endif +/* Initialization and application */ void swap_tiers_init (void );ssize_t swap_tiers_sysfs_show (char *buf);int swap_tiers_add (const char *name,int prio); -int swap_tiers_remove (const char *name); +int swap_tiers_remove (const char *name,int *mask);int swap_tiers_modify (const char *name,int prio);void swap_tiers_save (struct swap_tier_save_ctx ctx[]);void swap_tiers_restore (struct swap_tier_save_ctx ctx[]); -bool swap_tiers_update (void ); +bool swap_tiers_update (int mask);/* Tier assignment */ void swap_tiers_assign_dev (struct swap_info_struct *swp); +/* Memcg related functions */ +void swap_tiers_mask_show (struct seq_file *m,int mask); +void swap_tiers_memcg_inherit_mask (struct mem_cgroup *memcg, +struct mem_cgroup *parent); +void swap_tiers_memcg_sync_mask (struct mem_cgroup *memcg); +void __swap_tiers_memcg_sync_mask (struct mem_cgroup *memcg); + +/* Mask and tier lookup */ +int swap_tiers_mask_lookup (const char *name); + +/** +* swap_tiers_mask_test - Check if the tier mask is valid +* @tier_mask: The tier mask to check +* @mask: The mask to compare against +* +* Return: true if condition matches, false otherwise +*/ +static inline bool swap_tiers_mask_test (int tier_mask,int mask) +{ +return tier_mask & mask; +}#endif /* _SWAP_TIER_H */
mm/swapfile.c +4 -0
@@ -1348,10 +1348,14 @@ static bool swap_alloc_fast(struct folio *folio)static void swap_alloc_slow (struct folio *folio) {struct swap_info_struct *si, *next; +int mask =folio_tier_effective_mask (folio);spin_lock (&swap_avail_lock); start_over:plist_for_each_entry_safe (si, next, &swap_avail_head, avail_list) { +if (!swap_tiers_mask_test (si->tier_mask, mask)) +continue ; +/* Rotate the device and switch to a new cluster */ plist_requeue (&si->avail_list, &swap_avail_head);spin_unlock (&swap_avail_lock);
Signature · 1 line
2.34.1
kernel test robot
build botRe: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection
kernel test robot noticed the following build warnings:
Hi Youngjun,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2]
url: https://github.com/intel-lab-lkp/linux/commits/Youngjun-Park/mm-swap-introduce-swap-tier-infrastructure/20260201-005914 base: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2 patch link: https://lore.kernel.org/r/20260131125454.3187546-4-youngjun.park%40lge.com patch subject: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection reproduce: (https://download.01.org/0day-ci/archive/20260201/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
WARNING: No kernel-doc for file ./include/linux/pci.h
ERROR: Cannot find file ./include/linux/mod_devicetable.h
WARNING: No kernel-doc for file ./include/linux/mod_devicetable.h
ERROR: Cannot find file ./include/linux/bootconfig.h
WARNING: No kernel-doc for file ./include/linux/bootconfig.h
>> Documentation/admin-guide/cgroup-v2.rst:1876: WARNING: Bullet list ends without a blank line; unexpected unindent. [docutils]
ERROR: Cannot find file ./include/linux/pstore_zone.h
ERROR: Cannot find file ./include/linux/pstore_zone.h
WARNING: No kernel-doc for file ./include/linux/pstore_zone.h
ERROR: Cannot find file ./include/linux/pstore_blk.h
ERROR: Cannot find file ./include/linux/pstore_blk.h
vim +1876 Documentation/admin-guide/cgroup-v2.rst
1430
1431 ========== ================================ 1432 swappiness Swappiness value to reclaim with 1433 ========== ================================ 1434 1435 Specifying a swappiness value instructs the kernel to perform 1436 the reclaim with that swappiness value. Note that this has the 1437 same semantics as vm.swappiness applied to memcg reclaim with 1438 all the existing limitations and potential future extensions. 1439 1440 The valid range for swappiness is [0-200, max], setting 1441 swappiness=max exclusively reclaims anonymous memory. 1442 1443 memory.peak 1444 A read-write single value file which exists on non-root cgroups. 1445 1446 The max memory usage recorded for the cgroup and its descendants since 1447 either the creation of the cgroup or the most recent reset for that FD. 1448 1449 A write of any non-empty string to this file resets it to the 1450 current memory usage for subsequent reads through the same 1451 file descriptor. 1452 1453 memory.oom.group 1454 A read-write single value file which exists on non-root 1455 cgroups. The default value is "0". 1456 1457 Determines whether the cgroup should be treated as 1458 an indivisible workload by the OOM killer. If set, 1459 all tasks belonging to the cgroup or to its descendants 1460 (if the memory cgroup is not a leaf cgroup) are killed 1461 together or not at all. This can be used to avoid 1462 partial kills to guarantee workload integrity. 1463 1464 Tasks with the OOM protection (oom_score_adj set to -1000) 1465 are treated as an exception and are never killed. 1466 1467 If the OOM killer is invoked in a cgroup, it's not going 1468 to kill any tasks outside of this cgroup, regardless 1469 memory.oom.group values of ancestor cgroups. 1470 1471 memory.events 1472 A read-only flat-keyed file which exists on non-root cgroups. 1473 The following entries are defined. Unless specified 1474 otherwise, a value change in this file generates a file 1475 modified event. 1476 1477 Note that all fields in this file are hierarchical and the 1478 file modified event can be generated due to an event down the 1479 hierarchy. For the local events at the cgroup level see 1480 memory.events.local. 1481 1482 low 1483 The number of times the cgroup is reclaimed due to 1484 high memory pressure even though its usage is under 1485 the low boundary. This usually indicates that the low 1486 boundary is over-committed. 1487 1488 high 1489 The number of times processes of the cgroup are 1490 throttled and routed to perform direct memory reclaim 1491 because the high memory boundary was exceeded. For a 1492 cgroup whose memory usage is capped by the high limit 1493 rather than global memory pressure, this event's 1494 occurrences are expected. 1495 1496 max 1497 The number of times the cgroup's memory usage was 1498 about to go over the max boundary. If direct reclaim 1499 fails to bring it down, the cgroup goes to OOM state. 1500 1501 oom 1502 The number of time the cgroup's memory usage was 1503 reached the limit and allocation was about to fail. 1504 1505 This event is not raised if the OOM killer is not 1506 considered as an option, e.g. for failed high-order 1507 allocations or if caller asked to not retry attempts. 1508 1509 oom_kill 1510 The number of processes belonging to this cgroup 1511 killed by any kind of OOM killer. 1512 1513 oom_group_kill 1514 The number of times a group OOM has occurred. 1515 1516 sock_throttled 1517 The number of times network sockets associated with 1518 this cgroup are throttled. 1519 1520 memory.events.local 1521 Similar to memory.events but the fields in the file are local 1522 to the cgroup i.e. not hierarchical. The file modified event 1523 generated on this file reflects only the local events. 1524 1525 memory.stat 1526 A read-only flat-keyed file which exists on non-root cgroups. 1527 1528 This breaks down the cgroup's memory footprint into different 1529 types of memory, type-specific details, and other information 1530 on the state and past events of the memory management system. 1531 1532 All memory amounts are in bytes. 1533 1534 The entries are ordered to be human readable, and new entries 1535 can show up in the middle. Don't rely on items remaining in a 1536 fixed position; use the keys to look up specific values! 1537 1538 If the entry has no per-node counter (or not show in the 1539 memory.numa_stat). We use 'npn' (non-per-node) as the tag 1540 to indicate that it will not show in the memory.numa_stat. 1541 1542 anon 1543 Amount of memory used in anonymous mappings such as 1544 brk(), sbrk(), and mmap(MAP_ANONYMOUS). Note that 1545 some kernel configurations might account complete larger 1546 allocations (e.g., THP) if only some, but not all the 1547 memory of such an allocation is mapped anymore. 1548 1549 file 1550 Amount of memory used to cache filesystem data, 1551 including tmpfs and shared memory. 1552 1553 kernel (npn) 1554 Amount of total kernel memory, including 1555 (kernel_stack, pagetables, percpu, vmalloc, slab) in 1556 addition to other kernel memory use cases. 1557 1558 kernel_stack 1559 Amount of memory allocated to kernel stacks. 1560 1561 pagetables 1562 Amount of memory allocated for page tables. 1563 1564 sec_pagetables 1565 Amount of memory allocated for secondary page tables, 1566 this currently includes KVM mmu allocations on x86 1567 and arm64 and IOMMU page tables. 1568 1569 percpu (npn) 1570 Amount of memory used for storing per-cpu kernel 1571 data structures. 1572 1573 sock (npn) 1574 Amount of memory used in network transmission buffers 1575 1576 vmalloc (npn) 1577 Amount of memory used for vmap backed memory. 1578 1579 shmem 1580 Amount of cached filesystem data that is swap-backed, 1581 such as tmpfs, shm segments, shared anonymous mmap()s 1582 1583 zswap 1584 Amount of memory consumed by the zswap compression backend. 1585 1586 zswapped 1587 Amount of application memory swapped out to zswap. 1588 1589 file_mapped 1590 Amount of cached filesystem data mapped with mmap(). Note 1591 that some kernel configurations might account complete 1592 larger allocations (e.g., THP) if only some, but not 1593 not all the memory of such an allocation is mapped. 1594 1595 file_dirty 1596 Amount of cached filesystem data that was modified but 1597 not yet written back to disk 1598 1599 file_writeback 1600 Amount of cached filesystem data that was modified and 1601 is currently being written back to disk 1602 1603 swapcached 1604 Amount of swap cached in memory. The swapcache is accounted 1605 against both memory and swap usage. 1606 1607 anon_thp 1608 Amount of memory used in anonymous mappings backed by 1609 transparent hugepages 1610 1611 file_thp 1612 Amount of cached filesystem data backed by transparent 1613 hugepages 1614 1615 shmem_thp 1616 Amount of shm, tmpfs, shared anonymous mmap()s backed by 1617 transparent hugepages 1618 1619 inactive_anon, active_anon, inactive_file, active_file, unevictable 1620 Amount of memory, swap-backed and filesystem-backed, 1621 on the internal memory management lists used by the 1622 page reclaim algorithm. 1623 1624 As these represent internal list state (eg. shmem pages are on anon 1625 memory management lists), inactive_foo + active_foo may not be equal to 1626 the value for the foo counter, since the foo counter is type-based, not 1627 list-based. 1628 1629 slab_reclaimable 1630 Part of "slab" that might be reclaimed, such as 1631 dentries and inodes. 1632 1633 slab_unreclaimable 1634 Part of "slab" that cannot be reclaimed on memory 1635 pressure. 1636 1637 slab (npn) 1638 Amount of memory used for storing in-kernel data 1639 structures. 1640 1641 workingset_refault_anon 1642 Number of refaults of previously evicted anonymous pages. 1643 1644 workingset_refault_file 1645 Number of refaults of previously evicted file pages. 1646 1647 workingset_activate_anon 1648 Number of refaulted anonymous pages that were immediately 1649 activated. 1650 1651 workingset_activate_file 1652 Number of refaulted file pages that were immediately activated. 1653 1654 workingset_restore_anon 1655 Number of restored anonymous pages which have been detected as 1656 an active workingset before they got reclaimed. 1657 1658 workingset_restore_file 1659 Number of restored file pages which have been detected as an 1660 active workingset before they got reclaimed. 1661 1662 workingset_nodereclaim 1663 Number of times a shadow node has been reclaimed 1664 1665 pswpin (npn) 1666 Number of pages swapped into memory 1667 1668 pswpout (npn) 1669 Number of pages swapped out of memory 1670 1671 pgscan (npn) 1672 Amount of scanned pages (in an inactive LRU list) 1673 1674 pgsteal (npn) 1675 Amount of reclaimed pages 1676 1677 pgscan_kswapd (npn) 1678 Amount of scanned pages by kswapd (in an inactive LRU list) 1679 1680 pgscan_direct (npn) 1681 Amount of scanned pages directly (in an inactive LRU list) 1682 1683 pgscan_khugepaged (npn) 1684 Amount of scanned pages by khugepaged (in an inactive LRU list) 1685 1686 pgscan_proactive (npn) 1687 Amount of scanned pages proactively (in an inactive LRU list) 1688 1689 pgsteal_kswapd (npn) 1690 Amount of reclaimed pages by kswapd 1691 1692 pgsteal_direct (npn) 1693 Amount of reclaimed pages directly 1694 1695 pgsteal_khugepaged (npn) 1696 Amount of reclaimed pages by khugepaged 1697 1698 pgsteal_proactive (npn) 1699 Amount of reclaimed pages proactively 1700 1701 pgfault (npn) 1702 Total number of page faults incurred 1703 1704 pgmajfault (npn) 1705 Number of major page faults incurred 1706 1707 pgrefill (npn) 1708 Amount of scanned pages (in an active LRU list) 1709 1710 pgactivate (npn) 1711 Amount of pages moved to the active LRU list 1712 1713 pgdeactivate (npn) 1714 Amount of pages moved to the inactive LRU list 1715 1716 pglazyfree (npn) 1717 Amount of pages postponed to be freed under memory pressure 1718 1719 pglazyfreed (npn) 1720 Amount of reclaimed lazyfree pages 1721 1722 swpin_zero 1723 Number of pages swapped into memory and filled with zero, where I/O 1724 was optimized out because the page content was detected to be zero 1725 during swapout. 1726 1727 swpout_zero 1728 Number of zero-filled pages swapped out with I/O skipped due to the 1729 content being detected as zero. 1730 1731 zswpin 1732 Number of pages moved in to memory from zswap. 1733 1734 zswpout 1735 Number of pages moved out of memory to zswap. 1736 1737 zswpwb 1738 Number of pages written from zswap to swap. 1739 1740 thp_fault_alloc (npn) 1741 Number of transparent hugepages which were allocated to satisfy 1742 a page fault. This counter is not present when CONFIG_TRANSPARENT_HUGEPAGE 1743 is not set. 1744 1745 thp_collapse_alloc (npn) 1746 Number of transparent hugepages which were allocated to allow 1747 collapsing an existing range of pages. This counter is not 1748 present when CONFIG_TRANSPARENT_HUGEPAGE is not set. 1749 1750 thp_swpout (npn) 1751 Number of transparent hugepages which are swapout in one piece 1752 without splitting. 1753 1754 thp_swpout_fallback (npn) 1755 Number of transparent hugepages which were split before swapout. 1756 Usually because failed to allocate some continuous swap space 1757 for the huge page. 1758 1759 numa_pages_migrated (npn) 1760 Number of pages migrated by NUMA balancing. 1761 1762 numa_pte_updates (npn) 1763 Number of pages whose page table entries are modified by 1764 NUMA balancing to produce NUMA hinting faults on access. 1765 1766 numa_hint_faults (npn) 1767 Number of NUMA hinting faults. 1768 1769 pgdemote_kswapd 1770 Number of pages demoted by kswapd. 1771 1772 pgdemote_direct 1773 Number of pages demoted directly. 1774 1775 pgdemote_khugepaged 1776 Number of pages demoted by khugepaged. 1777 1778 pgdemote_proactive 1779 Number of pages demoted by proactively. 1780 1781 hugetlb 1782 Amount of memory used by hugetlb pages. This metric only shows 1783 up if hugetlb usage is accounted for in memory.current (i.e. 1784 cgroup is mounted with the memory_hugetlb_accounting option). 1785 1786 memory.numa_stat 1787 A read-only nested-keyed file which exists on non-root cgroups. 1788 1789 This breaks down the cgroup's memory footprint into different 1790 types of memory, type-specific details, and other information 1791 per node on the state of the memory management system. 1792 1793 This is useful for providing visibility into the NUMA locality 1794 information within an memcg since the pages are allowed to be 1795 allocated from any physical node. One of the use case is evaluating 1796 application performance by combining this information with the 1797 application's CPU allocation. 1798 1799 All memory amounts are in bytes. 1800 1801 The output format of memory.numa_stat is:: 1802 1803 type N0=<bytes in node 0> N1=<bytes in node 1> ... 1804 1805 The entries are ordered to be human readable, and new entries 1806 can show up in the middle. Don't rely on items remaining in a 1807 fixed position; use the keys to look up specific values! 1808 1809 The entries can refer to the memory.stat. 1810 1811 memory.swap.current 1812 A read-only single value file which exists on non-root 1813 cgroups. 1814 1815 The total amount of swap currently being used by the cgroup 1816 and its descendants. 1817 1818 memory.swap.high 1819 A read-write single value file which exists on non-root 1820 cgroups. The default is "max". 1821 1822 Swap usage throttle limit. If a cgroup's swap usage exceeds 1823 this limit, all its further allocations will be throttled to 1824 allow userspace to implement custom out-of-memory procedures. 1825 1826 This limit marks a point of no return for the cgroup. It is NOT 1827 designed to manage the amount of swapping a workload does 1828 during regular operation. Compare to memory.swap.max, which 1829 prohibits swapping past a set amount, but lets the cgroup 1830 continue unimpeded as long as other memory can be reclaimed. 1831 1832 Healthy workloads are not expected to reach this limit. 1833 1834 memory.swap.peak 1835 A read-write single value file which exists on non-root cgroups. 1836 1837 The max swap usage recorded for the cgroup and its descendants since 1838 the creation of the cgroup or the most recent reset for that FD. 1839 1840 A write of any non-empty string to this file resets it to the 1841 current memory usage for subsequent reads through the same 1842 file descriptor. 1843 1844 memory.swap.max 1845 A read-write single value file which exists on non-root 1846 cgroups. The default is "max". 1847 1848 Swap usage hard limit. If a cgroup's swap usage reaches this 1849 limit, anonymous memory of the cgroup will not be swapped out. 1850 1851 memory.swap.tiers 1852 A read-write nested-keyed file which exists on non-root 1853 cgroups. The default is to enable all tiers. 1854 1855 This interface allows selecting which swap tiers a cgroup can 1856 use for swapping out memory. 1857 1858 The effective tiers are inherited from the parent. Only tiers 1859 effective in the parent can be effective in the child. However, 1860 the child can explicitly disable tiers allowed by the parent. 1861 1862 When read, the file shows two lines: 1863 - The first line shows the operation string that was 1864 written to this file. 1865 - The second line shows the effective operation after 1866 merging with parent settings. 1867 1868 When writing, the format is: 1869 (+/-)(TIER_NAME) (+/-)(TIER_NAME) ... 1870 1871 Valid tier names are those configured in 1872 /sys/kernel/mm/swap/tiers. 1873 1874 Each tier can be prefixed with: 1875 + Enable this tier > 1876 - Disable this tier
1877
1878 memory.swap.events
1879 A read-only flat-keyed file which exists on non-root cgroups.
1880 The following entries are defined. Unless specified
1881 otherwise, a value change in this file generates a file
1882 modified event.
1883
1884 high
1885 The number of times the cgroup's swap usage was over
1886 the high threshold.
1887
1888 max
1889 The number of times the cgroup's swap usage was about
1890 to go over the max boundary and swap allocation
1891 failed.
1892
1893 fail
1894 The number of times swap allocation failed either
1895 because of running out of swap system-wide or max
1896 limit.
1897
1898 When reduced under the current usage, the existing swap
1899 entries are reclaimed gradually and the swap usage may stay
1900 higher than the limit for an extended period of time. This
1901 reduces the impact on the workload and memory management.
1902
1903 memory.zswap.current
1904 A read-only single value file which exists on non-root
1905 cgroups.
1906
1907 The total amount of memory consumed by the zswap compression
1908 backend.
1909
1910 memory.zswap.max
1911 A read-write single value file which exists on non-root
1912 cgroups. The default is "max".
1913
1914 Zswap usage hard limit. If a cgroup's zswap pool reaches this
1915 limit, it will refuse to take any more stores before existing
1916 entries fault back in or are written out to disk.
1917
1918 memory.zswap.writeback
1919 A read-write single value file. The default value is "1".
1920 Note that this setting is hierarchical, i.e. the writeback would be
1921 implicitly disabled for child cgroups if the upper hierarchy
1922 does so.
1923
1924 When this is set to 0, all swapping attempts to swapping devices
1925 are disabled. This included both zswap writebacks, and swapping due
1926 to zswap store failures. If the zswap store failures are recurring
1927 (for e.g if the pages are incompressible), users can observe
1928 reclaim inefficiency after disabling writeback (because the same
1929 pages might be rejected again and again).
1930
1931 Note that this is subtly different from setting memory.swap.max to
1932 0, as it still allows for pages to be written to the zswap pool.
1933 This setting has no effect if zswap is disabled, and swapping
1934 is allowed unless memory.swap.max is set to 0.
1935
1936 memory.pressure
1937 A read-only nested-keyed file.
1938
1939 Shows pressure stall information for memory. See
1940 :ref:Documentation/accounting/psi.rst <psi> for details.
1941
1942
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection
In reply to Youngjun Parkkernel test robot noticed the following build errors:
Hi Youngjun,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2]
url: https://github.com/intel-lab-lkp/linux/commits/Youngjun-Park/mm-swap-introduce-swap-tier-infrastructure/20260201-005914 base: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2 patch link: https://lore.kernel.org/r/20260131125454.3187546-4-youngjun.park%40lge.com patch subject: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection config: s390-randconfig-001-20260201 (https://download.01.org/0day-ci/archive/20260202/[email protected]/config) compiler: s390-linux-gcc (GCC) 13.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260202/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
s390-linux-ld: mm/memcontrol.o: in function `mem_cgroup_free':
>> mm/memcontrol.c:3695:(.text+0x662a): undefined reference to `swap_tiers_memcg_sync_mask' s390-linux-ld: mm/memcontrol.o: in function `mem_cgroup_css_alloc': >> mm/memcontrol.c:3798:(.ref.text+0x372): undefined reference to `swap_tiers_memcg_inherit_mask'
vim +3695 mm/memcontrol.c
3690
3691 static void mem_cgroup_free(struct mem_cgroup *memcg)
3692 {
3693 lru_gen_exit_memcg(memcg);
3694 memcg_wb_domain_exit(memcg);
> 3695 swap_tiers_memcg_sync_mask(memcg);
3696 __mem_cgroup_free(memcg);
3697 }
3698
3699 static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
3700 {
3701 struct memcg_vmstats_percpu *statc;
3702 struct memcg_vmstats_percpu __percpu *pstatc_pcpu;
3703 struct mem_cgroup *memcg;
3704 int node, cpu;
3705 int __maybe_unused i;
3706 long error;
3707
3708 memcg = kmem_cache_zalloc(memcg_cachep, GFP_KERNEL);
3709 if (!memcg)
3710 return ERR_PTR(-ENOMEM);
3711
3712 error = xa_alloc(&mem_cgroup_private_ids, &memcg->id.id, NULL,
3713 XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);
3714 if (error)
3715 goto fail;
3716 error = -ENOMEM;
3717
3718 memcg->vmstats = kzalloc(sizeof(struct memcg_vmstats),
3719 GFP_KERNEL_ACCOUNT);
3720 if (!memcg->vmstats)
3721 goto fail;
3722
3723 memcg->vmstats_percpu = alloc_percpu_gfp(struct memcg_vmstats_percpu,
3724 GFP_KERNEL_ACCOUNT);
3725 if (!memcg->vmstats_percpu)
3726 goto fail;
3727
3728 if (!memcg1_alloc_events(memcg))
3729 goto fail;
3730
3731 for_each_possible_cpu(cpu) {
3732 if (parent)
3733 pstatc_pcpu = parent->vmstats_percpu;
3734 statc = per_cpu_ptr(memcg->vmstats_percpu, cpu);
3735 statc->parent_pcpu = parent ? pstatc_pcpu : NULL;
3736 statc->vmstats = memcg->vmstats;
3737 }
3738
3739 for_each_node(node)
3740 if (!alloc_mem_cgroup_per_node_info(memcg, node))
3741 goto fail;
3742
3743 if (memcg_wb_domain_init(memcg, GFP_KERNEL))
3744 goto fail;
3745
3746 INIT_WORK(&memcg->high_work, high_work_func);
3747 vmpressure_init(&memcg->vmpressure);
3748 INIT_LIST_HEAD(&memcg->memory_peaks);
3749 INIT_LIST_HEAD(&memcg->swap_peaks);
3750 spin_lock_init(&memcg->peaks_lock);
3751 memcg->socket_pressure = get_jiffies_64();
3752 #if BITS_PER_LONG < 64
3753 seqlock_init(&memcg->socket_pressure_seqlock);
3754 #endif
3755 memcg1_memcg_init(memcg);
3756 memcg->kmemcg_id = -1;
3757 INIT_LIST_HEAD(&memcg->objcg_list);
3758 #ifdef CONFIG_CGROUP_WRITEBACK
3759 INIT_LIST_HEAD(&memcg->cgwb_list);
3760 for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++)
3761 memcg->cgwb_frn[i].done =
3762 __WB_COMPLETION_INIT(&memcg_cgwb_frn_waitq);
3763 #endif
3764 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
3765 spin_lock_init(&memcg->deferred_split_queue.split_queue_lock);
3766 INIT_LIST_HEAD(&memcg->deferred_split_queue.split_queue);
3767 memcg->deferred_split_queue.split_queue_len = 0;
3768 #endif
3769 lru_gen_init_memcg(memcg);
3770 return memcg;
3771 fail:
3772 mem_cgroup_private_id_remove(memcg);
3773 __mem_cgroup_free(memcg);
3774 return ERR_PTR(error);
3775 }
3776
3777 static struct cgroup_subsys_state * __ref
3778 mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
3779 {
3780 struct mem_cgroup *parent = mem_cgroup_from_css(parent_css);
3781 struct mem_cgroup *memcg, *old_memcg;
3782 bool memcg_on_dfl = cgroup_subsys_on_dfl(memory_cgrp_subsys);
3783
3784 old_memcg = set_active_memcg(parent);
3785 memcg = mem_cgroup_alloc(parent);
3786 set_active_memcg(old_memcg);
3787 if (IS_ERR(memcg))
3788 return ERR_CAST(memcg);
3789
3790 page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX);
3791 memcg1_soft_limit_reset(memcg);
3792 #ifdef CONFIG_ZSWAP
3793 memcg->zswap_max = PAGE_COUNTER_MAX;
3794 WRITE_ONCE(memcg->zswap_writeback, true);
3795 #endif
3796 page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX);
3797 memcg->tier_mask = TIER_ALL_MASK;
> 3798 swap_tiers_memcg_inherit_mask(memcg, parent); 3799
3800 if (parent) {
3801 WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent));
3802
3803 page_counter_init(&memcg->memory, &parent->memory, memcg_on_dfl);
3804 page_counter_init(&memcg->swap, &parent->swap, false);
3805 #ifdef CONFIG_MEMCG_V1
3806 memcg->memory.track_failcnt = !memcg_on_dfl;
3807 WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable));
3808 page_counter_init(&memcg->kmem, &parent->kmem, false);
3809 page_counter_init(&memcg->tcpmem, &parent->tcpmem, false);
3810 #endif
3811 } else {
3812 init_memcg_stats();
3813 init_memcg_events();
3814 page_counter_init(&memcg->memory, NULL, true);
3815 page_counter_init(&memcg->swap, NULL, false);
3816 #ifdef CONFIG_MEMCG_V1
3817 page_counter_init(&memcg->kmem, NULL, false);
3818 page_counter_init(&memcg->tcpmem, NULL, false);
3819 #endif
3820 root_mem_cgroup = memcg;
3821 return &memcg->css;
3822 }
3823
3824 if (memcg_on_dfl && !cgroup_memory_nosocket)
3825 static_branch_inc(&memcg_sockets_enabled_key);
3826
3827 if (!cgroup_memory_nobpf)
3828 static_branch_inc(&memcg_bpf_enabled_key);
3829
3830 return &memcg->css;
3831 }
3832
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection
In reply to Youngjun Parkkernel test robot noticed the following build errors:
Hi Youngjun,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2]
url: https://github.com/intel-lab-lkp/linux/commits/Youngjun-Park/mm-swap-introduce-swap-tier-infrastructure/20260201-005914 base: 5a3704ed2dce0b54a7f038b765bb752b87ee8cc2 patch link: https://lore.kernel.org/r/20260131125454.3187546-4-youngjun.park%40lge.com patch subject: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection config: s390-randconfig-002-20260201 (https://download.01.org/0day-ci/archive/20260202/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260202/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
s390-linux-ld: mm/memcontrol.o: in function `mem_cgroup_css_free':
>> memcontrol.c:(.text+0x2f2a): undefined reference to `swap_tiers_memcg_sync_mask' s390-linux-ld: mm/memcontrol.o: in function `mem_cgroup_css_alloc': >> memcontrol.c:(.ref.text+0xfc): undefined reference to `swap_tiers_memcg_inherit_mask'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Michal Koutný
maintainerRe: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection
In reply to Youngjun ParkHi.
This is merely the API feedback.
(Feedback to the propsed form, I'm not sure whether/how this should interact with memory.swap.max (formally cf io.weight).)
Quoted 32 lines · Youngjun Park
This patch integrates the swap tier infrastructure with cgroup, enabling the selection of specific swap devices per cgroup by configuring allowed swap tiers.
The new
memory.swap.tiersinterface controls allowed swap tiers via a mask. By default, the mask is set to include all tiers, allowing specific tiers to be excluded or restored. Note that effective tiers are calculated separately using a dedicated mask to respect the cgroup hierarchy. Consequently, configured tiers may differ from effective ones, as they must be a subset of the parent's.Note that cgroups do not pin swap tiers. This is similar to the
cpusetcontroller, which does not prevent CPU hotplug. This approach ensures flexibility by allowing tier configuration changes regardless of cgroup usage.Signed-off-by Youngjun Park <[email protected]>--- Documentation/admin-guide/cgroup-v2.rst | 27 ++++++++ include/linux/memcontrol.h | 3 +- mm/memcontrol.c | 85 +++++++++++++++++++++++ mm/swap_state.c | 6 +- mm/swap_tier.c | 89 ++++++++++++++++++++++++- mm/swap_tier.h | 39 ++++++++++- mm/swapfile.c | 4 ++ 7 files changed, 246 insertions(+), 7 deletions(-)Documentation/admin-guide/cgroup-v2.rst +0
-0
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1852
Quoted 5 lines
Documentation/admin-guide/cgroup-v2.rst +2
-0@@ -1848,6 +1848,33 @@ The following nested keys are defined. Swap usage hard limit. If a cgroup's swap usage reaches this limit, anonymous memory of the cgroup will not be swapped out. + memory.swap.tiers + A read-write nested-keyed file which exists on non-root
"nested-keyed" format is something else in this document's lingo, see e.g. io.stat.
I think you wanted to make this resemble cgroup.subtree_control (which is fine).
Quoted 4 lines
Documentation/admin-guide/cgroup-v2.rst +4
-0+ cgroups. The default is to enable all tiers. + + This interface allows selecting which swap tiers a cgroup can + use for swapping out memory.
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1866
Quoted 10 lines
Documentation/admin-guide/cgroup-v2.rst +10
-0+ + The effective tiers are inherited from the parent. Only tiers + effective in the parent can be effective in the child. However, + the child can explicitly disable tiers allowed by the parent. + + When read, the file shows two lines: + - The first line shows the operation string that was + written to this file. + - The second line shows the effective operation after + merging with parent settings.
The convention (in cpuset) is to split it in two files like memory.swap.tiers and memory.swap.tiers.effective.
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1877
Quoted 11 lines
Documentation/admin-guide/cgroup-v2.rst +11
-0+ + When writing, the format is: + (+/-)(TIER_NAME) (+/-)(TIER_NAME) ... + + Valid tier names are those configured in + /sys/kernel/mm/swap/tiers. + + Each tier can be prefixed with: + + Enable this tier + - Disable this tier +
I believe these are only superficial adjustments not affecting the implementation.
Thanks,
Michal
YoungJun Park
reviewerRe: [RFC PATCH v3 3/5] mm: memcontrol: add interface for swap tier selection
Quoted 43 lines · Michal Koutný
Hi.
This is merely the API feedback.
(Feedback to the propsed form, I'm not sure whether/how this should interact with memory.swap.max (formally cf io.weight).)
Quoted 35 lines · Youngjun Park
This patch integrates the swap tier infrastructure with cgroup, enabling the selection of specific swap devices per cgroup by configuring allowed swap tiers.
The new
memory.swap.tiersinterface controls allowed swap tiers via a mask. By default, the mask is set to include all tiers, allowing specific tiers to be excluded or restored. Note that effective tiers are calculated separately using a dedicated mask to respect the cgroup hierarchy. Consequently, configured tiers may differ from effective ones, as they must be a subset of the parent's.Note that cgroups do not pin swap tiers. This is similar to the
cpusetcontroller, which does not prevent CPU hotplug. This approach ensures flexibility by allowing tier configuration changes regardless of cgroup usage.Signed-off-by Youngjun Park <[email protected]>--- Documentation/admin-guide/cgroup-v2.rst | 27 ++++++++ include/linux/memcontrol.h | 3 +- mm/memcontrol.c | 85 +++++++++++++++++++++++ mm/swap_state.c | 6 +- mm/swap_tier.c | 89 ++++++++++++++++++++++++- mm/swap_tier.h | 39 ++++++++++- mm/swapfile.c | 4 ++ 7 files changed, 246 insertions(+), 7 deletions(-)Documentation/admin-guide/cgroup-v2.rst +0
-0@@ -1848,6 +1848,33 @@ The following nested keys are defined. Swap usage hard limit. If a cgroup's swap usage reaches this limit, anonymous memory of the cgroup will not be swapped out.
Quoted 8 lines
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1852
Quoted 2 lines
Documentation/admin-guide/cgroup-v2.rst +2
-0+ memory.swap.tiers + A read-write nested-keyed file which exists on non-root"nested-keyed" format is something else in this document's lingo, see e.g. io.stat.
I think you wanted to make this resemble cgroup.subtree_control (which is fine).
You are right, I used the wrong expression. Simply describing it as a "file" seems sufficient.
Quoted 10 lines
Quoted 10 lines
Documentation/admin-guide/cgroup-v2.rst +9
-0+ cgroups. The default is to enable all tiers. + + This interface allows selecting which swap tiers a cgroup can + use for swapping out memory. + + The effective tiers are inherited from the parent. Only tiers + effective in the parent can be effective in the child. However, + the child can explicitly disable tiers allowed by the parent. +
Quoted 8 lines
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1866
Quoted 5 lines
Documentation/admin-guide/cgroup-v2.rst +5
-0+ When read, the file shows two lines: + - The first line shows the operation string that was + written to this file. + - The second line shows the effective operation after + merging with parent settings.The convention (in cpuset) is to split it in two files like memory.swap.tiers and memory.swap.tiers.effective.
I will separate the two according to the convention. Thanks for correction.
Quoted 15 lines
Documentation/admin-guide/cgroup-v2.rst The following nested keys are defined. · line 1877
Quoted 11 lines
Documentation/admin-guide/cgroup-v2.rst +11
-0+ + When writing, the format is: + (+/-)(TIER_NAME) (+/-)(TIER_NAME) ... + + Valid tier names are those configured in + /sys/kernel/mm/swap/tiers. + + Each tier can be prefixed with: + + Enable this tier + - Disable this tier +I believe these are only superficial adjustments not affecting the implementation.
Quoted 2 lines
Thanks,
Michal
Thanks for the review, Michal.
Youngjun Park
Youngjun Park
reviewerRFC PATCH v3 4/5 mm, swap: change back to use each swap device's percpu cluster
In reply to Youngjun ParkThis reverts commit 1b7e90020eb7 ("mm, swap: use percpu cluster as allocation fast path").
Because in the newly introduced swap tiers, the global percpu cluster will cause two issues:
1) it will cause caching oscillation in the same order of different si if two different memcg can only be allowed to access different si and both of them are swapping out.
2) It can cause priority inversion on swap devices. Imagine a case where there are two memcg, say memcg1 and memcg2. Memcg1 can access si A, B and A is higher priority device. While memcg2 can only access si B. Then memcg 2 could write the global percpu cluster with si B, then memcg1 take si B in fast path even though si A is not exhausted.
Hence in order to support swap tier, revert commit to use each swap device's percpu cluster.
--- include/linux/swap.h | 17 +++-- mm/swapfile.c | 149 +++++++++++++++---------------------------- 2 files changed, 62 insertions(+), 104 deletions(-)
include/linux/swap.h +12 -5
@@ -247,11 +247,18 @@ enum {#define SWAP_NR_ORDERS 1#endif -/* -* We keep using same cluster for rotational device so IO will be sequential. -* The purpose is to optimize SWAP throughput on these device. -*/ +/* +* We assign a cluster to each CPU, so each CPU can allocate swap entry from +* its own cluster and swapout sequentially. The purpose is to optimize swapout +* throughput. +*/ +struct percpu_cluster { +local_lock_t lock;/* Protect the percpu_cluster above */ +unsigned int next[SWAP_NR_ORDERS ];/* Likely next allocation offset */ +}; +struct swap_sequential_cluster { +spinlock_t lock;/* Serialize usage of global cluster */ unsigned int next[SWAP_NR_ORDERS ];/* Likely next allocation offset */ };
@@ -277,8 +284,8 @@ struct swap_info_struct {/* list of cluster that are fragmented or contented */ unsigned int pages;/* total of usable pages of swap */ atomic_long_t inuse_pages;/* number of those currently in use */ +struct percpu_cluster __percpu *percpu_cluster;/* per cpu's swap location */ struct swap_sequential_cluster *global_cluster;/* Use one global cluster for rotating device */ -spinlock_t global_cluster_lock;/* Serialize usage of global cluster */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */ struct block_device *bdev;/* swap device or bdev of swap file */ struct file *swap_file;/* seldom referenced */
mm/swapfile.c +50 -99
276 lines not on this page · raw message
Signature · 1 line
2.34.1
Youngjun Park
reviewerRFC PATCH v3 5/5 mm, swap: introduce percpu swap device cache to avoid fragmentation
In reply to Youngjun ParkIn the previous commit that introduced per-device percpu clusters, the allocation logic caused swap device rotation on every allocation when multiple swap devices share the same priority. This led to cluster fragmentation on every allocation attemp.
To address this issue, this patch introduces a per-cpu swap device cache, restoring the allocation behavior to closely match the traditional fastpath and slowpath flow.
With swap tiers, cluster fragmentation can still occur when a CPU's cached swap device doesn't belong to the required tier for the current allocation - this is the intended behavior for tier-based allocation.
With swap tiers and same-priority swap devices, the slow path triggers device rotation and causes initial cluster fragmentation. However, once a cluster is allocated, subsequent allocations will continue using that cluster until it's exhausted, preventing repeated fragmentation. While this may not be severe, there is room for future optimization.
--- include/linux/swap.h | 1 - mm/swapfile.c | 87 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 19 deletions(-)
include/linux/swap.h +0 -1
@@ -253,7 +253,6 @@ enum {* throughput. */ struct percpu_cluster { -local_lock_t lock;/* Protect the percpu_cluster above */ unsigned int next[SWAP_NR_ORDERS ];/* Likely next allocation offset */ };
mm/swapfile.c +69 -18
168 lines not on this page · raw message
Signature · 1 line
2.34.1