xfs_io(8)
π xfs_io β the girlies' guide to poking at the XFS I/O path
okay so bestie, welcome to xfs_io(8), part of the System Manager's Manual. Yes it's a section 8 page. Yes it's about debugging. No you don't have to be scared. Let's go π«Ά
β¨ NAME β¨
xfs_io β debug the I/O path of an XFS filesystem π
πΈ SYNOPSIS πΈ
xfs_io [ -adfimrRstxT ] [ -c cmd ] ... [ -C cmd ] ... [ -p prog ] [ file ]
xfs_io -V
π¦ DESCRIPTION π¦
So xfs_io is a debugging tool β like its sibling xfs_db(8) β except instead of staring at the raw XFS volume itself, it's all about the regular file I/O paths. Not just the obvious read/write/mmap interfaces for manipulating files, but also every single XFS extension (space preallocation, additional inode flags, all of it). it's giving "I contain multitudes" β¨
π OPTIONS π
xfs_io commands can run interactively (that's the default, no cap) or as arguments right on the command line. Interactive mode always runs commands on the current open file. Command-line commands though? Those can be repeated across all open files, not just the current one. In general, open file iteration happens for commands that operate on file content or state. Meanwhile commands that touch filesystem- or system-wide state only run on the current file, no matter how many files you've got open. You can pass multiple arguments on the command line and they run in the sequence given. The program exits once all commands have been run. periodt π
-c cmdβ run the specified command on all currently open files. To keep compatibility with historical usage, commands that can't be run on all open files will still be run, but only execute once on the current open file. You can give multiple-carguments and interleave them on the command line in any order with-Ccommands. β¨-C cmdβ run the specified command only on the current open file. Multiple-Carguments allowed, and they can be interleaved on the command line in any order with-ccommands. π-p progβ set the program name used for prompts and some error messages. Default value isxfs_io. π«Ά-fβ create the file if it doesn't already exist. πΈ-rβ open the file read-only, initially. This is required if the file is immutable or append-only. π-iβ start an idle thread. The whole point of this idle thread is to test io from a multi threaded process. With a single threaded process, the file table is not shared and file structs are not reference counted. Spawning an idle thread can help detect file struct reference leaks. π-xβ expert mode. Dangerous commands are only available in this mode. These commands also tend to require additional privileges. π-Vβ prints the version number and exits. bye π
The other open(2) options described below are also available from the command line.
π CONCEPTS π
xfs_io keeps track of a number of open files and memory mappings. Files can be initially opened on the command line (optionally!), and more files can also be opened later. multitasking queen π
xfs_io commands break down into three groups. Some commands are aimed at doing regular file I/O β read, write, sync, space preallocation, etc.
The second set exists for manipulating memory mapped regions of a file β mapping, accessing, storing, unmapping, flushing, etc.
The remaining commands are for navigation and display of data structures relating to the open files, mappings, and the filesystems where they live.
Many commands have extensive online help. Use the help command for more details on any command. iykyk π§
β FILE I/O COMMANDS β
file [ N ]β display a list of all open files and (optionally) switch to an alternate current open file.open [[ -acdfrstRTPL ] path ]β closes the current file and opens the file specified by path instead. Without any arguments, displays statistics about the current file β see thestatcommand. π¦-aβ opens append-only (O_APPEND).-dβ opens for direct I/O (O_DIRECT).-fβ creates the file if it doesn't already exist (O_CREAT).-rβ opens read-only (O_RDONLY).-sβ opens for synchronous I/O (O_SYNC).-tβ truncates on open (O_TRUNC).-nβ opens in non-blocking mode if possible (O_NONBLOCK).-Tβ create a temporary file not linked into the filesystem namespace (O_TMPFILE). The pathname passed must refer to a directory which is treated as virtual parent for the newly created invisible file. Can not be used together with the-roption. π-Rβ marks the file as a realtime XFS file after opening it, if it is not already marked as such.-Pβ opens the path as a referent only (O_PATH). This is incompatible with other flags specifying otherO_xxxflags apart from-L.-Lβ doesn't follow symlinks (O_NOFOLLOW). This is incompatible with other flags specifying otherO_xxxflags apart from-P.
oβ see theopencommand.closeβ closes the current open file, marking the next open file as current (if one exists).cβ see theclosecommand.chmod -r | -wβ change the mode of the currently open file. The-roption sets the file permissions to read-only (0444), whilst-wsets the file permissions to read-write (0644). This letsxfs_ioset up mismatches between the file permissions and the open file descriptor read/write mode, so you can exercise permission checks inside various syscalls. messy on purpose, iconic β¨pread [ -b bsize ] [ -qUv ] [ -FBR [ -Z seed ] ] [ -V vectors ] offset lengthβ reads a range of bytes in a specified blocksize from the given offset.-bβ can be used to set the blocksize into which theread(2)requests will be split. The default blocksize is4096bytes.-qβ quiet mode, do not write anything to standard output.-Uβ perform thepreadv2(2)call withRWF_DONTCACHE.-vβ dump the contents of the buffer after reading. By default only the count of bytes actually read is dumped.-Fβ read the buffers in a forward sequential direction.-Bβ read the buffers in a reverse sequential direction.-Rβ read the buffers in the give range in a random order.-Z seedβ specify the random number seed used for random reads.-V vectorsβ use the vectored IO read syscallpreadv(2)with a number of blocksize length iovecs. The number of iovecs is set by the vectors parameter.
rβ see thepreadcommand.pwrite [ -i file ] [ -qAdDwNOUW ] [ -s skip ] [ -b size ] [ -S seed ] [ -FBR [ -Z zeed ] ] [ -V vectors ] offset lengthβ writes a range of bytes in a specified blocksize from the given offset. The bytes written can be either a set pattern or read in from another file before writing. πΈ-iβ allows an input file to be specified as the source of the data to be written.-qβ quiet mode, do not write anything to standard output.-dβ causes direct I/O, rather than the usual buffered I/O, to be used when reading the input file.-wβ callfdatasync(2)once all writes are complete (included in timing results).-Nβ perform thepwritev2(2)call withRWF_NOWAIT.-Dβ perform thepwritev2(2)call withRWF_DSYNC.-Aβ perform thepwritev2(2)call withRWF_ATOMIC.-Uβ perform thepwritev2(2)call withRWF_DONTCACHE.-Oβ perform pwrite once and return the (maybe partial) bytes written.-Wβ callfsync(2)once all writes are complete (included in timing results).-sβ specifies the number of bytes to skip from the start of the input file before starting to read.-bβ used to set the blocksize into which thewrite(2)requests will be split. The default blocksize is4096bytes.-Sβ used to set the (repeated) fill pattern which is used when the data to write is not coming from a file. The default buffer fill pattern value is0xcdcdcdcd.-Fβ write the buffers in a forward sequential direction.-Bβ write the buffers in a reverse sequential direction.-Rβ write the buffers in the give range in a random order.-Z seedβ specify the random number seed used for random write.-V vectorsβ use the vectored IO write syscallpwritev(2)with a number of blocksize length iovecs. The number of iovecs is set by the vectors parameter.
wβ see thepwritecommand.bmap [ -adelpv ] [ -n nx ]β prints the block mapping for the current open file. Refer to thexfs_bmap(8)manual page for complete documentation. πfiemap [ -alev ] [ -n nx ] [ offset [ len ]]β prints the block mapping for the current open file using the fiemap ioctl. Options behave as described in thexfs_bmap(8)manual page.
Optionally, this command also supports passing the start offset from where to begin the mapping and the length of that region. The kernel will return any full extents which intersect with the requested range, and the fiemap command will print them in their entirety. If the requested range starts or ends in a hole, fiemap will print the hole, truncated to the requested range. π³οΈβ¨
extsize [ -R | -D ] [ value ]β display and/or modify the preferred extent size used when allocating space for the currently open file. If the-Roption is specified, a recursive descent is performed for all directory entries below the currently open file (-Dcan be used to restrict the output to directories only). If the target file is a directory, then the inherited extent size is set for that directory (new files created in that directory inherit that extent size). The value should be specified in bytes, or using one of the usual units suffixes (k,m,g,b, etc). The extent size is always reported in units of bytes. π
more parts coming bestie, don't go anywhere π«Ά
cowextsize
cowextsize [ -R | -D ] [ value ]
Okay so this one is about the preferred copy-on-write extent size π β the size that gets used when allocating space for the file you currently have open. You can look at it, you can change it, dealer's choice.
-Rβ does a recursive descent through all the directory entries below the file you currently have open π-Dβ can be used to restrict the output to directories only π
If the target file is a directory, then the inherited CoW extent size gets set for that directory β meaning new files created in that directory inherit that CoW extent size π«Ά. The value should be given in bytes, or with one of the usual unit suffixes (k, m, g, b, etc). And no matter what, the extent size is always reported in units of bytes β¨.
allocsp
allocsp size 0
Sets the size of the file to size and zeroes any additional space that got allocated, using the XFS_IOC_ALLOCSP/XFS_IOC_FREESP system call described in the xfsctl(3) manual page. And here's the tea: allocsp and freesp do exactly the same thing π. Literally identical.
These commands are no longer supported as of Linux 5.17. π Gone. Retired. Do not come for them.
freesp
freesp size 0
See the allocsp command above, bestie β same thing, same fate πͺ¦.
fadvise
fadvise [ -r | -s | [[ -d | -n | -w ] offset length ]]
On platforms that support it, this lets you drop hints to the system about what I/O patterns you expect on the file π. The range arguments are required by some of the advise commands (the ones marked [*] below), and the others must have no range arguments at all.
With no arguments, the POSIX_FADV_NORMAL advice is implied β that's just the default readahead, no drama πΈ.
-dβ the data will not be accessed again in the near future (POSIX_FADV_DONTNEED[*])-nβ data will be accessed once and not be reused (POSIX_FADV_NOREUSE[*])-rβ expect access to data in random order (POSIX_FADV_RANDOM), which sets readahead to zero π«’-sβ expect access to data in sequential order (POSIX_FADV_SEQUENTIAL), which doubles the default readahead on the file π-wβ advises the specified data will be needed again (POSIX_FADV_WILLNEED[*]), which forces the maximum readahead π₯
fdatasync
Calls fdatasync(2) to flush the file's in-core data to disk πΎ.
fsync
Calls fsync(2) to flush all in-core file state to disk. Not just the data β the whole vibe β¨.
s
See the fsync command. That's it. That's the whole entry. A little nickname, as a treat π.
sync_range
sync_range [ -a | -b | -w ] offset length
On platforms that support it, lets you control syncing a range of the file to disk. With no options, SYNC_FILE_RANGE_WRITE is implied on the range you supplied π.
-aβ wait for IO in the given range to finish after writing (SYNC_FILE_RANGE_WAIT_AFTER)-bβ wait for IO in the given range to finish before writing (SYNC_FILE_RANGE_WAIT_BEFORE)-wβ start writeback of dirty data in the given range (SYNC_FILE_RANGE_WRITE)
sync
Calls sync(2) to flush all filesystems' in-core data to disk. Everybody. Every filesystem. All of them π
.
syncfs
Calls syncfs(2) to flush this filesystem's in-core data to disk. Just yours, main character energy π.
resvsp
resvsp offset length
Allocates reserved, unwritten space for part of a file, using the XFS_IOC_RESVSP system call described in the xfsctl(3) manual page π¦.
unresvsp
unresvsp offset length
Frees reserved space for part of a file, using the XFS_IOC_UNRESVSP system call described in the xfsctl(3) manual page. Undoing the reservation, as one does π§.
falloc
falloc [ -k ] offset length
Allocates reserved, unwritten space for part of a file using the fallocate routine as described in the fallocate(2) manual page.
-kβ will set theFALLOC_FL_KEEP_SIZEflag as described infallocate(2)π
fcollapse
fcollapse offset length
Calls fallocate with the FALLOC_FL_COLLAPSE_RANGE flag as described in the fallocate(2) manual page β this de-allocates blocks and eliminates the hole created in the process by shifting data blocks into the hole π³οΈβ¨.
finsert
finsert offset length
Calls fallocate with the FALLOC_FL_INSERT_RANGE flag as described in the fallocate(2) manual page, to create the hole by shifting data blocks πΈ.
fpunch
fpunch offset length
Punches (de-allocates) blocks in the file by calling fallocate with the FALLOC_FL_PUNCH_HOLE flag as described in the fallocate(2) manual page. Hole punch, but make it filesystem π
.
funshare
funshare offset length
Calls fallocate with the FALLOC_FL_UNSHARE_RANGE flag as described in the fallocate(2) manual page, to unshare all shared blocks within the range. Breaking up with the shared blocks, no hard feelings π«Ά.
fzero
fzero [ -k ] offset length
Calls fallocate with the FALLOC_FL_ZERO_RANGE flag as described in the fallocate(2) manual page, to allocate and zero blocks within the range. With the -k option, use the FALLOC_FL_KEEP_SIZE flag as well β.
fwzero
fwzero offset length
Calls fallocate with the FALLOC_FL_WRITE_ZEROES flag as described in the fallocate(2) manual page, to allocate and zero blocks within the range by submitting write zeroes βοΈ.
zero
zero offset length
Calls xfsctl with XFS_IOC_ZERO_RANGE as described in the xfsctl(3) manual page, to allocate and zero blocks within the range π.
truncate
truncate offset
Truncates the current file at the given offset using ftruncate(2) βοΈ.
sendfile
sendfile [ -q ] -i srcfile | -f N [ offset length ]
On platforms which support it, this allows a direct in-kernel copy between two file descriptors π₯. The currently open file is the target; the source must be specified as another open file (-f) or by path (-i).
-qβ quiet mode, do not write anything to standard output π€«
readdir
readdir [ -v ] [ -o offset ] [ -l length ]
Reads a range of directory entries from a given offset of a directory π.
-vβ verbose mode: dump dirent content as defined inreaddir(3)π-oβ specify starting offset-lβ specify total length to read (in bytes)
seek
seek -a | -d | -h [ -r ] [ -s ] offset
On platforms that support the lseek(2) SEEK_DATA and SEEK_HOLE options, display the offsets of the specified segments πΊοΈ.
-aβ Display both data and hole segments starting at the specified offset-dβ Display the data segment starting at the specified offset-hβ Display the hole segment starting at the specified offset-rβ Recursively display all the specified segments starting at the specified offset π-sβ Display the startinglseek(2)offset. This offset will be a calculated value when both data and holes are displayed together, or when performing a recursively display
reflink
reflink [ -C ] [ -q ] src_file [src_offset dst_offset length]
On filesystems that support the FICLONERANGE or BTRFS_IOC_CLONE_RANGE ioctls, maps length bytes at offset dst_offset in the open file to the same physical blocks that are mapped at offset src_offset in the file src_file, replacing any contents that may already have been there π.
And then here's the magic: if a program writes into a reflinked block range of either file, the dirty blocks will be cloned, written to, and remapped ("copy on write") in the affected file β leaving the other file(s) unchanged β¨. It's giving shared-but-not-really.
If src_offset, dst_offset, and length are omitted, all contents of src_file will be reflinked into the open file.
-Cβ Print timing statistics in a condensed format-qβ Do not print timing statistics at all π€«
dedupe
dedupe [ -C ] [ -q ] src_file src_offset dst_offset length
On filesystems that support the FIDEDUPERANGE or BTRFS_IOC_FILE_EXTENT_SAME ioctls, maps length bytes at offset dst_offset in the open file to the same physical blocks that are mapped at offset src_offset in the file src_file β but only if the contents of both ranges are identical π―. This is known as block-based deduplication.
Same COW situation as reflink: if a program writes into a reflinked block range of either file, the dirty blocks will be cloned, written to, and remapped ("copy on write") in the affected file, leaving the other file(s) unchanged π.
-Cβ Print timing statistics in a condensed format-qβ Do not print timing statistics at all π€«
copy_range
copy_range [ -s src_offset ] [ -d dst_offset ] [ -l length ] src_file |
-f N
On filesystems that support the copy_file_range(2) system call, copies data from the source file into the current open file π. The source must be specified either by path (src_file) or as another open file (-f). If length is not specified, this command copies data from src_offset to the end of src_file into the dst_file at dst_offset.
-sβ Copy data from src_file beginning from src_offset-dβ Copy data into the open file beginning at dst_offset-lβ Copy up to length bytes of data
swapext
swapext donor_file
Swaps extent forks between files π. The current open file is the target. The donor file is specified by path. Note that file data is not copied β the file content moves with the fork(s) π«.
exchangerange
exchangerange [OPTIONS] donor_file
Exchanges contents between files πβ¨. The current open file is the target. The donor file is specified by path. Note that file data is not copied β the file content moves with the fork(s).
Options include:
-Cβ Print timing information in a condensed format-cβ Exchange contents only if file2 has not changed-d dest_offsetβ Swap extents with open file beginning at dest_offset-fβ Flush changed file data and file metadata to disk πΎ-l lengthβ Swap up to length bytes of data-nβ Perform all the parameter validation checks but don't change anything (a little dress rehearsal π)-s src_offsetβ Swap extents with donor file beginning at src_offset-tβ Print timing information-wβ Only exchange written ranges in the supplied file
set_encpolicy β okay bestie, if your filesystem does encryption, this one slaps an encryption policy onto the file you've currently got open. π
set_encpolicy [ -c mode ] [ -n mode ] [ -f flags ] [ -s log2_dusize ] [ -v version ] [ keyspec ]
keyspec is a hex string that says which encryption key we're using. For v1 policies, keyspec has to be a 16-character hex string (that's 8 bytes). For v2 policies, keyspec has to be a 32-character hex string (16 bytes). And if you just... don't give one? An all-zeroes value gets used. no thoughts, head empty, zeroes. π
-c modeβ contents encryption mode (likeAES-256-XTS, iykyk)-n modeβ filenames encryption mode (likeAES-256-CTS)-f flagsβ policy flags, and they're numeric-s log2_dusizeβ log2 of the data unit size. Not supported by v1 policies, sorry babe.-v versionβ policy version. Defaults to 1 or 2 depending on how long keyspec is, or to 1 if keyspec is unspecified.
get_encpolicy β displays the encryption policy of the file you've got open, on filesystems that do encryption. Reading the room, but make it crypto. π
get_encpolicy [ -1 ] [ -t ]
-1β use only the old ioctl to get the encryption policy. Heads up: this only works if the file has a v1 encryption policy.-tβ test whether v2 encryption policies are supported. It prints"supported","unsupported", or an error message.
add_enckey β adds an encryption key to the filesystem that holds the file you currently have open. ποΈ By default, the raw key in binary (typically 64 bytes long, a whole chunk) gets read from standard input.
add_enckey [ -d descriptor ] [ -k key_id ]
-d descriptorβ the key descriptor, as a 16-character hex string (8 bytes). If you give it, the key becomes available for v1 encryption policies that use this descriptor. Otherwise, the key is added as a v2 policy key, and on success the resulting"key identifier"gets printed. β¨-k key_idβ ID of a kernel keyring key of type"fscrypt-provisioning". If you give it, the raw key gets taken from here instead of from standard input.
rm_enckey β removes an encryption key from the filesystem containing the currently open file. Bye bestie π keyspec is a hex string naming the key to remove, either as a 16-character "key descriptor" or a 32-character "key identifier".
rm_enckey [ -a ] keyspec
-aβ remove the key for all users who have added it, not just the current user. > Heads up: this is a privileged operation. main character energy, but with consequences. π
enckey_status β shows the status of an encryption key on a filesystem that supports encryption. keyspec is a hex string naming the key whose status you want, as a 16-character "key descriptor" or a 32-character "key identifier". the vibe check, but for keys π
enckey_status keyspec
lsattr β lists the extended inode flags on the file you've currently got open. π
lsattr [ -R | -D | -a | -v ]
If you pass -R, it does a recursive descent through all the directory entries below the currently open file (-D can be used to restrict the output to directories only). And listen β this is a depth first descent, it does not follow symlinks, and it also does not cross mount points. Respecting boundaries, periodt. π¦
The current inode flag letters are documented right here, and please refer to the ioctl_xfs_fsgetxattr(2) documentation for more details about what they actually mean:
rβ realtime file (XFS_XFLAG_REALTIME)pβ prealloc (XFS_XFLAG_PREALLOC)iβ immutable (XFS_XFLAG_IMMUTABLE)aβ append only (XFS_XFLAG_APPEND)sβ synchronous file writes (XFS_XFLAG_SYNC)Aβ noatime (XFS_XFLAG_NOATIME)dβ nodump (XFS_XFLAG_NODUMP)tβ inherit realtime flag (`XFS_XFLAG_RTINHERIT")Pβ inherit project id (XFS_XFLAG_PROJINHERIT)nβ no symlink creation (XFS_XFLAG_NOSYMLINKS)eβ extent size hint (XFS_XFLAG_EXTSIZE)Eβ inherit extent size hint (XFS_XFLAG_EXTSZINHERIT)fβ nodefrag (XFS_XFLAG_NODEFRAG)Sβ filestream allocator (XFS_XFLAG_FILESTREAM)xβ direct access persistent memory (XFS_XFLAG_DAX)Cβ copy on write extent hint (XFS_XFLAG_COWEXTSIZE)Xβ has extended attributes (XFS_XFLAG_HASATTR)
chattr β changes the extended inode flags on the file you currently have open. Glow-up for your inode. π
chattr [ -R | -D ] [ +/-riasAdtPneEfSxC ]
The -R and -D options mean exactly the same thing as they do above, and see the lsattr command above for the list of inode flag letters. (scroll up bestie, it's all there π«Ά)
flink β links the currently open file descriptor into the filesystem namespace.
flink path
stat β selected statistics from stat(2) and the XFS_IOC_GETXATTR system call on the current file. π
stat [ -v|-r ]
If you pass -v, the atime (last access), mtime (last modify), and ctime (last change) timestamps get displayed too. And -r dumps the raw fields straight out of the stat structure. raw. unfiltered. π
statx β selected statistics from stat(2) and the XFS_IOC_GETXATTR system call on the current file. stat's fancier cousin, no cap. β
statx [ -v|-r ][ -m basic | -m all | -m <mask> ][ -FD ]
-vβ show timestamps-rβ dump rawstatxstructure values-m basicβ set the field mask for thestatxcall toSTATX_BASIC_STATS-m allβ set all bits in the field mask for thestatxcall except forSTATX__RESERVED. And if you pass no-marguments at all, the default isSTATX_BASIC_STATSandSTATX_BTIME.-m <mask>β specify a numeric field mask for thestatxcall-m +valueβ add this value to thestatxfield value. Values can be numeric, or they can be words describing the fields you want. See thehelpcommand output for a list of recognized words. π-m -valueβ remove this value from thestatxfield value-m +value,-valueβ add and remove multiple values from thestatxfield value. doing both. iconic.-Fβ force the attributes to be synced with the server-Dβ don't sync attributes with the server
chproj β modifies the project identifier associated with the current path. The -R option will recursively descend if the current path is a directory. The -D option will also recursively descend, only setting/modifying projects on subdirectories. See the xfs_quota(8) manual page for more information about project identifiers. π§Ύ
chproj [ -R|-D ]
lsproj β displays the project identifier associated with the current path. The -R and -D options behave as described above, in chproj. πΈ
lsproj [ -R|-D ]
parent β by default this command prints out the parent inode numbers, inode generation numbers and basenames of all the hardlinks which point to the inode of the current file. it's giving family tree. π
parent [ -fpz ] [ -b bufsize ] [ -i ino ] [ -n name ] [ ino gen ]
If you pass the optional ino and gen parameters, they get used to create a file handle on the same filesystem as the open file. And then the parents of the file represented by that handle get reported instead of the open file. plot twist β¨
-bβ use a buffer of this size to receive parent pointer records from the kernel-iβ only show parent pointer records containing this inode number-nβ only show parent pointer records containing this directory entry name-pβ the output is similar to the default output, except pathnames up to the mount-point are printed out instead of the component name-sβ print records in short format:ino/gen/namelen/name-zβ print only the first path from the root
utimes β changes the atime and mtime of the current file. time travel but legal. β°
utimes atime_sec atime_nsec mtime_sec mtime_nsec
sec uses UNIX timestamp notation and is the seconds elapsed since 1970-01-01 00:00:00 UTC. nsec is the nanoseconds since the sec. This value needs to be in the range 0-999999999, with UTIME_NOW and UTIME_OMIT being the exceptions. Each (sec, nsec) pair counts as a single timestamp value. π«
startupdate β creates a temporary clone of a file in which to stage file updates. a lil rehearsal space for your changes. π
startupdate [ -e]
The -e option creates an empty staging file.
cancelupdate β abandons changes from an update staging file. never happened, we don't know her. π
commitupdate β commits changes from an update staging file to the real file. the moment of truth, bestie. π₯
commitupdate [OPTIONS]
-Cβ print timing information in a condensed format-hβ only swap ranges in the update staging file that were actually written-kβ do not change file size-nβ check parameters without changing anything (a lil dry run π)-qβ do not print timing information at all
cachestat β prints page cache statistics for the given file range. numbers about your pages, slay. π
cachestat off len
πΎ MEMORY MAPPED I/O COMMANDS πΎ
okay bestie, this section is the mmap squad β all about memory-mapped I/O, where you vibe with a file directly through memory. it's lowkey the most powerful energy in this whole page. β¨
mmap [ N | [[ -rwxS ] [-s size ] offset length ]]β no arguments and it shows the current mappings. pass a single numeric argumentNand it sets the current mapping. pass two arguments (a range given byoffsetandlength) and a new mapping gets created spanning that range β and you can set the protection mode as a combo ofPROT_READ(-r),PROT_WRITE(-w), andPROT_EXEC(-x). the mapping is created with theMAP_SHAREDflag by default, or with the Linux-specific(MAP_SYNC | MAP_SHARED_VALIDATE)flags if-Sis given.-s sizedoes ammap(size) && munmap(size)operation first, trying to reserve some extendible free memory space ifsizeis bigger than thelengthparameter. BUT there's no guarantee that the memory afterlength(up tosize) will stay free. π e.g."mmap -rw -s 8192 1024"will mmap0 ~ 1024bytes of memory, but try to reserve1024 ~ 8192free space (no guarantee). this free space will be helpful for"mremap 8192"without theMREMAP_MAYMOVEflag.mmβ see themmapcommand.mremap [ -f <new_address> ] [ -m ] new_lengthβ changes the current mapping size tonew_length. whether the mapping may be moved is controlled by the flags you pass:MREMAP_FIXED(-f), orMREMAP_MAYMOVE(-m).new_lengthspecifies a page-aligned address to which the mapping must be moved. it can be set to139946004389888,4096kor1getc.mrmβ see themremapcommand.munmapβ unmaps the current memory mapping.muβ see themunmapcommand.mread [ -f | -v ] [ -r ] [ offset length ]β accesses a segment of the current memory mapping, optionally dumping it to the standard output stream (with-vor-foption) for inspection. the accesses are performed sequentially from the start offset by default, but can also be done from the end backwards through the mapping if the-roption is specified. the two verbose modes differ only in the relative offsets they display:-fis relative to file start, whereas-vshows offsets relative to the start of the mapping.mrβ see themreadcommand.mwrite [ -r ] [ -S seed ] [ offset length ]β stores a byte into memory for a range within a mapping. the default stored value is'X', repeated to fill the range specified, but this can be changed using the-Soption. the memory stores are performed sequentially from the start offset by default, but can also be done from the end backwards through the mapping if the-roption is specified.mwβ see themwritecommand.msync [ -i ] [ -a | -s ] [ offset length ]β writes all modified copies of pages over the specified range (or the entire mapping if no range is specified) to their backing storage locations. also, optionally invalidates (-i) so that subsequent references to the pages will be obtained from their backing storage locations (instead of cached copies). the flush can be done synchronously (-s) or asynchronously (-a).msβ see themsynccommand.madvise [ -d | -r | -s | -w ] [ offset length ]β modifies page cache behavior when operating on the current mapping. the range arguments are required by some advise commands ([*] below). with no arguments, thePOSIX_MADV_NORMALadvice is implied (default readahead).-dβ the pages will not be needed (POSIX_MADV_DONTNEED[*]).-rβ expect random page references (POSIX_MADV_RANDOM), which sets readahead to zero.-sβ expect sequential page references (POSIX_MADV_SEQUENTIAL), which doubles the default readahead on the file.-wβ advises the specified pages will be needed again (POSIX_MADV_WILLNEED[*]) which forces the maximum readahead.
mincoreβ dumps a list of pages or ranges of pages that are currently in core, for the current memory mapping.
ποΈ FILESYSTEM COMMANDS ποΈ
okay so now we're talking to the actual filesystem itself β allocation groups, inodes, freezing, thawing, health monitoring, the whole backstage pass. some of these need expert mode and privileges, so consider this your VIP section. π
aginfo [ -a agno ]β show information about or update the state of allocation groups.-aagno β act only on a specific allocation group.
bulkstat [ -a agno ] [ -d ] [ -e endino ] [ -m ] [ -n batchsize ] [ -q ] [ -s startino ] [ -v version"]β display raw stat information about a bunch of inodes in an XFS filesystem. options are as follows:-aagno β display only results from the given allocation group. if not specified, all results returned will be displayed.-dβ print debugging information about call results.-eendino β stop displaying records when this inode number is reached. defaults to stopping when the system call stops returning results.-mβ include metadata directories in the output.-nbatchsize β retrieve at most this many records per call. defaults to4,096.-qβ run quietly. does not parse or output retrieved bulkstat information.-sstartino β display inode allocation records starting with this inode. defaults to the first inode in the filesystem. if the given inode is not allocated, results will begin with the next allocated inode in the filesystem.-vversion β use a particular version of the kernel interface. currently supported versions are1and5.
bulkstat_single [ -d ] [ -m ] [ -v version ] [ inum... | special... ]β display raw stat information about individual inodes in an XFS filesystem. the-d,-m, and-voptions are the same as thebulkstatcommand. arguments must be inode numbers or any of the special values:rootβ display information about the root directory inode.
freezeβ suspend all write I/O requests to the filesystem of the current file. only available in expert mode and requires privileges. πthawβ undo the effects of a filesystem freeze operation. only available in expert mode and requires privileges.healthmon [ -c bufsize ] [ -c ] [ -d delay_ms ] [ -p ] [ -v ]β watch for filesystem health events and write them to the console.-bbufsize β use a buffer of this size to read events from the kernel.-cβ close the open file and replace it with the monitor file.-ddelay_ms β sleep for this long between read attempts.-pβ probe for the existence of the functionality by opening the monitoring fd and closing it immediately.-vβ request all health events, even if nothing changed.
inject [ tag ]β inject errors into a filesystem to observe filesystem behavior at specific points under adverse conditions. without thetagargument, displays the list of error tags available. only available in expert mode and requires privileges. πverifymedia [ -bdlrsR ] [ start [ end ]]β check for media errors on the storage devices backing XFS. thestartandendparameters are the range of physical storage to verify, in bytes. thestartparameter is inclusive. theendparameter is exclusive. if neitherstartnorendare specified, the entire device will be verified.-bβ don't issue any IOs larger than this size.-dβ verify the data device. this is the default.-lβ verify the log device instead of the data device.-rβ verify the realtime device instead of the data device.-Rβ report media errors to fsnotify.-sβ sleep this many microseconds between IO requests.
rginfo [ -r rgno ]β show information about or update the state of realtime allocation groups.-rβ act only on a specific realtime group.
resblks [ blocks ]β get and/or set count of reserved filesystem blocks using theXFS_IOC_GET_RESBLKSorXFS_IOC_SET_RESBLKSsystem calls. note β this can be useful for exercising out of space behavior. only available in expert mode and requires privileges.shutdown [ -f ]β force the filesystem to shut down, preventing any further IO. XFS and other filesystems implement this functionality, although implementation details may differ slightly. only available in expert mode and requires privileges.
by default, the filesystem will not attempt to flush completed transactions to disk before shutting down the filesystem. this simulates a disk failure or crash. π
-fβ force the filesystem to flush all completed transactions to disk before shutting down, matching XFS behavior when critical corruption is encountered.
statfs [ -c ] [ -g ] [ -s ]β report selected statistics on the filesystem where the current file resides. the default behavior is to enable all three reporting options:-cβ displayXFS_IOC_FSCOUNTERSsummary counter data.-gβ displayXFS_IOC_FSGEOMETRYfilesystem geometry data.-sβ displaystatfs(2)data.
inode [ [ -n ] number ] [ -v ]β theinodecommand queries physical information about an inode. with no arguments, it will return1or0, indicating whether or not any inode numbers greater than 32 bits are currently in use in the filesystem. if given an inode number as an argument, the command will return the same inode number if it is in use, or0if not. with-nnumber, the next used inode number after this number will be returned, or zero if the supplied inode number is the highest one in use. with-vthe command will also report the number of bits (32or64) used by the inode number printed in the result; if no inode number was specified on the command line, the maximum possible inode number in the system will be printed along with its size.
inumbers [ -a agno ] [ -d ] [ -e endino ] [ -n batchsize ] [ -s startino ] [ -v version ]
Okay bestie, this one prints allocation information about groups of inodes in an XFS filesystem. Callers can use this info to figure out which inodes are allocated. The options are, like, totally important:
-a agnoβ Display only results from the given allocation group. If not specified, all results returned will be displayed.-dβ Print debugging information about call results.-e endinoβ Stop displaying records when this inode number is reached. Defaults to stopping when the system call stops returning results.-n batchsizeβ Retrieve at most this many records per call. Defaults to 4,096.-s startinoβ Display inode allocation records starting with this inode. Defaults to the first inode in the filesystem. If the given inode is not allocated, results will begin with the next allocated inode in the filesystem.-v versionβ Use a particular version of the kernel interface. Currently supported versions are 1 and 5.
scrub type [ agnumber | rgnumber | ino gen | metapath [ rgnumber ] ]
Scrub internal XFS filesystem metadata. The type parameter specifies which type of metadata to scrub. For AG metadata, one AG number must be specified. For realtime group metadata, one rtgroup number must be specified. For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For metapath, the name of a file or a raw number must be specified. If the metapath file is a per-rtgroup file, the group number must be specified.
scrubv [ -b NN ] [ -d ] [ -m oflags ] [ -r ] [ -v NN ] [ -w ms ] group [ agnumber | ino gen ]
Scrub a bunch of internal XFS filesystem metadata. The group parameter specifies which group of metadata to scrub. Valid groups are ag, agheader, inode, iscan, fs, probe, rtgroup, or summary.
For ag and agheader metadata, one AG number must be specified. For inode metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For rtgroup metadata, one rt group number must be specified.
-b NNβ Inject scrub barriers into the vector stream at the given interval. Barriers abort vector processing if any previous scrub function found corruption.-dβ Enables debug mode.-mβ Fail scrub barriers if any of these scrub output flags are seen.-rβ Repair metadata if corruptions are found. This option requires expert mode.-v NNβ Force a particular API version.singleselectsXFS_SCRUB_METADATA(one-by-one).vectorselectsXFS_SCRUBV_METADATA(vectored). If no option is specified, vector mode will be used, with a fallback to single mode if the kernel doesn't recognize the vector mode ioctl.-w usβ Wait the given number of microseconds between each scrub function.
π Yes, the synopsis says-w msbut the option description says-w us. That's exactly how the original rolls, so we're keeping both, fr fr.
repair type [ agnumber | ino gen ]
Repair internal XFS filesystem metadata. The type parameter specifies which type of metadata to repair. For AG metadata, one AG number must be specified. For file metadata, the repair is applied to the open file unless the inode number and generation number are specified. The -R option can be specified to force rebuilding of a metadata structure.
label [ -c | -s label ]
On filesystems that support online label manipulation, get, set, or clear the filesystem label. With no options, print the current filesystem label. The -c option clears the filesystem label by setting it to the null string. The -s label option sets the filesystem label to label. If the label is longer than the filesystem will accept, xfs_io will print an error message. XFS filesystem labels can be at most 12 characters long.
π¨ Bestie, 12 characters max! Don't try to sneak in a whole novel, okay?
fsmap [ -d | -l | -r ] [ -m | -v ] [ -n nx ] [ start ] [ end ]
Prints the mapping of disk blocks used by the filesystem hosting the current file. The map lists each extent used by files, allocation group metadata, journalling logs, and static filesystem metadata, as well as any regions that are unused. Each line of the listings takes the following form:
extent: major:minor [startblock..endblock]: owner
startoffset..endoffset length
Static filesystem metadata, allocation group metadata, btrees, journalling logs, and free space are marked by replacing the startoffset..endoffset with the appropriate marker. All blocks, offsets, and lengths are specified in units of 512-byte blocks, no matter what the filesystem's block size is. The optional start and end arguments can be used to constrain the output to a particular range of disk blocks. If these two options are specified, exactly one of -d, -l, or -r must also be set.
-dβ Display only extents from the data device. This option only applies for XFS filesystems.-lβ Display only extents from the external log device. This option only applies to XFS filesystems.-rβ Display only extents from the realtime device. This option only applies to XFS filesystems.-mβ Display results in a machine readable format (CSV). This option is not compatible with the-vflag. The columns of the output are: extent number, device major, device minor, physical start, physical end, owner, offset start, offset end, length. Thestart,end, andlengthnumbers are provided in units of 512b. Theownerfield is a special string that takes the form:inode_%lld_dataβ for inode data.inode_%lld_data_bmbtβ for inode data extent maps.inode_%lld_attrβ for inode extended attribute data.inode_%lld_attr_bmbtβ for inode extended attribute extent maps.special_%u:%uβ for other filesystem metadata.
-n num_extentsβ If this option is given,fsmapobtains the extent list of the file in groups ofnum_extentsextents. In the absence of-n,fsmapqueries the system for extents in groups of 131,072 records.-vβ Shows verbose information. When this flag is specified, additional AG specific information is appended to each line in the following form:
agno (startagblock..endagblock) nblocks flags
A second -v option will print out the flags legend. This option is not compatible with the -m flag.
fsuuid β Print the mounted filesystem UUID.
sysfspath β Print the sysfs or debugfs path for the mounted filesystem. The -d option selects debugfs instead of sysfs.
getfsprops name [ names... ] β Retrieve the values of the given filesystem properties.
listfsprops [ -v ] β List all filesystem properties that have been stored in the filesystem. If the -v flag is specified, prints the values of the properties.
setfsprops name=value [ name=value... ] β Set the given filesystem properties to the specified values.
removefsprops name [ names... ] β Remove the given filesystem properties.
listmount [ -f mask ] [ -i mnt_id ] [ -n path ] [ -r ] [ -tfstype ]
Print information about the mounted filesystems in a particular mount namespace. The information returned by this call corresponds to the information returned by the statmount(2) system call.
-f maskβ Pass this numeric argument as the mask argument tostatmount(8). Defaults to all bits set, to retrieve all possible information.-i mnt_idβ Only return information for mounts below this mount in the mount tree. Defaults to the root directory.-n pathβ Return information for the mount namespace given by this procfs path. For a given process, the path will most likely look like/proc/$pid/ns/mntthough any path can be provided. Defaults to the mount namespace of thexfs_ioprocess itself.-rβ Print raw bitmasks instead of converting them to strings.-t fstypeβ Only return information for filesystems of this type. If not specified, no filtering is performed.
statmount [ -f mask ] [ -r ]
Print information about the mounted filesystem for each open file. The information returned by this call corresponds to the information returned by the statmount(2) system call.
-f maskβ Pass this numeric argument as the mask argument tostatmount(8). Defaults to all bits set, to retrieve all possible information.-rβ Print raw bitmasks instead of converting them to strings.
β¨ OTHER COMMANDS β¨
help[command] β Display a brief description of one or all commands.printβ Display a list of all open files and memory mapped regions. The current file and current mapping are distinguishable from any others.pβ See theprintcommand.quitβ Exitxfs_io.qβ See thequitcommand.log_writes-d device -m markβ Create a mark namedmarkin the dm-log-writes log specified bydevice. This is intended to be equivalent to the shell command:
dmsetup message device 0 mark mark
lwβ See thelog_writescommand.crc32cselftestβ Test the internal crc32c implementation to make sure that it computes results correctly.
And that's the vibe for this chunk, bestie. Stay tuned for the next part! πβ¨π¦
π SEE ALSO π
okay bestie, here's the squad β the whole friend group that xfs_io rolls with. go read these when you wanna go deeper, no cap β¨
mkfs.xfs(8)β the one who makes the filesystem in the first place. xfs_io can't play if this one hasn't done its thing yet πxfsctl(3)β the lowkey OG behind a lot of the ioctl magicxfs_bmap(8)β for when you're obsessed with where your blocks actually live πΊοΈxfs_db(8)β the deep-dive debugger, main character energy for filesystem forensicsxfs(5)β the filesystem itself, the whole vibe πfdatasync(2)β sync those data changes, fr frfstat(2)β stat the file, know thyselffstatfs(2)β but for the filesystem's stats, periodtfsync(2)β the classic "make it stick" syscall π₯ftruncate(2)β resize that file, slayfutimens(3)β timestamps, updated with taste β¨mmap(2)β the memory-mapping bestie that makes all themmapcommands possible π¦msync(2)β the mmap counterpart that pushes those dirty pages homeopen(2)β how literally everything starts around herepread(2)β reading at an offset, iconicpwrite(2)β writing at an offset, also iconicreaddir(3)β directory reading, for the nosy ones (respectfully) πdmsetup(8)β device mapper tooling, for the layered storage girlies πΈ
and that's the whole page, bestie!! π«Ά you just read the entirety of xfs_io(8) β every command, every flag, every vibe. if this was a group chat, you'd be the one who actually read the whole thing before replying, and honestly? queen behaviour π
lowkey reminder: this is the xfs_io(8) manual page, and the footer line down there is just the page's own name and its source/version + date stamp β the little signature that says which manual and which build you're looking at. go check yours if you wanna know the exact version and date you're working with π
k bye, go run some commands, you got this πβ¨πΊ
π¦ where this page comes from
- arch rolling: xfsprogs 7.2.0-1
- arch rolling: xfsprogs 7.2.1-1 Β· GPL-2.0-only AND LGPL-2.1-only
- fedora 44: xfsprogs 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- nixpkgs unstable: xfsprogs 7.2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms