5
ll /srv/node/dcodxx/test.sh
-rw-r--r--. 1 root root 7 Nov  5 11:18 /srv/node/dcodxx/test.sh

The size of the file is shown in bytes. This file is stored in an xfs filesystem with block size 4096 bytes.

xfs_info /srv/node/sdaxx/
meta-data=/dev/sda               isize=256    agcount=32, agsize=7630958 blks
         =                       sectsz=4096  attr=2, projid32bit=0
data     =                       bsize=4096   blocks=244190646, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=119233, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Does this mean that a block can house more than one file, if not what happens to the remaining bytes (4096-7)? Also, where is the 256 bytes reserved for an inode stored, if it stored in the same block as the file, shouldn't the file size be larger(256+7)?

user2887201
  • 317
  • 2
  • 9
  • 19

2 Answers2

5

File data is stored in units of the filesystem block size, and no block sharing is currently possible across multiple files on XFS. So used disk space is always the number of bytes in the file rounded up to the next block size - a 1-byte file will consume 4k of diskspace on a 4k block size filesystem.

The inode itself contains file metadata such as size, timestamps, extent data, etc - and on xfs it can also contain extended attribute information.

The on-disk inode is separate from the file data blocks, and will always consume 256 bytes on a filesystem with 256 byte inodes, regardless of the amount of metadata used. If more than 256 bytes is required to store additional extent information or extended attribute data, additional filesystem-block-sized metadata blocks will be allocated.

Eric Sandeen
  • 141
  • 1
  • 5
  • Remark: While true back at that point in time, now XFS supports multiple references to the same extent with copy-on-write. So, tools like `duperemove` work really well, especially on things like archives of containers etc. – Marcus Müller Jun 16 '21 at 10:54
4

Does this mean that a block can house more than one file, if not what happens to the remaining bytes (4096-7)?

A block cannot contain more than one file. If a file is bigger than one block, multiple blocks are used.

Modern filesystems like XFS have a functionality called "inline", where files small enough (no more than 60 bytes) can be stored in the inode, in the space taken to store pointers to the blocks.

where is the 256 bytes reserved for an inode stored, if it stored in the same block as the file, shouldn't the file size be larger(256+7)?

Inode information is stored in the inode table.

Brian Cline
  • 20,012
  • 6
  • 26
  • 25
user2887201
  • 317
  • 2
  • 9
  • 19
  • 1
    I don't think XFS actually inlines small files yet. http://xfs.org/index.php/Unfinished_work#Inline_data_in_inodes. reiserfs had an option to pack multiple small files into the same block. What actually happens in most filesystems is internal fragmentation (http://en.wikipedia.org/wiki/Fragmentation_%28computing%29#Internal_fragmentation) (unless file size is a multiple of the FS block size.) – Peter Cordes Mar 02 '15 at 07:37
  • It would also be more useful to say that inodes are packed together into blocks. There isn't a single "inode table" anywhere. A block of inodes can be allocated anywhere, as I understand it. (Part of the motivation for the new crc=1 on-disk format. https://www.kernel.org/doc/Documentation/filesystems/xfs-self-describing-metadata.txt) – Peter Cordes Mar 02 '15 at 07:41