KF> Hi.
 KF> Having experienced the (not unexpected) heavy slowdown one gets by
 KF> fsyncing the directory after a rename/link/unlink/symlink operation, I
 KF> have a question. When I do:

 KF> fd=open(".");
 KF> fsync(fd);
 KF> close(fd);
 KF> /* I do error checking, in case you were wondering :) */

 KF> let's say "." has some hundred thousand files. Then this directory gets
 KF> pretty huge. How much of it is written to disk when I fsync it? All of it,
 KF> or only the dirty parts? And if only the dirty parts are written, how much
 KF> is that? Can this be optimised?

fs/reiserfs/dir.c :
int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) {
  int ret = 0 ;
  int windex ;
  struct reiserfs_transaction_handle th ;

  lock_kernel();

  journal_begin(&th, dentry->d_inode->i_sb, 1) ;
  windex = push_journal_writer("dir_fsync") ;
  reiserfs_prepare_for_journal(th.t_super, SB_BUFFER_WITH_SB(th.t_super), 1) ;
  journal_mark_dirty(&th, dentry->d_inode->i_sb, SB_BUFFER_WITH_SB 
(dentry->d_inode->i_sb)) ;
  pop_journal_writer(windex) ;
  journal_end_sync(&th, dentry->d_inode->i_sb, 1) ;

  unlock_kernel();

  return ret ;
}

fs/reiserfs/journal.c:
int journal_end_sync(struct reiserfs_transaction_handle *th, struct super_block 
*p_s_sb, unsigned long nblocks) {
  return do_journal_end(th, p_s_sb, nblocks, COMMIT_NOW | WAIT) ;
}

As you see reiserfs_dir_fsync does transaction commit and waits until
it is done. In short, all modified metadata blocks are being written
to disk.

Reiserfs works fast if can join many logical transactions into one and
commit that huge transaction once. If reiserfs does many commits
(application often calls dir_fsync, for example) for small
transactions it slows reiserfs.

-- 
Thanks,
Alex.

Reply via email to