diff options
author | Jaegeuk Kim <jaegeuk@google.com> | 2019-09-16 16:30:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-09-16 16:30:05 +0000 |
commit | cf4845b153edf7f3da9ab529b0d74d11a2c24c3f (patch) | |
tree | 9fd9ca43818056c21b0e23475363b951e999d465 | |
parent | 17438477cbb69d81fe9deef8ce0d0733b52bdb28 (diff) | |
parent | 5327d931acc20ce524e57cb5412ebf2c8b15b34d (diff) |
Merge "logcatd: fallocate and fadvise to logcat files"
-rw-r--r-- | logcat/logcat.cpp | 24 | ||||
-rw-r--r-- | logcat/logcatd.rc | 2 |
2 files changed, 21 insertions, 5 deletions
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index e2711af94..4dcb3383e 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -32,6 +32,7 @@ #include <stdlib.h> #include <string.h> #include <sys/cdefs.h> +#include <sys/ioctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> @@ -158,8 +159,22 @@ static void logcat_panic(android_logcat_context_internal* context, enum helpType showHelp, const char* fmt, ...) __printflike(3, 4); -static int openLogFile(const char* pathname) { - return open(pathname, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); +#ifndef F2FS_IOC_SET_PIN_FILE +#define F2FS_IOCTL_MAGIC 0xf5 +#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) +#endif + +static int openLogFile(const char* pathname, size_t sizeKB) { + int fd = open(pathname, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); + if (fd < 0) { + return fd; + } + + // no need to check errors + __u32 set = 1; + ioctl(fd, F2FS_IOC_SET_PIN_FILE, &set); + fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, (sizeKB << 10)); + return fd; } static void close_output(android_logcat_context_internal* context) { @@ -192,6 +207,7 @@ static void close_output(android_logcat_context_internal* context) { if (context->fds[1] == context->output_fd) { context->fds[1] = -1; } + posix_fadvise(context->output_fd, 0, 0, POSIX_FADV_DONTNEED); close(context->output_fd); } context->output_fd = -1; @@ -276,7 +292,7 @@ static void rotateLogs(android_logcat_context_internal* context) { } } - context->output_fd = openLogFile(context->outputFileName); + context->output_fd = openLogFile(context->outputFileName, context->logRotateSizeKBytes); if (context->output_fd < 0) { logcat_panic(context, HELP_FALSE, "couldn't open output file"); @@ -398,7 +414,7 @@ static void setupOutputAndSchedulingPolicy( close_output(context); - context->output_fd = openLogFile(context->outputFileName); + context->output_fd = openLogFile(context->outputFileName, context->logRotateSizeKBytes); if (context->output_fd < 0) { logcat_panic(context, HELP_FALSE, "couldn't open output file"); diff --git a/logcat/logcatd.rc b/logcat/logcatd.rc index 26c9de388..e98618440 100644 --- a/logcat/logcatd.rc +++ b/logcat/logcatd.rc @@ -52,7 +52,7 @@ on property:logd.logpersistd.enable=false stop logcatd # logcatd service -service logcatd /system/bin/logcatd -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r ${logd.logpersistd.rotate_kbytes:-1024} -n ${logd.logpersistd.size:-256} --id=${ro.build.id} +service logcatd /system/bin/logcatd -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r ${logd.logpersistd.rotate_kbytes:-2048} -n ${logd.logpersistd.size:-256} --id=${ro.build.id} class late_start disabled # logd for write to /data/misc/logd, log group for read from log daemon |