From patchwork Wed Dec 13 23:25:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10111109 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 2416760352 for ; Wed, 13 Dec 2017 23:25:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11AFD27F54 for ; Wed, 13 Dec 2017 23:25:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06C6D29728; Wed, 13 Dec 2017 23:25:39 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 A348027F54 for ; Wed, 13 Dec 2017 23:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750784AbdLMXZg (ORCPT ); Wed, 13 Dec 2017 18:25:36 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33606 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750737AbdLMXZf (ORCPT ); Wed, 13 Dec 2017 18:25:35 -0500 Received: by mail-wr0-f196.google.com with SMTP id v22so3620845wrb.0 for ; Wed, 13 Dec 2017 15:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=JJ/pBRYK/xvTqZmFum7RoAbATISkuB/FDUCelCf7KLQ=; b=o9hSUtmlJkXXVN7rBxbcOQLZAlanoWiV4k39ZXArIFwJsnQ+ZtDERaVANGlY32SYd4 s/JS0US2WyaT5hNdRNMfqkBhleefnN26ahF/XToqgzAm1GGOkCRxeRVKK3OqshvVbWTN I857cPUwkOE0ZWWK5SGjS26Dx5sKa5iTMLeNaYkAlxTrVQHzeHUGmZL4HjKyjwYdAPU2 BvBitfGbVvgDyz/OVbgZO63r/Xq+GdAoNUVpdSyfsKFrvKyk0kQxsiPtxIrdQQ2vLTta m1Gws7mQitLG4nKFpy96ksgB7OWZnCjVuxZ/xU2xss3iayxIlAK83RvaeK5O5o3eIXPY tNiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JJ/pBRYK/xvTqZmFum7RoAbATISkuB/FDUCelCf7KLQ=; b=ZCOeHKFynyAFFXrN65un/JQMHnZO8E4DubX3JWrqGBlxjwdcoR5io50NO9F/5XV0kt K0KhCj4Mm+/pUiA6YMz1BX3ixZMdTps485OOvMUMIrS8TVYRvemXuK9/byzLT4KKzLfH 7zbdzeAQ9UJIQIoIqQfs+YSqPpEjzkfgttX7wA3ff0SduvSSEO0tHnmzkIhWaUn51wWd hHeSlVFwzLeLW6ywBOV/4R1BDZ/pn82E3MVv1vU7kgbE3Dp/GRkgrRqBKd9xqu/uV0Qs nVsWrFI78hBIx37GPLfUk8Wta3e07iKIdxVAvQKzAsbHRGYSuaPhKm7/XLRKfMIFenfO aPDA== X-Gm-Message-State: AKGB3mKI00QdJvgZXkpnvzSqTYsbIfx02tq1UBz2qmeuNBTsKIwTvJsP P01H2l6r6rfWs3igljBKUiaHtA== X-Google-Smtp-Source: ACJfBosJV+pcCaN2Gc/mnBLwUPhvNi8+LEklfMI9jTE3G+uK5E0puGEwyeM+uTGFodmToSdEP0JJsg== X-Received: by 10.223.187.3 with SMTP id r3mr4178955wrg.34.1513207534121; Wed, 13 Dec 2017 15:25:34 -0800 (PST) Received: from titovetst-beplan.lan (nat6-minsk-pool-46-53-208-190.telecom.by. [46.53.208.190]) by smtp.gmail.com with ESMTPSA id y2sm3936539wra.18.2017.12.13.15.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Dec 2017 15:25:33 -0800 (PST) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [RFC PATCH] Btrfs: btrfs_defrag_file() force use target extent size SZ_128KiB for compressed data Date: Thu, 14 Dec 2017 02:25:24 +0300 Message-Id: <20171213232524.3709-1-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Defrag heuristic use extent lengh as threshold, kernel autodefrag use SZ_256KiB and btrfs-progs use SZ_32MiB as target extent lengh. Problem: Compressed extents always have lengh at < 128KiB (BTRFS_MAX_COMPRESSED) So btrfs_defrag_file() always rewrite all extents in defrag range. Hot fix that by force set target extent size to BTRFS_MAX_COMPRESSED, if file allowed to be compressed. Signed-off-by: Timofey Titovets --- fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index be5bd81b3669..952364ff4108 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1232,6 +1232,26 @@ static int cluster_pages_for_defrag(struct inode *inode, } +static inline int inode_use_compression(struct inode *inode) +{ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + + /* force compress */ + if (btrfs_test_opt(fs_info, FORCE_COMPRESS)) + return 1; + /* defrag ioctl */ + if (BTRFS_I(inode)->defrag_compress) + return 1; + /* bad compression ratios */ + if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) + return 0; + if (btrfs_test_opt(fs_info, COMPRESS) || + BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS || + BTRFS_I(inode)->prop_compress) + return 1; + return 0; +} + int btrfs_defrag_file(struct inode *inode, struct file *file, struct btrfs_ioctl_defrag_range_args *range, u64 newer_than, unsigned long max_to_defrag) @@ -1270,6 +1290,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, compress_type = range->compress_type; } + if (inode_use_compression(inode)) + extent_thresh = BTRFS_MAX_COMPRESSED; + if (extent_thresh == 0) extent_thresh = SZ_256K;