Skip to contentSkip to conversation

Add write throttling to NFS client

PATCH Shantanu Goel 1 participant 1 message Feb 25, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Apologies for replying to my own message. I realized there was a bug in the patch shortly after sending it. Attached is a fixed one.

Thanks,
Shantanu

Quoted 20 lines · --- Shantanu Goel

Hi,

I posted an earlier version of the attached patch to the kernel mailing list a few days back but did not receive any feedback. Hopefully, I'll have better luck here. ;-)

The stock NFS client does not regulate the # async write requests causing other accesses to block in the
presence of streaming writes. This patch adds such support. For instance, a single dd running in the background writing to a file in my home directory causes my X session to hang until dd exits. With this
patch the session does not experience such hangs. Please test it out and let me know if you see anything
problems. I'd like to see this integrated soon.

Quoted 2 lines

Thanks,
Shantanu

__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

include/linux/nfs_page.h +2 -1
Index: include/linux/nfs_page.h
===================================================================
@@ -53,7 +53,8 @@
 extern	void nfs_list_add_request(struct nfs_page *, struct list_head *);
 
 extern	int nfs_scan_list(struct list_head *, struct list_head *,
-			  struct file *, unsigned long, unsigned int);
+			  struct file *, unsigned long, unsigned int,
+			  unsigned int, unsigned int);
 extern	int nfs_coalesce_requests(struct list_head *, struct list_head *,
 				  unsigned int);
 extern  int nfs_wait_on_request(struct nfs_page *);
include/linux/nfs_fs_sb.h +1 -0
Index: include/linux/nfs_fs_sb.h
===================================================================
@@ -28,6 +28,7 @@
 	char *			hostname;	/* remote hostname */
 	struct nfs_fh		fh;
 	struct sockaddr_in	addr;
+	atomic_t		wactive;	/* # active write requests */
 #ifdef CONFIG_NFS_V4
 	/* Our own IP address, as a null-terminated string.
 	 * This is used to generate the clientid, and the callback address.
fs/nfs/inode.c +2 -0
Index: fs/nfs/inode.c
===================================================================
@@ -364,6 +364,8 @@
 	if (sb->s_maxbytes > MAX_LFS_FILESIZE) 
 		sb->s_maxbytes = MAX_LFS_FILESIZE; 
 
+	atomic_set(&server->wactive, 0);
+
 	/* We're airborne Set socket buffersize */
 	rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
 	return 0;
fs/nfs/pagelist.c +33 -3
Index: fs/nfs/pagelist.c
===================================================================
@@ -249,6 +249,8 @@
  * @file: if set, ensure we match requests from this file
  * @idx_start: lower bound of page->index to scan
  * @npages: idx_start + npages sets the upper bound to scan.
+ * @nreq: if set, stop after this many coalesced requests.
+ * @rpages: if nreq is set, # pages per request.
  *
  * Moves elements from one of the inode request lists.
  * If the number of requests is set to 0, the entire address_space
@@ -259,18 +261,22 @@
 int
 nfs_scan_list(struct list_head *head, struct list_head *dst,
 	      struct file *file,
-	      unsigned long idx_start, unsigned int npages)
+	      unsigned long idx_start, unsigned int npages,
+	      unsigned int nreq, unsigned int rpages)
 {
 	struct list_head	*pos, *tmp;
-	struct nfs_page		*req;
+	struct nfs_page		*req, *prev;
 	unsigned long		idx_end;
-	int			res;
+	int			res, is_contig;
+	unsigned int		pages, nr;
 
 	res = 0;
 	if (npages == 0)
 		idx_end = ~0;
 	else
 		idx_end = idx_start + npages - 1;
+	nr = pages = 0;
+	prev = NULL;
 
 	list_for_each_safe(pos, tmp, head) {
 
@@ -286,9 +292,33 @@
 
 		if (!nfs_lock_request(req))
 			continue;
+
+		is_contig = (nreq &&
+			     prev &&
+			     pages < rpages &&
+			     req->wb_pgbase == 0 &&
+			     prev->wb_pgbase + prev->wb_bytes == PAGE_CACHE_SIZE &&
+			     req->wb_index == prev->wb_index + 1 &&
+			     req->wb_cred == prev->wb_cred);
+
+		if (!is_contig && nreq && nr == nreq) {
+			spin_unlock(&nfs_wreq_lock);
+			nfs_unlock_request(req);
+			spin_lock(&nfs_wreq_lock);
+			break;
+		}
+
 		nfs_list_remove_request(req);
 		nfs_list_add_request(req, dst);
 		res++;
+
+		if (is_contig)
+			pages++;
+		else {
+			pages = 1;
+			nr++;
+		}
+		prev = req;
 	}
 	return res;
 }
fs/nfs/write.c +108 -16

229 lines not on this page · raw message