From 2e5b7c425f82041e3b51fb318df8d8e5de9b9796 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 23 Apr 2020 08:28:35 -0700 Subject: [PATCH] logcatd: unset pinning log files commit 5327d931acc2 ("logcatd: fallocate and fadvise to logcat files") introduced pinning log files in order to avoid f2fs fragmentation. But, logcatd does not guarantee to write data within fallocated 2MB space. So, we can see some bytes written beyond 2MB boundary which results in pinning small chunks across the filesystem. This makes F2FS GC have to unset the pinning blocks via GC loop. If this happens during checkpoint=disable at booting time, we can see long delay to mount /data accordingly. Bug: 136483670 Bug: 137180754 Bug: 149418646 Fixes: 5327d931acc2 ("logcatd: fallocate and fadvise to logcat files") Signed-off-by: Jaegeuk Kim Change-Id: I986221d6d1da9b8e46e63d1be98ddf0ce4cb099f --- logcat/logcat.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 9a0602393..8185f0165 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -123,6 +123,18 @@ static int openLogFile(const char* pathname, size_t sizeKB) { return fd; } +static void closeLogFile(const char* pathname) { + int fd = open(pathname, O_WRONLY | O_CLOEXEC); + if (fd == -1) { + return; + } + + // no need to check errors + __u32 set = 0; + ioctl(fd, F2FS_IOC_SET_PIN_FILE, &set); + close(fd); +} + void Logcat::RotateLogs() { // Can't rotate logs if we're not outputting to a file if (!output_file_name_) return; @@ -153,6 +165,8 @@ void Logcat::RotateLogs() { break; } + closeLogFile(file0.c_str()); + int err = rename(file0.c_str(), file1.c_str()); if (err < 0 && errno != ENOENT) {