SUNRPC: Add svc_rqst_replace_page() API
[sfrench/cifs-2.6.git] / net / sunrpc / svc.c
index 0de918cb3d90da4842fdb0facc54ac2f8b0ddc5a..d2d412d4382778a0a4d2186e553597160e0dca2d 100644 (file)
@@ -838,6 +838,27 @@ svc_set_num_threads_sync(struct svc_serv *serv, struct svc_pool *pool, int nrser
 }
 EXPORT_SYMBOL_GPL(svc_set_num_threads_sync);
 
+/**
+ * svc_rqst_replace_page - Replace one page in rq_pages[]
+ * @rqstp: svc_rqst with pages to replace
+ * @page: replacement page
+ *
+ * When replacing a page in rq_pages, batch the release of the
+ * replaced pages to avoid hammering the page allocator.
+ */
+void svc_rqst_replace_page(struct svc_rqst *rqstp, struct page *page)
+{
+       if (*rqstp->rq_next_page) {
+               if (!pagevec_space(&rqstp->rq_pvec))
+                       __pagevec_release(&rqstp->rq_pvec);
+               pagevec_add(&rqstp->rq_pvec, *rqstp->rq_next_page);
+       }
+
+       get_page(page);
+       *(rqstp->rq_next_page++) = page;
+}
+EXPORT_SYMBOL_GPL(svc_rqst_replace_page);
+
 /*
  * Called from a server thread as it's exiting. Caller must hold the "service
  * mutex" for the service.