[PATCH 4/4] f2fs: add swap space for memory using

From: Guowei Du
Date: Mon Jun 27 2022 - 23:45:41 EST


From: duguowei <duguowei@xxxxxxxxxx>

If device enables swap file, enlarging the memory usage for each
monitored item. It can be adjusted by ram_thresh sysfs node.

Signed-off-by: duguowei <duguowei@xxxxxxxxxx>
---
fs/f2fs/node.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 836c79a20afc..f1cf3d2bc7c2 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -54,9 +54,12 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
return true;

si_meminfo(&val);
+ si_swapinfo(&val);

/* only uses low memory */
avail_ram = val.totalram - val.totalhigh;
+ /* if there is swap space, use it too.*/
+ avail_ram += val.totalswap;

/*
* give 25%, 25%, 50%, 50%, 50% memory for each components respectively
@@ -96,7 +99,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
res = mem_size < (avail_ram * nm_i->ram_thresh / 100);
} else if (type == COMPRESS_PAGE) {
#ifdef CONFIG_F2FS_FS_COMPRESSION
- unsigned long free_ram = val.freeram;
+ unsigned long free_ram = val.freeram + val.freeswap;

/*
* free memory is lower than watermark or cached page count
--
2.36.1