From patchwork Tue Oct 20 13:29:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 7447491 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 14A7B9F1B9 for ; Tue, 20 Oct 2015 13:30:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6828320865 for ; Tue, 20 Oct 2015 13:30:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EF8A2073A for ; Tue, 20 Oct 2015 13:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752653AbbJTNa2 (ORCPT ); Tue, 20 Oct 2015 09:30:28 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:34992 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751669AbbJTNa1 (ORCPT ); Tue, 20 Oct 2015 09:30:27 -0400 Received: by lbbes7 with SMTP id es7so15259652lbb.2 for ; Tue, 20 Oct 2015 06:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=AafhSb7eoeHqmHicZEFGPZ3oF7GTWOXC4IIJ7OlEs8U=; b=nfJ9jCtImFazJ4aSkKbX7gyThFn+QmXeEPtHZ7YSa//02KfJlqhaaafzVTWZqP7Mvn TNk2ihmKzwS5m58c2lPFBWemYIWwLx92hmvPSwY12FfHMm9P8OezEk08khr92NETeo+g u/Ud2nSd0TMKHn/OJfyVbEm1UGhHqJAjqiiV1GsxZrELkpzY++2ml61BgC0ZTOHvT74X V3c9DiaUTsnV7HG0T3H4Ykrq0nZWovbZo7CwlN76RNw3nFuCmNdctvaRHqB8kZbhEH4B AHDSJNb4R8iALpmUUMc4DaxgT7mid1r74V9CoA1TsiXEADHAt8y3WbtMaZcehzhBKaz9 r9XA== X-Received: by 10.112.168.228 with SMTP id zz4mr1901378lbb.73.1445347826040; Tue, 20 Oct 2015 06:30:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.73.138 with HTTP; Tue, 20 Oct 2015 06:29:46 -0700 (PDT) From: Timofey Titovets Date: Tue, 20 Oct 2015 16:29:46 +0300 Message-ID: Subject: [RFC PATCH] btrfs/ioctl.c: Prefer inode with lowest offset as source for clone To: linux-btrfs Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, T_TVD_MIME_EPI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For performance reason, leave data at the start of disk, is preferable while deduping It's might sense for the reasons: 1. Spinning rust - start of the disk is much faster 2. Btrfs can deallocate empty data chunk from the end of fs - ie it's compact fs Signed-off-by: Timofey Titovets --- fs/btrfs/ioctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) unlock_extent(&BTRFS_I(src)->io_tree, same_lock_start, From 5ed3822bc308c726d91a837fbd97ebacaa51e58d Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Tue, 20 Oct 2015 15:53:20 +0300 Subject: [RFC PATCH] btrfs/ioctl.c: Prefer inode with lowest offset as source for clone For performance reason, leave data at the start of disk, is preferable Signed-off-by: Timofey Titovets --- fs/btrfs/ioctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 3e3e613..3eb77c0 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3074,8 +3074,13 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, /* pass original length for comparison so we stay within i_size */ ret = btrfs_cmp_data(src, loff, dst, dst_loff, olen, &cmp); - if (ret == 0) - ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1); + if (ret == 0) { + /* prefer inode with lowest offset as source for clone*/ + if (loff > dest_loff) + ret = btrfs_clone(dst, src, dst_loff, olen, len, loff, 1); + else + ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1); + } if (same_inode) unlock_extent(&BTRFS_I(src)->io_tree, same_lock_start, -- 2.6.1