@@ -65,21 +65,69 @@ def __init__(self) -> None:
6565 self ._config : SwapConfig | None = None
6666
6767 def load (self ) -> SwapConfig :
68- """Load configuration from system files."""
68+ """Load configuration from system files.
69+
70+ Priority:
71+ 1. /etc/systemd/swap.conf (user config)
72+ 2. /usr/share/systemd-swap/swap-default.conf (defaults)
73+ 3. Current kernel values from /sys/module/zswap/parameters/ (fallback)
74+ """
6975 config = SwapConfig ()
7076
77+ # Track which values were explicitly set in config files
78+ explicitly_set : set [str ] = set ()
79+
7180 if DEFAULT_CONFIG .exists ():
7281 default_values = self ._parse_config_file (DEFAULT_CONFIG )
82+ explicitly_set .update (default_values .keys ())
7383 config = self ._apply_values (config , default_values )
7484
7585 if CONFIG_FILE .exists ():
7686 user_values = self ._parse_config_file (CONFIG_FILE )
87+ explicitly_set .update (user_values .keys ())
7788 config = self ._apply_values (config , user_values )
7889
90+ # Read current kernel values for parameters not explicitly configured
91+ self ._apply_kernel_values (config , explicitly_set )
92+
7993 self ._config = config
8094 logger .info ("Configuration loaded" )
8195 return config
8296
97+ def _apply_kernel_values (
98+ self , config : SwapConfig , explicitly_set : set [str ]
99+ ) -> None :
100+ """Read current kernel values for parameters not in config files.
101+
102+ This ensures the GUI shows the actual system state, not hardcoded defaults.
103+ """
104+ zswap_params = Path ("/sys/module/zswap/parameters" )
105+
106+ # Read zswap compressor from kernel if not in config
107+ if "zswap_compressor" not in explicitly_set and zswap_params .is_dir ():
108+ compressor_path = zswap_params / "compressor"
109+ if compressor_path .exists ():
110+ try :
111+ kernel_compressor = compressor_path .read_text ().strip ()
112+ with contextlib .suppress (ValueError ):
113+ config .zswap .compressor = Compressor (kernel_compressor )
114+ logger .debug (
115+ "Using kernel zswap compressor: %s" , kernel_compressor
116+ )
117+ except OSError :
118+ pass
119+
120+ # Read zswap max_pool_percent from kernel if not in config
121+ if "zswap_max_pool_percent" not in explicitly_set and zswap_params .is_dir ():
122+ pool_path = zswap_params / "max_pool_percent"
123+ if pool_path .exists ():
124+ try :
125+ kernel_pool = pool_path .read_text ().strip ()
126+ config .zswap .max_pool_percent = int (kernel_pool )
127+ logger .debug ("Using kernel zswap max_pool_percent: %s" , kernel_pool )
128+ except (OSError , ValueError ):
129+ pass
130+
83131 def get (self ) -> SwapConfig :
84132 """Get current config, loading if necessary."""
85133 if self ._config is None :
0 commit comments