Problems: In environments that require high-performance file access, the tmpfs is often employed. It's important to note that the memory pages used by tmpfs are eligible to be swapped out. A potential efficiency issue arises when the system also uses zram and the tmpfs contains pre-compressed files (such as .gz files). Under memory pressure, the kernel may select the memory pages belonging to these .gz files to be swapped out into zram. However, since the data within .gz files is already compressed, zram gains negligible benefit from compressing them a second time and can hardly reduce their size further. This process not only fails to free up a meaningful amount of memory but also unnecessarily consumes the limited capacity of the zram device, resulting in a net waste of resources. Solution: This patch introduces a feature that marks memory pages of files with specific extensions (e.g., .gz) in a tmpfs filesystem as Unevictable. This prevents these in-memory compressed files from being swapped out to zram, thereby effectively mitigating the issue described above. Usage: This feature is controlled by a global switch that dynamically enables or disables the functionality. It is disabled by default. Disable: echo 0 > /sys/fs/shmem/extension_list_enable Enable: echo 1 > /sys/fs/shmem/extension_list_enable The file /sys/fs/shmem/extension_list is used to configure which file extensions are affected by this feature. the default list of configured suffixes: cat /sys/fs/shmem/extension_list unevictable file extension: gz bz2 xz Add a new file extension: echo 'zip' > /sys/fs/shmem/extension_list Remove a file extension: echo '!zip' > /sys/fs/shmem/extension_list Signed-off-by: Chen Junlin <chen.junlin@zte.com.cn>
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/5838