cifs: allow cifs to do readpages larger and asynchronously (try #6)
Subsystems (2)
cover cifs: allow cifs to do readpages larger and asynchronously (try #6)
Just some small changes since the last patchset to fix problems noticed by Pavel Shilovsky:
- the max rsize when posix extensions are not in force was too large by 1 byte
- some of the debug printks in cifs_readv_receive were using the wrong width specifier for size_t and ssize_t (%lu instead of %zu)
This patchset uses the infrastructure added in the receive path overhaul to allow cifs to vastly increase the rsize. It also is more efficient and does less copying as the data is read directly into the pagecache.
Additionally, readpages is now done asynchronously with this set. cifs_readpages just puts the pages in the cache, fires off the reads and returns. Eventually, when the reads complete, a workqueue job is queued that will mark the pages uptodate and unlock them.
With this set in place, I see a dramatic increase in performance for buffered read calls. On a simple dd test of a 1GB file to /dev/null:
prepatch, with 16k rsize:
1073741824 bytes (1.1 GB) copied, 47.2119 s, 22.7 MB/s
postpatch, with 1M rsize:
1073741824 bytes (1.1 GB) copied, 11.1602 s, 96.2 MB/s
postpatch, with 60k rsize:
1073741824 bytes (1.1 GB) copied, 12.5183 s, 85.8 MB/s
Other tests show similar results. These results are from my craptacular KVM-based test rig. I expect that the performance boost will be even more dramatic on real hardware or on higher-latency connections.
Steve, I'd like to see both of these sets go into 3.2 if at all possible. Both of these sets should be bisectable, so committing them in order is highly recommended.
This set and the preceding overhaul of the receive codepath are also available in the cifs-3.2 branch of my git tree on git.samba.org:
git: git://git.samba.org/jlayton/linux.git
gitweb: http://git.samba.org/?p=jlayton/linux.git;a=shortlog;h=refs/heads/cifs-3.2Jeff Layton (5):
cifs: fix protocol definition for READ_RSP
cifs: add cifs_async_readv
cifs: convert cifs_readpages to use async reads
cifs: allow for larger rsize= options and change defaults
cifs: tune bdi.ra_pages in accordance with the rsize
fs/cifs/cifspdu.h | 4 +- fs/cifs/cifsproto.h | 24 ++++ fs/cifs/cifssmb.c | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/connect.c | 167 +++++++++++++++--------- fs/cifs/file.c | 293 ++++++++++++++++++------------------------ 5 files changed, 609 insertions(+), 235 deletions(-)
Signature · 1 line
1.7.6.4
PATCH 1/5 cifs: fix protocol definition for READ_RSP
In reply to a message not in the archiveThere is no pad, and it simplifies the code to remove the "Data" field.
None of the existing code relies on these fields, or on the READ_RSP being a particular length.
--- fs/cifs/cifspdu.h | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
fs/cifs/cifspdu.h +1 -3
@@ -1089,9 +1089,7 @@ typedef struct smb_com_read_rsp {__le16 DataLengthHigh;__u64 Reserved2;__u16 ByteCount; -__u8 Pad;/* BB check for whether padded to DWORD -boundary and optimum performance here */ -char Data[1 ]; +/* read response data immediately follows */ } __attribute__((packed)) READ_RSP; typedef struct locking_andx_range {
Signature · 1 line
1.7.6.4
PATCH 2/5 cifs: add cifs_async_readv
In reply to a message not in the archive...which will allow cifs to do an asynchronous read call to the server. The caller will allocate and set up cifs_readdata for each READ_AND_X call that should be issued on the wire. The pages passed in are added to the pagecache, but not placed on the LRU list yet (as we need the page->lru to keep the pages on the list in the readdata).
When cifsd identifies the mid, it will see that there is a special receive handler for the call, and use that to receive the rest of the frame. cifs_readv_receive will then marshal up a kvec array with kmapped pages from the pagecache, which eliminates one copy of the data. Once the data is received, the pages are added to the LRU list, set uptodate, and unlocked.
--- fs/cifs/cifsproto.h | 24 ++++ fs/cifs/cifssmb.c | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/connect.c | 26 ++-- 3 files changed, 393 insertions(+), 13 deletions(-)
fs/cifs/cifsproto.h +24 -0
@@ -152,6 +152,12 @@ extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *,extern int set_cifs_acl (struct cifs_ntsd *,__u32 ,struct inode *,const char *); +extern void dequeue_mid (struct mid_q_entry *mid,bool malformed); +extern int cifs_read_from_socket (struct TCP_Server_Info *server,char *buf, +unsigned int to_read); +extern int cifs_readv_from_socket (struct TCP_Server_Info *server, +struct kvec *iov_orig,unsigned int nr_segs, +unsigned int to_read);extern void cifs_setup_cifs_sb (struct smb_vol *pvolume_info,struct cifs_sb_info *cifs_sb);extern int cifs_match_super (struct super_block *,void *);
@@ -441,6 +447,24 @@ extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);extern int SMBencrypt (unsigned char *passwd,const unsigned char *c8,unsigned char *p24); +/* asynchronous read support */ +struct cifs_readdata { +struct cifsFileInfo *cfile; +struct address_space *mapping; +__u64 offset; +unsigned int bytes; +pid_t pid; +int result; +struct list_head pages; +struct work_struct work; +unsigned int nr_iov; +struct kvec iov[1 ]; +}; + +struct cifs_readdata *cifs_readdata_alloc (unsigned int nr_pages); +void cifs_readdata_free (struct cifs_readdata *rdata); +int cifs_async_readv (struct cifs_readdata *rdata); +/* asynchronous write support */ struct cifs_writedata {struct kref refcount;
fs/cifs/cifssmb.c +356 -0
380 lines not on this page · raw message
fs/cifs/connect.c +13 -13
@@ -422,9 +422,9 @@ get_server_iovec(struct TCP_Server_Info *server, unsigned int nr_segs)return new_iov; } -static int -readv_from_socket (struct TCP_Server_Info *server,struct kvec *iov_orig, -unsigned int nr_segs,unsigned int to_read) +int +cifs_readv_from_socket (struct TCP_Server_Info *server,struct kvec *iov_orig, +unsigned int nr_segs,unsigned int to_read) {int length =0 ;int total_read;
@@ -479,16 +479,16 @@ readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig,return total_read; } -static int -read_from_socket (struct TCP_Server_Info *server,char *buf, -unsigned int to_read) +int +cifs_read_from_socket (struct TCP_Server_Info *server,char *buf, +unsigned int to_read) {struct kvec iov; iov.iov_base = buf; iov.iov_len = to_read; -return readv_from_socket (server, &iov,1 , to_read); +return cifs_readv_from_socket (server, &iov,1 , to_read); } static bool
@@ -553,8 +553,8 @@ find_mid(struct TCP_Server_Info *server, struct smb_hdr *buf)return NULL ; } -static void -dequeue_mid (struct mid_q_entry *mid,int malformed) +void +dequeue_mid (struct mid_q_entry *mid,bool malformed) {#ifdef CONFIG_CIFS_STATS2 mid->when_received = jiffies;
@@ -731,7 +731,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) }/* now read the rest */ - length =read_from_socket (server, + length =cifs_read_from_socket (server, buf +sizeof (struct smb_hdr ) -1 , pdu_length -sizeof (struct smb_hdr ) +1 +4 );if (length <0 )
@@ -792,7 +792,7 @@ cifs_demultiplex_thread(void *p) buf = server->smallbuf; pdu_length =4 ;/* enough to get RFC1001 header */ - length =read_from_socket (server, buf, pdu_length); + length =cifs_read_from_socket (server, buf, pdu_length);if (length <0 )continue ; server->total_read = length;
@@ -817,8 +817,8 @@ cifs_demultiplex_thread(void *p) }/* read down to the MID */ - length =read_from_socket (server, buf +4 , -sizeof (struct smb_hdr ) -1 -4 ); + length =cifs_read_from_socket (server, buf +4 , +sizeof (struct smb_hdr ) -1 -4 );if (length <0 )continue ; server->total_read += length;
Signature · 1 line
1.7.6.4
PATCH 3/5 cifs: convert cifs_readpages to use async reads
In reply to a message not in the archiveNow that we have code in place to do asynchronous reads, convert cifs_readpages to use it. The new cifs_readpages walks the page_list that gets passed in, locks and adds the pages to the pagecache and sets up cifs_readdata to handle the reads.
The rest is handled by the cifs_async_readv infrastructure.
--- fs/cifs/file.c | 281 +++++++++++++++++++++++--------------------------------- 1 files changed, 113 insertions(+), 168 deletions(-)
fs/cifs/file.c +113 -168
@@ -32,6 +32,7 @@#include <linux/delay.h> #include <linux/mount.h> #include <linux/slab.h> +#include <linux/swap.h> #include <asm/div64.h> #include "cifsfs.h" #include "cifspdu.h"
@@ -1957,82 +1958,24 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)return rc; } - -static void cifs_copy_cache_pages (struct address_space *mapping, -struct list_head *pages,int bytes_read,char *data) -{ -struct page *page; -char *target; - -while (bytes_read >0 ) { -if (list_empty (pages)) -break ; - - page = list_entry(pages->prev, struct page, lru); -list_del (&page->lru); - -if (add_to_page_cache_lru (page, mapping, page->index, -GFP_KERNEL )) { -page_cache_release (page); -cFYI (1 ,"Add page cache failed" ); - data +=PAGE_CACHE_SIZE ; - bytes_read -=PAGE_CACHE_SIZE ; -continue ; - } -page_cache_release (page); - - target =kmap_atomic (page,KM_USER0 ); - -if (PAGE_CACHE_SIZE > bytes_read) { -memcpy (target, data, bytes_read); -/* zero the tail end of this partial page */ -memset (target + bytes_read,0 , -PAGE_CACHE_SIZE - bytes_read); - bytes_read =0 ; - }else { -memcpy (target, data,PAGE_CACHE_SIZE ); - bytes_read -=PAGE_CACHE_SIZE ; - } -kunmap_atomic (target,KM_USER0 ); - -flush_dcache_page (page); -SetPageUptodate (page); -unlock_page (page); - data +=PAGE_CACHE_SIZE ; - -/* add page to FS-Cache */ -cifs_readpage_to_fscache (mapping->host, page); - } -return ; -} -static int cifs_readpages (struct file *file,struct address_space *mapping,struct list_head *page_list,unsigned num_pages) { -int rc = -EACCES ; -int xid; -loff_t offset; -struct page *page; -struct cifs_sb_info *cifs_sb; -struct cifs_tcon *pTcon; -unsigned int bytes_read =0 ; -unsigned int read_size, i; -char *smb_read_data =NULL ; -struct smb_com_read_rsp *pSMBr; -struct cifsFileInfo *open_file; -struct cifs_io_parms io_parms; -int buf_type =CIFS_NO_BUFFER ; -__u32 pid; +int rc; +struct list_head tmplist; +struct cifsFileInfo *open_file = file->private_data; +struct cifs_sb_info *cifs_sb =CIFS_SB (file->f_path.dentry->d_sb); +unsigned int rsize = cifs_sb->rsize; +pid_t pid; - xid =GetXid (); -if (file->private_data ==NULL ) { - rc = -EBADF ; -FreeXid (xid); -return rc; - } - open_file = file->private_data; - cifs_sb =CIFS_SB (file->f_path.dentry->d_sb); - pTcon =tlink_tcon (open_file->tlink); +/* +* Give up immediately if rsize is too small to read an entire page. +* The VFS will fall back to readpage. We should never reach this +* point however since we set ra_pages to 0 when the rsize is smaller +* than a cache page. +*/ +if (unlikely (rsize <PAGE_CACHE_SIZE )) +return 0 ;/* * Reads as many pages as possible from fscache. Returns -ENOBUFS
@@ -2041,125 +1984,127 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, rc =cifs_readpages_from_fscache (mapping->host, mapping, page_list, &num_pages);if (rc ==0 ) - goto read_complete; +return rc; -cFYI (DBG2 ,"rpages: num pages %d" , num_pages);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_RWPIDFORWARD ) pid = open_file->pid;else pid = current->tgid; -for (i =0 ; i < num_pages; ) { -unsigned contig_pages; -struct page *tmp_page; -unsigned long expected_index; + rc =0 ; +INIT_LIST_HEAD (&tmplist); -if (list_empty (page_list)) -break ; +cFYI (1 ,"%s: file=%p mapping=%p num_pages=%u" , __func__, file, + mapping, num_pages); + +/* +* Start with the page at end of list and move it to private +* list. Do the same with any following pages until we hit +* the rsize limit, hit an index discontinuity, or run out of +* pages. Issue the async read and then start the loop again +* until the list is empty. +* +* Note that list order is important. The page_list is in +* the order of declining indexes. When we put the pages in +* the rdata->pages, then we want them in increasing order. +*/ +while (!list_empty (page_list)) { +unsigned int bytes =PAGE_CACHE_SIZE ; +unsigned int expected_index; +unsigned int nr_pages =1 ; +loff_t offset; +struct page *page, *tpage; +struct cifs_readdata *rdata; page = list_entry(page_list->prev, struct page, lru); + +/* +* Lock the page and put it in the cache. Since no one else +* should have access to this page, we're safe to simply set +* PG_locked without checking it first. +*/ +__set_page_locked (page); + rc =add_to_page_cache_locked (page, mapping, + page->index,GFP_KERNEL ); + +/* give up if we can't stick it in the cache */ +if (rc) { +__clear_page_locked (page); +break ; + } + +/* move first page to the tmplist */ offset = (loff_t )page->index <<PAGE_CACHE_SHIFT ; +list_move_tail (&page->lru, &tmplist); + +/* now try and add more pages onto the request */ + expected_index = page->index +1 ; +list_for_each_entry_safe_reverse (page, tpage, page_list, lru) { +/* discontinuity ? */ +if (page->index != expected_index) +break ; -/* count adjacent pages that we will read into */ - contig_pages =0 ; - expected_index = - list_entry(page_list->prev, struct page, lru)->index; -list_for_each_entry_reverse (tmp_page, page_list, lru) { -if (tmp_page->index == expected_index) { - contig_pages++; - expected_index++; - }else +/* would this page push the read over the rsize? */ +if (bytes +PAGE_CACHE_SIZE > rsize)break ; + +__set_page_locked (page); +if (add_to_page_cache_locked (page, mapping, + page->index,GFP_KERNEL )) { +__clear_page_locked (page); +break ; + } +list_move_tail (&page->lru, &tmplist); + bytes +=PAGE_CACHE_SIZE ; + expected_index++; + nr_pages++; } -if (contig_pages + i > num_pages) - contig_pages = num_pages - i; - -/* for reads over a certain size could initiate async -read ahead */ - - read_size = contig_pages *PAGE_CACHE_SIZE ; -/* Read size needs to be in multiples of one page */ - read_size = min_t(const unsigned int, read_size, - cifs_sb->rsize &PAGE_CACHE_MASK ); -cFYI (DBG2 ,"rpages: read size 0x%x contiguous pages %d" , - read_size, contig_pages); - rc = -EAGAIN ; -while (rc == -EAGAIN ) { + + rdata =cifs_readdata_alloc (nr_pages); +if (!rdata) { +/* best to give up if we're out of mem */ +list_for_each_entry_safe (page, tpage, &tmplist, lru) { +list_del (&page->lru); +lru_cache_add_file (page); +unlock_page (page); +page_cache_release (page); + } + rc = -ENOMEM ; +break ; + } + +spin_lock (&cifs_file_list_lock); +cifsFileInfo_get (open_file); +spin_unlock (&cifs_file_list_lock); + rdata->cfile = open_file; + rdata->mapping = mapping; + rdata->offset = offset; + rdata->bytes = bytes; + rdata->pid = pid; +list_splice_init (&tmplist, &rdata->pages); + +do {if (open_file->invalidHandle) { rc =cifs_reopen_file (open_file, true);if (rc !=0 ) -break ; - } - io_parms.netfid = open_file->netfid; - io_parms.pid = pid; - io_parms.tcon = pTcon; - io_parms.offset = offset; - io_parms.length = read_size; - rc =CIFSSMBRead (xid, &io_parms, &bytes_read, - &smb_read_data, &buf_type); -/* BB more RC checks ? */ -if (rc == -EAGAIN ) { -if (smb_read_data) { -if (buf_type ==CIFS_SMALL_BUFFER ) -cifs_small_buf_release (smb_read_data); -else if (buf_type ==CIFS_LARGE_BUFFER ) -cifs_buf_release (smb_read_data); - smb_read_data =NULL ; - } +continue ; } - } -if ((rc <0 ) || (smb_read_data ==NULL )) { -cFYI (1 ,"Read error in readpages: %d" , rc); -break ; - }else if (bytes_read >0 ) { -task_io_account_read (bytes_read); - pSMBr = (struct smb_com_read_rsp *)smb_read_data; -cifs_copy_cache_pages (mapping, page_list, bytes_read, - smb_read_data +4 /* RFC1001 hdr */ + -le16_to_cpu (pSMBr->DataOffset)); - - i += bytes_read >>PAGE_CACHE_SHIFT ; -cifs_stats_bytes_read (pTcon, bytes_read); -if ((bytes_read &PAGE_CACHE_MASK ) != bytes_read) { - i++;/* account for partial page */ - -/* server copy of file can have smaller size -than client */ -/* BB do we need to verify this common case ? -this case is ok - if we are at server EOF -we will hit it on next read */ + rc =cifs_async_readv (rdata); + }while (rc == -EAGAIN ); -/* break; */ +if (rc !=0 ) { +list_for_each_entry_safe (page, tpage, &rdata->pages, + lru) { +list_del (&page->lru); +lru_cache_add_file (page); +unlock_page (page); +page_cache_release (page); } - }else { -cFYI (1 ,"No bytes read (%d) at offset %lld . " -"Cleaning remaining pages from readahead list" , - bytes_read, offset); -/* BB turn off caching and do new lookup on -file size at server? */ +cifs_readdata_free (rdata);break ; } -if (smb_read_data) { -if (buf_type ==CIFS_SMALL_BUFFER ) -cifs_small_buf_release (smb_read_data); -else if (buf_type ==CIFS_LARGE_BUFFER ) -cifs_buf_release (smb_read_data); - smb_read_data =NULL ; - } - bytes_read =0 ; - } - -/* need to free smb_read_data buf before exit */ -if (smb_read_data) { -if (buf_type ==CIFS_SMALL_BUFFER ) -cifs_small_buf_release (smb_read_data); -else if (buf_type ==CIFS_LARGE_BUFFER ) -cifs_buf_release (smb_read_data); - smb_read_data =NULL ; } -read_complete: -FreeXid (xid);return rc; }
Signature · 1 line
1.7.6.4
PATCH 4/5 cifs: allow for larger rsize= options and change defaults
In reply to a message not in the archiveCurrently we cap the rsize at a value that fits in CIFSMaxBufSize. That's not needed any longer for readpages. Allow the use of larger values for readpages. cifs_iovec_read and cifs_read however are still limited to the CIFSMaxBufSize. Make sure they don't exceed that.
The patch also changes the rsize defaults. The default when unix extensions are enabled is set to 1M for parity with the wsize, and there is a hard cap of ~16M.
When unix extensions are not enabled, the default is set to 60k. According to MS-CIFS, Windows servers can only send a max of 60k at a time, so this is more efficient than requesting a larger size. If the user wishes however, the max can be extended up to 128k - the length of the READ_RSP header.
Really old servers however require a special hack to ensure that we don't request too large a read.
--- fs/cifs/connect.c | 120 ++++++++++++++++++++++++++++++++--------------------- fs/cifs/file.c | 12 ++++- 2 files changed, 83 insertions(+), 49 deletions(-)
fs/cifs/connect.c +73 -47
@@ -2292,16 +2292,16 @@ compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data) (new->mnt_cifs_flags & CIFS_MOUNT_MASK))return 0 ; -if (old->rsize != new->rsize) -return 0 ; -/* -* We want to share sb only if we don't specify wsize or specified wsize -* is greater or equal than existing one. +* We want to share sb only if we don't specify an r/wsize or +* specified r/wsize is greater than or equal to existing one. */ if (new->wsize && new->wsize < old->wsize)return 0 ; +if (new->rsize && new->rsize < old->rsize) +return 0 ; +if (old->mnt_uid != new->mnt_uid || old->mnt_gid != new->mnt_gid)return 0 ;
@@ -2739,14 +2739,6 @@ void reset_cifs_unix_caps(int xid, struct cifs_tcon *tcon,CIFS_MOUNT_POSIX_PATHS ; } -if (cifs_sb && (cifs_sb->rsize >127 *1024 )) { -if ((cap &CIFS_UNIX_LARGE_READ_CAP ) ==0 ) { - cifs_sb->rsize =127 *1024 ; -cFYI (DBG2 ,"larger reads not supported by srv" ); - } - } - -cFYI (1 ,"Negotiate caps 0x%x" , (int )cap);#ifdef CONFIG_CIFS_DEBUG2 if (cap &CIFS_UNIX_FCNTL_CAP )
@@ -2791,27 +2783,11 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,spin_lock_init (&cifs_sb->tlink_tree_lock); cifs_sb->tlink_tree =RB_ROOT ; -if (pvolume_info->rsize > CIFSMaxBufSize) { -cERROR (1 ,"rsize %d too large, using MaxBufSize" , - pvolume_info->rsize); - cifs_sb->rsize = CIFSMaxBufSize; - }else if ((pvolume_info->rsize) && - (pvolume_info->rsize <= CIFSMaxBufSize)) - cifs_sb->rsize = pvolume_info->rsize; -else /* default */ - cifs_sb->rsize = CIFSMaxBufSize; - -if (cifs_sb->rsize <2048 ) { - cifs_sb->rsize =2048 ; -/* Windows ME may prefer this */ -cFYI (1 ,"readsize set to minimum: 2048" ); - } -/* -* Temporarily set wsize for matching superblock. If we end up using -* new sb then cifs_negotiate_wsize will later negotiate it downward -* if needed. +* Temporarily set r/wsize for matching superblock. If we end up using +* new sb then client will later negotiate it downward if needed. */ + cifs_sb->rsize = pvolume_info->rsize; cifs_sb->wsize = pvolume_info->wsize; cifs_sb->mnt_uid = pvolume_info->linux_uid;
@@ -2878,29 +2854,41 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, }/* -* When the server supports very large writes via POSIX extensions, we can -* allow up to 2^24-1, minus the size of a WRITE_AND_X header, not including -* the RFC1001 length. +* When the server supports very large reads and writes via POSIX extensions, +* we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not +* including the RFC1001 length. * * Note that this might make for "interesting" allocation problems during * writeback however as we have to allocate an array of pointers for the * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096. +* +* For reads, there is a similar problem as we need to allocate an array +* of kvecs to handle the receive, though that should only need to be done +* once. */ #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) +#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4)/* -* When the server doesn't allow large posix writes, only allow a wsize of -* 128k minus the size of the WRITE_AND_X header. That allows for a write up -* to the maximum size described by RFC1002. +* When the server doesn't allow large posix writes, only allow a rsize/wsize +* of (128k - 1) minus the size of the call header. That allows for a read or +* write up to the maximum size described by RFC1002. */ #define CIFS_MAX_RFC1002_WSIZE (128 * 1024 - sizeof(WRITE_REQ) + 4) +#define CIFS_MAX_RFC1002_RSIZE (128 * 1024 - 1 - sizeof(READ_RSP) + 4)/* * The default wsize is 1M. find_get_pages seems to return a maximum of 256 * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill * a single wsize request with a single call. */ -#define CIFS_DEFAULT_WSIZE (1024 * 1024) +#define CIFS_DEFAULT_IOSIZE (1024 * 1024) + +/* +* Windows only supports a max of 60k reads. Default to that when posix +* extensions aren't in force. +*/ +#define CIFS_DEFAULT_NON_POSIX_RSIZE (60 *1024)static unsigned int cifs_negotiate_wsize (struct cifs_tcon *tcon,struct smb_vol *pvolume_info)
@@ -2908,7 +2896,7 @@ cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)__u64 unix_cap =le64_to_cpu (tcon->fsUnixInfo.Capability);struct TCP_Server_Info *server = tcon->ses->server;unsigned int wsize = pvolume_info->wsize ? pvolume_info->wsize : -CIFS_DEFAULT_WSIZE ; +CIFS_DEFAULT_IOSIZE ;/* can server support 24-bit write sizes? (via UNIX extensions) */ if (!tcon->unix_ext || !(unix_cap &CIFS_UNIX_LARGE_WRITE_CAP ))
@@ -2931,6 +2919,50 @@ cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)return wsize; } +static unsigned int +cifs_negotiate_rsize (struct cifs_tcon *tcon,struct smb_vol *pvolume_info) +{ +__u64 unix_cap =le64_to_cpu (tcon->fsUnixInfo.Capability); +struct TCP_Server_Info *server = tcon->ses->server; +unsigned int rsize, defsize; + +/* +* Set default value... +* +* HACK alert! Ancient servers have very small buffers. Even though +* MS-CIFS indicates that servers are only limited by the client's +* bufsize for reads, testing against win98se shows that it throws +* INVALID_PARAMETER errors if you try to request too large a read. +* +* If the server advertises a MaxBufferSize of less than one page, +* assume that it also can't satisfy reads larger than that either. +* +* FIXME: Is there a better heuristic for this? +*/ +if (tcon->unix_ext && (unix_cap &CIFS_UNIX_LARGE_READ_CAP )) + defsize =CIFS_DEFAULT_IOSIZE ; +else if (server->capabilities &CAP_LARGE_READ_X ) + defsize =CIFS_DEFAULT_NON_POSIX_RSIZE ; +else if (server->maxBuf >=PAGE_CACHE_SIZE ) + defsize = CIFSMaxBufSize; +else + defsize = server->maxBuf -sizeof (READ_RSP ); + + rsize = pvolume_info->rsize ? pvolume_info->rsize : defsize; + +/* +* no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to +* the client's MaxBufferSize. +*/ +if (!(server->capabilities &CAP_LARGE_READ_X )) + rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); + +/* hard limit of CIFS_MAX_RSIZE */ + rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); + +return rsize; +} +static int is_path_accessible (int xid,struct cifs_tcon *tcon,struct cifs_sb_info *cifs_sb,const char *full_path)
@@ -3208,14 +3240,8 @@ try_mount_again:CIFSSMBQFSAttributeInfo (xid, tcon); } -if ((tcon->unix_ext ==0 ) && (cifs_sb->rsize > (1024 *127 ))) { - cifs_sb->rsize =1024 *127 ; -cFYI (DBG2 ,"no very large read support, rsize now 127K" ); - } -if (!(tcon->ses->capabilities &CAP_LARGE_READ_X )) - cifs_sb->rsize =min (cifs_sb->rsize, CIFSMaxBufSize); - cifs_sb->wsize =cifs_negotiate_wsize (tcon, volume_info); + cifs_sb->rsize =cifs_negotiate_rsize (tcon, volume_info); remote_path_check: #ifdef CONFIG_CIFS_DFS_UPCALL
fs/cifs/file.c +10 -2
@@ -1715,6 +1715,7 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,struct smb_com_read_rsp *pSMBr;struct cifs_io_parms io_parms;char *read_data; +unsigned int rsize;__u32 pid;if (!nr_segs)
@@ -1727,6 +1728,9 @@ cifs_iovec_read(struct file *file, const struct iovec *iov, xid =GetXid (); cifs_sb =CIFS_SB (file->f_path.dentry->d_sb); +/* FIXME: set up handlers for larger reads and/or convert to async */ + rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize); + open_file = file->private_data; pTcon =tlink_tcon (open_file->tlink);
@@ -1739,7 +1743,7 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,cFYI (1 ,"attempting read on write only file instance" );for (total_read =0 ; total_read < len; total_read += bytes_read) { - cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize); + cur_len = min_t(const size_t, len - total_read, rsize); rc = -EAGAIN ; read_data =NULL ;
@@ -1831,6 +1835,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,unsigned int bytes_read =0 ;unsigned int total_read;unsigned int current_read_size; +unsigned int rsize;struct cifs_sb_info *cifs_sb;struct cifs_tcon *pTcon;int xid;
@@ -1843,6 +1848,9 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, xid =GetXid (); cifs_sb =CIFS_SB (file->f_path.dentry->d_sb); +/* FIXME: set up handlers for larger reads and/or convert to async */ + rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize); +if (file->private_data ==NULL ) { rc = -EBADF ;FreeXid (xid);
@@ -1863,7 +1871,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, read_size > total_read; total_read += bytes_read, current_offset += bytes_read) { current_read_size = min_t(const int, read_size - total_read, - cifs_sb->rsize); + rsize);/* For windows me and 9x we do not want to request more than it negotiated since it will refuse the read then */ if ((pTcon->ses) &&
Signature · 1 line
1.7.6.4
PATCH 5/5 cifs: tune bdi.ra_pages in accordance with the rsize
In reply to a message not in the archiveTune bdi.ra_pages to be a multiple of the rsize. This prevents the VFS from asking for pages that require small reads to satisfy.
--- fs/cifs/connect.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-)
fs/cifs/connect.c +19 -2
@@ -3156,6 +3156,22 @@ cifs_get_volume_info(char *mount_data, const char *devname)return volume_info; } +/* make sure ra_pages is a multiple of rsize */ +static inline unsigned int +cifs_ra_pages (struct cifs_sb_info *cifs_sb) +{ +unsigned int reads; +unsigned int rsize_pages = cifs_sb->rsize /PAGE_CACHE_SIZE ; + +if (rsize_pages >= default_backing_dev_info.ra_pages) +return default_backing_dev_info.ra_pages; +else if (rsize_pages ==0 ) +return rsize_pages; + + reads = default_backing_dev_info.ra_pages / rsize_pages; +return reads * rsize_pages; +} +int cifs_mount (struct cifs_sb_info *cifs_sb,struct smb_vol *volume_info) {
@@ -3174,8 +3190,6 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)if (rc)return rc; - cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages; -#ifdef CONFIG_CIFS_DFS_UPCALL try_mount_again:/* cleanup activities if we're chasing a referral */
@@ -3243,6 +3257,9 @@ try_mount_again: cifs_sb->wsize =cifs_negotiate_wsize (tcon, volume_info); cifs_sb->rsize =cifs_negotiate_rsize (tcon, volume_info); +/* tune readahead according to rsize */ + cifs_sb->bdi.ra_pages =cifs_ra_pages (cifs_sb); + remote_path_check: #ifdef CONFIG_CIFS_DFS_UPCALL/*
Signature · 1 line
1.7.6.4
Re: [PATCH 4/5] cifs: allow for larger rsize= options and change defaults
In reply to a message not in the archive2011/10/11 Jeff Layton <[email protected]>:
...
Quoted 13 lines
fs/cifs/connect.c +13
-0+ + /* +* Set default value... +* +* HACK alert! Ancient servers have very small buffers. Even though +* MS-CIFS indicates that servers are only limited by the client's +* bufsize for reads, testing against win98se shows that it throws +* INVALID_PARAMETER errors if you try to request too large a read. +* +* If the server advertises a MaxBufferSize of less than one page, +* assume that it also can't satisfy reads larger than that either. +* +* FIXME: Is there a better heuristic for this?
fs/cifs/connect.c cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info) · line 2950
Quoted 10 lines
fs/cifs/connect.c +10
-0+*/ + if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) + defsize = CIFS_DEFAULT_IOSIZE; + else if (server->capabilities & CAP_LARGE_READ_X) + defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; + else if (server->maxBuf >= PAGE_CACHE_SIZE) + defsize = CIFSMaxBufSize; + else + defsize = server->maxBuf - sizeof(READ_RSP); +
So, if the max buffer size that the server supports is greater or equal that PAGE_CACHE_SIZE than we set it to CIFSMaxBufSize. But if maxBuf is less than CIFSMaxBufSize? I think the server refects such a request.
Signature · 2 lines
Best regards, Pavel Shilovsky.
Re: [PATCH 4/5] cifs: allow for larger rsize= options and change defaults
In reply to a message not in the archiveQuoted 22 lines · On Wed, 12 Oct 2011 16:22:25 +0400 Pavel Shilovsky…
2011/10/11 Jeff Layton <[email protected]>:
...Quoted 20 lines
+
+ /*
+ * Set default value...
+ *
+ * HACK alert! Ancient servers have very small buffers. Even though
+ * MS-CIFS indicates that servers are only limited by the client's
+ * bufsize for reads, testing against win98se shows that it throws
+ *INVALID_PARAMETERerrors if you try to request too large a read.
+ *
+ * If the server advertises a MaxBufferSize of less than one page,
+ * assume that it also can't satisfy reads larger than that either.
+ *
+ * FIXME: Is there a better heuristic for this?
+ */
+ if (tcon->unix_ext&& (unix_cap&CIFS_UNIX_LARGE_READ_CAP))
+ defsize =CIFS_DEFAULT_IOSIZE;
+ else if (server->capabilities&CAP_LARGE_READ_X)
+ defsize =CIFS_DEFAULT_NON_POSIX_RSIZE;
+ else if (server->maxBuf>=PAGE_CACHE_SIZE)
+ defsize = CIFSMaxBufSize;
Quoted 9 lines
Quoted 3 lines
+ else
+ defsize =server->maxBuf-sizeof(READ_RSP); +So, if the max buffer size that the server supports is greater or equal that
PAGE_CACHE_SIZEthan we set it to CIFSMaxBufSize. But if maxBuf is less than CIFSMaxBufSize? I think the server refects such a request.
I guess you mean "rejects" ?
In principle, the server's maxBuf should have no bearing at all on the size of a read that it can satisfy.
In practice though, it seems like much older servers (such as win9x era) *do* have such a limitation. We have no clear way to identify such servers though, so I came up with this one (maxBuf less than PAGE_CACHE_SIZE).
I'm open to suggestions for a better heuristic here if you have one. Note too that this is just the default setting, and the user can override it if they wish.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 2/5] cifs: add cifs_async_readv
In reply to a message not in the archive2011/10/11 Jeff Layton <[email protected]>:
...
Quoted 9 lines
(quoted diff) +9
-0+ +static void +cifs_readv_complete(struct work_struct *work) +{ + struct cifs_readdata *rdata = container_of(work, + struct cifs_readdata, work); + struct page *page, *tpage; + + list_for_each_entry_safe(page, tpage, &rdata->pages, lru) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ list_del(&page->lru); + lru_cache_add_file(page); + + if (rdata->result == 0) { + kunmap(page); + flush_dcache_page(page); + SetPageUptodate(page); + unlock_page(page); + cifs_readpage_to_fscache(rdata->mapping->host, page); + }
It seems that we should to kunmap and unlock_page for error case too. This change works to me (applied on top of this patch):
fs/cifs/cifssmb.c +6 -3
@@ -1619,15 +1619,18 @@ cifs_readv_complete(struct work_struct *work)list_for_each_entry_safe (page, tpage, &rdata->pages, lru) {list_del (&page->lru);lru_cache_add_file (page); +kunmap (page);if (rdata->result ==0 ) { -kunmap (page);flush_dcache_page (page);SetPageUptodate (page); -unlock_page (page); -cifs_readpage_to_fscache (rdata->mapping->host, page); } +unlock_page (page); + +if (rdata->result ==0 ) +cifs_readpage_to_fscache (rdata->mapping->host, page); +page_cache_release (page); }cifs_readdata_free (rdata);
Quoted 6 lines
(quoted diff) +6
-0+ + page_cache_release(page); + } + cifs_readdata_free(rdata); +} +
Signature · 2 lines
Best regards, Pavel Shilovsky.
Re: [PATCH 2/5] cifs: add cifs_async_readv
In reply to a message not in the archiveQuoted 52 lines · On Wed, 19 Oct 2011 14:01:48 +0400 Pavel Shilovsky…
2011/10/11 Jeff Layton <[email protected]>:
...Quoted 9 lines
(quoted diff) +9
-0+ +static void +cifs_readv_complete(struct work_struct *work) +{ + struct cifs_readdata *rdata = container_of(work, + struct cifs_readdata, work); + struct page *page, *tpage; + + list_for_each_entry_safe(page, tpage, &rdata->pages, lru) {Review
Quoted 10 lines
(quoted diff) +10
-0+ list_del(&page->lru); + lru_cache_add_file(page); + + if (rdata->result == 0) { + kunmap(page); + flush_dcache_page(page); + SetPageUptodate(page); + unlock_page(page); + cifs_readpage_to_fscache(rdata->mapping->host, page); + }It seems that we should to kunmap and
unlock_pagefor error case too. This change works to me (applied on top of this patch):fs/cifs/cifssmb.c +6
-3@@ -1619,15 +1619,18 @@ cifs_readv_complete(struct work_struct *work)list_for_each_entry_safe (page, tpage, &rdata->pages, lru) {list_del (&page->lru);lru_cache_add_file (page); +kunmap (page);if (rdata->result ==0 ) { -kunmap (page);flush_dcache_page (page);SetPageUptodate (page); -unlock_page (page); -cifs_readpage_to_fscache (rdata->mapping->host, page); } +unlock_page (page); + +if (rdata->result ==0 ) +cifs_readpage_to_fscache (rdata->mapping->host, page); +page_cache_release (page); }cifs_readdata_free (rdata);
Quoted 7 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + page_cache_release(page); + } + cifs_readdata_free(rdata); +} +
Good catch -- patch looks correct to me. Since Steve hasn't merged this yet, I'll go ahead and roll this into the patch that adds this code.
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>