From patchwork Sat Nov 19 00:17:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 23159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp501544wrr; Fri, 18 Nov 2022 17:24:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4w8Th56ytNdOf/MvK25Y+u8sqrAbQ5XKjzC4hjjgG8KCWJMLF5rSRKvJLbqJRDnS3Wx2mT X-Received: by 2002:a17:903:191:b0:186:5cda:1e01 with SMTP id z17-20020a170903019100b001865cda1e01mr2021528plg.111.1668821046799; Fri, 18 Nov 2022 17:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668821046; cv=none; d=google.com; s=arc-20160816; b=POLjAhmfNFZ4qpYKqSL4GU8ajJoJCwAUbgj0txXzhiCPBowTsAJZrig81Z5MQkBuHk KnvenDcTTuMj6olOwL00KhXLTgHHMGxw17GquDbDCZJxbIXwQhT1v2Z+MkOst2vLd9Tu p+xQU9SmxlGohsLcL5oBHgKlpiVC9e4gqBQWu5+PSLPxKEEq5Zs27VpZfviNOKlHw2lU yc3acCHAH5wDdI8fB4LKAlfAE/g4Yy9W25Jnteh//9E7S7ldPuWPaJr+nmLCydEpn8N5 Yhu6tW5XzI7ctjNeaNH2cqk7+vKqoJ0lRnoV4AxTb1z9rFg6mEAHZyC4VYJY6eUvi1re y21A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ya/HZho/hYNS3aLaSnNK+OWu7yXKQvRmTWMTtCIGZCs=; b=FvQDcI6+FXtdsI5w/myN8Hh3LxGXvZSXZAqlgU2XIQw3SUljDwaSk1rnXknCCpEq9K wVOjZZd7HMHo1qaeDnFQfHfJjKQ/uQcJG8dh2QUt3juoA4SA20vrooAudQ4DRw1UiX4i mt6MfeZjRjveW/CvquNz+G55w/w6XU9m1fluGvJVcAwQaa4dJhET5u0dItpciwLTnuqb c7Pk3CHhQwjLEOS+dLUl6vwXdVzmsvZfO3gWSHvmZv6ZcLJeJsyLYPf7sn66RrhC4MgE v0o9dtOEvahwQtJGH1yUtE7NDG+U2uuUSslpWOBECM+II8bJNsv3YWQzlco2XDY3w52w HIjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F8XLLukw; 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 nn6-20020a17090b38c600b00200462c3f5csi5008741pjb.74.2022.11.18.17.23.54; Fri, 18 Nov 2022 17:24:06 -0800 (PST) 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=F8XLLukw; 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 S229606AbiKSBUT (ORCPT + 99 others); Fri, 18 Nov 2022 20:20:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbiKSBTy (ORCPT ); Fri, 18 Nov 2022 20:19:54 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB56CB7035; Fri, 18 Nov 2022 16:17:56 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id 8so4609944qka.1; Fri, 18 Nov 2022 16:17:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ya/HZho/hYNS3aLaSnNK+OWu7yXKQvRmTWMTtCIGZCs=; b=F8XLLukwWdeSfpJFx5dfa4W8KDFebDhg3tPacc8OuiBvRe1fKVh0t9XveWdsqxUm42 TKWCYUBtrP1ZLwU5EYR6bmjolzEVs11VCfg49bOLLV/kZbyQFYb9mtsEqRBEFPb+6Kfa a2tzsmyZkg6QBD0XKoMfEKrBHgICpi7UBsSVA4wvcku4fYLn1Ca1mO4Q0c8yKDhM1Y55 7btDhYaMJ1ycnUCD1mAcRAwmpPgguDDvU6KtnNBNBknq5RFQDMNWfORXN46KnySrtHgG 0FgACME+IZ+o9TDsFN3KgUDFmTFazdgIzdhiKdZGOtL68rQLvmAlykcGNhzD2szdXnh/ DNiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ya/HZho/hYNS3aLaSnNK+OWu7yXKQvRmTWMTtCIGZCs=; b=r6MnErTEHeB2l2CnUr5iQ2EtiNk7uNYU/xZkEtv4xLbdHgQdRTF7tdfsD++heaslNc 4LOh3iQqaFQ777Jj4NuNlJqjjFJO0d2W0cyG+GtgzR8+gcbcmfQ1j6t5YgY5h1OyHB0L o0zVzUWlMYf5AxwRrJnTnAu73WksACH/7ubv86ao/0v0XZ08XaFyJWLzXMFi6iKSdHqH 5cE0NAju+g0yVVQSZXgFqqYP49/knXvVCJQaCITIs5MUm6fQZT/AUBs3yoYYcFyDUCam w7djMJ600HNpooiE7qTORHxwtPQduY8eD1BS+gXlCKbT/2WHKKWGSLs9vx4qk1vObcrI rnJw== X-Gm-Message-State: ANoB5plU9VJQdfSwV6TNLyYvevZDWvmxm4gzaV6EhpgALNGbTDD2F469 E77lvI+P2Usf2Bd91Wfldg== X-Received: by 2002:a37:b746:0:b0:6fa:1d5c:ba00 with SMTP id h67-20020a37b746000000b006fa1d5cba00mr7766196qkf.202.1668817075926; Fri, 18 Nov 2022 16:17:55 -0800 (PST) Received: from bytedance.attlocal.net ([130.44.212.155]) by smtp.gmail.com with ESMTPSA id bs10-20020ac86f0a000000b003992448029esm2835719qtb.19.2022.11.18.16.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 16:17:55 -0800 (PST) From: Peilin Ye To: Alexander Viro Cc: Peilin Ye , Cong Wang , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye Subject: [PATCH v2 RESEND] coredump: Use vmsplice_to_pipe() for pipes in dump_emit_page() Date: Fri, 18 Nov 2022 16:17:40 -0800 Message-Id: <20221119001740.2642-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221031210349.3346-1-yepeilin.cs@gmail.com> References: <20221031210349.3346-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 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: 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?1749885698365880858?= From: Peilin Ye 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 Signed-off-by: Peilin Ye --- Hi all, Resending this after 2+ weeks. Any suggestions, testing would be much appreciated, thanks! change in v2: - fix warning in net/tls/tls_sw.c (kernel test robot) Peilin Ye fs/coredump.c | 7 ++++++- fs/splice.c | 4 ++-- include/linux/splice.h | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index da0e9525c4e8..c0a8713d9971 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -862,7 +863,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..38b3560a318b 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -10,6 +10,7 @@ #define SPLICE_H #include +#include /* * 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);