2.4.22 NFS O_DIRECT a la mode ->direct_IO2()
Subsystems (5)
PATCH RESEND 1/1 2.4.22 NFS O_DIRECT a la mode ->direct_IO2()
The following patch reimplements NFS O_DIRECT using a new
address_space_operation.
Cheers,
Trond
Documentation/Configure.help +24 -0
@@ -15938,6 +15938,30 @@ If unsure, say N. +Allow direct I/O on files in NFS +CONFIG_NFS_DIRECTIO + There are important applications whose performance or correctness + depends on uncached access to file data. Database clusters (multiple + copies of the same instance running on separate hosts) implement their + own cache coherency protocol that subsumes the NFS cache protocols. + Applications that process datasets considerably larger than the client's + memory do not always benefit from a local cache. A streaming video + server, for instance, has no need to cache the contents of a file. + + This option enables applications to perform direct I/O on files in NFS + file systems using the O_DIRECT open() flag. When O_DIRECT is set for + files, their data is not cached in the system's page cache. Direct + read and write operations are aligned to block boundaries. Data is + moved to and from user-level application buffers directly. + + Unless your program is designed to use O_DIRECT properly, you are much + better off allowing the NFS client to manage caching for you. Misusing + O_DIRECT can cause poor server performance or network storms. This + kernel build option defaults OFF to avoid exposing system administrators + unwittingly to a potentially hazardous feature. + + If unsure, say N. + Root file system on NFS CONFIG_ROOT_NFS If you want your Linux box to mount its whole root file system (the
fs/Config.in +1 -0
@@ -106,6 +106,7 @@ dep_tristate 'InterMezzo file system support (replicating fs) (EXPERIMENTAL)' CONFIG_INTERMEZZO_FS $CONFIG_INET $CONFIG_EXPERIMENTAL dep_tristate 'NFS file system support' CONFIG_NFS_FS $CONFIG_INET dep_mbool ' Provide NFSv3 client support' CONFIG_NFS_V3 $CONFIG_NFS_FS + dep_mbool ' Allow direct I/O on NFS files (EXPERIMENTAL)' CONFIG_NFS_DIRECTIO $CONFIG_NFS_FS $CONFIG_EXPERIMENTAL dep_bool ' Root file system on NFS' CONFIG_ROOT_NFS $CONFIG_NFS_FS $CONFIG_IP_PNP dep_tristate 'NFS server support' CONFIG_NFSD $CONFIG_INET
fs/nfs/direct.c +382 -0
382 lines not on this page · raw message
fs/nfs/file.c +4 -0
@@ -16,6 +16,7 @@* nfs regular file handling functions */ +#include <linux/config.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/errno.h>
@@ -199,6 +200,9 @@ readpage: nfs_readpage, sync_page: nfs_sync_page, writepage: nfs_writepage, +#ifdef CONFIG_NFS_DIRECTIO + direct_fileIO: nfs_direct_IO, +#endif prepare_write: nfs_prepare_write, commit_write: nfs_commit_write };
fs/nfs/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_ROOT_NFS) += nfsroot.o mount_clnt.o obj-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o +obj-$(CONFIG_NFS_DIRECTIO) += direct.o obj-m := $(O_TARGET)
fs/nfs/write.c +0 -17
@@ -123,23 +123,6 @@ }/* -* This function will be used to simulate weak cache consistency -* under NFSv2 when the NFSv3 attribute patch is included. -* For the moment, we just call nfs_refresh_inode(). -*/ -static __inline__int -nfs_write_attributes (struct inode *inode,struct nfs_fattr *fattr) -{ -if ((fattr->valid &NFS_ATTR_FATTR ) && !(fattr->valid &NFS_ATTR_WCC )) { - fattr->pre_size =NFS_CACHE_ISIZE (inode); - fattr->pre_mtime =NFS_CACHE_MTIME (inode); - fattr->pre_ctime =NFS_CACHE_CTIME (inode); - fattr->valid |=NFS_ATTR_WCC ; - } -return nfs_refresh_inode (inode, fattr); -} - -/* * Write a page synchronously. * Offset is the data offset within the page. */
include/linux/fs.h +2 -0
@@ -396,6 +396,8 @@int (*releasepage) (struct page *,int );#define KERNEL_HAS_O_DIRECT /* this is for modules out of the kernel */ int (*direct_IO)(int ,struct inode *,struct kiobuf *,unsigned long ,int ); +#define KERNEL_HAS_DIRECT_FILEIO /* Unfortunate kludge due to lack of foresight */ +int (*direct_fileIO)(int ,struct file *,struct kiobuf *,unsigned long ,int );void (*removepage)(struct page *);/* called when page gets removed from the inode */ };
include/linux/nfs_fs.h +22 -0
@@ -274,6 +274,11 @@#define NFS_TestClearPageSync (page) test_and_clear_bit(PG_fs_1, &(page)->flags)/* +* linux/fs/nfs/direct.c +*/ +extern int nfs_direct_IO (int ,struct file *,struct kiobuf *,unsigned long ,int ); + +/* * linux/fs/mount_clnt.c * (Used only by nfsroot module) */
@@ -302,6 +307,23 @@return __nfs_refresh_inode (inode,fattr); } +/* +* This function will be used to simulate weak cache consistency +* under NFSv2 when the NFSv3 attribute patch is included. +* For the moment, we just call nfs_refresh_inode(). +*/ +static __inline__int +nfs_write_attributes (struct inode *inode,struct nfs_fattr *fattr) +{ +if ((fattr->valid &NFS_ATTR_FATTR ) && !(fattr->valid &NFS_ATTR_WCC )) { + fattr->pre_size =NFS_CACHE_ISIZE (inode); + fattr->pre_mtime =NFS_CACHE_MTIME (inode); + fattr->pre_ctime =NFS_CACHE_CTIME (inode); + fattr->valid |=NFS_ATTR_WCC ; + } +return nfs_refresh_inode (inode, fattr); +} +static inline loff_t nfs_size_to_loff_t (__u64 size) {
include/linux/nfs_xdr.h +2 -2
@@ -59,7 +59,7 @@/* Arguments to the read call. * Note that NFS_READ_MAXIOV must be <= (MAX_IOVEC-2) from sunrpc/xprt.h */ -#define NFS_READ_MAXIOV 8 +#define NFS_READ_MAXIOV (9)struct nfs_readargs {struct nfs_fh * fh;
@@ -78,7 +78,7 @@/* Arguments to the write call. * Note that NFS_WRITE_MAXIOV must be <= (MAX_IOVEC-2) from sunrpc/xprt.h */ -#define NFS_WRITE_MAXIOV 8 +#define NFS_WRITE_MAXIOV (9)struct nfs_writeargs {struct nfs_fh * fh;__u64 offset;
mm/filemap.c +17 -2
@@ -1557,6 +1557,21 @@UPDATE_ATIME (inode); } +static inline int have_mapping_directIO (struct address_space * mapping) +{ +return mapping->a_ops->direct_IO || mapping->a_ops->direct_fileIO; +} + +/* Switch between old and new directIO formats */ +static inline int do_call_directIO (int rw,struct file *filp,struct kiobuf *iobuf,unsigned long offset,int blocksize) +{ +struct address_space * mapping = filp->f_dentry->d_inode->i_mapping; + +if (mapping->a_ops->direct_fileIO) +return mapping->a_ops->direct_fileIO (rw, filp, iobuf, offset, blocksize); +return mapping->a_ops->direct_IO (rw, mapping->host, iobuf, offset, blocksize); +} +/* * i_sem and i_alloc_sem should be held already. i_sem may be dropped * later once we've mapped the new IO. i_alloc_sem is kept until the IO
@@ -1593,7 +1608,7 @@ retval = -EINVAL ;if ((offset & blocksize_mask) || (count & blocksize_mask) || ((unsigned long ) buf & blocksize_mask)) goto out_free; -if (!mapping->a_ops->direct_IO) +if (!have_mapping_directIO (mapping)) goto out_free;if ((rw ==READ ) && (offset + count > size))
@@ -1621,7 +1636,7 @@if (retval)break ; - retval = mapping->a_ops->direct_IO (rw, inode, iobuf, (offset+progress) >> blocksize_bits, blocksize); + retval =do_call_directIO (rw, filp, iobuf, (offset+progress) >> blocksize_bits, blocksize);if (rw ==READ && retval >0 )mark_dirty_kiobuf (iobuf, retval);