From patchwork Thu Feb 24 12:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 12758477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0416AC433EF for ; Thu, 24 Feb 2022 12:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234379AbiBXM3a (ORCPT ); Thu, 24 Feb 2022 07:29:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbiBXM3Z (ORCPT ); Thu, 24 Feb 2022 07:29:25 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CA67269AAC for ; Thu, 24 Feb 2022 04:28:54 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1B89021155; Thu, 24 Feb 2022 12:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645705733; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T5ulqCZi825YATFHCgWBmh8z9ETSPkh7Wmvh7vrmUR8=; b=bRjG14vxFscrbhWQjeUn4xxJZ4k5YSzBz52QVFlSlIujedQiy+M7kJOkK72amClr9dwCxl g9rSx5JL5PgSMDbAsynHuzP5uJSMfgzqH0okucnZ/IiFq545cu50ipzmewQm6XIzvfJYqj hA66Q+TfFsb5uYybrl1gk4ASkO9esPw= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2A5B613AD9; Thu, 24 Feb 2022 12:28:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YDZFOAN6F2LhAgAAMHmgww (envelope-from ); Thu, 24 Feb 2022 12:28:51 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Filipe Manana Subject: [PATCH 6/7] btrfs: defrag: make btrfs_defrag_file() to report accurate number of defragged sectors Date: Thu, 24 Feb 2022 20:28:40 +0800 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Previously rework btrfs_defrag_file() can only report the number of sectors from the first run of defrag_collect_targets(). This number is not accurate as if holes are punched after the first defrag_collect_targets() call, we will not choose to defrag the holes. Originally this is to avoid passing @sectors_defragged to every involved functions. But now since we have btrfs_defrag_ctrl, there is no need to do such inaccurate accounting, just update btrfs_defrag_ctrl::sectors_defragged after a successful defrag_one_locked_target() call. Signed-off-by: Qu Wenruo Reviewed-by: Filipe Manana --- fs/btrfs/ioctl.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 72d157b89a17..1f0bf6181013 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1652,6 +1652,8 @@ static int defrag_one_range(struct btrfs_inode *inode, &cached_state); if (ret < 0) break; + ctrl->sectors_defragged += entry->len >> + inode->root->fs_info->sectorsize_bits; } list_for_each_entry_safe(entry, tmp, &target_list, list) { @@ -1716,17 +1718,9 @@ static int defrag_one_cluster(struct btrfs_inode *inode, ra, NULL, entry->start >> PAGE_SHIFT, ((entry->start + range_len - 1) >> PAGE_SHIFT) - (entry->start >> PAGE_SHIFT) + 1); - /* - * Here we may not defrag any range if holes are punched before - * we locked the pages. - * But that's fine, it only affects the @sectors_defragged - * accounting. - */ ret = defrag_one_range(inode, ctrl, entry->start, range_len); if (ret < 0) break; - ctrl->sectors_defragged += range_len >> - inode->root->fs_info->sectorsize_bits; } out: list_for_each_entry_safe(entry, tmp, &target_list, list) {