Skip to contentSkip to conversation

mm/swapfile.c: select the swap device with default priority round robin

PATCH Superseded Baoquan He 2 participants 8 messages Sep 26, 2025 – Sep 28, 2025

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Baoquan He

author
#0 lore raw

v2 cover mm/swapfile.c: select the swap device with default priority round robin

The detailed information about patch can be found in patch log. Here I would like to add testing related information.

On my system, it has 8 nodes, 64G RAM. So I created 4 zram devices of
size 16G. Doing this because I can't find system with 4 free SSD disk which can be used as swap devices. And nowadays, swap, zram become more and more popular, even default setup, so I create zram to test patch.

# free -h
               total        used        free      shared  buff/cache   available
Mem:            62Gi       1.6Gi        61Gi       4.8Mi       276Mi        61Gi
Swap:           63Gi          0B        63Gi

1) create zram
#My fedora will add one zram0 by default, I reset it because the zram size if not enough swapoff /dev/zram0

cd /sys/block/
echo 1 > zram0/reset
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add

echo 16G > zram0/disksize
echo 16G > zram1/disksize
echo 16G > zram2/disksize
echo 16G > zram3/disksize

mkswap /dev/zram0
mkswap /dev/zram1
mkswap /dev/zram2
mkswap /dev/zram3

swapon /dev/zram0
swapon /dev/zram1
swapon /dev/zram2
swapon /dev/zram3

2) Create memcg with 4G (this avoids noise from other anon process in system) cd /sys/fs/cgroup/
mkdir testing
echo 4G > testing/memory.max
echo 3G > testing/memory.high

3) Run usemem in memcg
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt

The usemem output is not easy to understand, I will attach my draft script in thread for easing result collecting and statistics.

Changelog:
v1->v2:
- Remove Documentation/admin-guide/mm/swap_numa.rst;
- Add back mistakenly removed lockdep_assert_held() line;
- Remove the unneeded code comment in _enable_swap_info(). Thanks a lot for careful reviewing from Chris, YoungJun and Kairui.

Baoquan He (1):
mm/swapfile.c: select the swap device with default priority round
robin

 Documentation/admin-guide/mm/swap_numa.rst |  78 ---------------
 include/linux/swap.h                       |  11 +--
 mm/swapfile.c                              | 109 +++------------------
 3 files changed, 16 insertions(+), 182 deletions(-)
 delete mode 100644 Documentation/admin-guide/mm/swap_numa.rst
Signature · 1 line
2.41.0
author
#1 lore raw

PATCH v2 1/1 mm/swapfile.c: select the swap device with default priority round robin

Currently, on system with multiple swap devices, swap allocation will select one swap device according to priority. The swap device with the highest priority will be chosen to allocate firstly.

People can specify a priority from 0 to 32767 when swapon a swap device, or the system will set it from -2 then downwards by default. Meanwhile, on NUMA system, the swap device with node_id will be considered first on that NUMA node of the node_id.

In the current code, an array of plist, swap_avail_heads[nid], is used to organize swap devices on each NUMA node. For each NUMA node, there is a plist organizing all swap devices. The 'prio' value in the plist is the negated value of the device's priority due to plist being sorted from low to high. The swap device owning one node_id will be promoted to the front position on that NUMA node, then other swap devices are put in order of their default priority.

E.g I got a system with 8 NUMA nodes, and I setup 4 zram partition as swap devices.

Current behaviour:
their priorities will be(note that -1 is skipped):
NAME TYPE SIZE USED PRIO

/dev/zram0 partition  16G   0B   -2
/dev/zram1 partition  16G   0B   -3
/dev/zram2 partition  16G   0B   -4
/dev/zram3 partition  16G   0B   -5

And their positions in the 8 swap_avail_lists[nid] will be:
swap_avail_lists[0]: /* node 0's available swap device list */
zram0 -> zram1 -> zram2 -> zram3
prio:1 prio:3 prio:4 prio:5
swap_avali_lists[1]: /* node 1's available swap device list */
zram1 -> zram0 -> zram2 -> zram3
prio:1 prio:2 prio:4 prio:5
swap_avail_lists[2]: /* node 2's available swap device list */
zram2 -> zram0 -> zram1 -> zram3
prio:1 prio:2 prio:3 prio:5
swap_avail_lists[3]: /* node 3's available swap device list */
zram3 -> zram0 -> zram1 -> zram2
prio:1 prio:2 prio:3 prio:4
swap_avail_lists[4-7]: /* node 4,5,6,7's available swap device list */
zram0 -> zram1 -> zram2 -> zram3
prio:2 prio:3 prio:4 prio:5

The adjustment for swap device with node_id intended to decrease the pressure of lock contention for one swap device by taking different swap device on different node. The adjustment was introduced in commit a2468cc9bfdf ("swap: choose swap device according to numa node"). However, the adjustment is a little coarse-grained. On the node, the swap device sharing the node's id will always be selected firstly by node's CPUs until exhausted, then next one. And on other nodes where no swap device shares its node id, swap device with priority '-2' will be selected firstly until exhausted, then next with priority '-3'.

This is the swapon output during the process high pressure vm-scability test is being taken. It's clearly showing zram0 is heavily exploited until exhausted.
===================================
[root@hp-dl385g10-03 ~]# swapon
NAME TYPE SIZE USED PRIO

/dev/zram0 partition  16G 15.7G   -2
/dev/zram1 partition  16G  3.4G   -3
/dev/zram2 partition  16G  3.4G   -4
/dev/zram3 partition  16G  2.6G   -5

This is unreasonable because swap devices are assumed to have similar accessing speed if no priority is specified when swapon. It's unfair and doesn't make sense just because one swap device is swapped on firstly, its priority will be higher than the one swapped on later.

So here change is made to select the swap device round robin if default priority. In code, the plist array swap_avail_heads[nid] is replaced with a plist swap_avail_head which reverts commit a2468cc9bfdf. Meanwhile, on top of the revert, further change is taken to make any device w/o specified priority get the same default priority '-1'. Surely, swap device with specified priority are always put foremost, this is not impacted. If you care about their different accessing speed, then use 'swapon -p xx' to deploy priority for your swap devices.

New behaviour:

swap_avail_list: /* one global available swap device list */
zram0 -> zram1 -> zram2 -> zram3
prio:1 prio:1 prio:1 prio:1

This is the swapon output during the process high pressure vm-scability being taken, all is selected round robin:
=======================================
[root@hp-dl385g10-03 linux]# swapon
NAME TYPE SIZE USED PRIO

/dev/zram0 partition  16G 12.6G   -1
/dev/zram1 partition  16G 12.6G   -1
/dev/zram2 partition  16G 12.6G   -1
/dev/zram3 partition  16G 12.6G   -1

With the change, we can see about 18% efficiency promotion as below:

vm-scability test:
==================
Test with:
usemem --init-time -O -y -x -n 31 2G (4G memcg, zram as swap)

                           Before:          After:
System time:               637.92 s         526.74 s      (lower is better)
Sum Throughput:            3546.56 MB/s     4207.56 MB/s  (higher is better)
Single process Throughput: 114.40 MB/s      135.72 MB/s   (higher is better)
free latency:              10138455.99 us   6810119.01 us (low is better)
---
 Documentation/admin-guide/mm/swap_numa.rst |  78 ---------------
 include/linux/swap.h                       |  11 +--
 mm/swapfile.c                              | 109 +++------------------
 3 files changed, 16 insertions(+), 182 deletions(-)
 delete mode 100644 Documentation/admin-guide/mm/swap_numa.rst
Documentation/admin-guide/mm/swap_numa.rst deleted +0 -78
deleted file mode 100644
index 2e630627bcee..000000000000
@@ -1,78 +0,0 @@
-===========================================
-Automatically bind swap device to numa node
-===========================================
-
-If the system has more than one swap device and swap device has the node
-information, we can make use of this information to decide which swap
-device to use in get_swap_pages() to get better performance.
-
-
-How to use this feature
-=======================
-
-Swap device has priority and that decides the order of it to be used. To make
-use of automatically binding, there is no need to manipulate priority settings
-for swap devices. e.g. on a 2 node machine, assume 2 swap devices swapA and
-swapB, with swapA attached to node 0 and swapB attached to node 1, are going
-to be swapped on. Simply swapping them on by doing::
-
-	# swapon /dev/swapA
-	# swapon /dev/swapB
-
-Then node 0 will use the two swap devices in the order of swapA then swapB and
-node 1 will use the two swap devices in the order of swapB then swapA. Note
-that the order of them being swapped on doesn't matter.
-
-A more complex example on a 4 node machine. Assume 6 swap devices are going to
-be swapped on: swapA and swapB are attached to node 0, swapC is attached to
-node 1, swapD and swapE are attached to node 2 and swapF is attached to node3.
-The way to swap them on is the same as above::
-
-	# swapon /dev/swapA
-	# swapon /dev/swapB
-	# swapon /dev/swapC
-	# swapon /dev/swapD
-	# swapon /dev/swapE
-	# swapon /dev/swapF
-
-Then node 0 will use them in the order of::
-
-	swapA/swapB -> swapC -> swapD -> swapE -> swapF
-
-swapA and swapB will be used in a round robin mode before any other swap device.
-
-node 1 will use them in the order of::
-
-	swapC -> swapA -> swapB -> swapD -> swapE -> swapF
-
-node 2 will use them in the order of::
-
-	swapD/swapE -> swapA -> swapB -> swapC -> swapF
-
-Similaly, swapD and swapE will be used in a round robin mode before any
-other swap devices.
-
-node 3 will use them in the order of::
-
-	swapF -> swapA -> swapB -> swapC -> swapD -> swapE
-
-
-Implementation details
-======================
-
-The current code uses a priority based list, swap_avail_list, to decide
-which swap device to use and if multiple swap devices share the same
-priority, they are used round robin. This change here replaces the single
-global swap_avail_list with a per-numa-node list, i.e. for each numa node,
-it sees its own priority based list of available swap devices. Swap
-device's priority can be promoted on its matching node's swap_avail_list.
-
-The current swap device's priority is set as: user can set a >=0 value,
-or the system will pick one starting from -1 then downwards. The priority
-value in the swap_avail_list is the negated value of the swap device's
-due to plist being sorted from low to high. The new policy doesn't change
-the semantics for priority >=0 cases, the previous starting from -1 then
-downwards now becomes starting from -2 then downwards and -1 is reserved
-as the promoted value. So if multiple swap devices are attached to the same
-node, they will all be promoted to priority -1 on that node's plist and will
-be used round robin before any other swap devices.
include/linux/swap.h +1 -10
index 3473e4247ca3..f72c8e5e0635 100644
@@ -337,16 +337,7 @@ struct swap_info_struct {
 	struct work_struct discard_work; /* discard worker */
 	struct work_struct reclaim_work; /* reclaim worker */
 	struct list_head discard_clusters; /* discard clusters list */
-	struct plist_node avail_lists[]; /*
-					   * entries in swap_avail_heads, one
-					   * entry per node.
-					   * Must be last as the number of the
-					   * array is nr_node_ids, which is not
-					   * a fixed value so have to allocate
-					   * dynamically.
-					   * And it has to be an array so that
-					   * plist_for_each_* can work.
-					   */
+	struct plist_node avail_list;   /* entry in swap_avail_head */
 };
 
 static inline swp_entry_t page_swap_entry(struct page *page)
mm/swapfile.c +15 -94

240 lines not on this page · raw message

Signature · 1 line
2.41.0
#2 lore raw
kernel test robot noticed the following build errors:

Hi Baoquan,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.17-rc7 next-20250926]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/mm-swapfile-c-select-the-swap-device-with-default-priority-round-robin/20250926-235740
base:   linus/master
patch link:    https://lore.kernel.org/r/20250926155504.5122-2-bhe%40redhat.com
patch subject: [PATCH v2 1/1] mm/swapfile.c: select the swap device with default priority round robin
config: x86_64-buildonly-randconfig-002-20250927 (https://download.01.org/0day-ci/archive/20250927/[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/20250927/[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 >>):

>> mm/swapfile.c:2550:24: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2550 |         plist_add(&si->list, &swap_active_head);
         |                               ^~~~~~~~~~~~~~~~
         |                               swap_avail_head
   mm/swapfile.c:99:19: note: 'swap_avail_head' declared here
      99 | static PLIST_HEAD(swap_avail_head);
         |                   ^
   mm/swapfile.c:2655:27: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
         |                                  swap_avail_head
   include/linux/plist.h:173:30: note: expanded from macro 'plist_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |                                     ^
   include/linux/list.h:770:30: note: expanded from macro 'list_for_each_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                                     ^
   include/linux/list.h:612:14: note: expanded from macro 'list_first_entry'
     612 |         list_entry((ptr)->next, type, member)
         |                     ^
   include/linux/list.h:601:15: note: expanded from macro 'list_entry'
     601 |         container_of(ptr, type, member)
         |                      ^
   include/linux/container_of.h:20:26: note: expanded from macro 'container_of'
      20 |         void *__mptr = (void *)(ptr);                                   \
         |                                 ^
   mm/swapfile.c:99:19: note: 'swap_avail_head' declared here
      99 | static PLIST_HEAD(swap_avail_head);
         |                   ^
   mm/swapfile.c:2655:27: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
         |                                  swap_avail_head
   include/linux/plist.h:173:30: note: expanded from macro 'plist_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |                                     ^
   include/linux/list.h:770:30: note: expanded from macro 'list_for_each_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                                     ^
   include/linux/list.h:612:14: note: expanded from macro 'list_first_entry'
     612 |         list_entry((ptr)->next, type, member)
         |                     ^
   note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:507:63: note: expanded from macro '__same_type'
     507 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
      77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
         |                                                  ^
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
      78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                                        ^
   mm/swapfile.c:99:19: note: 'swap_avail_head' declared here
      99 | static PLIST_HEAD(swap_avail_head);
         |                   ^
   mm/swapfile.c:2655:27: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
         |                                  swap_avail_head
   include/linux/plist.h:173:30: note: expanded from macro 'plist_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |                                     ^
   include/linux/list.h:770:30: note: expanded from macro 'list_for_each_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                                     ^
   include/linux/list.h:612:14: note: expanded from macro 'list_first_entry'
     612 |         list_entry((ptr)->next, type, member)
         |                     ^
   note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:507:63: note: expanded from macro '__same_type'
     507 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
      77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
         |                                                  ^
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
      78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                                        ^
   mm/swapfile.c:99:19: note: 'swap_avail_head' declared here
      99 | static PLIST_HEAD(swap_avail_head);
         |                   ^
   mm/swapfile.c:2655:27: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
         |                                  swap_avail_head
   include/linux/plist.h:173:30: note: expanded from macro 'plist_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |                                     ^
   include/linux/list.h:771:32: note: expanded from macro 'list_for_each_entry'
     771 |              !list_entry_is_head(pos, head, member);                    \
         |                                       ^
   include/linux/list.h:761:30: note: expanded from macro 'list_entry_is_head'
     761 |         list_is_head(&pos->member, (head))
         |                                     ^
   mm/swapfile.c:99:19: note: 'swap_avail_head' declared here
      99 | static PLIST_HEAD(swap_avail_head);
         |                   ^
   mm/swapfile.c:2677:23: error: use of undeclared identifier 'swap_active_head'; did you mean 'swap_avail_head'?
    2677 |         plist_del(&p->list, &swap_active_head);
         |                              ^~~~~~~~~~~~~~~~
         |                              swap_avail_head

vim +2550 mm/swapfile.c

eb085574a7526c Ying Huang           2019-07-11  2542  
b85508d7de901c Barry Song           2024-08-08  2543  static void _enable_swap_info(struct swap_info_struct *si)
eb085574a7526c Ying Huang           2019-07-11  2544  {
b85508d7de901c Barry Song           2024-08-08  2545  	atomic_long_add(si->pages, &nr_swap_pages);
b85508d7de901c Barry Song           2024-08-08  2546  	total_swap_pages += si->pages;
40531542e28324 Cesar Eduardo Barros 2011-03-22  2547  
adfab836f4908d Dan Streetman        2014-06-04  2548  	assert_spin_locked(&swap_lock);
5b648db56b50e1 Baoquan He           2025-09-26  2549  
b85508d7de901c Barry Song           2024-08-08 @2550  	plist_add(&si->list, &swap_active_head);
c70699e555537b Ma Wupeng            2023-06-27  2551  
b228386cf237e6 Kairui Song          2025-01-14  2552  	/* Add back to available list */
b228386cf237e6 Kairui Song          2025-01-14  2553  	add_to_avail_list(si, true);

cf0cac0a093415 Cesar Eduardo Barros 2012-12-11 2554 } cf0cac0a093415 Cesar Eduardo Barros 2012-12-11 2555

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Baoquan He
kernel test robot noticed the following build warnings:

Hi Baoquan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.17-rc7 next-20250926]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/mm-swapfile-c-select-the-swap-device-with-default-priority-round-robin/20250926-235740
base:   linus/master
patch link:    https://lore.kernel.org/r/20250926155504.5122-2-bhe%40redhat.com
patch subject: [PATCH v2 1/1] mm/swapfile.c: select the swap device with default priority round robin
config: sparc-randconfig-001-20250927 (https://download.01.org/0day-ci/archive/20250928/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250928/[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/swapfile.c: In function '_enable_swap_info':
mm/swapfile.c:2550:31: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?

    2550 |         plist_add(&si->list, &swap_active_head);
         |                               ^~~~~~~~~~~~~~~~
         |                               swap_avail_head
   mm/swapfile.c:2550:31: note: each undeclared identifier is reported only once for each function it appears in
   In file included from include/linux/list.h:5,
                    from include/linux/wait.h:7,
                    from include/linux/wait_bit.h:8,
                    from include/linux/fs.h:7,
                    from include/linux/highmem.h:5,
                    from include/linux/bvec.h:10,
                    from include/linux/blk_types.h:10,
                    from include/linux/blkdev.h:9,
                    from mm/swapfile.c:9:
   mm/swapfile.c: In function '__do_sys_swapoff':
   mm/swapfile.c:2655:34: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
   include/linux/container_of.h:20:33: note: in definition of macro 'container_of'
      20 |         void *__mptr = (void *)(ptr);                                   \
         |                                 ^~~
   include/linux/list.h:612:9: note: in expansion of macro 'list_entry'
     612 |         list_entry((ptr)->next, type, member)
         |         ^~~~~~~~~~
   include/linux/list.h:770:20: note: in expansion of macro 'list_first_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                    ^~~~~~~~~~~~~~~~
   include/linux/plist.h:173:10: note: in expansion of macro 'list_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |          ^~~~~~~~~~~~~~~~~~~
   mm/swapfile.c:2655:9: note: in expansion of macro 'plist_for_each_entry'
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/init.h:5,
                    from include/linux/printk.h:6,
                    from include/asm-generic/bug.h:22,
                    from arch/sparc/include/asm/bug.h:25,
                    from include/linux/bug.h:5,
                    from include/linux/vfsdebug.h:5,
                    from include/linux/fs.h:5,
                    from include/linux/highmem.h:5,
                    from include/linux/bvec.h:10,
                    from include/linux/blk_types.h:10,
                    from include/linux/blkdev.h:9,
                    from mm/swapfile.c:9:
   include/linux/compiler_types.h:507:27: error: expression in static assertion is not an integer
     507 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
      78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                                        ^~~~
   include/linux/container_of.h:21:9: note: in expansion of macro 'static_assert'
      21 |         static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
         |         ^~~~~~~~~~~~~
   include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
      21 |         static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
         |                       ^~~~~~~~~~~
   include/linux/list.h:601:9: note: in expansion of macro 'container_of'
     601 |         container_of(ptr, type, member)
         |         ^~~~~~~~~~~~
   include/linux/list.h:612:9: note: in expansion of macro 'list_entry'
     612 |         list_entry((ptr)->next, type, member)
         |         ^~~~~~~~~~
   include/linux/list.h:770:20: note: in expansion of macro 'list_first_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                    ^~~~~~~~~~~~~~~~
   include/linux/plist.h:173:10: note: in expansion of macro 'list_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |          ^~~~~~~~~~~~~~~~~~~
   mm/swapfile.c:2655:9: note: in expansion of macro 'plist_for_each_entry'
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |         ^~~~~~~~~~~~~~~~~~~~
   mm/swapfile.c: In function '__has_usable_swap':
   mm/swapfile.c:3835:35: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?
    3835 |         return !plist_head_empty(&swap_active_head);
         |                                   ^~~~~~~~~~~~~~~~
         |                                   swap_avail_head
>> mm/swapfile.c:3836:1: warning: control reaches end of non-void function [-Wreturn-type]
    3836 | }
         | ^

vim +3836 mm/swapfile.c

a2468cc9bfdff6 Aaron Lu    2017-09-06  3831  
2cf855837b89d9 Tejun Heo   2018-07-03  3832  #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
0ff67f990bd457 Kairui Song 2025-03-14  3833  static bool __has_usable_swap(void)
0ff67f990bd457 Kairui Song 2025-03-14  3834  {
0ff67f990bd457 Kairui Song 2025-03-14  3835  	return !plist_head_empty(&swap_active_head);

0ff67f990bd457 Kairui Song 2025-03-14 @3836 }
0ff67f990bd457 Kairui Song 2025-03-14 3837

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#4 lore raw
Quoted 24 lines · kernel test robot

Hi Baoquan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.17-rc7 next-20250926]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/mm-swapfile-c-select-the-swap-device-with-default-priority-round-robin/20250926-235740
base:   linus/master
patch link:    https://lore.kernel.org/r/20250926155504.5122-2-bhe%40redhat.com
patch subject: [PATCH v2 1/1] mm/swapfile.c: select the swap device with default priority round robin
config: sparc-randconfig-001-20250927 (https://download.01.org/0day-ci/archive/20250928/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250928/[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]/

Quoted 7 lines

All warnings (new ones prefixed by >>):

mm/swapfile.c: In function '_enable_swap_info':

   mm/swapfile.c:2550:31: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?
    2550 |         plist_add(&si->list, &swap_active_head);
         |                               ^~~~~~~~~~~~~~~~
         |                               swap_avail_head

Sorry, I mistakenly removed the definition of swap_avail_head. I planned to remove swap_avail_head in later work, but mixed the draft code to this patch. I will post v3 to split patch as Chris suggested, will fix it this at the same time. Thanks for reporting this, please drop this v2 patch from testing.

Quoted 92 lines
   mm/swapfile.c:2550:31: note: each undeclared identifier is reported only once for each function it appears in
   In file included from include/linux/list.h:5,
                    from include/linux/wait.h:7,
                    from include/linux/wait_bit.h:8,
                    from include/linux/fs.h:7,
                    from include/linux/highmem.h:5,
                    from include/linux/bvec.h:10,
                    from include/linux/blk_types.h:10,
                    from include/linux/blkdev.h:9,
                    from mm/swapfile.c:9:
   mm/swapfile.c: In function '__do_sys_swapoff':
   mm/swapfile.c:2655:34: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |                                  ^~~~~~~~~~~~~~~~
   include/linux/container_of.h:20:33: note: in definition of macro 'container_of'
      20 |         void *__mptr = (void *)(ptr);                                   \
         |                                 ^~~
   include/linux/list.h:612:9: note: in expansion of macro 'list_entry'
     612 |         list_entry((ptr)->next, type, member)
         |         ^~~~~~~~~~
   include/linux/list.h:770:20: note: in expansion of macro 'list_first_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                    ^~~~~~~~~~~~~~~~
   include/linux/plist.h:173:10: note: in expansion of macro 'list_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |          ^~~~~~~~~~~~~~~~~~~
   mm/swapfile.c:2655:9: note: in expansion of macro 'plist_for_each_entry'
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/init.h:5,
                    from include/linux/printk.h:6,
                    from include/asm-generic/bug.h:22,
                    from arch/sparc/include/asm/bug.h:25,
                    from include/linux/bug.h:5,
                    from include/linux/vfsdebug.h:5,
                    from include/linux/fs.h:5,
                    from include/linux/highmem.h:5,
                    from include/linux/bvec.h:10,
                    from include/linux/blk_types.h:10,
                    from include/linux/blkdev.h:9,
                    from mm/swapfile.c:9:
   include/linux/compiler_types.h:507:27: error: expression in static assertion is not an integer
     507 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
      78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                                        ^~~~
   include/linux/container_of.h:21:9: note: in expansion of macro 'static_assert'
      21 |         static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
         |         ^~~~~~~~~~~~~
   include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
      21 |         static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
         |                       ^~~~~~~~~~~
   include/linux/list.h:601:9: note: in expansion of macro 'container_of'
     601 |         container_of(ptr, type, member)
         |         ^~~~~~~~~~~~
   include/linux/list.h:612:9: note: in expansion of macro 'list_entry'
     612 |         list_entry((ptr)->next, type, member)
         |         ^~~~~~~~~~
   include/linux/list.h:770:20: note: in expansion of macro 'list_first_entry'
     770 |         for (pos = list_first_entry(head, typeof(*pos), member);        \
         |                    ^~~~~~~~~~~~~~~~
   include/linux/plist.h:173:10: note: in expansion of macro 'list_for_each_entry'
     173 |          list_for_each_entry(pos, &(head)->node_list, mem.node_list)
         |          ^~~~~~~~~~~~~~~~~~~
   mm/swapfile.c:2655:9: note: in expansion of macro 'plist_for_each_entry'
    2655 |         plist_for_each_entry(p, &swap_active_head, list) {
         |         ^~~~~~~~~~~~~~~~~~~~
   mm/swapfile.c: In function '__has_usable_swap':
   mm/swapfile.c:3835:35: error: 'swap_active_head' undeclared (first use in this function); did you mean 'swap_avail_head'?
    3835 |         return !plist_head_empty(&swap_active_head);
         |                                   ^~~~~~~~~~~~~~~~
         |                                   swap_avail_head
Quoted 1 line
Quoted 1 line

mm/swapfile.c:3836:1: warning: control reaches end of non-void function [-Wreturn-type]

    3836 | }
         | ^

vim +3836 mm/swapfile.c

a2468cc9bfdff6 Aaron Lu    2017-09-06  3831  
2cf855837b89d9 Tejun Heo   2018-07-03  3832  #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
0ff67f990bd457 Kairui Song 2025-03-14  3833  static bool __has_usable_swap(void)
0ff67f990bd457 Kairui Song 2025-03-14  3834  {
0ff67f990bd457 Kairui Song 2025-03-14  3835  	return !plist_head_empty(&swap_active_head);

0ff67f990bd457 Kairui Song 2025-03-14 @3836 }
0ff67f990bd457 Kairui Song 2025-03-14 3837

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#5 lore raw
In reply to Baoquan He
Quoted 43 lines · Baoquan He

The detailed information about patch can be found in patch log. Here I would like to add testing related information.

On my system, it has 8 nodes, 64G RAM. So I created 4 zram devices of
size 16G. Doing this because I can't find system with 4 free SSD disk which can be used as swap devices. And nowadays, swap, zram become more and more popular, even default setup, so I create zram to test patch.

# free -h
               total        used        free      shared  buff/cache   available
Mem:            62Gi       1.6Gi        61Gi       4.8Mi       276Mi        61Gi
Swap:           63Gi          0B        63Gi

1) create zram
#My fedora will add one zram0 by default, I reset it because the zram size if not enough swapoff /dev/zram0

cd /sys/block/
echo 1 > zram0/reset
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add

echo 16G > zram0/disksize
echo 16G > zram1/disksize
echo 16G > zram2/disksize
echo 16G > zram3/disksize

mkswap /dev/zram0
mkswap /dev/zram1
mkswap /dev/zram2
mkswap /dev/zram3

swapon /dev/zram0
swapon /dev/zram1
swapon /dev/zram2
swapon /dev/zram3

2) Create memcg with 4G (this avoids noise from other anon process in system) cd /sys/fs/cgroup/
mkdir testing
echo 4G > testing/memory.max
echo 3G > testing/memory.high

Quoted 5 lines

3) Run usemem in memcg
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt

The usemem output is not easy to understand, I will attach my draft script in thread for easing result collecting and statistics.

1)
Yon can fetch usemem from here:
https://kernel.googlesource.com/pub/scm/linux/kernel/git/wfg/vm-scalability

2) In attachments, usemem-calc.sh is used to analyze raw data from usemem output, then output an unstandable result. You can copy below commands to run ten times or how many times you want on usemem.

for i in {1..10}; do
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt ~/usemem-calc.sh ~/vm-scalability/temp.txt
echo "The $i""th time to run usemem"
done

3) Please keep all the output of usemem-calc.sh to a file, then use result.sh to get an average value.

Any unclear part, please feel free to ask me privately or publicly in thread.

Thanks
Baoquan

author
#6 lore raw
Quoted 50 lines · Baoquan He
Quoted 43 lines · Baoquan He

The detailed information about patch can be found in patch log. Here I would like to add testing related information.

On my system, it has 8 nodes, 64G RAM. So I created 4 zram devices of
size 16G. Doing this because I can't find system with 4 free SSD disk which can be used as swap devices. And nowadays, swap, zram become more and more popular, even default setup, so I create zram to test patch.

# free -h
               total        used        free      shared  buff/cache   available
Mem:            62Gi       1.6Gi        61Gi       4.8Mi       276Mi        61Gi
Swap:           63Gi          0B        63Gi

1) create zram
#My fedora will add one zram0 by default, I reset it because the zram size if not enough swapoff /dev/zram0

cd /sys/block/
echo 1 > zram0/reset
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add

echo 16G > zram0/disksize
echo 16G > zram1/disksize
echo 16G > zram2/disksize
echo 16G > zram3/disksize

mkswap /dev/zram0
mkswap /dev/zram1
mkswap /dev/zram2
mkswap /dev/zram3

swapon /dev/zram0
swapon /dev/zram1
swapon /dev/zram2
swapon /dev/zram3

2) Create memcg with 4G (this avoids noise from other anon process in system) cd /sys/fs/cgroup/
mkdir testing
echo 4G > testing/memory.max
echo 3G > testing/memory.high

Quoted 5 lines

3) Run usemem in memcg
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt

The usemem output is not easy to understand, I will attach my draft script in thread for easing result collecting and statistics.

Quoted 6 lines

1)
Yon can fetch usemem from here:
https://kernel.googlesource.com/pub/scm/linux/kernel/git/wfg/vm-scalability

2) In attachments, usemem-calc.sh is used to analyze raw data from usemem output, then output an unstandable result. You can copy below

~~ understandable, sorry, typo

Quoted 16 lines

commands to run ten times or how many times you want on usemem.

for i in {1..10}; do
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt ~/usemem-calc.sh ~/vm-scalability/temp.txt
echo "The $i""th time to run usemem"
done

3) Please keep all the output of usemem-calc.sh to a file, then use result.sh to get an average value.

Any unclear part, please feel free to ask me privately or publicly in thread.

Thanks
Baoquan

author
#7 lore raw
In reply to Baoquan He
Quoted 5 lines · Baoquan He

The detailed information about patch can be found in patch log. Here I would like to add testing related information.

On my system, it has 8 nodes, 64G RAM. So I created 4 zram devices of
size 16G. Doing this because I can't find system with 4 free SSD disk

                                                        ~~~~~~~

This description is misleading, testing this patch needs multiple SSD disks, 2 disks is enough, more is better. Sorry I was dizzy when posting last night.

Quoted 9 lines

which can be used as swap devices. And nowadays, swap, zram become more and more popular, even default setup, so I create zram to test patch.

# free -h
               total        used        free      shared  buff/cache   available
Mem:            62Gi       1.6Gi        61Gi       4.8Mi       276Mi        61Gi
Swap:           63Gi          0B        63Gi

1) create zram
#My fedora will add one zram0 by default, I reset it because the zram size if not enough

                                                                             ~s/if/is/
Quoted 18 lines

swapoff /dev/zram0

cd /sys/block/
echo 1 > zram0/reset
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add
cat /sys/class/zram-control/hot_add

echo 16G > zram0/disksize
echo 16G > zram1/disksize
echo 16G > zram2/disksize
echo 16G > zram3/disksize

mkswap /dev/zram0
mkswap /dev/zram1
mkswap /dev/zram2
mkswap /dev/zram3

Quoted 6 lines

swapon /dev/zram0
swapon /dev/zram1
swapon /dev/zram2
swapon /dev/zram3

2) Create memcg with 4G (this avoids noise from other anon process in system)

~~~~~~~~~~~
it should be anon mem regions from other process

Quoted 11 lines

cd /sys/fs/cgroup/
mkdir testing
echo 4G > testing/memory.max
echo 3G > testing/memory.high

3) Run usemem in memcg
cgexec -g memory:testing ~/vm-scalability/usemem --init-time -O -y -x -n 31 2G > ~/vm-scalability/temp.txt

The usemem output is not easy to understand, I will attach my draft script in thread for easing result collecting and statistics.