fs: dlm: memory cache for writequeue_entry
authorAlexander Aring <aahringo@redhat.com>
Tue, 30 Nov 2021 19:47:19 +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 writequeue entry. A writequeue
entry get quite a lot allocated if dlm transmit messages.

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 4919faf7970979922eb8bc2f6482fa1189a336cb..300f44c5d13265182735e93f15b456734fc6d7f0 100644 (file)
@@ -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;
 }
 
index 8108ea24ec30123849f0c924e0e3d691d8b78ada..6c8f4ce457f05e26b07af57d9d2e89c497f54c2a 100644 (file)
@@ -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__ */
 
index 8996c6453ad5c4ef02732e946ad2629124cdf5d1..94af986e83c6d7d49d6f6551f2487579ad799a23 100644 (file)
 
 #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);
+}
index c4d46be778a29d7e8ce06d8a5624cf03343efcb2..854269eacd4457b86bf463ae135ae23536874a17 100644 (file)
@@ -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__ */