Skip to content

Commit 91a76be

Browse files
author
Dominique Martinet
committed
9p: add a per-client fcall kmem_cache
Having a specific cache for the fcall allocations helps speed up end-to-end latency. The caches will automatically be merged if there are multiple caches of items with the same size so we do not need to try to share a cache between different clients of the same size. Since the msize is negotiated with the server, only allocate the cache after that negotiation has happened - previous allocations or allocations of different sizes (e.g. zero-copy fcall) are made with kmalloc directly. Some figures on two beefy VMs with Connect-IB (sriov) / trans=rdma, with ior running 32 processes in parallel doing small 32 bytes IOs: - no alloc (4.18-rc7 request cache): 65.4k req/s - non-power of two alloc, no patch: 61.6k req/s - power of two alloc, no patch: 62.2k req/s - non-power of two alloc, with patch: 64.7k req/s - power of two alloc, with patch: 65.1k req/s Link: http://lkml.kernel.org/r/1532943263-24378-2-git-send-email-asmadeus@codewreck.org Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr> Acked-by: Jun Piao <piaojun@huawei.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Greg Kurz <groug@kaod.org>
1 parent 523adb6 commit 91a76be

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎include/net/9p/9p.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ enum p9_qid_t {
336336
#define P9_NOFID (u32)(~0)
337337
#define P9_MAXWELEM 16
338338

339+
/* Minimal header size: size[4] type[1] tag[2] */
340+
#define P9_HDRSZ 7
341+
339342
/* ample room for Twrite/Rread header */
340343
#define P9_IOHDRSZ 24
341344

@@ -558,6 +561,7 @@ struct p9_fcall {
558561
size_t offset;
559562
size_t capacity;
560563

564+
struct kmem_cache *cache;
561565
u8 *sdata;
562566
};
563567

‎include/net/9p/client.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct p9_client {
123123
struct p9_trans_module *trans_mod;
124124
enum p9_trans_status status;
125125
void *trans;
126+
struct kmem_cache *fcall_cache;
126127

127128
union {
128129
struct {

‎net/9p/client.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,16 @@ static int parse_opts(char *opts, struct p9_client *clnt)
231231
return ret;
232232
}
233233

234-
static int p9_fcall_init(struct p9_fcall *fc, int alloc_msize)
234+
static int p9_fcall_init(struct p9_client *c, struct p9_fcall *fc,
235+
int alloc_msize)
235236
{
236-
fc->sdata = kmalloc(alloc_msize, GFP_NOFS);
237+
if (likely(c->fcall_cache) && alloc_msize == c->msize) {
238+
fc->sdata = kmem_cache_alloc(c->fcall_cache, GFP_NOFS);
239+
fc->cache = c->fcall_cache;
240+
} else {
241+
fc->sdata = kmalloc(alloc_msize, GFP_NOFS);
242+
fc->cache = NULL;
243+
}
237244
if (!fc->sdata)
238245
return -ENOMEM;
239246
fc->capacity = alloc_msize;
@@ -242,7 +249,16 @@ static int p9_fcall_init(struct p9_fcall *fc, int alloc_msize)
242249

243250
void p9_fcall_fini(struct p9_fcall *fc)
244251
{
245-
kfree(fc->sdata);
252+
/* sdata can be NULL for interrupted requests in trans_rdma,
253+
* and kmem_cache_free does not do NULL-check for us
254+
*/
255+
if (unlikely(!fc->sdata))
256+
return;
257+
258+
if (fc->cache)
259+
kmem_cache_free(fc->cache, fc->sdata);
260+
else
261+
kfree(fc->sdata);
246262
}
247263
EXPORT_SYMBOL(p9_fcall_fini);
248264

@@ -267,9 +283,9 @@ p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size)
267283
if (!req)
268284
return NULL;
269285

270-
if (p9_fcall_init(&req->tc, alloc_msize))
286+
if (p9_fcall_init(c, &req->tc, alloc_msize))
271287
goto free_req;
272-
if (p9_fcall_init(&req->rc, alloc_msize))
288+
if (p9_fcall_init(c, &req->rc, alloc_msize))
273289
goto free;
274290

275291
p9pdu_reset(&req->tc);
@@ -951,6 +967,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
951967

952968
clnt->trans_mod = NULL;
953969
clnt->trans = NULL;
970+
clnt->fcall_cache = NULL;
954971

955972
client_id = utsname()->nodename;
956973
memcpy(clnt->name, client_id, strlen(client_id) + 1);
@@ -987,6 +1004,15 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
9871004
if (err)
9881005
goto close_trans;
9891006

1007+
/* P9_HDRSZ + 4 is the smallest packet header we can have that is
1008+
* followed by data accessed from userspace by read
1009+
*/
1010+
clnt->fcall_cache =
1011+
kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize,
1012+
0, 0, P9_HDRSZ + 4,
1013+
clnt->msize - (P9_HDRSZ + 4),
1014+
NULL);
1015+
9901016
return clnt;
9911017

9921018
close_trans:
@@ -1018,6 +1044,7 @@ void p9_client_destroy(struct p9_client *clnt)
10181044

10191045
p9_tag_cleanup(clnt);
10201046

1047+
kmem_cache_destroy(clnt->fcall_cache);
10211048
kfree(clnt);
10221049
}
10231050
EXPORT_SYMBOL(p9_client_destroy);

0 commit comments

Comments
 (0)