From patchwork Wed Sep 14 12:43:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9331329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0523F6077A for ; Wed, 14 Sep 2016 12:44:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAF8229DC3 for ; Wed, 14 Sep 2016 12:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFB9629DC5; Wed, 14 Sep 2016 12:44:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8305929DC3 for ; Wed, 14 Sep 2016 12:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761476AbcINMoA (ORCPT ); Wed, 14 Sep 2016 08:44:00 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35856 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761871AbcINMn4 (ORCPT ); Wed, 14 Sep 2016 08:43:56 -0400 Received: by mail-wm0-f68.google.com with SMTP id b184so2421157wma.3; Wed, 14 Sep 2016 05:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WauomRfhplEk3vHkIZidO8Xp4Wdq2tiU8wHGzWAP6JU=; b=QTypNctLNecBR8sGUxmWFyP5BO/KJlKtK56ne6kgzxgvnuOqNnr3RIwR6WcaoqvMeh 5ROCTNXrj1o/PANz4/QR+LyxXSi/9O5OUMIeniLTqIzorTB9emRYVTGj+G3QakomaYRV Wyc5j/E4h0b2Ac92G8fGhakir9O3MyPOByJjHIkldoMNlqU+37QoO5Qyg0FkNhuNKYd8 0v6dyVTFgBUTbiSoLf8piN4MK0FS+ESZYYHHea1wYadpHMN9HJUVrzW4n1OfPO6ko/wx TrQCdC+UTDamtoIPdgaBVCA/vZm2L62FAJZef25gEiKWvqvrNrKT5eEYhoO2afVV4YdC dASw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WauomRfhplEk3vHkIZidO8Xp4Wdq2tiU8wHGzWAP6JU=; b=IToKb0+Zv++nVOJWT8J6yntDqcQXQ6uzj7h2xihE1wM+xZ6lU3c9+CDVkS5nfMnjhP P7b2i3t/2Jz8TeQSeQk4MKGYuoO4Geaby5xBsLZXpvoeLFi4ZTRA1yjegu1ThK89h35J Hc5Uee4dSRlhEFirUdp7ZSaZPNjZqKH+YE+x8PvUCbQXsXwj+KeOcMPeoMN9g53iE616 Or2QX+NXC3h7LXe27ASX5NGy0HFOlfTGm909+6yKdMZ4nvqqknrHAsKE305E4b5mSZvl MsiKcioYjfVt5PJqp8ZrpJ5BH1XqYJ5VKv3vCaN2Mvd2+9YgPlVaN4gDNYhkeragHno1 VKzw== X-Gm-Message-State: AE9vXwNb/g5bCg9NufNPjhaLmKzuock/SsyItME26y5aAiO22l7myh8ByETV7E258iHCSA== X-Received: by 10.28.156.144 with SMTP id f138mr11027979wme.86.1473857034725; Wed, 14 Sep 2016 05:43:54 -0700 (PDT) Received: from localhost.localdomain (bzq-82-81-193-202.cablep.bezeqint.net. [82.81.193.202]) by smtp.gmail.com with ESMTPSA id m133sm10629574wmg.0.2016.09.14.05.43.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Sep 2016 05:43:54 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , Dave Chinner , linux-unionfs@vger.kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, "Darrick J . Wong" , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/4] ovl: use vfs_clone_file_range() for copy up if possible Date: Wed, 14 Sep 2016 15:43:12 +0300 Message-Id: <1473856994-27463-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473856994-27463-1-git-send-email-amir73il@gmail.com> References: <1473856994-27463-1-git-send-email-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When copying up within the same fs, try to use vfs_clone_file_range(). This is very efficient when lower and upper are on the same fs with file reflink support. If vfs_clone_file_range() fails because lower and upper are not on the same fs or if fs has no reflink support, copy up falls back to the regular data copy code. Tested correct behavior when lower and upper are on: 1. same ext4 (copy) 2. same xfs + reflink patches + mkfs.xfs (copy) 3. same xfs + reflink patches + mkfs.xfs -m reflink=1 (reflink) 4. different xfs + reflink patches + mkfs.xfs -m reflink=1 (copy) For comparison, on my laptop, xfstest overlay/001 (copy up of large sparse files) takes less than 1 second in the xfs reflink setup vs. 25 seconds on the rest of the setups. Signed-off-by: Amir Goldstein --- fs/overlayfs/copy_up.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 43fdc27..ba039f8 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -136,6 +136,16 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) goto out_fput; } + /* Try to use clone_file_range to clone up within the same fs */ + error = vfs_clone_file_range(old_file, 0, new_file, 0, len); + if (!error) + goto out; + /* If we can clone but clone failed - abort */ + if (error != -EXDEV && error != -EOPNOTSUPP) + goto out; + /* Can't clone, so now we try to copy the data */ + error = 0; + /* FIXME: copy up sparse files efficiently */ while (len) { size_t this_len = OVL_COPY_UP_CHUNK_SIZE; @@ -160,7 +170,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) len -= bytes; } - +out: fput(new_file); out_fput: fput(old_file);