Description of problem: The ramdisk memory utilization can only go up when data is written to new pages. Implement discard to provide the possibility to reduce memory usage for pages no longer in use. Aligned discards will free the associated pages, if any, and determinisitically return zeroed data until written again. See upstream: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9ead7efc6f3f2b46c4ec68209bca4888cfbd4c19 Version-Release number of selected component (if applicable): How reproducible: #!/bin/bash modprobe brd rd_size=2048000 mkfs.xfs /dev/ram0 mount -o discard /dev/ram0 /mnt echo create before free -m dd if=/dev/zero of=/mnt/testfile-400M oflag=direct bs=1M count=400 &> /dev/null echo create after free -m rm -fr /mnt/testfile-400M sync echo remove after free -m umount /mnt Steps to Reproduce: 1. 2. 3. Actual results: "used" memory will not decrease. Expected results: "used" memory will decrease. Additional info: This feature has been merged since kernel 6.8, Anolis OS can support it.
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/4187
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/4188
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/4190
Merged.