From mboxrd@z Thu Jan 1 00:00:00 1970 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 EDA7DCD98C5 for ; Mon, 15 Jun 2026 15:52:08 +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: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version:References: Message-ID:To:Date:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4EkBQUqhbaIx2lNE9DmG1srXo6YOIrpxLyIXNOfFkXk=; b=Pg8ZY2F1DYOb77cE5EPCTnv6l5 B3wclztrM6jhNQG4rituy7VtdFJdG7BG7V2oxP0s0/wangG09Grc0SIc9NPADvuKlpIzcFKf9F8d+ 2hNduvSoXSHA8Z85pf+3jQzccMt+LrEQbHsBYBPAZnrovWFT3zTyTFBIzqViDyJAwClI=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wZ9bb-00063t-FE; Mon, 15 Jun 2026 15:52:08 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wZ9bZ-00063g-NP for linux-f2fs-devel@lists.sourceforge.net; Mon, 15 Jun 2026 15:52:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i3PHX3YhmYx5IUXzivGPU0J+kzZvhb/igWU6Z27SlGk=; b=fsMVraIrPt+Z6wEEHo1d6RepWk 0FF3SSkWolB6SocSjZXbrYPDPqv9UAxG+NIK3rK2DDvusE+18eBBzFJBha26nyDMQUsaoXuc5R/wf Xrl+2KajUAwHKeikHAiTuYW/TaJMUCtDOWRv1IlT01fplVLm18ayrq7bjwvNig6wrEeE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=i3PHX3YhmYx5IUXzivGPU0J+kzZvhb/igWU6Z27SlGk=; b=k5EO5gVzNCP2AwdlZpzIcKZzKi J/cMsQkf0IELuuv4L9M6S66RISdznxPHjLSmzQiW/OZeUabNSDNV/PHsspymtpZYmbs+JnjglQaSL sdg4pTvA0R48NjsaLTd8ZIU2poq6b8ZKzCq/fH/L+hPFuhcyK5AyqFVuxVYXw+pb+gRE=; Received: from sea.source.kernel.org ([172.234.252.31]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wZ9bY-0007Wq-If for linux-f2fs-devel@lists.sourceforge.net; Mon, 15 Jun 2026 15:52:06 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id AB9DE43526; Mon, 15 Jun 2026 15:51:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A1A1F000E9; Mon, 15 Jun 2026 15:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781538714; bh=i3PHX3YhmYx5IUXzivGPU0J+kzZvhb/igWU6Z27SlGk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=gnH8q6JqE9JCINpAeMSoUIVTaWwV5zCu6FI05Oslwn6cldzgr0/Te6Na3JuHl65nn RxdFauUhwtxadpq6yPKvgLhiyN3HaeAukGw1jaRmlNT0syR8TTh1ND6xjH7vrikLIW TE9pgBzAzxbllaOC4dAlgnPsFxycOgmK4nhdo1mLwvJ72Rt6tvPbblE1UEbwuZBDRM 4gZfJH0+NhdkgPDEFBUq7UEa2PAB8/6Ypr4UXRxvgRrfoav3K0r/PN3IGBVzE+0piP fK8BseOCGDw0QWxmBzlZeo7wMnZASKMO8Ww3dvX/cXeG2DehBF65CesArt4EC0hvFJ MCRnZvys+4GhQ== Date: Mon, 15 Jun 2026 15:51:52 +0000 To: Chao Yu Message-ID: References: <20260612115839.2065903-2-yangyongpeng.storage@gmail.com> <20260612115839.2065903-6-yangyongpeng.storage@gmail.com> <8738e84f-6fef-479d-a100-7df0e130f75a@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8738e84f-6fef-479d-a100-7df0e130f75a@kernel.org> X-Headers-End: 1wZ9bY-0007Wq-If Subject: Re: [f2fs-dev] [PATCH RESEND 5/5] f2fs: add ioctl to export read extent cache to userspace for debug 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: , From: Jaegeuk Kim via Linux-f2fs-devel Reply-To: Jaegeuk Kim Cc: Yongpeng Yang , Yongpeng Yang , Yongpeng Yang , 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 On 06/15, Chao Yu via Linux-f2fs-devel wrote: > On 6/12/26 19:58, Yongpeng Yang wrote: > > From: Yongpeng Yang > > > > Add F2FS_IOC_GET_READ_CACHE_EXTENTS ioctl that allows userspace to > > retrieve all cached read extents for a given file. This uses a two-call > > pattern similar to fiemap: the first call with ext_count=0 queries the > > node_count, and the second call fetches the actual extent entries. > > It looks a little bit heavy to maintain a debug purpose ioctl interface. > > Maybe set ino via sysfs and dump extent cache via procfs? only enabled > if F2FS_CHECK_FS=y? > > Jaegeuk, do you have any suggestion? Agreed, and even not sure we need sysfs or procfs. Can we dump the extents via fsck? > > Thanks, > > > > > Signed-off-by: Yongpeng Yang > > --- > > fs/f2fs/extent_cache.c | 70 +++++++++++++++++++++++++++++++++++++++ > > fs/f2fs/f2fs.h | 3 ++ > > fs/f2fs/file.c | 11 ++++++ > > include/uapi/linux/f2fs.h | 21 ++++++++++++ > > 4 files changed, 105 insertions(+) > > > > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c > > index e141ffb64e5f..0c10d5639d68 100644 > > --- a/fs/f2fs/extent_cache.c > > +++ b/fs/f2fs/extent_cache.c > > @@ -14,6 +14,7 @@ > > > > #include > > #include > > +#include > > > > #include "f2fs.h" > > #include "node.h" > > @@ -1267,6 +1268,75 @@ static void __init_extent_tree_info(struct extent_tree_info *eti) > > atomic_set(&eti->total_ext_node, 0); > > } > > > > +int f2fs_get_read_cache_extents(struct inode *inode, > > + struct f2fs_read_cache_extent __user *uarg) > > +{ > > + struct extent_tree *et = F2FS_I(inode)->extent_tree[EX_READ]; > > + struct f2fs_cache_extent_info *kbuf = NULL; > > + struct f2fs_cache_extent_info largest = {}; > > + struct rb_node *node; > > + struct extent_node *en; > > + unsigned int capacity, count = 0; > > + __u32 flags = 0; > > + int ret = 0; > > + > > + if (get_user(capacity, &uarg->ext_count)) > > + return -EFAULT; > > + > > + if (is_inode_flag_set(inode, FI_NO_EXTENT)) > > + flags |= F2FS_EXT_FL_NO_EXTENT; > > + > > + if (!et || (flags & F2FS_EXT_FL_NO_EXTENT)) { > > + if (put_user(0U, &uarg->ext_count) || > > + put_user(flags, &uarg->flags) || > > + put_user(0U, &uarg->node_count)) > > + return -EFAULT; > > + return 0; > > + } > > + > > + if (capacity) { > > + kbuf = f2fs_kvmalloc(F2FS_I_SB(inode), capacity * sizeof(*kbuf), GFP_KERNEL); > > + if (!kbuf) > > + return -ENOMEM; > > + } > > + > > + read_lock(&et->lock); > > + > > + largest.fofs = et->largest.fofs; > > + largest.blk = et->largest.blk; > > + largest.len = et->largest.len; > > + largest.last_access_mode = et->largest.last_access_mode; > > + > > + for (node = rb_first_cached(&et->root); node; node = rb_next(node)) { > > + if (count >= capacity) > > + break; > > + en = rb_entry(node, struct extent_node, rb_node); > > + > > + kbuf[count].fofs = en->ei.fofs; > > + kbuf[count].blk = en->ei.blk; > > + kbuf[count].len = en->ei.len; > > + kbuf[count].last_access_mode = en->ei.last_access_mode; > > + count++; > > + } > > + > > + read_unlock(&et->lock); > > + > > + if (count && copy_to_user(uarg->extents, kbuf, > > + count * sizeof(*kbuf))) { > > + ret = -EFAULT; > > + goto out; > > + } > > + > > + if (put_user(count, &uarg->ext_count) || > > + put_user(flags, &uarg->flags) || > > + put_user((u32)atomic_read(&et->node_cnt), &uarg->node_count) || > > + copy_to_user(&uarg->largest, &largest, sizeof(largest))) > > + ret = -EFAULT; > > +out: > > + kvfree(kbuf); > > + return ret; > > +} > > + > > void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi) > > { > > __init_extent_tree_info(&sbi->extent_tree[EX_READ]); > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > index 1588b64d04a3..69641fc31c51 100644 > > --- a/fs/f2fs/f2fs.h > > +++ b/fs/f2fs/f2fs.h > > @@ -26,6 +26,7 @@ > > #include > > #include > > > > +#include > > #include > > #include > > > > @@ -4590,6 +4591,8 @@ void f2fs_update_read_extent_cache(struct dnode_of_data *dn); > > void f2fs_update_read_extent_cache_range(struct dnode_of_data *dn, > > pgoff_t fofs, block_t blkaddr, unsigned int len, > > enum extent_access_mode access_mode); > > +int f2fs_get_read_cache_extents(struct inode *inode, > > + struct f2fs_read_cache_extent __user *uarg); > > unsigned int f2fs_shrink_read_extent_tree(struct f2fs_sb_info *sbi, > > int nr_shrink); > > > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > index a3a5d499eadf..66ec9927d667 100644 > > --- a/fs/f2fs/file.c > > +++ b/fs/f2fs/file.c > > @@ -3672,6 +3672,14 @@ static int f2fs_ioc_precache_extents(struct file *filp) > > return f2fs_precache_extents(file_inode(filp)); > > } > > > > +static int f2fs_ioc_get_read_cache_extents(struct file *filp, unsigned long arg) > > +{ > > + struct inode *inode = file_inode(filp); > > + > > + return f2fs_get_read_cache_extents(inode, > > + (struct f2fs_read_cache_extent __user *)arg); > > +} > > + > > static int f2fs_ioc_resize_fs(struct file *filp, unsigned long arg) > > { > > struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); > > @@ -4744,6 +4752,8 @@ static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > return f2fs_ioc_get_dev_alias_file(filp, arg); > > case F2FS_IOC_IO_PRIO: > > return f2fs_ioc_io_prio(filp, arg); > > + case F2FS_IOC_GET_READ_CACHE_EXTENTS: > > + return f2fs_ioc_get_read_cache_extents(filp, arg); > > default: > > return -ENOTTY; > > } > > @@ -5506,6 +5516,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > case F2FS_IOC_COMPRESS_FILE: > > case F2FS_IOC_GET_DEV_ALIAS_FILE: > > case F2FS_IOC_IO_PRIO: > > + case F2FS_IOC_GET_READ_CACHE_EXTENTS: > > break; > > default: > > return -ENOIOCTLCMD; > > diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h > > index 795e26258355..6ff9003bc030 100644 > > --- a/include/uapi/linux/f2fs.h > > +++ b/include/uapi/linux/f2fs.h > > @@ -45,6 +45,8 @@ > > #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25) > > #define F2FS_IOC_GET_DEV_ALIAS_FILE _IOR(F2FS_IOCTL_MAGIC, 26, __u32) > > #define F2FS_IOC_IO_PRIO _IOW(F2FS_IOCTL_MAGIC, 27, __u32) > > +#define F2FS_IOC_GET_READ_CACHE_EXTENTS _IOWR(F2FS_IOCTL_MAGIC, 28, \ > > + struct f2fs_read_cache_extent) > > > > /* > > * should be same as XFS_IOC_GOINGDOWN. > > @@ -104,4 +106,23 @@ struct f2fs_comp_option { > > __u8 log_cluster_size; > > }; > > > > +struct f2fs_cache_extent_info { > > + __u32 fofs; /* start file offset in blocks */ > > + __u32 blk; /* start block address */ > > + __u32 len; /* length in blocks */ > > + __u32 last_access_mode; /* last access mode of extent_node */ > > +}; > > + > > +/* flags for f2fs_read_cache_extent */ > > +#define F2FS_EXT_FL_NO_EXTENT 0x1 /* extent cache disabled for this inode */ > > + > > +struct f2fs_read_cache_extent { > > + __u32 ext_count; /* in: array capacity; out: mapped extent count */ > > + __u32 flags; /* out: status flags */ > > + __u32 node_count; /* out: total extent nodes in tree */ > > + __u32 reserved; > > + struct f2fs_cache_extent_info largest; /* out: largest extent */ > > + struct f2fs_cache_extent_info extents[]; /* out: extent array */ > > +}; > > + > > #endif /* _UAPI_LINUX_F2FS_H */ > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel