From 5c16febbc19bb463bfb8e80cb5b24ec6ff1a439f Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Tue, 2 Nov 2021 15:17:19 -0400 Subject: fs: dlm: let handle callback data as void This patch changes the dlm_lowcomms_new_msg() function pointer private data from "struct mhandle *" to "void *" to provide different structures than just "struct mhandle". Signed-off-by: Alexander Aring Signed-off-by: David Teigland --- fs/dlm/lowcomms.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fs/dlm/lowcomms.h') diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index 4ccae07cf005..8108ea24ec30 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h @@ -38,8 +38,8 @@ void dlm_lowcomms_stop(void); void dlm_lowcomms_exit(void); int dlm_lowcomms_close(int nodeid); struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, gfp_t allocation, - char **ppc, void (*cb)(struct dlm_mhandle *mh), - struct dlm_mhandle *mh); + char **ppc, void (*cb)(void *data), + void *data); void dlm_lowcomms_commit_msg(struct dlm_msg *msg); void dlm_lowcomms_put_msg(struct dlm_msg *msg); int dlm_lowcomms_resend_msg(struct dlm_msg *msg); -- cgit v1.2.3 From 3af2326ca0a13cf84aeb75e001e757ff3cefeae9 Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Tue, 30 Nov 2021 14:47:19 -0500 Subject: fs: dlm: memory cache for writequeue_entry This patch introduces a kmem cache for writequeue entry. A writequeue entry get quite a lot allocated if dlm transmit messages. Signed-off-by: Alexander Aring Signed-off-by: David Teigland --- fs/dlm/lowcomms.c | 26 +++++++++++++++++++++----- fs/dlm/lowcomms.h | 1 + fs/dlm/memory.c | 21 ++++++++++++++++++++- fs/dlm/memory.h | 2 ++ 4 files changed, 44 insertions(+), 6 deletions(-) (limited to 'fs/dlm/lowcomms.h') diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 4919faf79709..300f44c5d132 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -58,6 +58,7 @@ #include "dlm_internal.h" #include "lowcomms.h" #include "midcomms.h" +#include "memory.h" #include "config.h" #define NEEDED_RMEM (4*1024*1024) @@ -190,6 +191,19 @@ static const struct dlm_proto_ops *dlm_proto_ops; static void process_recv_sockets(struct work_struct *work); static void process_send_sockets(struct work_struct *work); +static void writequeue_entry_ctor(void *data) +{ + struct writequeue_entry *entry = data; + + INIT_LIST_HEAD(&entry->msgs); +} + +struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void) +{ + return kmem_cache_create("dlm_writequeue", sizeof(struct writequeue_entry), + 0, 0, writequeue_entry_ctor); +} + /* need to held writequeue_lock */ static struct writequeue_entry *con_next_wq(struct connection *con) { @@ -728,7 +742,7 @@ static void dlm_page_release(struct kref *kref) ref); __free_page(e->page); - kfree(e); + dlm_free_writequeue(e); } static void dlm_msg_release(struct kref *kref) @@ -1177,21 +1191,23 @@ static struct writequeue_entry *new_writequeue_entry(struct connection *con) { struct writequeue_entry *entry; - entry = kzalloc(sizeof(*entry), GFP_ATOMIC); + entry = dlm_allocate_writequeue(); if (!entry) return NULL; entry->page = alloc_page(GFP_ATOMIC | __GFP_ZERO); if (!entry->page) { - kfree(entry); + dlm_free_writequeue(entry); return NULL; } + entry->offset = 0; + entry->len = 0; + entry->end = 0; + entry->dirty = false; entry->con = con; entry->users = 1; kref_init(&entry->ref); - INIT_LIST_HEAD(&entry->msgs); - return entry; } diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index 8108ea24ec30..6c8f4ce457f0 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h @@ -47,6 +47,7 @@ int dlm_lowcomms_connect_node(int nodeid); 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); #endif /* __LOWCOMMS_DOT_H__ */ diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 8996c6453ad5..94af986e83c6 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -11,9 +11,11 @@ #include "dlm_internal.h" #include "midcomms.h" +#include "lowcomms.h" #include "config.h" #include "memory.h" +static struct kmem_cache *writequeue_cache; static struct kmem_cache *mhandle_cache; static struct kmem_cache *lkb_cache; static struct kmem_cache *rsb_cache; @@ -21,9 +23,13 @@ static struct kmem_cache *rsb_cache; int __init dlm_memory_init(void) { + writequeue_cache = dlm_lowcomms_writequeue_cache_create(); + if (!writequeue_cache) + goto out; + mhandle_cache = dlm_midcomms_cache_create(); if (!mhandle_cache) - goto out; + goto mhandle; lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb), __alignof__(struct dlm_lkb), 0, NULL); @@ -41,12 +47,15 @@ rsb: kmem_cache_destroy(lkb_cache); lkb: kmem_cache_destroy(mhandle_cache); +mhandle: + kmem_cache_destroy(writequeue_cache); out: return -ENOMEM; } void dlm_memory_exit(void) { + kmem_cache_destroy(writequeue_cache); kmem_cache_destroy(mhandle_cache); kmem_cache_destroy(lkb_cache); kmem_cache_destroy(rsb_cache); @@ -110,3 +119,13 @@ void dlm_free_mhandle(struct dlm_mhandle *mhandle) { kmem_cache_free(mhandle_cache, mhandle); } + +struct writequeue_entry *dlm_allocate_writequeue(void) +{ + return kmem_cache_alloc(writequeue_cache, GFP_ATOMIC); +} + +void dlm_free_writequeue(struct writequeue_entry *writequeue) +{ + kmem_cache_free(writequeue_cache, writequeue); +} diff --git a/fs/dlm/memory.h b/fs/dlm/memory.h index c4d46be778a2..854269eacd44 100644 --- a/fs/dlm/memory.h +++ b/fs/dlm/memory.h @@ -22,6 +22,8 @@ char *dlm_allocate_lvb(struct dlm_ls *ls); void dlm_free_lvb(char *l); 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); #endif /* __MEMORY_DOT_H__ */ -- cgit v1.2.3 From e4dc81ed5a8069b8ae56116058ebbad77ff559ec Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Tue, 30 Nov 2021 14:47:20 -0500 Subject: fs: dlm: memory cache for lowcomms hotpath 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 Signed-off-by: David Teigland --- fs/dlm/lowcomms.c | 13 ++++++++++--- fs/dlm/lowcomms.h | 1 + fs/dlm/memory.c | 18 ++++++++++++++++++ fs/dlm/memory.h | 2 ++ 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'fs/dlm/lowcomms.h') diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 300f44c5d132..23a1ff690725 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -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) { @@ -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) @@ -1259,7 +1264,7 @@ 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; @@ -1267,10 +1272,12 @@ static struct dlm_msg *dlm_lowcomms_new_msg_con(struct connection *con, int len, 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; diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index 6c8f4ce457f0..29369feea991 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h @@ -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__ */ diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 94af986e83c6..ce35c3c19aeb 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -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; @@ -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) @@ -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); @@ -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); } @@ -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); +} diff --git a/fs/dlm/memory.h b/fs/dlm/memory.h index 854269eacd44..7bd3f1a391ca 100644 --- a/fs/dlm/memory.h +++ b/fs/dlm/memory.h @@ -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__ */ -- cgit v1.2.3