Skip to content

Commit 60ece08

Browse files
cschoenebeckmartinetd
authored andcommitted
net/9p: allocate appropriate reduced message buffers
So far 'msize' was simply used for all 9p message types, which is far too much and slowed down performance tremendously with large values for user configurable 'msize' option. Let's stop this waste by using the new p9_msg_buf_size() function for allocating more appropriate, smaller buffers according to what is actually sent over the wire. Only exception: RDMA transport is currently excluded from this message size optimization - for its response buffers that is - as RDMA transport would not cope with it, due to its response buffers being pulled from a shared pool. [1] Link: https://lore.kernel.org/all/Ys3jjg52EIyITPua@codewreck.org/ [1] Link: https://lkml.kernel.org/r/3f51590535dc96ed0a165b8218c57639cfa5c36c.1657920926.git.linux_oss@crudebyte.com Signed-off-by: Christian Schoenebeck <linux_oss@crudebyte.com> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent 01d205d commit 60ece08

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

net/9p/client.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,35 @@ static struct kmem_cache *p9_req_cache;
255255
* p9_tag_alloc - Allocate a new request.
256256
* @c: Client session.
257257
* @type: Transaction type.
258-
* @t_size: Buffer size for holding this request.
259-
* @r_size: Buffer size for holding server's reply on this request.
258+
* @t_size: Buffer size for holding this request
259+
* (automatic calculation by format template if 0).
260+
* @r_size: Buffer size for holding server's reply on this request
261+
* (automatic calculation by format template if 0).
262+
* @fmt: Format template for assembling 9p request message
263+
* (see p9pdu_vwritef).
264+
* @ap: Variable arguments to be fed to passed format template
265+
* (see p9pdu_vwritef).
260266
*
261267
* Context: Process context.
262268
* Return: Pointer to new request.
263269
*/
264270
static struct p9_req_t *
265-
p9_tag_alloc(struct p9_client *c, int8_t type, uint t_size, uint r_size)
271+
p9_tag_alloc(struct p9_client *c, int8_t type, uint t_size, uint r_size,
272+
const char *fmt, va_list ap)
266273
{
267274
struct p9_req_t *req = kmem_cache_alloc(p9_req_cache, GFP_NOFS);
268-
int alloc_tsize = min(c->msize, t_size);
269-
int alloc_rsize = min(c->msize, r_size);
275+
int alloc_tsize;
276+
int alloc_rsize;
270277
int tag;
278+
va_list apc;
279+
280+
va_copy(apc, ap);
281+
alloc_tsize = min_t(size_t, c->msize,
282+
t_size ?: p9_msg_buf_size(c, type, fmt, apc));
283+
va_end(apc);
284+
285+
alloc_rsize = min_t(size_t, c->msize,
286+
r_size ?: p9_msg_buf_size(c, type + 1, fmt, ap));
271287

272288
if (!req)
273289
return ERR_PTR(-ENOMEM);
@@ -599,6 +615,7 @@ static struct p9_req_t *p9_client_prepare_req(struct p9_client *c,
599615
{
600616
int err;
601617
struct p9_req_t *req;
618+
va_list apc;
602619

603620
p9_debug(P9_DEBUG_MUX, "client %p op %d\n", c, type);
604621

@@ -610,7 +627,9 @@ static struct p9_req_t *p9_client_prepare_req(struct p9_client *c,
610627
if (c->status == BeginDisconnect && type != P9_TCLUNK)
611628
return ERR_PTR(-EIO);
612629

613-
req = p9_tag_alloc(c, type, t_size, r_size);
630+
va_copy(apc, ap);
631+
req = p9_tag_alloc(c, type, t_size, r_size, fmt, apc);
632+
va_end(apc);
614633
if (IS_ERR(req))
615634
return req;
616635

@@ -645,9 +664,18 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
645664
int sigpending, err;
646665
unsigned long flags;
647666
struct p9_req_t *req;
667+
/* Passing zero for tsize/rsize to p9_client_prepare_req() tells it to
668+
* auto determine an appropriate (small) request/response size
669+
* according to actual message data being sent. Currently RDMA
670+
* transport is excluded from this response message size optimization,
671+
* as it would not cope with it, due to its pooled response buffers
672+
* (using an optimized request size for RDMA as well though).
673+
*/
674+
const uint tsize = 0;
675+
const uint rsize = c->trans_mod->pooled_rbuffers ? c->msize : 0;
648676

649677
va_start(ap, fmt);
650-
req = p9_client_prepare_req(c, type, c->msize, c->msize, fmt, ap);
678+
req = p9_client_prepare_req(c, type, tsize, rsize, fmt, ap);
651679
va_end(ap);
652680
if (IS_ERR(req))
653681
return req;

0 commit comments

Comments
 (0)