O_SYNC patches for 2.4.0-test1-ac11
Subsystems (8)
Hi all,
The following patch fully implements O_SYNC, fsync and fdatasync, at least for ext2. The infrastructure it includes should make it trivial for any other filesystem to do likewise.
The basic changes are:
Include a per-inode list of dirty buffers
Pass a "datasync" parameter down to the filesystems when fsync or fdatasync are called, to distinguish between the two (when fdatasync is specified, we don't have to flush the inode to disk if only timestamps have changed)
Split I_DIRTY into two bits, one (I_DIRTY_SYNC) which is set for all dirty inodes, and the other (I_DIRTY_DATASYNC) which is set only if fdatasync needs to flush the inode (ie. it is set for everything except for timestamp updates). This means:
The old (flags & I_DIRTY) construct still returns true if the inode is in any way dirty; and
(flags |= I_DIRTY) sets both bits, as expected.
fs/ext2 and __block_commit_write are modified to record the all newly dirtied buffers (both data and metadata) on the inode's dirty block list
generic_file_write now honours the O_SYNC flag and calls generic_osync_inode(), which flushes the inode dirty buffer list and calls the inode's fsync method.
Note: currently, the O_SYNC code in generic_file_write calls generic_osync_inode with datasync==1, which means that O_SYNC is interpreted as O_DSYNC according to the SUS spec. In other words, O_SYNC is not guaranteed to flush timestamp updates to disk (but fsync is). This is important: we do not currently have an O_DSYNC flag (although that would now be trivial to implement), so existing apps are forced to use O_SYNC instead. Apps such as Oracle rely on O_SYNC for write ordering, but due to a 2.2 bug, existing kernels don't do the timestamp update and hence we achieve decent performance even without O_DSYNC. We cannot suddenly cause all of those applications to experience a massive performance drop.
One way round this would be to split O_SYNC into O_DSYNC and O_TRUESYNC, and in glibc to redefine O_SYNC to be (O_DSYNC | O_TRUESYNC). If we keep the new O_DSYNC to have the same value as the old O_SYNC, then:
* Old applications which specified O_SYNC will continue to get their expected (O_DSYNC) behaviour
* New applications can specify O_SYNC or O_DSYNC and get the selected behaviour on new kernels
* New applications calling either O_SYNC or O_DSYNC will still get O_SYNC on old kernels.
In performance testing, "dd" with 64k blocks and writing into an existing, preallocated file, gets close to theoretical disk bandwidth (about 13MB/sec on a Cheetah), when using O_SYNC or when doing a fdatasync between each write. Doing fsync instead gives only about 3MB/sec and results in a lot of audible disk seeking, as expected. If I don't preallocate the file, then even fdatasync is slow, as it now has to sync the changed i_size information after every write (and it gets slower as the file grows and the distance between the inode and the data being written increases).
--Stephen
fs/block_dev.c renamed from fs/block_dev.c.~1~ +1 -1
@@ -313,7 +313,7 @@* since the vma has no handle. */ -static int block_fsync (struct file *filp,struct dentry *dentry) +static int block_fsync (struct file *filp,struct dentry *dentry,int datasync) {return fsync_dev (dentry->d_inode->i_rdev); }
fs/buffer.c renamed from fs/buffer.c.~1~ +188 -9
284 lines not on this page · raw message
fs/coda/dir.c renamed from fs/coda/dir.c.~1~ +1 -1
@@ -50,7 +50,7 @@/* support routines */ static int coda_venus_readdir (struct file *filp,void *dirent,filldir_t filldir); -int coda_fsync (struct file *,struct dentry *dentry); +int coda_fsync (struct file *,struct dentry *dentry,int );int coda_crossvol_rename =0 ;int coda_hasmknod =0 ;
fs/coda/file.c renamed from fs/coda/file.c.~1~ +3 -3
@@ -30,7 +30,7 @@static int coda_file_mmap (struct file * file,struct vm_area_struct * vma);/* also exported from this file (used for dirs) */ -int coda_fsync (struct file *,struct dentry *dentry); +int coda_fsync (struct file *,struct dentry *dentry,int );struct inode_operations coda_file_inode_operations = { permission: coda_permission,
@@ -65,7 +65,7 @@return res; } -int coda_fsync (struct file *coda_file,struct dentry *coda_dentry) +int coda_fsync (struct file *coda_file,struct dentry *coda_dentry,int datasync) {struct coda_inode_info *cnp;struct inode *coda_inode = coda_dentry->d_inode;
@@ -96,7 +96,7 @@down (&cont_inode->i_sem); - result =file_fsync (&cont_file ,&cont_dentry); + result =file_fsync (&cont_file ,&cont_dentry,0 );if ( result ==0 ) { result =venus_fsync (coda_inode->i_sb, &(cnp->c_fid)); }
fs/ext2/dir.c renamed from fs/ext2/dir.c.~1~ +1 -1
@@ -26,7 +26,7 @@ read: generic_read_dir, readdir: ext2_readdir, ioctl: ext2_ioctl, - fsync: ext2_sync_file, + fsync: ext2_fsync_file, }; int ext2_check_dir_entry (const char * function, struct inode * dir,
fs/ext2/file.c renamed from fs/ext2/file.c.~1~ +2 -1
@@ -91,6 +91,7 @@return 0 ; } +/* * We have mostly NULL's here: the current defaults are ok for * the ext2 filesystem.
@@ -103,7 +104,7 @@ mmap: generic_file_mmap, open: ext2_open_file, release: ext2_release_file, - fsync: ext2_sync_file, + fsync: ext2_fsync_file, };struct inode_operations ext2_file_inode_operations = {
fs/ext2/fsync.c renamed from fs/ext2/fsync.c.~1~ +15 -118
146 lines not on this page · raw message
fs/ext2/inode.c renamed from fs/ext2/inode.c.~1~ +4 -6
@@ -403,11 +403,9 @@ *new =1 ; } *p =le32_to_cpu (tmp); -mark_buffer_dirty (bh,1 ); -if (IS_SYNC (inode) || inode->u.ext2_i.i_osync) { +mark_buffer_dirty_inode (bh,1 , inode); +if (IS_SYNC (inode) || inode->u.ext2_i.i_osync)ll_rw_block (WRITE ,1 , &bh); -wait_on_buffer (bh); - } inode->i_ctime =CURRENT_TIME ; inode->i_blocks += blocksize/512 ;mark_inode_dirty (inode);
@@ -918,10 +916,10 @@return err; } -void ext2_write_inode (struct inode * inode) +void ext2_write_inode (struct inode * inode,int wait) {lock_kernel (); -ext2_update_inode (inode,0 ); +ext2_update_inode (inode, wait);unlock_kernel (); }
fs/ext2/namei.c renamed from fs/ext2/namei.c.~1~ +2 -2
@@ -451,7 +451,7 @@strcpy (de->name,".." );ext2_set_de_type (dir->i_sb, de,S_IFDIR ); inode->i_nlink =2 ; -mark_buffer_dirty (dir_block,1 ); +mark_buffer_dirty_inode (dir_block,1 , dir);brelse (dir_block); inode->i_mode =S_IFDIR | mode;if (dir->i_mode &S_ISGID )
@@ -788,7 +788,7 @@mark_inode_dirty (old_dir);if (dir_bh) {PARENT_INO (dir_bh->b_data) =le32_to_cpu (new_dir->i_ino); -mark_buffer_dirty (dir_bh,1 ); +mark_buffer_dirty_inode (dir_bh,1 , old_inode); old_dir->i_nlink--;mark_inode_dirty (old_dir);if (new_inode) {
fs/ext2/truncate.c renamed from fs/ext2/truncate.c.~1~ +2 -2
@@ -211,7 +211,7 @@ inode->i_ino, tmp); *p =0 ;if (dind_bh) -mark_buffer_dirty (dind_bh,1 ); +mark_buffer_dirty_inode (dind_bh,1 , inode);else mark_inode_dirty (inode);return 0 ;
@@ -279,7 +279,7 @@ inode->i_ino, tmp); *p =0 ;if (tind_bh) -mark_buffer_dirty (tind_bh,1 ); +mark_buffer_dirty_inode (tind_bh,1 , inode);else mark_inode_dirty (inode);return 0 ;
fs/inode.c renamed from fs/inode.c.~1~ +73 -13
178 lines not on this page · raw message
fs/minix/fsync.c renamed from fs/minix/fsync.c.~1~ +1 -1
@@ -329,7 +329,7 @@* NULL */ -int minix_sync_file (struct file * file,struct dentry *dentry) +int minix_sync_file (struct file * file,struct dentry *dentry,int datasync) {struct inode *inode = dentry->d_inode;
fs/ncpfs/file.c renamed from fs/ncpfs/file.c.~1~ +1 -1
@@ -26,7 +26,7 @@return a < b ? a : b; } -static int ncp_fsync (struct file *file,struct dentry *dentry) +static int ncp_fsync (struct file *file,struct dentry *dentry,int datasync) {return 0 ; }
fs/nfs/file.c renamed from fs/nfs/file.c.~1~ +2 -2
@@ -39,7 +39,7 @@static ssize_t nfs_file_read (struct file *,char *,size_t ,loff_t *);static ssize_t nfs_file_write (struct file *,const char *,size_t ,loff_t *);static int nfs_file_flush (struct file *); -static int nfs_fsync (struct file *,struct dentry *dentry); +static int nfs_fsync (struct file *,struct dentry *dentry,int );struct file_operations nfs_file_operations = { read: nfs_file_read,
@@ -124,7 +124,7 @@* whether any write errors occurred for this process. */ static int -nfs_fsync (struct file *file,struct dentry *dentry) +nfs_fsync (struct file *file,struct dentry *dentry,int datasync) {struct inode *inode = dentry->d_inode;int status;
fs/nfsd/vfs.c renamed from fs/nfsd/vfs.c.~1~ +7 -7
@@ -312,7 +312,7 @@if (err) goto out_nfserr;if (EX_ISSYNC (fhp->fh_export)) -write_inode_now (inode); +write_inode_now (inode,0 ); err =0 ;/* Don't unlock inode; the nfssvc_release functions are supposed
@@ -514,7 +514,7 @@ {dprintk ("nfsd: sync file %s\n" , filp->f_dentry->d_name.name);down (&filp->f_dentry->d_inode->i_sem); - filp->f_op->fsync (filp, filp->f_dentry); + filp->f_op->fsync (filp, filp->f_dentry,0 );up (&filp->f_dentry->d_inode->i_sem); }
@@ -522,10 +522,10 @@ nfsd_sync_dir(struct dentry *dp) {struct inode *inode = dp->d_inode; -int (*fsync) (struct file *,struct dentry *); +int (*fsync) (struct file *,struct dentry *,int );if (inode->i_fop && (fsync = inode->i_fop->fsync)) { -fsync (NULL , dp); +fsync (NULL , dp,0 ); } }
@@ -893,7 +893,7 @@if (EX_ISSYNC (fhp->fh_export)) {nfsd_sync_dir (dentry); -write_inode_now (dchild->d_inode); +write_inode_now (dchild->d_inode,0 ); }
@@ -1120,7 +1120,7 @@ | S_IFLNK; err =notify_change (dnew, iap);if (!err &&EX_ISSYNC (fhp->fh_export)) -write_inode_now (dentry->d_inode); +write_inode_now (dentry->d_inode,0 ); } } }else
@@ -1180,7 +1180,7 @@if (!err) {if (EX_ISSYNC (ffhp->fh_export)) {nfsd_sync_dir (ddir); -write_inode_now (dest); +write_inode_now (dest,0 ); } }else {if (err == -EXDEV && rqstp->rq_vers ==2 )
fs/qnx4/fsync.c renamed from fs/qnx4/fsync.c.~1~ +1 -1
@@ -147,7 +147,7 @@return err; } -int qnx4_sync_file (struct file *file,struct dentry *dentry) +int qnx4_sync_file (struct file *file,struct dentry *dentry,int datasync) {struct inode *inode = dentry->d_inode;int wait, err =0 ;
fs/smbfs/file.c renamed from fs/smbfs/file.c.~1~ +1 -1
@@ -27,7 +27,7 @@/* #define pr_debug printk */ static int -smb_fsync (struct file *file,struct dentry * dentry) +smb_fsync (struct file *file,struct dentry * dentry,int datasync) {#ifdef SMBFS_DEBUG_VERBOSE printk("smb_fsync: sync file %s/%s\n",
fs/sysv/fsync.c renamed from fs/sysv/fsync.c.~1~ +1 -1
@@ -178,7 +178,7 @@return err; } -int sysv_sync_file (struct file * file,struct dentry *dentry) +int sysv_sync_file (struct file * file,struct dentry *dentry,int datasync) {int wait, err =0 ;struct inode *inode = dentry->d_inode;
include/linux/ext2_fs.h renamed from include/linux/ext2_fs.h.~1~ +4 -2
@@ -548,7 +548,9 @@extern int ext2_write (struct inode *,struct file *,char *,int );/* fsync.c */ -extern int ext2_sync_file (struct file *,struct dentry *); +extern int ext2_fsync_file (struct file *,struct dentry *,int ); +extern int ext2_fsync_inode (struct inode *,int ); +extern int ext2_osync_inode (struct inode *,int );/* ialloc.c */ extern struct inode *ext2_new_inode (const struct inode *,int ,int *);
@@ -562,7 +564,7 @@extern struct buffer_head *ext2_bread (struct inode *,int ,int ,int *);extern void ext2_read_inode (struct inode *); -extern void ext2_write_inode (struct inode *); +extern void ext2_write_inode (struct inode *,int );extern void ext2_put_inode (struct inode *);extern void ext2_delete_inode (struct inode *);extern int ext2_sync_inode (struct inode *);
include/linux/fs.h renamed from include/linux/fs.h.~1~ +35 -11
101 lines not on this page · raw message
include/linux/minix_fs.h renamed from include/linux/minix_fs.h.~1~ +1 -1
@@ -101,7 +101,7 @@extern void minix_truncate (struct inode *);extern int minix_sync_inode (struct inode *); -extern int minix_sync_file (struct file *,struct dentry *); +extern int minix_sync_file (struct file *,struct dentry *,int );extern struct address_space_operations minix_aops;extern struct inode_operations minix_file_inode_operations;
include/linux/qnx4_fs.h renamed from include/linux/qnx4_fs.h.~1~ +1 -1
@@ -116,7 +116,7 @@extern void qnx4_free_inode (struct inode *inode);extern int qnx4_unlink (struct inode *dir,struct dentry *dentry);extern int qnx4_rmdir (struct inode *dir,struct dentry *dentry); -extern int qnx4_sync_file (struct file *file,struct dentry *dentry); +extern int qnx4_sync_file (struct file *file,struct dentry *dentry,int );extern int qnx4_sync_inode (struct inode *inode);extern int qnx4_get_block (struct inode *inode,long iblock,struct buffer_head *bh,int create);
mm/filemap.c renamed from mm/filemap.c.~1~ +8 -2
@@ -1815,7 +1815,7 @@if (!error && (flags &MS_SYNC )) {struct file * file = vma->vm_file;if (file && file->f_op && file->f_op->fsync) - error = file->f_op->fsync (file, file->f_dentry); + error = file->f_op->fsync (file, file->f_dentry,1 ); }return error; }
@@ -2554,7 +2554,7 @@if (count) {remove_suid (inode); inode->i_ctime = inode->i_mtime =CURRENT_TIME ; -mark_inode_dirty (inode); +mark_inode_dirty_sync (inode); }while (count) {
@@ -2611,7 +2611,13 @@if (cached_page)page_cache_free (cached_page); +/* For now, when the user asks for O_SYNC, we'll actually +* provide O_DSYNC. */ +if ((status >=0 ) && (file->f_flags &O_SYNC )) + status =generic_osync_inode (inode,1 );/* 1 means datasync */ + err = written ? written : status; + out:up (&inode->i_sem);return err;
Quoted 8 lines · Stephen C. Tweedie
* Old applications which specified
O_SYNCwill continue to get their expected (O_DSYNC) behaviour* New applications can specify
O_SYNCorO_DSYNCand get the selected behaviour on new kernels* New applications calling either
O_SYNCorO_DSYNCwill still getO_SYNCon old kernels.
Have you thought about O_RSYNC and whether it is possible/useful to support it separately?
Signature · 7 lines
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com `------------------------ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux.eu.org/Linux-MM/
Sorry for the separate mail:
Quoted 1 line · Stephen C. Tweedie
If I don't preallocate the file, then even fdatasync is slow, [...]
This might be a good argument to implement posix_fallocate() in the kernel.
Signature · 7 lines
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com `------------------------ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux.eu.org/Linux-MM/
Hi,
Quoted 3 lines · Ulrich Drepper
Have you thought about
O_RSYNCand whether it is possible/useful to support it separately?
It would be possible and useful, but it's entirely separate from the write path and probably doesn't make sense until we've got O_DIRECT working (O_RSYNC is closely related to that).
Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Hi,
Quoted 5 lines · Ulrich Drepper
Quoted 2 lines
If I don't preallocate the file, then even fdatasync is slow, [...]
This might be a good argument to implement
posix_fallocate()in the kernel.
No. If we do posix_fallocate(), then there are only two choices:
we either pre-zero the file contents (in which case we are as well doing it from user space), or we record in the inode that the file isn't pre-zeroed and so optimise things.
If we do that optimisation, then doing an O_DSYNC write to the already-allocated file will have to record in the inode that we are pushing forward the non-prezeroed fencepost in the file, so we end up having to seek back to the inode for each write anyway, so we lose any possible benefit during the writes.
Once you have a database file written and preallocated, this is all academic since all further writes will be in place and so will be fast the th O_DSYNC/fdatasync support.
Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 4 lines · Stephen C. Tweedie
No. If we do
posix_fallocate(), then there are only two choices:
we either pre-zero the file contents (in which case we are as well doing it from user space), or we record in the inode that the file isn't pre-zeroed and so optimise things.
3rd choice: preallocate space with room for interleaved indirection blocks. You don't need to record anything in the inode: it's the indirection blocks that get changed as you fill up the file. And they're in exactly the right place.
-- Jamie
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Quoted 2 lines · Jamie Lokier
3rd choice: preallocate space with room for interleaved indirection blocks.
Sorry I take that thinko back. Too little sleep last night :-)
-- Jamie
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/