From patchwork Thu Sep 8 15:29:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9321675 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 7F6FC60752 for ; Thu, 8 Sep 2016 15:31:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70FC129861 for ; Thu, 8 Sep 2016 15:31:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 657FD298E5; Thu, 8 Sep 2016 15:31:16 +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=-4.4 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 0450929861 for ; Thu, 8 Sep 2016 15:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757608AbcIHPbG (ORCPT ); Thu, 8 Sep 2016 11:31:06 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36331 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757539AbcIHPbF (ORCPT ); Thu, 8 Sep 2016 11:31:05 -0400 Received: by mail-wm0-f68.google.com with SMTP id l65so8371720wmf.3; Thu, 08 Sep 2016 08:31:04 -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; bh=bkVkWVOd/ieZe4hBG5gIJQYENQkKVnQJtehmmrYU6+Q=; b=tQP9tOsCNFJ3IPmJqJltiMXHrBLyHDhCUOClI545Oqur40ELG8FxEgCIYz2CXvrJ13 2TfemnHD1bNa5XLSF2kewQLTm/uICFyicj6TWg/nhPuxKAZnP211yJUsDq4Edqdn7uQR tSps4G32/B4rLoKs6fCP3+C4hJfeKoZxFqpNLeZ5qv/W0KH9sdjlqT359UJkDqIC+Wgd 5oeQg8yg0StGaqHi0lLAfCNKOqHt+qZWbOYj9jGlOHxbLe9NdNmfHo3P8V67Gp/2pc9X reB2mn2oIFOHx0fo5jf0un3RAdB2JhjhQKMp3saJfKUgfLj4EJZJiiMvNXahK8oMvdzg c9vw== 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; bh=bkVkWVOd/ieZe4hBG5gIJQYENQkKVnQJtehmmrYU6+Q=; b=g6EftQB2kqOPSNc9WPKwVc/Azy3Tq2C9uTf21iW6aKmhZYwes7mh6pdrwB3ZA19SYi 9b1ZKMDJv/YWQN+sLrfiz1xaLqYTTWHxgbzsLzCygHafYjXzyna2FypSgekVgbinZ6U5 OFhbF9jnYMmKuUncDfdoJd+z7eILVulFrDU8l9xxBRTa9RnFyf5wP0LRJliW0c6/Wbee eC7TVNhyB/YuHsIiD9tVDWLSXfup9QWdaheCaKhEDBjrvNorAe3wQHH1c738XEWvEbEQ tB9uMOoIllYWvssYstYb5+xzy9eFQ3HPxMuOt8ey3JUmMtGjYEpDkbA9kHR1RCxCQpC0 02qw== X-Gm-Message-State: AE9vXwNVgGxQ9HjL4o/3JoNEtapGKwny3rTY5czIsQ0wYpZlFrs6pzYVmh1Tse2tM6nRNA== X-Received: by 10.194.172.42 with SMTP id az10mr229453wjc.178.1473348663209; Thu, 08 Sep 2016 08:31:03 -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 r4sm44845438wjs.13.2016.09.08.08.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Sep 2016 08:31:02 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , "Darrick J . Wong" Cc: linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Amir Goldstein Subject: [PATCH] ovl: use copy_file_range for copy up if possible Date: Thu, 8 Sep 2016 18:29:54 +0300 Message-Id: <1473348594-31425-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 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 f_op->copy_file_range(). This becomes very efficient when lower and upper are on the same fs with file reflink support. 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 (clone) 4. different xfs + reflink patches + mkfs.xfs -m reflink=1 (copy) Verified that all the overlay xfstests pass in the 'same xfs+reflink' setup. 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 | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 43fdc27..400567b 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -121,6 +121,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) struct file *new_file; loff_t old_pos = 0; loff_t new_pos = 0; + int try_copy_file = 0; int error = 0; if (len == 0) @@ -136,6 +137,13 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) goto out_fput; } + /* + * When copying up within the same fs, try to use fs's copy_file_range + */ + if (file_inode(old_file)->i_sb == file_inode(new_file)->i_sb) { + try_copy_file = (new_file->f_op->copy_file_range != NULL); + } + /* FIXME: copy up sparse files efficiently */ while (len) { size_t this_len = OVL_COPY_UP_CHUNK_SIZE; @@ -149,9 +157,23 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) break; } - bytes = do_splice_direct(old_file, &old_pos, - new_file, &new_pos, - this_len, SPLICE_F_MOVE); + if (try_copy_file) { + bytes = new_file->f_op->copy_file_range( + old_file, old_pos, + new_file, new_pos, + len, 0); + if (bytes == -EOPNOTSUPP) { + try_copy_file = 0; + continue; + } else if (bytes > 0) { + old_pos += bytes; + new_pos += bytes; + } + } else { + bytes = do_splice_direct(old_file, &old_pos, + new_file, &new_pos, + this_len, SPLICE_F_MOVE); + } if (bytes <= 0) { error = bytes; break;