Product SiteDocumentation Site

4.2.5. Exercise 5 - attr2 and inode literal space competition

With attr2, there is more competition allowed for the literal space of the inode. To show this we will create a file with 1 EA and see how many data extents we can fit within an inode. Then we will try this all again with 24 Eas and now see how many data extents we can fit inline. At each stage, you can look at what the new forkoffset is set to.
  1. Create a filesystem with 512 byte inodes and attr2
    # mkfs.xfs -f -i “attr=2,size=512” $SCRATCH_DEV
    # mount $SCRATCH_DEV $SCRATCH_MNT
    
  2. Create and examine a file with a single attribute
    # cd $SCRATCH_MNT
    # touch file
    # setfattr -n user.name.1 -v value file
    # xfs_bmap file
    # ls –i file
    # cd /
    # umount $SCRATCH_MNT
    # xfs_ncheck $SCRATCH_DEV
    # xfs_db -r $SCRATCH_DEV -c 'inode inode_number' -c 'p'
    
    We can see from this output that we have 1 EA and a fork offset of 47 which is equivalent to 376 bytes worth of space left over for data extents.
  3. Let's now see how many extents we can fill up before they go out of line.
    # mount $SCRATCH_DEV $SCRATCH_MNT
    # cd $SCRATCH_MNT
    # $BINDIR/makeextents -p -n 23 file
    
    The “-p” option is to preserve the file and its extents – it won't create 23 more extents, rather it should create enough extents to have 23 extents in total.
    # xfs_bmap file
    # cd /
    # umount $SCRATCH_MNT
    # xfs_db -r $SCRATCH_DEV -c 'inode inode_number' -c 'p'
    
    From this we can see that we can fit 23 extents inline.
  4. Now you should try it with 24 extents.
  5. Clear all the data extents in the file by truncating it to zero.
    # mount $SCRATCH_DEV $SCRATCH_MNT
    # cd $SCRATCH_MNT
    # >file
    # xfs_bmap file
    
  6. 1.Now add 23 more EA's so that we have 24 EA's in total.
    # for i in {2..24}
    > do
    > setfattr -n user.name.$i -v value file
    > done
    # getfattr -d file
    
  7. Now unmount and look at the fork offset in xfs_db. It should be at about 7 which is equivalent to 56 bytes into the literal space. So in adding 23 EA's we have gone from 376 bytes down to 56 bytes.
  8. How many extents we can fit in there before going out of line for the data extents? Try first creating 3 extents and then 4.
    # mount $SCRATCH_DEV $SCRATCH_MNT
    # cd $SCRATCH_MNT
    # $BINDIR/makeextents -p -n 3 file
    # xfs_bmap file
    # cd /
    # umount $SCRATCH_MNT
    # xfs_db -r $SCRATCH_DEV -c 'inode inode_number' -c 'p'
    
    In the answers section below is a table which lists the various fork offsets for EA's created in the same way we did above. It also shows how many data extents we can fit inline with that fork offset – although only 2 rows for this column have been filled in.