fiemap: filesystem free space mapping
Subsystems (4)
cover fiemap: filesystem free space mapping
So, I was bored a few days ago, and I was sick of having to run xfs_db incorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.
Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
There are two methods of mapping - one is reporting free space in ascending extent start offset order, then other in ascending extent length order. Both a useful to have (e.g. defragmenter might want to know about the nearest free block to given offset or the largest free extent in a given region). Either way, XFS keeps indexes ordered in both ways, so they can be exported directly with minimal overhead.
The only "interesting" abuse of the interface is really the use of FIEMAP_EXTENT_LAST. This means that the last extent in a freespace index is being returned, rather than the last freespace extent. This is done because filesystems often have multiple free space indexes, and it may be difficult to sort/scan over multiple indexes in a single map.
This means an application needs to keep track of what freespace has been returned to it and adjust it's fiemap ranges apprpritately, or be aware of the underlying filesystem structure to for requests that don't span free space indexes. I don't see this a bug problem, because any application that is digging in freespace maps needs to know how the filesystem is structured to make any sense of the infomration returned. As such, I see this interface purely for filesystem diagnostics or utilities tightly bound to the filesystem (e.g. xfs_fsr).
I'll attach a patch for a small utility that uses this interace to replicate the xfs_db freespace command in a short while so people can see how it is used. that shoul dmake it easier to comment on. :)
Cheers,
Dave.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/2 fiemap: add freespace mapping to FS_IOC_FIEMAP
From: Dave Chinner <[email protected]>
fiemap is used to map extents of used space on files. it's just an array of extents, though, so there's no reason it can only index *used* space.
Ther eis need for getting freespace layout information into userspace. For example, defragmentation programs would find it useful to be able to map the free space in the filesystem to work out where it is best to move data to defragment it. Alternatively, knowing where free space is enables us to identify extents that need to be moved to defragment free space.
Hence, extend fiemap with the FIEMAP_FLAG_FREESPACE to indicate that the caller wants to map free space in the range fm_start bytes from the start of the filesystem for fm_length bytes.
Because XFS can report extents in size order without needing to sort, and this information is useful to xfs_fsr, also add FIEMAP_FLAG_FREESPACE_SIZE to tell the filesystem to return a freespace map ordered by extent size rather than offset. If there are multiple extents of the same size, then they are ordered by offset.
--- Documentation/filesystems/fiemap.txt | 37 +++++++++++++++++++++++++++++++--- include/linux/fiemap.h | 6 +++++- 2 files changed, 39 insertions(+), 4 deletions(-)
Documentation/filesystems/fiemap.txt +34 -3
@@ -2,9 +2,9 @@ Fiemap Ioctl ============ -The fiemap ioctl is an efficient method for userspace to get file -extent mappings. Instead of block-by-block mapping (such as bmap), fiemap -returns a list of extents. +The fiemap ioctl is an efficient method for userspace to get file or +filesystem extent mappings. Instead of block-by-block mapping (such as +bmap), fiemap returns a list of extents. Request Basics
@@ -58,6 +58,37 @@ If this flag is set, the kernel will sync the file before mapping extents. If this flag is set, the extents returned will describe the inodes extended attribute lookup tree, instead of its data tree. +* FIEMAP_FLAG_FREESPACE +If this flag is set, the extents returned will describe the +*filesystem's* free space map, with fm_start specifying the start offset +into the filesystems address range (in bytes) of the region to be +mapped. fm_length is the the byte range that will be mapped. Free space +extents will be mapped in ascending offset order. + +Filesystems with multiple freespace indexes may return +FIEMAP_EXTENT_LAST at the end of a specific freespace index map. Hence +FIEMAP_EXTENT_LAST does not mean there is no more free space to be +mapped, just that the requested range spanned multiple free space +indexes. + +Hence the caller needs to be aware of the underlying filesystem +implementation and geometry to make correct use of this call. As such, +this functionality is only intended for use by filesystem management +utilities (e.g. defragmentation tools) and not general purpose +applications. + +* FIEMAP_FLAG_FREESPACE_SIZE +If this flag is set, the filesystem freespace tree will be mapped +similar to FIEMAP_FLAG_FREESPACE, but extents will be ordered from +smallest free space extent to largest Where extents have the same size, +they will be ordered by ascending offset order similar to +FIEMAP_FLAG_FREESPACE. It is up to the application to track the highest +offset extent seen by this walk so that if it doesn't see a +FIEMAP_EXTENT_LAST flag, the application knows what offset to start the +next mapping from. + +The same caveats exist for this call for FIEMAP_EXTENT_LAST as for +FIEMAP_FLAG_FREESPACE. Extent Mapping --------------
include/linux/fiemap.h +5 -1
@@ -40,8 +40,12 @@ struct fiemap {#define FIEMAP_FLAG_SYNC 0x00000001/* sync file data before map */ #define FIEMAP_FLAG_XATTR 0x00000002/* map extended attribute tree */ +#define FIEMAP_FLAG_FREESPACE 0x00000004/* map fs freespace tree */ +#define FIEMAP_FLAG_FREESPACE_SIZE 0x00000008/* map freespace in size order */ -#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR) +#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR | \ + FIEMAP_FLAG_FREESPACE | \ + FIEMAP_FLAG_FREESPACE_SIZE)#define FIEMAP_EXTENT_LAST 0x00000001/* Last extent in file. */ #define FIEMAP_EXTENT_UNKNOWN 0x00000002/* Data location unknown. */
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/2 xfs: implement FIEMAP_FLAG_FREESPACE_*
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
As you wish.
--- fs/xfs/xfs_alloc.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_alloc.h | 7 ++ fs/xfs/xfs_iops.c | 12 ++- 3 files changed, 237 insertions(+), 1 deletion(-)
fs/xfs/xfs_alloc.c +219 -0
@@ -2470,3 +2470,222 @@ error0:xfs_perag_put (args.pag);return error; } + +/* +* Walk the extents in the tree given by the cursor, and dump them all into the +* fieinfo. At the last extent in the tree, set the FIEMAP_EXTENT_LAST flag so +* that we return only free space from this tree in a given request. +*/ +static int +xfs_alloc_ag_freespace_map ( +struct xfs_btree_cur *cur, +struct fiemap_extent_info *fieinfo, +xfs_agblock_t sagbno, +xfs_agblock_t eagbno) +{ +int error =0 ; +int i =1 ; + +/* +* Loop until we have either filled the fiemap or reached the end of +* the AG walk. +*/ +while (i) { +xfs_agblock_t fbno; +xfs_extlen_t flen; +xfs_daddr_t dbno; +xfs_fileoff_t dlen; +int flags =0 ; + + error =xfs_alloc_get_rec (cur, &fbno, &flen, &i); +if (error) +break ; +XFS_WANT_CORRUPTED_RETURN (i ==1 ); + +/* +* move the cursor now to make it easy to continue the loop and +* detect the last extent in the lookup. +*/ + error =xfs_btree_increment (cur,0 , &i); +if (error) +break ; + +/* range check - must be wholly withing requested range */ +if (fbno < sagbno || + (eagbno !=NULLAGBLOCK && fbno + flen > eagbno)) { +xfs_warn (cur->bc_mp,"10: %d/%d, %d/%d" , sagbno, eagbno, fbno, flen); +continue ; + } + +/* +* use daddr format for all range/len calculations as that is +* the format the range/len variables are supplied in by +* userspace. +*/ + dbno =XFS_AGB_TO_DADDR (cur->bc_mp, cur->bc_private.a.agno, fbno); + dlen =XFS_FSB_TO_BB (cur->bc_mp, flen); + +if (i ==0 ) + flags |=FIEMAP_EXTENT_LAST ; + error = -fiemap_fill_next_extent (fieinfo,BBTOB (dbno), +BBTOB (dbno),BBTOB (dlen), flags); +if (error) +break ; + } +return error; + +} + +/* +* Map the freespace from the requested range in the requested order. +* +* To make things simple, this function will only return the freespace from a +* single AG regardless of the size of the map passed in. That AG will be the AG +* that the first freespace is found in. In other words, FIEMAP_EXTENT_LAST does +* not mean the last freespace extent has been mapped, just that the last extent +* in a given freespace index has been mapped. The caller is responsible for +* moving the range to the next freespace region if it needs to query for more +* information. +* +* IOWs, the caller is responsible for knowing about the XFS filesystem +* structure and how it indexes freespace to use this call effectively. +*/ +#define XFS_FREESP_FLAGS (FIEMAP_FLAG_FREESPACE | FIEMAP_FLAG_FREESPACE_SIZE) +int +xfs_alloc_freespace_map ( +struct xfs_mount *mp, +struct fiemap_extent_info *fieinfo, +u64 start, +u64 length) +{ +struct xfs_btree_cur *cur; +struct xfs_buf *agbp; +struct xfs_perag *pag; +xfs_agnumber_t agno; +xfs_agnumber_t sagno; +xfs_agblock_t sagbno; +xfs_agnumber_t eagno; +xfs_agblock_t eagbno; +bool bycnt; +int error =0 ; + +/* can only have one type of mapping */ +if ((fieinfo->fi_flags &XFS_FREESP_FLAGS ) ==XFS_FREESP_FLAGS ) { +xfs_warn (mp,"1: 0x%x\n" , fieinfo->fi_flags); +return EINVAL ; + } + bycnt = (fieinfo->fi_flags &FIEMAP_FLAG_FREESPACE_SIZE ); + +if (XFS_B_TO_FSB (mp, start) >= mp->m_sb.sb_dblocks) { +xfs_warn (mp,"2: %lld, %lld/%lld\n" , start, +XFS_B_TO_FSB (mp, start), mp->m_sb.sb_dblocks); +return EINVAL ; + } +if (length < mp->m_sb.sb_blocksize) { +xfs_warn (mp,"3: %lld, %d\n" , length, mp->m_sb.sb_blocksize); +return EINVAL ; + } +if (start + length < start) { +xfs_warn (mp,"4: %lld/%lld, %lld" , start, length, start + length); +return EINVAL ; + } + + sagno =xfs_daddr_to_agno (mp,BTOBB (start)); + sagbno =xfs_daddr_to_agbno (mp,BTOBB (start)); + + eagno =xfs_daddr_to_agno (mp,BTOBB (start + length)); + eagbno =xfs_daddr_to_agbno (mp,BTOBB (start + length)); + +if (sagno == eagno && sagbno == eagbno) { +xfs_warn (mp,"5: %d/%d, %d/%d" , sagno, eagno, sagbno, eagbno); +return EINVAL ; + } + +/* +* Force out the log. This means any transactions that might have freed +* space before we took the AGF buffer lock are now on disk, and the +* volatile disk cache is flushed. +*/ +xfs_log_force (mp,XFS_LOG_SYNC ); + +/* +* Do initial lookup in by-bno tree. Keep skipping AGs until with +* either find a free space extent or reach the end of the search. +*/ +for (agno = sagno; agno < eagno; agno++) { +int i; + error =0 ; + + error =xfs_alloc_read_agf (mp,NULL , agno,0 , &agbp); +if (error || !agbp) { +xfs_warn (mp,"7: %p, %d" , agbp, error); + goto next; + } + + pag =xfs_perag_get (mp, agno); +if (pag->pagf_freeblks <= pag->pagf_flcount) { +/* no free space worth reporting */ +xfs_warn (mp,"6: %d %d" , pag->pagf_freeblks, + pag->pagf_flcount); + goto put_agbp; + } + + cur =xfs_allocbt_init_cursor (mp,NULL , agbp, agno, +XFS_BTNUM_BNO ); + error =xfs_alloc_lookup_ge (cur,0 , sagbno, &i); +if (error) { +xfs_warn (mp,"8: %d/%d, %d/%d" , sagno, eagno, sagbno, eagbno); + goto del_cursor; + } +XFS_WANT_CORRUPTED_GOTO (i ==1 , del_cursor); + +if (!bycnt) { +/* +* if we are doing a bno ordered lookup, we can just +* loop across the free space extents formatting them +* until we get to the end of the AG, eagbno or fill the +* fieinfo map. +*/ + error =xfs_alloc_ag_freespace_map (cur, fieinfo, sagbno, + agno == eagno ? eagbno :NULLAGBLOCK ); + }else { +/* +* We are doing a size ordered lookup. We know there is +* a free space extent somewhere past out start bno, so +* just kill the current cursor and start a size +* ordered scan to find all the freespace in the given +* range. +*/ +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); + cur =xfs_allocbt_init_cursor (mp,NULL , agbp, agno, +XFS_BTNUM_CNT ); + error =xfs_alloc_lookup_ge (cur,0 ,1 , &i); +if (error) + goto del_cursor; +XFS_WANT_CORRUPTED_GOTO (i ==1 , del_cursor); + + error =xfs_alloc_ag_freespace_map (cur, fieinfo, sagbno, + agno == eagno ? eagbno :NULLAGBLOCK ); + } + +del_cursor: +xfs_btree_del_cursor (cur, error <0 ?XFS_BTREE_ERROR + :XFS_BTREE_NOERROR ); +put_agbp: +xfs_perag_put (pag); +xfs_buf_relse (agbp); +next: +if (error) +break ; + sagbno =0 ; + } + +/* +* negative errno indicates that we hit a FIEMAP_EXTENT_LAST flag. Clear +* the error in that case. +*/ +if (error <0 ) + error =0 ; + +return error;; +}
fs/xfs/xfs_alloc.h +7 -0
@@ -231,4 +231,11 @@ xfs_alloc_get_rec( xfs_extlen_t *len,/* output: length of extent */ int *stat); /* output: success/failure */ +int +xfs_alloc_freespace_map ( +struct xfs_mount *mp, +struct fiemap_extent_info *fieinfo, +u64 start, +u64 length); +#endif /* __XFS_ALLOC_H__ */
fs/xfs/xfs_iops.c +11 -1
@@ -938,7 +938,9 @@ xfs_vn_update_time(return -xfs_trans_commit (tp,0 ); } -#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) +#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR | \ + FIEMAP_FLAG_FREESPACE | \ + FIEMAP_FLAG_FREESPACE_SIZE)/* * Call fiemap helper to fill in user data.
@@ -997,6 +999,13 @@ xfs_vn_fiemap(if (error)return error; +if ((fieinfo->fi_flags & + (FIEMAP_FLAG_FREESPACE |FIEMAP_FLAG_FREESPACE_SIZE ))) { + error =xfs_alloc_freespace_map (ip->i_mount, fieinfo, + start, length); + goto out; + } +/* Set up bmap header for xfs internal routine */ bm.bmv_offset =BTOBB (start);/* Special case for whole file */
@@ -1017,6 +1026,7 @@ xfs_vn_fiemap( bm.bmv_iflags |=BMV_IF_DELALLOC ; error =xfs_getbmap (ip, &bm, xfs_fiemap_format, fieinfo); +out:if (error)return -error;
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
[RFC, PATCH 3/2] xfsprogs: space management tool
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
xfs_spaceman is intended as a diagnostic and control tool for space management operations within XFS. Operations like examining free space, managing allocation policies, issuing block discards on free space, etc.
The tool is modelled on the xfs_io interface, allowing both interactive and command line control of the tool, enabling it to be used in scripts and automated management tools.
--- Makefile | 3 +- spaceman/Makefile | 34 +++++ spaceman/file.c | 149 +++++++++++++++++++++ spaceman/freesp.c | 377 +++++++++++++++++++++++++++++++++++++++++++++++++++++ spaceman/init.c | 117 +++++++++++++++++ spaceman/init.h | 24 ++++ spaceman/space.h | 37 ++++++ 7 files changed, 740 insertions(+), 1 deletion(-)
Makefile +2 -1
@@ -41,7 +41,7 @@ endif LIB_SUBDIRS = libxfs libxlog libxcmd libhandle libdisk TOOL_SUBDIRS = copy db estimate fsck fsr growfs io logprint mkfs quota \ - mdrestore repair rtcp m4 man doc po debian + mdrestore repair rtcp m4 man doc po debian spaceman SUBDIRS = include $(LIB_SUBDIRS) $(TOOL_SUBDIRS)
@@ -62,6 +62,7 @@ io: libxcmd libhandle mkfs: libxfs quota: libxcmd repair: libxfs libxlog +space: libxcmd ifneq ($(ENABLE_BLKID), yes) mkfs: libdisk
spaceman/Makefile new file +34 -0
@@ -0,0 +1,34 @@ +# +# Copyright (c) 2012 Red Hat, Inc. All Rights Reserved. +# + +TOPDIR = .. +include $(TOPDIR)/include/builddefs + +LTCOMMAND = xfs_spaceman +HFILES = init.h space.h +CFILES = init.c \ + file.c freesp.c + +LLDLIBS = $(LIBXCMD) +LTDEPENDENCIES = $(LIBXCMD) +LLDFLAGS = -static + +ifeq ($(ENABLE_READLINE),yes) +LLDLIBS += $(LIBREADLINE) $(LIBTERMCAP) +endif + +ifeq ($(ENABLE_EDITLINE),yes) +LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP) +endif + +default: depend $(LTCOMMAND) + +include $(BUILDRULES) + +install: default + $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) + $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) +install-dev: + +-include .dep
spaceman/file.c new file +149 -0
149 lines not on this page · raw message
spaceman/freesp.c new file +377 -0
377 lines not on this page · raw message
spaceman/init.c new file +117 -0
117 lines not on this page · raw message
spaceman/init.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2012 Red Hat, Inc. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +extern char *progname; +extern int exitcode; + +#define min (a,b) (((a)<(b))?(a):(b)) +#define max (a,b) (((a)>(b))?(a):(b)) +
spaceman/space.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2012 Red Hat, Inc. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +typedef struct fileio { +int fd;/* open file descriptor */ +int flags;/* flags describing file state */ +char *name;/* file name at time of open */ +xfs_fsop_geom_t geom;/* XFS filesystem geometry */ +}fileio_t ; + +extern fileio_t *filetable;/* open file table */ +extern int filecount;/* number of open files */ +extern fileio_t *file;/* active file in file table */ +extern int filelist_f (void ); + +extern int openfile (char *,xfs_fsop_geom_t *,int ,mode_t ); +extern int addfile (char *,int ,xfs_fsop_geom_t *,int ); + +extern void file_init (void ); +extern void help_init (void ); +extern void quit_init (void ); +extern void freesp_init (void );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
One question about the usage of this interface - is the ioctl() called on an open fd for the root inode, or is it called on any open fd in the filesystem? In some sense, getting the free space on the root (or preferably block dev inode if that would work) would make the most sense, since FIEMAP is intended to be related to a specific file.
That said, it is a lot easier to use if it can be on any open file handle in the filesystem, and one could consider the free space as being related to every file in the filesystem (e.g. for the next block allocation or defrag migration).
Quoted 8 lines
There are two methods of mapping - one is reporting free space in ascending extent start offset order, then other in ascending extent length order. Both a useful to have (e.g. defragmenter might want to know about the nearest free block to given offset or the largest free extent in a given region). Either way, XFS keeps indexes ordered in both ways, so they can be exported directly with minimal overhead.
Quoted 6 lines
The only "interesting" abuse of the interface is really the use of
FIEMAP_EXTENT_LAST. This means that the last extent in a freespace index is being returned, rather than the last freespace extent. This is done because filesystems often have multiple free space indexes, and it may be difficult to sort/scan over multiple indexes in a single map.
I'm not sure I understand the distinction you are trying to convey here. Could you elaborate?
Quoted 14 lines
This means an application needs to keep track of what freespace has been returned to it and adjust it's fiemap ranges apprpritately, or be aware of the underlying filesystem structure to for requests that don't span free space indexes. I don't see this a bug problem, because any application that is digging in freespace maps needs to know how the filesystem is structured to make any sense of the infomration returned. As such, I see this interface purely for filesystem diagnostics or utilities tightly bound to the filesystem (e.g.
xfs_fsr).I'll attach a patch for a small utility that uses this interace to replicate the
xfs_dbfreespace command in a short while so people can see how it is used. that shoul dmake it easier to comment on. :)
Quoted 7 lines
Cheers,
Dave.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers, Andreas
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [RFC, PATCH 3/2] xfsprogs: space management tool
In reply to Dave ChinnerQuoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfs_spacemanis intended as a diagnostic and control tool for space management operations within XFS. Operations like examining free space, managing allocation policies, issuing block discards on free space, etc.The tool is modelled on the
xfs_iointerface, allowing both interactive and command line control of the tool, enabling it to be used in scripts and automated management tools.
Manual page seems to be missing.
Signature · 6 lines
Arkadiusz Miśkiewicz, arekm / maven.pl _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 12 lines · Andreas Dilger
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
Quoted 6 lines
One question about the usage of this interface - is the
ioctl()called on an open fd for the root inode, or is it called on any open fd in the filesystem? In some sense, getting the free space on the root (or preferably block dev inode if that would work) would make the most sense, since FIEMAP is intended to be related to a specific file.
fiemap in XFs is currently only hooked up to files, not directories. I didn't change that, so it needs an open regular file in the filesystem to work. I need to change that for it to work on directories - I think that having it work on the root dir of a filesystem is the right thing to do, but really having it behave like fstatfs(2) is where it shoul dend up, I think.
Quoted 4 lines
That said, it is a lot easier to use if it can be on any open file handle in the filesystem, and one could consider the free space as being related to every file in the filesystem (e.g. for the next block allocation or defrag migration).
*nod*
Quoted 15 lines
Quoted 8 lines
There are two methods of mapping - one is reporting free space in ascending extent start offset order, then other in ascending extent length order. Both a useful to have (e.g. defragmenter might want to know about the nearest free block to given offset or the largest free extent in a given region). Either way, XFS keeps indexes ordered in both ways, so they can be exported directly with minimal overhead.
Quoted 6 lines
The only "interesting" abuse of the interface is really the use of
FIEMAP_EXTENT_LAST. This means that the last extent in a freespace index is being returned, rather than the last freespace extent. This is done because filesystems often have multiple free space indexes, and it may be difficult to sort/scan over multiple indexes in a single map.
Quoted 2 lines
I'm not sure I understand the distinction you are trying to convey here. Could you elaborate?
XFs has multiple Allocation Groups with separate indexes in each AG. It only make sense for filesystem tools to be finding free space in a specific region (i.e. the AG they want to allocate in). xfs-fsr already controls the AG that the new extents are allocated in, but it has no idea of whether that is the best AG to relocate the data to - it just follows the kernel allocation rules based on the location of the inode. If we want to select a new AG based on, say, largest free extent size, then we need to know what the largest sizes in each AG are. Hence we want to know when we reach the end of an AG index when pulling the freespace data out of the kernel so we categorise it by AG.
I suspect a similar thing might be useful for btrfs, with per-device freespace mappings...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [RFC, PATCH 3/2] xfsprogs: space management tool
In reply to Arkadiusz MiśkiewiczQuoted 8 lines · Arkadiusz Miśkiewicz
Quoted 7 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfs_spacemanis intended as a diagnostic and control tool for space management operations within XFS. Operations like examining free space, managing allocation policies, issuing block discards on free space, etc.
Quoted 5 lines
Quoted 3 lines
The tool is modelled on the
xfs_iointerface, allowing both interactive and command line control of the tool, enabling it to be used in scripts and automated management tools.Manual page seems to be missing.
Sure, I haven't written one. Way off the radar at the moment - this is just a prototype tool. I won't write a man page until it's ready for gneral use....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
I think the right way to handle this is to introduce a new ioctl which uses the same structures. That way we have a reasonable interface, without issue like which file does it need to be called on because the VFS glue can turn it into a superblock op.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
Quoted 4 lines
I think the right way to handle this is to introduce a new ioctl which uses the same structures. That way we have a reasonable interface, without issue like which file does it need to be called on because the VFS glue can turn it into a superblock op.
A VFS level ioctl or an XFS ioctl?
I thought about a new ioctl, but then what's the point of having an extensible fiemap interface if we create new ioctls with an identical interface for doing something that the existing ioctl is perfectly capable of doing? I'd still need special flags to control the ioctl behaviour even though it uses struct fiemap and plumbing, so it seemed pointless to introduce a new ioctl....
As it is, the only reason fiemap doesn't work on directory ioctls for XFS is that it hasn't been hooked up to directories. I can't see anything in the fiemap VFS layers that prevents us from mapping directories and we know the mapping code in XFS works on directories. So that would the "what file" problem go away - any file would do as long as the user has the permissions to run the free space mapping command....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 18 lines · Dave Chinner
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
Quoted 4 lines
I think the right way to handle this is to introduce a new ioctl which uses the same structures. That way we have a reasonable interface, without issue like which file does it need to be called on because the VFS glue can turn it into a superblock op.
Quoted 8 lines
A VFS level ioctl or an XFS ioctl?
I thought about a new ioctl, but then what's the point of having an extensible fiemap interface if we create new ioctls with an identical interface for doing something that the existing ioctl is perfectly capable of doing? I'd still need special flags to control the ioctl behaviour even though it uses struct fiemap and plumbing, so it seemed pointless to introduce a new ioctl....
This brings us one step close to the norton disk doctor defrag display. I'm all for it in the main fiemap call, it makes much more sense for the users I think.
-chris
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 17 lines · Chris Mason
Quoted 16 lines · Dave Chinner
Quoted 15 lines · Christoph Hellwig
Quoted 10 lines · Dave Chinner
So, I was bored a few days ago, and I was sick of having to run
xfs_dbincorrectly report free space extents when the filesytem is mounted, so I decided to extend fiemap to export freespace mappings to userspace so I could get the information coherently through the mounted filesystem.Yes, this could probably be considered interface abuse but, well, it was simple to do because extent mapping is exactly what fiemap is designed to do. Hence I didn't have to write new walkers/formatters and I was using code I knew worked correctly.
I think the right way to handle this is to introduce a new ioctl which uses the same structures. That way we have a reasonable interface, without issue like which file does it need to be called on because the VFS glue can turn it into a superblock op.
Quoted 8 lines
Quoted 8 lines
A VFS level ioctl or an XFS ioctl?
I thought about a new ioctl, but then what's the point of having an extensible fiemap interface if we create new ioctls with an identical interface for doing something that the existing ioctl is perfectly capable of doing? I'd still need special flags to control the ioctl behaviour even though it uses struct fiemap and plumbing, so it seemed pointless to introduce a new ioctl....
Hi Dave,
I am writing XFS shrinkfs feature, and I really need an approach to get the free space of an XFS file system sincexfs_db can not fetch agf->agf_freeblks and agf_btreeblks against a mounted partition to calculate it out for
online shrink operation that just as what's you have mentioned above.
So currently I add a new ioctl for this purpose, that's would be fine if we can have a fiemap interface to do it so that
I can kill this new ioctl to avoid duplicate efforts.
Thanks,
-Jeff
Quoted 10 lines
This brings us one step close to the norton disk doctor defrag display. I'm all for it in the main fiemap call, it makes much more sense for the users I think.
-chris
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 2 lines · Chris Mason
I'm all for it in the main fiemap call, it makes much more sense for the users I think.
How so? Current fiemap is a per-inode information, Daves new call is per-fs. Making one a flag of another is a gross user interface. In addition we're bound to get issue where filesystems fail to wire up fiemap to the tons of different iops just for this operation, or accidentally wire up "real" fiemap to things like special files or pipes.
Btw, I'd like t orestate that I really love to see this functionality in the VFS, just not multiplexed over FIEMAP.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · Christoph Hellwig
Quoted 2 lines · Chris Mason
I'm all for it in the main fiemap call, it makes much more sense for the users I think.
How so? Current fiemap is a per-inode information, Daves new call is per-fs. Making one a flag of another is a gross user interface. In addition we're bound to get issue where filesystems fail to wire up fiemap to the tons of different iops just for this operation, or accidentally wire up "real" fiemap to things like special files or pipes.
Quoted 2 lines
Btw, I'd like t orestate that I really love to see this functionality in the VFS, just not multiplexed over FIEMAP.
That's fine. I just wanted to clarify what you were asking. FIEMAPFS it is, then...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/2] fiemap: add freespace mapping to FS_IOC_FIEMAP
In reply to Dave ChinnerQuoted 26 lines · Dave Chinner
From: Dave Chinner<[email protected]>
fiemap is used to map extents of used space on files. it's just an array of extents, though, so there's no reason it can only index *used* space.
Ther eis need for getting freespace layout information into userspace. For example, defragmentation programs would find it useful to be able to map the free space in the filesystem to work out where it is best to move data to defragment it. Alternatively, knowing where free space is enables us to identify extents that need to be moved to defragment free space.
Hence, extend fiemap with the
FIEMAP_FLAG_FREESPACEto indicate that the caller wants to map free space in the rangefm_startbytes from the start of the filesystem forfm_lengthbytes.Because XFS can report extents in size order without needing to sort, and this information is useful to
xfs_fsr, also addFIEMAP_FLAG_FREESPACE_SIZEto tell the filesystem to return a freespace map ordered by extent size rather than offset. If there are multiple extents of the same size, then they are ordered by offset.Signed-off-by Dave Chinner<[email protected]>---
...
include/linux/fiemap.h
Quoted 5 lines
--------------
include/linux/fiemap.h +0
-0
include/uabi/linux/fiemap.h
^^^^
other than that, it looks good.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/2] fiemap: add freespace mapping to FS_IOC_FIEMAP
Quoted 37 lines · Mark Tinguely
Quoted 26 lines · Dave Chinner
From: Dave Chinner<[email protected]>
fiemap is used to map extents of used space on files. it's just an array of extents, though, so there's no reason it can only index *used* space.
Ther eis need for getting freespace layout information into userspace. For example, defragmentation programs would find it useful to be able to map the free space in the filesystem to work out where it is best to move data to defragment it. Alternatively, knowing where free space is enables us to identify extents that need to be moved to defragment free space.
Hence, extend fiemap with the
FIEMAP_FLAG_FREESPACEto indicate that the caller wants to map free space in the rangefm_startbytes from the start of the filesystem forfm_lengthbytes.Because XFS can report extents in size order without needing to sort, and this information is useful to
xfs_fsr, also addFIEMAP_FLAG_FREESPACE_SIZEto tell the filesystem to return a freespace map ordered by extent size rather than offset. If there are multiple extents of the same size, then they are ordered by offset.Signed-off-by Dave Chinner<[email protected]>---
...
include/linux/fiemap.h
Quoted 5 lines
--------------
include/linux/fiemap.h +0
-0
include/uabi/linux/fiemap.h
Quoted 2 lines
^^^^other than that, it looks good.
include/uapi/ actaully, but that change was made after I posted the patches so there's no surprise that It didn't apply.
As it is, this needs to be redone into an FS_IOC_FIEMAPFS ioctl in response to other reviews. I've already done that work (a week ago), I just haven't fully tested it yet so I haven't reported it...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/2] fiemap: add freespace mapping to FS_IOC_FIEMAP
Quoted 44 lines · Dave Chinner
Quoted 38 lines · Mark Tinguely
Quoted 26 lines · Dave Chinner
From: Dave Chinner<[email protected]>
fiemap is used to map extents of used space on files. it's just an array of extents, though, so there's no reason it can only index *used* space.
Ther eis need for getting freespace layout information into userspace. For example, defragmentation programs would find it useful to be able to map the free space in the filesystem to work out where it is best to move data to defragment it. Alternatively, knowing where free space is enables us to identify extents that need to be moved to defragment free space.
Hence, extend fiemap with the
FIEMAP_FLAG_FREESPACEto indicate that the caller wants to map free space in the rangefm_startbytes from the start of the filesystem forfm_lengthbytes.Because XFS can report extents in size order without needing to sort, and this information is useful to
xfs_fsr, also addFIEMAP_FLAG_FREESPACE_SIZEto tell the filesystem to return a freespace map ordered by extent size rather than offset. If there are multiple extents of the same size, then they are ordered by offset.Signed-off-by Dave Chinner<[email protected]>---
...
include/linux/fiemap.h
Quoted 5 lines
--------------
include/linux/fiemap.h +0
-0include/uabi/linux/fiemap.h ^^^^Quoted 1 line
other than that, it looks good.
include/uapi/actaully, but that change was made after I posted the patches so there's no surprise that It didn't apply.
Quoted 7 lines
As it is, this needs to be redone into an
FS_IOC_FIEMAPFSioctl in response to other reviews. I've already done that work (a week ago), I just haven't fully tested it yet so I haven't reported it...Cheers,
Dave.
Okay. Thank-you for the update.
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs