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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D188BFD9E31 for ; Fri, 27 Feb 2026 03:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:Message-Id:Date:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=HxLEeOsUuj2afpxiHUypH1WnKs+gF+uTsxdht3VT59M=; b=jKs0Pyw1teRuMD2G7jwKP4HYB+ pgwYXySN1WTpviYApRhA+EdIIhxqUCu8MLDe5pnx6aOrBiWfdUB61gPwahjjozq60f49KzfJdpKRT ectPhARS+6yMREH2y10A/AdvTN6fu8ngYw//bthBMx2yMS+VbthJpb6oEhC4p1PrxBWQ=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vvoAK-0000U3-TR; Fri, 27 Feb 2026 03:05:20 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vvoA8-0000To-K7 for linux-f2fs-devel@lists.sourceforge.net; Fri, 27 Feb 2026 03:05:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jq18IXbAB97kgSWlEnqzxj9rB0v4G74hCUBEo9g6j2U=; b=LmxZiDkZxexUwhovZd5x0/8sJG Cta9l1ovoG+CY2RLdMQ4+q4TS++9O8ymvvigNq2HUp8Q1aXQyd0IFwtEry7xFcOK8oil2PZybV8KV XPKRaN0aOdLGFsKpDg/DnVZfZ2gKL/fKKVS48P7uZrMPUs9YQLkRbLFzaUkBbwjro+co=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=Jq18IXbAB97kgSWlEnqzxj9rB0v4G74hCUBEo9g6j2U=; b=X 9EAdO4ADukr0TUtjJUeU9b2K09gjS/RJEkO7UTOt9bVi7M6p7yqxRdh02+oMF9wKU/82KkeGTtq5d KaG2gs1pegWhq6otnB0TVQOKDcThbmZuHCuTNU7ePDhuTE671NLH6rKY32mSAxQJIWEpeB2DehxOA SDFHD1tPQ3kekrpM=; Received: from mail-pj1-f46.google.com ([209.85.216.46]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1vvoA7-0001WA-Dx for linux-f2fs-devel@lists.sourceforge.net; Fri, 27 Feb 2026 03:05:08 +0000 Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3590c295150so585174a91.1 for ; Thu, 26 Feb 2026 19:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772161502; x=1772766302; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Jq18IXbAB97kgSWlEnqzxj9rB0v4G74hCUBEo9g6j2U=; b=iERRtlqfeNoNXv5oi2XOks71C8299TVeJUtzS+ckGnP2Cx73hTtfJ+bIFINirsoQvt aAxV/03j4pp+aJdA/IUECpemyGLo8jcLQ15Atx0QGKxpgfzYk3DUeCpf7TBBygxmGt5U PiVQuyZMElensM5vDIg68WfGDk+LBDqs1Whav4aXpEviUSqEgHFB8MWV5oemaa4kJeU/ u27P0JUHZ/6pqDgb/m1Mc25lIAzuToOoN2FV8NfL7yud1M4jqh9Puhc9z040STQ39guS sVTN8MJeIW9rVW5eQVkndSSSkdJGPIebgQdFv7df6dQiIvHmKikTWoIF6Ax9Muof8CO6 C8GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772161502; x=1772766302; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Jq18IXbAB97kgSWlEnqzxj9rB0v4G74hCUBEo9g6j2U=; b=wOxUnpqnaqLdc2MC21t2Q8fulXoRWHYLVIxSOCRkl6DEtMle+ib9P+IGBTaur+YV+5 QdOoyPiw5TS15aT44hgCY4fsNodWuwtt+ZSSn/acpK50p9X9PKuEUZUJ5P2/ZrlbdZAV DTQFASyW4A1dxY8KghvL/1ecpthH+aZZhR0OOCVdaSH39qtFfRHbc+FPsfca2EA97shV HrbwSjPqmoiICU2HI7JILVaHCG+CnMtqNOJautIHUJV84ior9IT5IgB5zITEiITezeRR SaqgpUeDNBSOgxi4YKcOZVtOgPa+wEgG+m6OFwlEuXON6ubpNT36cTz7mtfYpEO40GG8 rT4Q== X-Forwarded-Encrypted: i=1; AJvYcCX+U/AAPDfl9XTLvxlubaMkLChOnyW+k8y8Ww/GHqMH8TAyS3qsO2Opyfb28jHHTpm9g/zpu/8X75Z16Ut6RVVB@lists.sourceforge.net X-Gm-Message-State: AOJu0YzZYGBlELP60jH1CTLx0pzSDPR1/vl4PQVnJeZVwih7dxzN2GJg 1369VkE45RRG0UIeUoLIgR1PXhSkn4OI+bqkbA72qkRthgDrd8sXXTFs X-Gm-Gg: ATEYQzzVtwgwHX/0Zb8p4EvUwYbE6LG6A0mTTKME/kmxgg4U3FG/fcaKsaWy0W1WJFQ qgVokPbFYcw+srfSPyRYdCI9LWg2K8+7HUFaagUMBrMHjp1X48gqRFmAKlqoVcE98Q5Nl2NGLWY eWiiMai46n/CD0ODvd8ezn8X4YU/jJPKZmsEZItRl+UA3ADjP7CxojsJ5LVJeiNlbupUSrO69xc MfLsbbyodxfuHdJOKGzYpJ/FgfjHExPdXYYBF3I3sW0hdsZW6B+w1P+4+DKelcBg8vi4YgiIvGo p7kEb2yRxq7b7T7ohNn6LvipFQ+nzb5AUI8hIFz+/gY2BxK++hvTKhJtMink5RV8wjQ3ztPvlWi KtiRshpXPVr5vzPOnjWjm7PYtnWPRvTYO9Jcq0v1OW48w8nM4mLRoDjWWG/wcp4Sw0/6WcnS5lx EFvLjACXecST4piqgkrloMz2kz3ZuiLw== X-Received: by 2002:a17:90b:544b:b0:354:bd08:480c with SMTP id 98e67ed59e1d1-35965d029fcmr1153382a91.30.1772161501650; Thu, 26 Feb 2026 19:05:01 -0800 (PST) Received: from mi.mioffice.cn ([43.224.245.243]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35912e1137csm2523491a91.0.2026.02.26.19.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 19:05:01 -0800 (PST) From: liujinbao1 To: jaegeuk@kernel.org Date: Fri, 27 Feb 2026 11:02:54 +0800 Message-Id: <20260227030254.270068-1-jinbaoliu365@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Headers-End: 1vvoA7-0001WA-Dx Subject: [f2fs-dev] [PATCH] f2fs: Add defrag_blocks sysfs node X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jinbaoliu365@gmail.com, Sheng Yong , liujinbao1 , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: liujinbao1 Add the defrag_blocks sysfs node to track the amount of data blocks moved during filesystem defragmentation. Signed-off-by: Sheng Yong Signed-off-by: liujinbao1 --- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++ fs/f2fs/debug.c | 1 + fs/f2fs/f2fs.h | 5 +++++ fs/f2fs/file.c | 4 +++- fs/f2fs/sysfs.c | 10 ++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index c1d2b3fd9c65..423ec40e2e4e 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -407,6 +407,12 @@ Contact: "Hridya Valsaraju" Description: Average number of valid blocks. Available when CONFIG_F2FS_STAT_FS=y. +What: /sys/fs/f2fs//defrag_blocks +Date: February 2026 +Contact: "Jinbao Liu" +Description: Number of blocks moved by defragment. + Available when CONFIG_F2FS_STAT_FS=y. + What: /sys/fs/f2fs//mounted_time_sec Date: February 2020 Contact: "Jaegeuk Kim" diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 8e1040e375a7..af88db8fdb71 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -659,6 +659,7 @@ static int stat_show(struct seq_file *s, void *v) si->bg_node_blks); seq_printf(s, "BG skip : IO: %u, Other: %u\n", si->io_skip_bggc, si->other_skip_bggc); + seq_printf(s, "defrag blocks : %u\n", si->defrag_blks); seq_puts(s, "\nExtent Cache (Read):\n"); seq_printf(s, " - Hit Count: L1-1:%llu L1-2:%llu L2:%llu\n", si->hit_largest, si->hit_cached[EX_READ], diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index bb34e864d0ef..dbf23cb2c501 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4288,6 +4288,7 @@ struct f2fs_stat_info { int gc_secs[2][2]; int tot_blks, data_blks, node_blks; int bg_data_blks, bg_node_blks; + unsigned int defrag_blks; int blkoff[NR_CURSEG_TYPE]; int curseg[NR_CURSEG_TYPE]; int cursec[NR_CURSEG_TYPE]; @@ -4422,6 +4423,9 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ } while (0) +#define stat_inc_defrag_blk_count(sbi, blks) \ + (F2FS_STAT(sbi)->defrag_blks += (blks)) + int f2fs_build_stats(struct f2fs_sb_info *sbi); void f2fs_destroy_stats(struct f2fs_sb_info *sbi); void __init f2fs_create_root_stats(void); @@ -4463,6 +4467,7 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi); #define stat_inc_tot_blk_count(si, blks) do { } while (0) #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) +#define stat_inc_defrag_blk_count(sbi, blks) do { } while (0) static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c8a2f17a8f11..2c4880f24b54 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3043,8 +3043,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, clear_inode_flag(inode, FI_OPU_WRITE); unlock_out: inode_unlock(inode); - if (!err) + if (!err) { range->len = (u64)total << PAGE_SHIFT; + stat_inc_defrag_blk_count(sbi, total); + } return err; } diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 5fbfdc96e502..969e06b65b04 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -338,6 +338,14 @@ static ssize_t avg_vblocks_show(struct f2fs_attr *a, f2fs_update_sit_info(sbi); return sysfs_emit(buf, "%llu\n", (unsigned long long)(si->avg_vblocks)); } + +static ssize_t defrag_blocks_show(struct f2fs_attr *a, + struct f2fs_sb_info *sbi, char *buf) +{ + struct f2fs_stat_info *si = F2FS_STAT(sbi); + + return sysfs_emit(buf, "%llu\n", (unsigned long long)(si->defrag_blks)); +} #endif static ssize_t main_blkaddr_show(struct f2fs_attr *a, @@ -1351,6 +1359,7 @@ F2FS_GENERAL_RO_ATTR(gc_mode); F2FS_GENERAL_RO_ATTR(moved_blocks_background); F2FS_GENERAL_RO_ATTR(moved_blocks_foreground); F2FS_GENERAL_RO_ATTR(avg_vblocks); +F2FS_GENERAL_RO_ATTR(defrag_blocks); #endif #ifdef CONFIG_FS_ENCRYPTION @@ -1473,6 +1482,7 @@ static struct attribute *f2fs_attrs[] = { ATTR_LIST(moved_blocks_foreground), ATTR_LIST(moved_blocks_background), ATTR_LIST(avg_vblocks), + ATTR_LIST(defrag_blocks), #endif #ifdef CONFIG_BLK_DEV_ZONED ATTR_LIST(unusable_blocks_per_sec), -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel