From: Peilin Ye <yepeilin.cs@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Peilin Ye <peilin.ye@bytedance.com>,
Cong Wang <cong.wang@bytedance.com>,
Muchun Song <songmuchun@bytedance.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Peilin Ye <yepeilin.cs@gmail.com>
Subject: [PATCH v3 RESEND] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page()
Date: Thu, 12 Jan 2023 14:43:48 -0800 [thread overview]
Message-ID: <20230112224348.5384-1-yepeilin.cs@gmail.com> (raw)
In-Reply-To: <20221130053734.2811-1-yepeilin.cs@gmail.com>
From: Peilin Ye <peilin.ye@bytedance.com>
Currently, there is a copy for each page when dumping VMAs to pipe
handlers using dump_emit_page(). For example:
fs/binfmt_elf.c:elf_core_dump()
fs/coredump.c:dump_user_range()
:dump_emit_page()
fs/read_write.c:__kernel_write_iter()
fs/pipe.c:pipe_write()
lib/iov_iter.c:copy_page_from_iter()
Use vmsplice_to_pipe() instead of __kernel_write_iter() to avoid this
copy for pipe handlers.
Tested by dumping a 32-GByte core into a simple handler that splice()s
from stdin to disk in a loop, PIPE_DEF_BUFFERS (16) pages at a time.
Before After Improved by
Time to Completion 40.77 seconds 35.49 seconds 12.95%
CPU Usage 92.27% 86.40% 6.36%
Suggested-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
fs/coredump.c | 10 +++++++++-
fs/splice.c | 4 ++--
include/linux/coredump.h | 3 +++
include/linux/splice.h | 3 +++
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/coredump.c b/fs/coredump.c
index f27d734f3102..4078069ede88 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -42,6 +42,7 @@
#include <linux/timekeeping.h>
#include <linux/sysctl.h>
#include <linux/elf.h>
+#include <linux/splice.h>
#include <linux/uaccess.h>
#include <asm/mmu_context.h>
@@ -586,6 +587,8 @@ void do_coredump(const kernel_siginfo_t *siginfo)
goto fail_unlock;
}
+ set_bit(COREDUMP_USE_PIPE, &cprm.flags);
+
if (cprm.limit == 1) {
/* See umh_pipe_setup() which sets RLIMIT_CORE = 1.
*
@@ -861,7 +864,12 @@ static int dump_emit_page(struct coredump_params *cprm, struct page *page)
return 0;
pos = file->f_pos;
iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE);
- n = __kernel_write_iter(cprm->file, &iter, &pos);
+
+ if (test_bit(COREDUMP_USE_PIPE, &cprm->flags))
+ n = vmsplice_to_pipe(file, &iter, 0);
+ else
+ n = __kernel_write_iter(cprm->file, &iter, &pos);
+
if (n != PAGE_SIZE)
return 0;
file->f_pos = pos;
diff --git a/fs/splice.c b/fs/splice.c
index 5969b7a1d353..c9be20f4115e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1234,8 +1234,8 @@ static long vmsplice_to_user(struct file *file, struct iov_iter *iter,
* as splice-from-memory, where the regular splice is splice-from-file (or
* to file). In both cases the output is a pipe, naturally.
*/
-static long vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
- unsigned int flags)
+long vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
+ unsigned int flags)
{
struct pipe_inode_info *pipe;
long ret = 0;
diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index d3eba4360150..3e34009487bf 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -28,8 +28,11 @@ struct coredump_params {
int vma_count;
size_t vma_data_size;
struct core_vma_metadata *vma_meta;
+ unsigned long flags;
};
+#define COREDUMP_USE_PIPE 0
+
/*
* These are the only things you should do on a core-file: use only these
* functions to write out all the necessary info.
diff --git a/include/linux/splice.h b/include/linux/splice.h
index a55179fd60fc..38b3560a318b 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
@@ -10,6 +10,7 @@
#define SPLICE_H
#include <linux/pipe_fs_i.h>
+#include <linux/uio.h>
/*
* Flags passed in from splice/tee/vmsplice
@@ -81,6 +82,8 @@ extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
extern long do_splice(struct file *in, loff_t *off_in,
struct file *out, loff_t *off_out,
size_t len, unsigned int flags);
+extern long vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
+ unsigned int flags);
extern long do_tee(struct file *in, struct file *out, size_t len,
unsigned int flags);
--
2.20.1
prev parent reply other threads:[~2023-01-12 22:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-29 0:51 [PATCH v1] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page() Peilin Ye
2022-10-29 7:20 ` kernel test robot
2022-10-29 9:12 ` kernel test robot
2022-10-31 21:03 ` [PATCH v2] " Peilin Ye
2022-11-19 0:17 ` [PATCH v2 RESEND] " Peilin Ye
2022-11-19 4:46 ` [PATCH v2] " Al Viro
2022-11-30 3:40 ` Peilin Ye
2022-11-30 5:37 ` [PATCH v3] " Peilin Ye
2023-01-12 22:43 ` Peilin Ye [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230112224348.5384-1-yepeilin.cs@gmail.com \
--to=yepeilin.cs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cong.wang@bytedance.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peilin.ye@bytedance.com \
--cc=songmuchun@bytedance.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).