From patchwork Thu Jul 28 11:17:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9251105 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 341D660757 for ; Thu, 28 Jul 2016 11:17:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 248A826D17 for ; Thu, 28 Jul 2016 11:17:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177522723E; Thu, 28 Jul 2016 11:17:35 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 76FDC26D17 for ; Thu, 28 Jul 2016 11:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756811AbcG1LRb (ORCPT ); Thu, 28 Jul 2016 07:17:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:42770 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756737AbcG1LR3 (ORCPT ); Thu, 28 Jul 2016 07:17:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3DC16ACAB for ; Thu, 28 Jul 2016 11:17:28 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5A75EDA8F8; Thu, 28 Jul 2016 13:17:10 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH] btrfs-progs: fi defrag: change default extent target size to 32 MiB Date: Thu, 28 Jul 2016 13:17:09 +0200 Message-Id: <1469704629-25512-1-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.7.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 The kernel default is too low, 32 MiB is recommended and should give better results. Signed-off-by: David Sterba --- Documentation/btrfs-filesystem.asciidoc | 16 ++++++++++++---- cmds-filesystem.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc index 8fb15eacafc9..28e772466cfa 100644 --- a/Documentation/btrfs-filesystem.asciidoc +++ b/Documentation/btrfs-filesystem.asciidoc @@ -117,15 +117,23 @@ compression. See also section 'EXAMPLES'. -r:::: defragment files recursively in given directories -f:::: -flush data for each file before going to the next file. This will limit the amount -of dirty data to current file, otherwise the amount cumulates from several files -and may increase system load. +flush data for each file before going to the next file. ++ +This will limit the amount of dirty data to current file, otherwise the amount +cumulates from several files and will increase system load. This can also lead +to ENOSPC if there's too much dirty data to write and it's not possible to make +the reservations for the new data (ie. how the COW design works). ++ -s [kKmMgGtTpPeE]:::: defragmentation will start from the given offset, default is beginning of a file -l [kKmMgGtTpPeE]:::: defragment only up to 'len' bytes, default is the file size -t [kKmMgGtTpPeE]:::: -target extent size, do not touch extents bigger than 'size' +target extent size, do not touch extents bigger than 'size', default: 32 MiB ++ +The value is only advisory and the final size of the extents may differ, +depending on the state of the free space and fragmentation or other internal +logic. Reasonable values are from tens to hundreds of megabytes. *du* [options] [..]:: Calculate disk usage of the target files using FIEMAP. For individual diff --git a/cmds-filesystem.c b/cmds-filesystem.c index ef1f550b51c0..6b381c582ea7 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -968,7 +968,7 @@ static const char * const cmd_filesystem_defrag_usage[] = { "-f flush data to disk immediately after defragmenting", "-s start defragment only from byte onward", "-l len defragment only up to len bytes", - "-t size target extent size hint", + "-t size target extent size hint (default: 32 MiB)", NULL }; @@ -1029,7 +1029,7 @@ static int cmd_filesystem_defrag(int argc, char **argv) int flush = 0; u64 start = 0; u64 len = (u64)-1; - u64 thresh = 0; + u64 thresh; int i; int recursive = 0; int ret = 0; @@ -1037,6 +1037,13 @@ static int cmd_filesystem_defrag(int argc, char **argv) int compress_type = BTRFS_COMPRESS_NONE; DIR *dirstream; + /* + * Kernel has a different default (256K) that is supposed to be safe, + * but it does not defragment very well. The 32M will likely lead to + * better results and is independent of the kernel default. + */ + thresh = 32 * 1024 * 1024; + defrag_global_errors = 0; defrag_global_verbose = 0; defrag_global_errors = 0;