Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1373412rwb; Fri, 18 Nov 2022 17:46:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf74MYS9sm+3IFKu3niWg1XYeMIYSBr/7VqH6CYQDPJUkJXWPaZmpjU0vmpRY7luFc5qWr4Q X-Received: by 2002:a17:90a:1041:b0:213:b4ad:7290 with SMTP id y1-20020a17090a104100b00213b4ad7290mr16742289pjd.197.1668822383437; Fri, 18 Nov 2022 17:46:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668822383; cv=none; d=google.com; s=arc-20160816; b=pNzaM/vP5uYZDDm9SLwrjNTZ5D6AZnNcjWAOAnbUWYayz41bi7FuM4sxHlnfLOd845 0K1biCIBX7R8RSKV3z9UV64ZXeZ1YJqjZTfqup3Yh/Yv4NdbcOp3plNMP/ct8ph3Q5xX FrjnYE7WJ+EoNVxI3BNSPaB7NtFjs8y3YuMh0AcPcd8DV1/CE30+7SSMn/nm+RqSlJ69 d3dqm+CsartlllSyzkL58N5N4Uakfu8MIWT1JHytGudMsRcsFg6rGLIIZwVDbPj7iTPZ t+zKuzYriNZ51MfON6EiRp8zU/WtdrbbME3u6MoU6QnpsuFIn7nHFKhy4qhY4N/GIWJF ABFA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j189-20020a636ec6000000b0046f5808167asi5427439pgc.812.2022.11.18.17.46.12; Fri, 18 Nov 2022 17:46:23 -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 + 90 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.20.1