diff options
author | 2022-01-19 17:06:08 -0800 | |
---|---|---|
committer | 2022-02-17 11:08:34 -0800 | |
commit | a7c4bd1afd8a3b73a2f92db6b115e55ae6b8a39e (patch) | |
tree | 91ce37ba0cee5ea98ca686224872d1c8a3899bbd | |
parent | 00ff352c34cb46d96156cdef69a6acf0bdfa5356 (diff) |
dumpstate: improve performance
Two changes:
1. There were some seemingly-unnecessary fsyncs scattered throughout
dumpstate. Remove those.
2. Profiling revealed that a significant amount of dumpstate's CPU
overhead was spent copying/destroying PTEs around fork/exec. Switch to
vfork() to avoid the PTE copies.
Test: bug reports work
Bug: 215574756
Change-Id: Ib202fd5c8d1f37548ee53bd64eaf4e114098a062
-rw-r--r-- | cmds/dumpstate/DumpstateUtil.cpp | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/cmds/dumpstate/DumpstateUtil.cpp b/cmds/dumpstate/DumpstateUtil.cpp index 81baf855f0..aa42541a66 100644 --- a/cmds/dumpstate/DumpstateUtil.cpp +++ b/cmds/dumpstate/DumpstateUtil.cpp @@ -247,7 +247,6 @@ int DumpFileToFd(int out_fd, const std::string& title, const std::string& path) dprintf(out_fd, "*** Error dumping %s (%s): %s\n", path.c_str(), title.c_str(), strerror(err)); } - fsync(out_fd); return -1; } return DumpFileFromFdToFd(title, path, fd.get(), out_fd, PropertiesHelper::IsDryRun()); @@ -295,7 +294,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri if (!title.empty()) { dprintf(fd, "------ %s (%s) ------\n", title.c_str(), command); - fsync(fd); } const std::string& logging_message = options.LoggingMessage(); @@ -314,14 +312,13 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri // There is no title, but we should still print a dry-run message dprintf(fd, "%s: skipped on dry run\n", command_string.c_str()); } - fsync(fd); return 0; } const char* path = args[0]; uint64_t start = Nanotime(); - pid_t pid = fork(); + pid_t pid = vfork(); /* handle error case */ if (pid < 0) { @@ -338,7 +335,7 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri strerror(errno)); } MYLOGE("*** could not drop root before running %s: %s\n", command, strerror(errno)); - return -1; + _exit(EXIT_FAILURE); } if (options.ShouldCloseAllFileDescriptorsOnExec()) { @@ -391,7 +388,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri /* handle parent case */ int status; bool ret = waitpid_with_timeout(pid, options.TimeoutInMs(), &status); - fsync(fd); uint64_t elapsed = Nanotime() - start; if (!ret) { |