From 191afb8903afd93149be99d436f00b574bd16798 Mon Sep 17 00:00:00 2001 From: Yuan Wang Date: Fri, 9 May 2025 10:05:37 +0800 Subject: [PATCH] Reclaim page cache memory used by the AOF file after loading (#13811) We can reclaim page cache memory used by the AOF file after loading, since we don't read AOF again, corresponding to https://github.com/redis/redis/pull/11248 There is a test after loading 9.5GB AOF, this PR uses much less `buff/cache` than unstable. **Unstable** ``` $ free -m total used free shared buff/cache available Mem: 31293 16181 4562 13 10958 15111 Swap: 0 0 0 ``` **This PR** ``` $ free -m total used free shared buff/cache available Mem: 31293 15391 15854 13 439 15902 Swap: 0 0 0 ``` --------- Co-authored-by: debing.sun --- src/aof.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aof.c b/src/aof.c index ae8bec7a3..06cd51c79 100644 --- a/src/aof.c +++ b/src/aof.c @@ -1725,7 +1725,10 @@ cleanup: if (fakeClient) freeClient(fakeClient); server.current_client = old_cur_client; server.executing_client = old_exec_client; + int fd = dup(fileno(fp)); fclose(fp); + /* Reclaim page cache memory used by the AOF file in background. */ + if (fd >= 0) bioCreateCloseJob(fd, 0, 1); sdsfree(aof_filepath); return ret; }