Skip to content

Commit

Permalink
fs: dlm: memory cache for lowcomms hotpath
Browse files Browse the repository at this point in the history
This patch introduces a kmem cache for dlm_msg handles which are used
always if dlm sends a message out. Even if their are covered by midcomms
layer or not.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
  • Loading branch information
Alexander Aring authored and David Teigland committed Dec 7, 2021
1 parent 3af2326 commit e4dc81e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fs/dlm/lowcomms.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void)
0, 0, writequeue_entry_ctor);
}

struct kmem_cache *dlm_lowcomms_msg_cache_create(void)
{
return kmem_cache_create("dlm_msg", sizeof(struct dlm_msg), 0, 0, NULL);
}

/* need to held writequeue_lock */
static struct writequeue_entry *con_next_wq(struct connection *con)
{
Expand Down Expand Up @@ -750,7 +755,7 @@ static void dlm_msg_release(struct kref *kref)
struct dlm_msg *msg = container_of(kref, struct dlm_msg, ref);

kref_put(&msg->entry->ref, dlm_page_release);
kfree(msg);
dlm_free_msg(msg);
}

static void free_entry(struct writequeue_entry *e)
Expand Down Expand Up @@ -1259,18 +1264,20 @@ static struct dlm_msg *dlm_lowcomms_new_msg_con(struct connection *con, int len,
struct writequeue_entry *e;
struct dlm_msg *msg;

msg = kzalloc(sizeof(*msg), allocation);
msg = dlm_allocate_msg(allocation);
if (!msg)
return NULL;

kref_init(&msg->ref);

e = new_wq_entry(con, len, ppc, cb, data);
if (!e) {
kfree(msg);
dlm_free_msg(msg);
return NULL;
}

msg->retransmit = false;
msg->orig_msg = NULL;
msg->ppc = *ppc;
msg->len = len;
msg->entry = e;
Expand Down
1 change: 1 addition & 0 deletions fs/dlm/lowcomms.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark);
int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);
void dlm_midcomms_receive_done(int nodeid);
struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void);
struct kmem_cache *dlm_lowcomms_msg_cache_create(void);

#endif /* __LOWCOMMS_DOT_H__ */

18 changes: 18 additions & 0 deletions fs/dlm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

static struct kmem_cache *writequeue_cache;
static struct kmem_cache *mhandle_cache;
static struct kmem_cache *msg_cache;
static struct kmem_cache *lkb_cache;
static struct kmem_cache *rsb_cache;

Expand All @@ -36,6 +37,10 @@ int __init dlm_memory_init(void)
if (!lkb_cache)
goto lkb;

msg_cache = dlm_lowcomms_msg_cache_create();
if (!msg_cache)
goto msg;

rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
__alignof__(struct dlm_rsb), 0, NULL);
if (!rsb_cache)
Expand All @@ -44,6 +49,8 @@ int __init dlm_memory_init(void)
return 0;

rsb:
kmem_cache_destroy(msg_cache);
msg:
kmem_cache_destroy(lkb_cache);
lkb:
kmem_cache_destroy(mhandle_cache);
Expand All @@ -57,6 +64,7 @@ void dlm_memory_exit(void)
{
kmem_cache_destroy(writequeue_cache);
kmem_cache_destroy(mhandle_cache);
kmem_cache_destroy(msg_cache);
kmem_cache_destroy(lkb_cache);
kmem_cache_destroy(rsb_cache);
}
Expand Down Expand Up @@ -129,3 +137,13 @@ void dlm_free_writequeue(struct writequeue_entry *writequeue)
{
kmem_cache_free(writequeue_cache, writequeue);
}

struct dlm_msg *dlm_allocate_msg(gfp_t allocation)
{
return kmem_cache_alloc(msg_cache, allocation);
}

void dlm_free_msg(struct dlm_msg *msg)
{
kmem_cache_free(msg_cache, msg);
}
2 changes: 2 additions & 0 deletions fs/dlm/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct dlm_mhandle *dlm_allocate_mhandle(void);
void dlm_free_mhandle(struct dlm_mhandle *mhandle);
struct writequeue_entry *dlm_allocate_writequeue(void);
void dlm_free_writequeue(struct writequeue_entry *writequeue);
struct dlm_msg *dlm_allocate_msg(gfp_t allocation);
void dlm_free_msg(struct dlm_msg *msg);

#endif /* __MEMORY_DOT_H__ */

0 comments on commit e4dc81e

Please sign in to comment.