fs: dlm: memory cache for lowcomms hotpath
authorAlexander Aring <aahringo@redhat.com>
Tue, 30 Nov 2021 19:47:20 +0000 (14:47 -0500)
committerDavid Teigland <teigland@redhat.com>
Tue, 7 Dec 2021 18:42:26 +0000 (12:42 -0600)
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>
fs/dlm/lowcomms.c
fs/dlm/lowcomms.h
fs/dlm/memory.c
fs/dlm/memory.h

index 300f44c5d13265182735e93f15b456734fc6d7f0..23a1ff690725237b852cea0a290cdf6e30ab5f59 100644 (file)
@@ -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;
index 6c8f4ce457f05e26b07af57d9d2e89c497f54c2a..29369feea9916846ced5a8c01ccfb462773ffb8a 100644 (file)
@@ -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__ */
 
index 94af986e83c6d7d49d6f6551f2487579ad799a23..ce35c3c19aeb5fbe32fe533036826753794d6987 100644 (file)
@@ -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);
+}
index 854269eacd4457b86bf463ae135ae23536874a17..7bd3f1a391ca787033770874563df947d4363e31 100644 (file)
@@ -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__ */