Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

swap: add a limit for readahead page-cluster value

Currenty there is no upper limit for /proc/sys/vm/page-cluster, and it's a
bit shift value, so it could result in overflow of the 32-bit integer.
Add a reasonable upper limit for it, read-in at most 2**31 pages, which is
a large enough value for readahead.

Link: https://lkml.kernel.org/r/20221023162533.81561-1-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
ea0ffd0c 5033091d

+4 -1
+1
include/linux/mm.h
··· 74 74 75 75 extern void * high_memory; 76 76 extern int page_cluster; 77 + extern const int page_cluster_max; 77 78 78 79 #ifdef CONFIG_SYSCTL 79 80 extern int sysctl_legacy_va_layout;
+1
kernel/sysctl.c
··· 2125 2125 .mode = 0644, 2126 2126 .proc_handler = proc_dointvec_minmax, 2127 2127 .extra1 = SYSCTL_ZERO, 2128 + .extra2 = (void *)&page_cluster_max, 2128 2129 }, 2129 2130 { 2130 2131 .procname = "dirtytime_expire_seconds",
+2 -1
mm/swap.c
··· 43 43 #define CREATE_TRACE_POINTS 44 44 #include <trace/events/pagemap.h> 45 45 46 - /* How many pages do we try to swap or page in/out together? */ 46 + /* How many pages do we try to swap or page in/out together? As a power of 2 */ 47 47 int page_cluster; 48 + const int page_cluster_max = 31; 48 49 49 50 /* Protecting only lru_rotate.fbatch which requires disabling interrupts */ 50 51 struct lru_rotate {