Message ID | 20221029005147.2553-1-yepeilin.cs@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1128628wru; Fri, 28 Oct 2022 18:19:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BSD/efLy9SC6BrkP7uReBg1xM36/4kdcOl8HD04Rix7L6ySrU+TTqLNl7OHu6f7og8Nds X-Received: by 2002:aa7:d889:0:b0:460:62ef:2695 with SMTP id u9-20020aa7d889000000b0046062ef2695mr1979570edq.273.1667006358885; Fri, 28 Oct 2022 18:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667006358; cv=none; d=google.com; s=arc-20160816; b=Wo5HPHFUJ7PU/hYCMPpxyqkmLYZsH5tgPxohbfWYhMXZBecqtNa+bOC3LktNssXWvb lKBq+3VyvsHbX80tV4Az2gw/rKDlybjlQzXQ9D1VnpJ6QvlJDpg9JYZ1BUUHpdzujQba uJOXuf2Bz7mfUQHX7FM6TRXXQC+zcOXbEmdj7o5eGZRvKNFJQELGy4+7d5hy+h95Rz8e QJVESmOYysGVU+egUg4+OGrdBaPcx2WVQ3mSvzeXd2iYJTQ7vQ0d3NgGSMBzmjrL1NOs NuJK3dZTdJCkdRjfPLPuiSSSy5BKXUApgOd8gwqgd98FGoVJY8ncVw2Af2vGOLm+GJPK SiBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=v5RiV+Px8WS2ShlcDdYeA2/trOi8fP9YvmZ25k/CKak=; b=HvBgWRdMZQqc2uUCidjG/okfbFW4O4cwMh2diQbQhYqh/lfWGS8qTB4kbROvqiuMht ii002WIPebXV2IbZa5Sq1+eyxLeesxdmXxuzxi9HzsK+ZuVGl2p05CfXx/bQrXQTUCBM 88xUSl8i9nhSXjrv+hyNZFjcDtjxZWcITEDuW7XZ1LkSNehgCKnl2Iv1BHNXLvr7uDAC NR/MkmILBQIape1r4Gb1Uj8RpvIqcRXrGeiLjUr8u2xCfnfzGQZI1QrlnAeJ7zkRnon8 bw3G8crAOPvNQQ0/pdpptyr5HBfVD+TkVxc5wal8uzE5qKlnjAY0W86NzJomuG4aanHK nLcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g02qEJsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji10-20020a170907980a00b007123952b00dsi329786ejc.100.2022.10.28.18.18.55; Fri, 28 Oct 2022 18:19:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g02qEJsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbiJ2AwE (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Fri, 28 Oct 2022 20:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiJ2AwD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Oct 2022 20:52:03 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C39B2D0185; Fri, 28 Oct 2022 17:52:00 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id ay12so3878314qtb.12; Fri, 28 Oct 2022 17:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v5RiV+Px8WS2ShlcDdYeA2/trOi8fP9YvmZ25k/CKak=; b=g02qEJsW4N4aEjtM2laW+nJCEU2K+n+vd3qaVpXcdBqYfi35cSrb3J3RhQhtftmcpj 7Sw42lNEJuQJl4x0yoJ3nc+1xtoXk9y2NWCHBbEPGN1jUPz82/lddDcLogq7H/pYt6Wd 7jR21fg86kFw6FI99VHNURki10cISy3GEFpKpdAZUa+7le46Nz6rRd/d0SviYF7hthIi 6ryQBP76Vsa2qA+AVxLu4pxRbhA+sXdDp3CLlCB3M9FsgEYO567PpOyr2TQRho8cesCu RwfDRjeABE64l5SRnc6xmdEJw62+9Crx31nLjWi+PZSnoMU6bq95n3O/xhrk8mn3giY8 ljzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v5RiV+Px8WS2ShlcDdYeA2/trOi8fP9YvmZ25k/CKak=; b=VFxa9D0TF4M1N/jWArU1nOxlr27Tt3fTildtXBVmlxN65krywv9oSGcBsjKPIG3Jue lYTpW5gSTF3m1tgy9ssKV4RsVCuH5w79DV+qlCHsSDwpZeCJH4YEnuDQo131CxPKakUc px6PH5UyUOIq/7AoF/g4x6p+jzDSasXKk9HOEuOxdU2RIywdso6oyZe+FLeu1W11tKgV RRMb/TfvENxAhCKaW2vluLRUIMvIINvz9Yafw9bNqWlNQ3IrqEilYPP0aZbPubpkqaOi tZcvQoE3QVjaTlCgpfJTSq9w6BfSwwO47CBmIR7HV/HmpOzR/R4uB1kxJ7+mTgutKZTy ymIA== X-Gm-Message-State: ACrzQf1oVGvDGTKAd07WEE98jLK6coak6Zujoizlyr01OrLScn0YphBD qPoTWicpuaiZ2whK+iV8TQ== X-Received: by 2002:a05:622a:198e:b0:39c:e98c:d3e1 with SMTP id u14-20020a05622a198e00b0039ce98cd3e1mr1934014qtc.378.1667004719888; Fri, 28 Oct 2022 17:51:59 -0700 (PDT) Received: from bytedance.attlocal.net ([130.44.212.155]) by smtp.gmail.com with ESMTPSA id bs6-20020a05620a470600b006b61b2cb1d2sm133935qkb.46.2022.10.28.17.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 17:51:59 -0700 (PDT) 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>, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye <yepeilin.cs@gmail.com> Subject: [PATCH v1] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page() Date: Fri, 28 Oct 2022 17:51:47 -0700 Message-Id: <20221029005147.2553-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747982859483774529?= X-GMAIL-MSGID: =?utf-8?q?1747982859483774529?= |
Series |
[v1] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page()
|
|
Commit Message
Peilin Ye
Oct. 29, 2022, 12:51 a.m. UTC
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 40-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 52.04 seconds 46.30 seconds 11.03% CPU Usage 89.43% 84.90% 5.07% Suggested-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Peilin Ye <peilin.ye@bytedance.com> --- fs/coredump.c | 7 ++++++- fs/splice.c | 4 ++-- include/linux/splice.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-)
Comments
Hi Peilin, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on linus/master] [also build test WARNING on v6.1-rc2 next-20221028] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Peilin-Ye/coredump-Use-vmsplice_to_pipe-for-pipes-in-dump_emit_page/20221029-085307 patch link: https://lore.kernel.org/r/20221029005147.2553-1-yepeilin.cs%40gmail.com patch subject: [PATCH v1] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page() config: x86_64-allyesconfig compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/49da2daf3c9dc6a687c0f64c047bec6199f232af git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Peilin-Ye/coredump-Use-vmsplice_to_pipe-for-pipes-in-dump_emit_page/20221029-085307 git checkout 49da2daf3c9dc6a687c0f64c047bec6199f232af # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash net/tls/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from net/tls/tls_sw.c:41: >> include/linux/splice.h:84:56: warning: 'struct iov_iter' declared inside parameter list will not be visible outside of this definition or declaration 84 | extern long vmsplice_to_pipe(struct file *file, struct iov_iter *iter, | ^~~~~~~~ vim +84 include/linux/splice.h 64 65 typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, 66 struct splice_desc *); 67 typedef int (splice_direct_actor)(struct pipe_inode_info *, 68 struct splice_desc *); 69 70 extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, 71 loff_t *, size_t, unsigned int, 72 splice_actor *); 73 extern ssize_t __splice_from_pipe(struct pipe_inode_info *, 74 struct splice_desc *, splice_actor *); 75 extern ssize_t splice_to_pipe(struct pipe_inode_info *, 76 struct splice_pipe_desc *); 77 extern ssize_t add_to_pipe(struct pipe_inode_info *, 78 struct pipe_buffer *); 79 extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, 80 splice_direct_actor *); 81 extern long do_splice(struct file *in, loff_t *off_in, 82 struct file *out, loff_t *off_out, 83 size_t len, unsigned int flags); > 84 extern long vmsplice_to_pipe(struct file *file, struct iov_iter *iter, 85 unsigned int flags); 86
Hi Peilin, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on linus/master] [also build test WARNING on v6.1-rc2 next-20221028] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Peilin-Ye/coredump-Use-vmsplice_to_pipe-for-pipes-in-dump_emit_page/20221029-085307 patch link: https://lore.kernel.org/r/20221029005147.2553-1-yepeilin.cs%40gmail.com patch subject: [PATCH v1] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page() config: hexagon-randconfig-r041-20221029 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/49da2daf3c9dc6a687c0f64c047bec6199f232af git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Peilin-Ye/coredump-Use-vmsplice_to_pipe-for-pipes-in-dump_emit_page/20221029-085307 git checkout 49da2daf3c9dc6a687c0f64c047bec6199f232af # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash net/tls/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from net/tls/tls_sw.c:41: >> include/linux/splice.h:84:56: warning: declaration of 'struct iov_iter' will not be visible outside of this function [-Wvisibility] extern long vmsplice_to_pipe(struct file *file, struct iov_iter *iter, ^ In file included from net/tls/tls_sw.c:44: In file included from include/net/strparser.h:11: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from net/tls/tls_sw.c:44: In file included from include/net/strparser.h:11: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from net/tls/tls_sw.c:44: In file included from include/net/strparser.h:11: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ 7 warnings generated. vim +84 include/linux/splice.h 64 65 typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, 66 struct splice_desc *); 67 typedef int (splice_direct_actor)(struct pipe_inode_info *, 68 struct splice_desc *); 69 70 extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, 71 loff_t *, size_t, unsigned int, 72 splice_actor *); 73 extern ssize_t __splice_from_pipe(struct pipe_inode_info *, 74 struct splice_desc *, splice_actor *); 75 extern ssize_t splice_to_pipe(struct pipe_inode_info *, 76 struct splice_pipe_desc *); 77 extern ssize_t add_to_pipe(struct pipe_inode_info *, 78 struct pipe_buffer *); 79 extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, 80 splice_direct_actor *); 81 extern long do_splice(struct file *in, loff_t *off_in, 82 struct file *out, loff_t *off_out, 83 size_t len, unsigned int flags); > 84 extern long vmsplice_to_pipe(struct file *file, struct iov_iter *iter, 85 unsigned int flags); 86
diff --git a/fs/coredump.c b/fs/coredump.c index 7bad7785e8e6..a6ef406dee43 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> @@ -854,7 +855,11 @@ static int dump_emit_page(struct coredump_params *cprm, struct page *page) return 0; pos = file->f_pos; iov_iter_bvec(&iter, WRITE, &bvec, 1, PAGE_SIZE); - n = __kernel_write_iter(cprm->file, &iter, &pos); + + n = vmsplice_to_pipe(file, &iter, 0); + if (n == -EBADF) + 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 0878b852b355..2051700cda79 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/splice.h b/include/linux/splice.h index a55179fd60fc..0cd955cf5ee2 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -81,6 +81,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);