All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Banks <gnb@sgi.com>
To: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Linux NFS ML <linux-nfs@vger.kernel.org>
Subject: [patch 11/14] sunrpc: Allocate cache_requests in a single allocation.
Date: Thu, 08 Jan 2009 19:25:21 +1100	[thread overview]
Message-ID: <20090108082604.735830000@sgi.com> (raw)
In-Reply-To: 20090108082510.050854000@sgi.com

Allocate the cache_request object and it's buffer in a single
contiguous memory allocation instead of two separate ones.
Code trawling shows that none of the users of caches make upcalls
anywhere near even the small x86 PAGE_SIZE, so we can afford to lose
a few bytes.  One less allocation makes the code a little simpler.

Signed-off-by: Greg Banks <gnb@sgi.com>
---

 net/sunrpc/cache.c |   28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

Index: bfields/net/sunrpc/cache.c
===================================================================
--- bfields.orig/net/sunrpc/cache.c
+++ bfields/net/sunrpc/cache.c
@@ -689,8 +689,8 @@ void cache_clean_deferred(void *owner)
 struct cache_request {
 	struct list_head	list;
 	struct cache_head	*item;
-	char			* buf;
 	int			len;
+	char			buf[0];
 };
 
 static ssize_t
@@ -741,7 +741,6 @@ cache_read(struct file *filp, char __use
 error:
 	/* need to release rq */
 	cache_put(rq->item, cd);
-	kfree(rq->buf);
 	kfree(rq);
 
 	return err;
@@ -893,7 +892,6 @@ static void cache_remove_queued(struct c
 	/* if found, destroy */
 	if (rq) {
 		cache_put(rq->item, cd);
-		kfree(rq->buf);
 		kfree(rq);
 	}
 }
@@ -983,15 +981,13 @@ static void warn_no_listener(struct cach
 
 /*
  * register an upcall request to user-space.
- * Each request is at most one page long.
+ * Each request is at most (slightly less than) one page long.
  */
 static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-
-	char *buf;
 	struct cache_request *rq;
 	char *bp;
-	int len;
+	int len;	/* bytes remaining in the buffer */
 
 	if (cd->cache_request == NULL)
 		return -EINVAL;
@@ -1002,28 +998,20 @@ static int cache_make_upcall(struct cach
 		return -EINVAL;
 	}
 
-	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!buf)
-		return -EAGAIN;
-
-	rq = kmalloc(sizeof (*rq), GFP_KERNEL);
-	if (!rq) {
-		kfree(buf);
+	rq = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!rq)
 		return -EAGAIN;
-	}
-
-	bp = buf; len = PAGE_SIZE;
 
+	bp = rq->buf;
+	len = PAGE_SIZE - sizeof(*rq);
 	cd->cache_request(cd, h, &bp, &len);
 
 	if (len < 0) {
-		kfree(buf);
 		kfree(rq);
 		return -EAGAIN;
 	}
 	rq->item = cache_get(h);
-	rq->buf = buf;
-	rq->len = PAGE_SIZE - len;
+	rq->len = PAGE_SIZE - sizeof(*rq) - len;
 	spin_lock(&cd->queue_lock);
 	list_add_tail(&rq->list, &cd->to_read);
 	spin_unlock(&cd->queue_lock);

--
-- 
Greg Banks, P.Engineer, SGI Australian Software Group.
the brightly coloured sporks of revolution.
I don't speak for SGI.

  parent reply	other threads:[~2009-01-08  8:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-08  8:25 [patch 00/14] sunrpc: Sunrpc cache cleanups and upcall rework Greg Banks
2009-01-08  8:25 ` [patch 01/14] sunrpc: Use consistent naming for variables of type struct cache_detail* Greg Banks
2009-01-08  8:25 ` [patch 02/14] sunrpc: Use consistent naming for variables of type struct cache_head* Greg Banks
2009-01-08  8:25 ` [patch 03/14] sunrpc: Use consistent naming for variables of type struct cache_request* Greg Banks
2009-01-08  8:25 ` [patch 04/14] sunrpc: Minor indentation cleanup in cache.c Greg Banks
2009-01-08  8:25 ` [patch 05/14] sunrpc: Rename queue_loose() to cache_remove_queued() Greg Banks
2009-01-08  8:25 ` [patch 06/14] sunrpc: Gather forward declarations of static functions in cache.c Greg Banks
2009-01-08  8:25 ` [patch 07/14] sunrpc: Make the global queue_lock per-cache-detail Greg Banks
2009-01-08  8:25 ` [patch 08/14] sunrpc: Make the global queue_wait per-cache-detail Greg Banks
2009-01-08  8:25 ` [patch 09/14] sunrpc: Remove the global lock queue_io_mutex Greg Banks
2009-01-08  8:25 ` [patch 10/14] sunrpc: Reorganise the queuing of cache upcalls Greg Banks
2009-01-08 19:57   ` J. Bruce Fields
2009-01-09  2:40     ` Greg Banks
     [not found]       ` <4966B92F.8060008-cP1dWloDopni96+mSzHFpQC/G2K4zDHf@public.gmane.org>
2009-01-09  2:57         ` J. Bruce Fields
2009-01-09  3:12           ` Greg Banks
     [not found]             ` <4966C0AB.7000604-cP1dWloDopni96+mSzHFpQC/G2K4zDHf@public.gmane.org>
2009-01-09 16:53               ` Chuck Lever
2009-01-10  1:28                 ` Greg Banks
2009-01-09 21:29         ` J. Bruce Fields
2009-01-09 21:41           ` J. Bruce Fields
2009-01-09 23:40             ` Greg Banks
2009-01-09 23:29           ` Greg Banks
2009-01-08  8:25 ` Greg Banks [this message]
2009-01-08  8:25 ` [patch 12/14] sunrpc: Centralise memory management of cache_requests Greg Banks
2009-01-08  8:25 ` [patch 13/14] sunrpc: Move struct cache_request to linux/sunrpc/cache.h Greg Banks
2009-01-08  8:25 ` [patch 14/14] sunrpc: Improve the usefulness of debug printks in the sunrpc cache code Greg Banks
2009-01-08 19:52 ` [patch 00/14] sunrpc: Sunrpc cache cleanups and upcall rework J. Bruce Fields
2009-01-09  1:42   ` Greg Banks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090108082604.735830000@sgi.com \
    --to=gnb@sgi.com \
    --cc=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.