diff --git a/kernel-arm64.config b/kernel-arm64.config index 01af04f..ff7a0f3 100644 --- a/kernel-arm64.config +++ b/kernel-arm64.config @@ -961,6 +961,9 @@ CONFIG_COREDUMP=y # CONFIG_SELECT_MEMORY_MODEL=y CONFIG_SPARSEMEM_MANUAL=y +CONFIG_UNEVICTABLE_ACTIVEFILE=y +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW=102400 +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN=51200 CONFIG_SPARSEMEM=y CONFIG_NEED_MULTIPLE_NODES=y CONFIG_SPARSEMEM_EXTREME=y @@ -1006,14 +1009,14 @@ CONFIG_ZSWAP=y # CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4HC is not set CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD=y CONFIG_ZSWAP_COMPRESSOR_DEFAULT="zstd" -CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y -# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set +# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD=y # CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set -CONFIG_ZSWAP_ZPOOL_DEFAULT="zbud" -# CONFIG_ZSWAP_DEFAULT_ON is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT="z3fold" +CONFIG_ZSWAP_DEFAULT_ON=y CONFIG_ZPOOL=y CONFIG_ZBUD=y -CONFIG_Z3FOLD=m +CONFIG_Z3FOLD=y CONFIG_ZSMALLOC=y # CONFIG_ZSMALLOC_STAT is not set CONFIG_GENERIC_EARLY_IOREMAP=y diff --git a/kernel-i586.config b/kernel-i586.config index 4d243bb..af84c3c 100644 --- a/kernel-i586.config +++ b/kernel-i586.config @@ -974,6 +974,9 @@ CONFIG_COREDUMP=y # CONFIG_SELECT_MEMORY_MODEL=y CONFIG_SPARSEMEM_MANUAL=y +CONFIG_UNEVICTABLE_ACTIVEFILE=y +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW=102400 +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN=51200 CONFIG_SPARSEMEM=y CONFIG_NEED_MULTIPLE_NODES=y CONFIG_SPARSEMEM_EXTREME=y @@ -1023,14 +1026,14 @@ CONFIG_ZSWAP=y # CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4HC is not set CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD=y CONFIG_ZSWAP_COMPRESSOR_DEFAULT="zstd" -CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y -# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set +# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD=y # CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set -CONFIG_ZSWAP_ZPOOL_DEFAULT="zbud" -# CONFIG_ZSWAP_DEFAULT_ON is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT="z3fold" +CONFIG_ZSWAP_DEFAULT_ON=y CONFIG_ZPOOL=y CONFIG_ZBUD=y -CONFIG_Z3FOLD=m +CONFIG_Z3FOLD=y CONFIG_ZSMALLOC=y # CONFIG_ZSMALLOC_STAT is not set CONFIG_GENERIC_EARLY_IOREMAP=y @@ -8501,7 +8504,7 @@ CONFIG_AD2S1210=m CONFIG_FB_SM750=m CONFIG_STAGING_MEDIA=y -CONFIG_INTEL_ATOMISP=y +# CONFIG_INTEL_ATOMISP is not set # CONFIG_VIDEO_ZORAN is not set CONFIG_VIDEO_IPU3_IMGU=m @@ -8647,6 +8650,7 @@ CONFIG_THINKPAD_ACPI_DEBUGFACILITIES=y CONFIG_THINKPAD_ACPI_VIDEO=y CONFIG_THINKPAD_ACPI_HOTKEY_POLL=y CONFIG_INTEL_ATOMISP2_LED=m +CONFIG_INTEL_ATOMISP2_PM=m CONFIG_INTEL_CHT_INT33FE=m CONFIG_INTEL_HID_EVENT=m CONFIG_INTEL_INT0002_VGPIO=m diff --git a/kernel-x86_64.config b/kernel-x86_64.config index 5081c3f..31545b5 100644 --- a/kernel-x86_64.config +++ b/kernel-x86_64.config @@ -982,6 +982,9 @@ CONFIG_COREDUMP=y # CONFIG_SELECT_MEMORY_MODEL=y CONFIG_SPARSEMEM_MANUAL=y +CONFIG_UNEVICTABLE_ACTIVEFILE=y +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW=102400 +CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN=51200 CONFIG_SPARSEMEM=y CONFIG_NEED_MULTIPLE_NODES=y CONFIG_SPARSEMEM_EXTREME=y @@ -1031,14 +1034,14 @@ CONFIG_ZSWAP=y # CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4HC is not set CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD=y CONFIG_ZSWAP_COMPRESSOR_DEFAULT="zstd" -CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD=y -# CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD is not set +# CONFIG_ZSWAP_ZPOOL_DEFAULT_ZBUD is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT_Z3FOLD=y # CONFIG_ZSWAP_ZPOOL_DEFAULT_ZSMALLOC is not set -CONFIG_ZSWAP_ZPOOL_DEFAULT="zbud" -# CONFIG_ZSWAP_DEFAULT_ON is not set +CONFIG_ZSWAP_ZPOOL_DEFAULT="z3fold" +CONFIG_ZSWAP_DEFAULT_ON=y CONFIG_ZPOOL=y CONFIG_ZBUD=y -CONFIG_Z3FOLD=m +CONFIG_Z3FOLD=y CONFIG_ZSMALLOC=y # CONFIG_ZSMALLOC_STAT is not set CONFIG_GENERIC_EARLY_IOREMAP=y @@ -8510,7 +8513,7 @@ CONFIG_AD2S1210=m CONFIG_FB_SM750=m CONFIG_STAGING_MEDIA=y -CONFIG_INTEL_ATOMISP=y +# CONFIG_INTEL_ATOMISP is not set # CONFIG_VIDEO_ZORAN is not set CONFIG_VIDEO_IPU3_IMGU=m @@ -8656,6 +8659,7 @@ CONFIG_THINKPAD_ACPI_DEBUGFACILITIES=y CONFIG_THINKPAD_ACPI_VIDEO=y CONFIG_THINKPAD_ACPI_HOTKEY_POLL=y CONFIG_INTEL_ATOMISP2_LED=m +CONFIG_INTEL_ATOMISP2_PM=m CONFIG_INTEL_CHT_INT33FE=m CONFIG_INTEL_HID_EVENT=m CONFIG_INTEL_INT0002_VGPIO=m diff --git a/kernel.spec b/kernel.spec index 1940a5f..770a109 100644 --- a/kernel.spec +++ b/kernel.spec @@ -24,7 +24,7 @@ %define sublevel 2 # Release number. Increase this before a rebuild. -%define rpmrel 4 +%define rpmrel 5 %define fullrpmrel %{rpmrel} %define rpmtag %{disttag} @@ -309,8 +309,16 @@ Patch302: 0001-sign-file-full-functionality-with-modern-LibreSSL.patch Patch305: 0001-crypto-support-loading-GOST-signed-kernel-modules.patch # Allow to off modules signature check dynamically Patch306: 0001-ROSA-ima-allow-to-off-modules-signature-check-dynami.patch -# (WIP, experimantal) https://www.linux.org.ru/news/kernel/16052362 -#Patch307: rosa-le9.diff +# Experimental patch to reduce freezes in low memory conditions +# Config values are the following: +# CONFIG_UNEVICTABLE_ACTIVEFILE=y +# CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW=102400 (100 MB) +# CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN=51200 (50 MB) +# + zswap is enabled by default +# 50 MB is default value of min_filelist_kbytes in Chromium OS +# https://chromium.googlesource.com/chromiumos/third_party/kernel-next/+/545e2917dbd863760a51379de8c26631e667c563%5E!/ +# 256 and 512 MB values are too big as a distro default because many systems have 512MB-2GB RAM +# TODO: tune 50 and 100 MB to some not random and mathemetically explainable values # https://www.linux.org.ru/news/kernel/16052362?cid=16075323 Patch307: le9pf.diff diff --git a/rosa-le9.diff b/rosa-le9.diff deleted file mode 100644 index 027a550..0000000 --- a/rosa-le9.diff +++ /dev/null @@ -1,216 +0,0 @@ -diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst -index f455fa00c00f..a6146e0fc88a 100644 ---- a/Documentation/admin-guide/sysctl/vm.rst -+++ b/Documentation/admin-guide/sysctl/vm.rst -@@ -69,6 +69,8 @@ Currently, these files are in /proc/sys/vm: - - stat_refresh - - numa_stat - - swappiness -+- unevictable_activefile_kbytes_low -+- unevictable_activefile_kbytes_min - - unprivileged_userfaultfd - - user_reserve_kbytes - - vfs_cache_pressure -@@ -881,6 +883,31 @@ privileged users (with SYS_CAP_PTRACE capability). - The default value is 1. - - -+unevictable_activefile_kbytes_low -+================================= -+ -+Keep some active file pages still mapped under memory pressure to avoid -+potential disk thrashing that may occur due to evicting running executables -+code. This implements soft eviction throttling, and some file pages can still -+be discarded. -+ -+Setting it to 0 effectively disables this feature. -+ -+The default value is 512 MiB. -+ -+ -+unevictable_activefile_kbytes_min -+================================= -+ -+Keep all active file pages still mapped under memory pressure to avoid -+potential disk thrashing that may occur due to evicting running executables -+code. This is the hard limit. -+ -+Setting it to 0 effectively disables this feature. -+ -+The default value is 256 MiB. -+ -+ - user_reserve_kbytes - =================== - -diff --git a/kernel/sysctl.c b/kernel/sysctl.c -index afad085960b8..1a2423c7f4a3 100644 ---- a/kernel/sysctl.c -+++ b/kernel/sysctl.c -@@ -111,6 +111,22 @@ - static int sixty = 60; - #endif - -+#if defined(CONFIG_UNEVICTABLE_ACTIVEFILE) -+#if CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW < 0 -+#error "CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW should be >= 0" -+#endif -+#if CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN < 0 -+#error "CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN should be >= 0" -+#endif -+#if CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW < CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN -+#error "CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW should be >= CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN" -+#endif -+unsigned long sysctl_unevictable_activefile_kbytes_low __read_mostly = -+ CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_LOW; -+unsigned long sysctl_unevictable_activefile_kbytes_min __read_mostly = -+ CONFIG_UNEVICTABLE_ACTIVEFILE_KBYTES_MIN; -+#endif -+ - static int __maybe_unused neg_one = -1; - static int __maybe_unused two = 2; - static int __maybe_unused four = 4; -@@ -3081,6 +3097,26 @@ static struct ctl_table vm_table[] = { - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -+#endif -+#if defined(CONFIG_UNEVICTABLE_ACTIVEFILE) -+ { -+ .procname = "unevictable_activefile_kbytes_low", -+ .data = &sysctl_unevictable_activefile_kbytes_low, -+ .maxlen = sizeof(sysctl_unevictable_activefile_kbytes_low), -+ .mode = 0644, -+ .proc_handler = proc_doulongvec_minmax, -+ .extra1 = &sysctl_unevictable_activefile_kbytes_min, -+ .extra2 = &long_max, -+ }, -+ { -+ .procname = "unevictable_activefile_kbytes_min", -+ .data = &sysctl_unevictable_activefile_kbytes_min, -+ .maxlen = sizeof(sysctl_unevictable_activefile_kbytes_min), -+ .mode = 0644, -+ .proc_handler = proc_doulongvec_minmax, -+ .extra1 = &zero_ul, -+ .extra2 = &sysctl_unevictable_activefile_kbytes_low, -+ }, - #endif - { - .procname = "user_reserve_kbytes", -diff --git a/mm/Kconfig b/mm/Kconfig -index 390165ffbb0f..055b8b4a893f 100644 ---- a/mm/Kconfig -+++ b/mm/Kconfig -@@ -63,6 +63,41 @@ config SPARSEMEM_MANUAL - - endchoice - -+config UNEVICTABLE_ACTIVEFILE -+ bool "Keep some active file pages under memory pressure" -+ depends on SYSCTL -+ def_bool y -+ help -+ Keep some active file pages still mapped under memory pressure to avoid -+ potential disk thrashing that may occur due to evicting running executables -+ code. -+ -+ The UNEVICTABLE_ACTIVEFILE_KBYTES_LOW value defines a threshold to activate -+ file pages eviction throttling. The vm.unevictable_activefile_kbytes_low -+ sysctl knob is used to change the amount in the runtime (setting it to 0 -+ effectively disables this feature). -+ -+ Recommended value: 153600 for typical desktop workload. -+ -+ The UNEVICTABLE_ACTIVEFILE_KBYTES_MIN value sets the amount of pages to keep -+ as a hard limit. The vm.unevictable_activefile_kbytes_min sysctl knob is used -+ to change the amount in the runtime (setting it to 0 effectively disables -+ this feature). -+ -+ Recommended value: 51200 for typical desktop workload. -+ -+ See also: Documentation/admin-guide/sysctl/vm.rst -+ -+config UNEVICTABLE_ACTIVEFILE_KBYTES_LOW -+ int "Default value for vm.unevictable_activefile_kbytes_low" -+ depends on UNEVICTABLE_ACTIVEFILE -+ default "153600" -+ -+config UNEVICTABLE_ACTIVEFILE_KBYTES_MIN -+ int "Default value for vm.unevictable_activefile_kbytes_min" -+ depends on UNEVICTABLE_ACTIVEFILE -+ default "51200" -+ - config DISCONTIGMEM - def_bool y - depends on (!SELECT_MEMORY_MODEL && ARCH_DISCONTIGMEM_ENABLE) || DISCONTIGMEM_MANUAL -diff --git a/mm/vmscan.c b/mm/vmscan.c -index 7b4e31eac2cf..a14daf648df1 100644 ---- a/mm/vmscan.c -+++ b/mm/vmscan.c -@@ -166,6 +166,11 @@ struct scan_control { - #define prefetchw_prev_lru_page(_page, _base, _field) do { } while (0) - #endif - -+#if defined(CONFIG_UNEVICTABLE_ACTIVEFILE) -+extern unsigned long sysctl_unevictable_activefile_kbytes_low; -+extern unsigned long sysctl_unevictable_activefile_kbytes_min; -+#endif -+ - /* - * From 0 .. 200. Higher means more swappy. - */ -@@ -2225,6 +2230,10 @@ enum scan_balance { - SCAN_FILE, - }; - -+#if defined(CONFIG_UNEVICTABLE_ACTIVEFILE) -+#define K(x) ((x) << (PAGE_SHIFT - 10)) -+#endif -+ - /* - * Determine how aggressively the anon and file LRU lists should be - * scanned. The relative value of each set of LRU lists is determined -@@ -2290,7 +2299,32 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, - scan_balance = SCAN_FILE; - goto out; - } -+ -+#ifdef CONFIG_UNEVICTABLE_ACTIVEFILE -+ bool skip_evecting_active_file; -+ skip_evecting_active_file = false; -+ unsigned long kib_active_file_now = K(global_node_page_state(NR_ACTIVE_FILE)); -+ if (kib_active_file_now <= sysctl_unevictable_activefile_kbytes_min) { -+ skip_evecting_active_file = true; -+ goto cua_done; -+ } else if (kib_active_file_now < sysctl_unevictable_activefile_kbytes_low && -+ kib_active_file_now > sysctl_unevictable_activefile_kbytes_min) { -+ /* Integer division: taking decision whether to skip evicting active file or not */ -+ if (( -+ (kib_active_file_now - sysctl_unevictable_activefile_kbytes_min) / -+ (sysctl_unevictable_activefile_kbytes_low - sysctl_unevictable_activefile_kbytes_min) -+ ) < 1) -+ skip_evecting_active_file = true; -+ } else { -+ goto scan_fract; -+ } -+cua_done: -+ /* Skip not needed calculations */ -+ scan_balance = SCAN_ANON; -+ goto out; -+#endif - -+scan_fract: - scan_balance = SCAN_FRACT; - /* - * Calculate the pressure balance between anon and file pages. -@@ -2412,6 +2446,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, - /* Scan one type exclusively */ - if ((scan_balance == SCAN_FILE) != file) - scan = 0; -+#ifdef CONFIG_UNEVICTABLE_ACTIVEFILE -+ if ((skip_evecting_active_file) && (lru == LRU_ACTIVE_FILE)) -+ scan = 0; -+#endif - break; - default: - /* Look ma, no brain */