Commit cca9f93a authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: don't do IO when creating an new inode

When we are allocating a new inode, we read the inode cluster off
disk to increment the generation number. We are already using a
random generation number for newly allocated inodes, so if we are not
using the ikeep mode, we can just generate a new generation number
when we initialise the newly allocated inode.

This avoids the need for reading the inode buffer during inode
creation. This will speed up allocation of inodes in cold, partially
allocated clusters as they will no longer need to be read from disk
during allocation. It will also reduce the CPU overhead of inode
allocation by not having the process the buffer read, even on cache
hits.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarMark Tinguely <tinguely@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent 133eeb17
...@@ -1028,6 +1028,11 @@ xfs_dinode_calc_crc( ...@@ -1028,6 +1028,11 @@ xfs_dinode_calc_crc(
/* /*
* Read the disk inode attributes into the in-core inode structure. * Read the disk inode attributes into the in-core inode structure.
*
* If we are initialising a new inode and we are not utilising the
* XFS_MOUNT_IKEEP inode cluster mode, we can simple build the new inode core
* with a random generation number. If we are keeping inodes around, we need to
* read the inode cluster to get the existing generation number off disk.
*/ */
int int
xfs_iread( xfs_iread(
...@@ -1047,6 +1052,22 @@ xfs_iread( ...@@ -1047,6 +1052,22 @@ xfs_iread(
if (error) if (error)
return error; return error;
/* shortcut IO on inode allocation if possible */
if ((iget_flags & XFS_IGET_CREATE) &&
!(mp->m_flags & XFS_MOUNT_IKEEP)) {
/* initialise the on-disk inode core */
memset(&ip->i_d, 0, sizeof(ip->i_d));
ip->i_d.di_magic = XFS_DINODE_MAGIC;
ip->i_d.di_gen = prandom_u32();
if (xfs_sb_version_hascrc(&mp->m_sb)) {
ip->i_d.di_version = 3;
ip->i_d.di_ino = ip->i_ino;
uuid_copy(&ip->i_d.di_uuid, &mp->m_sb.sb_uuid);
} else
ip->i_d.di_version = 2;
return 0;
}
/* /*
* Get pointers to the on-disk inode and the buffer containing it. * Get pointers to the on-disk inode and the buffer containing it.
*/ */
...@@ -1133,17 +1154,16 @@ xfs_iread( ...@@ -1133,17 +1154,16 @@ xfs_iread(
xfs_buf_set_ref(bp, XFS_INO_REF); xfs_buf_set_ref(bp, XFS_INO_REF);
/* /*
* Use xfs_trans_brelse() to release the buffer containing the * Use xfs_trans_brelse() to release the buffer containing the on-disk
* on-disk inode, because it was acquired with xfs_trans_read_buf() * inode, because it was acquired with xfs_trans_read_buf() in
* in xfs_imap_to_bp() above. If tp is NULL, this is just a normal * xfs_imap_to_bp() above. If tp is NULL, this is just a normal
* brelse(). If we're within a transaction, then xfs_trans_brelse() * brelse(). If we're within a transaction, then xfs_trans_brelse()
* will only release the buffer if it is not dirty within the * will only release the buffer if it is not dirty within the
* transaction. It will be OK to release the buffer in this case, * transaction. It will be OK to release the buffer in this case,
* because inodes on disk are never destroyed and we will be * because inodes on disk are never destroyed and we will be locking the
* locking the new in-core inode before putting it in the hash * new in-core inode before putting it in the cache where other
* table where other processes can find it. Thus we don't have * processes can find it. Thus we don't have to worry about the inode
* to worry about the inode being changed just because we released * being changed just because we released the buffer.
* the buffer.
*/ */
out_brelse: out_brelse:
xfs_trans_brelse(tp, bp); xfs_trans_brelse(tp, bp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment