[Devel] [PATCH RHEL8 COMMIT] ploop: Introduce mem_cache for pio allocation

Konstantin Khorenko khorenko at virtuozzo.com
Thu Aug 5 18:32:01 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.vz8.7.2
------>
commit f8b11e63dd43fe238397a0f8dfd4882c06c2fc73
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu Aug 5 18:32:01 2021 +0300

    ploop: Introduce mem_cache for pio allocation
    
    Save some space in comparison to kmalloc caches.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-target.c | 8 +++++++-
 drivers/md/dm-ploop.h        | 5 +++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 7e04993084b7..364c48e118f1 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -27,6 +27,7 @@ module_param(ignore_signature_disk_in_use, bool, 0444);
 MODULE_PARM_DESC(ignore_signature_disk_in_use,
                 "Does not check for SIGNATURE_DISK_IN_USE");
 
+struct kmem_cache *pio_cache;
 struct kmem_cache *cow_cache;
 
 static void ploop_aio_do_completion(struct pio *pio)
@@ -526,9 +527,12 @@ static int __init dm_ploop_init(void)
 {
 	int r = -ENOMEM;
 
+	/* This saves some memory in comparison with kmalloc memcache */
+	pio_cache = kmem_cache_create("ploop-pio", sizeof(struct pio),
+				      0, 0, NULL);
 	cow_cache = kmem_cache_create("ploop-cow", sizeof(struct ploop_cow),
 				      0, 0, NULL);
-	if (!cow_cache)
+	if (!pio_cache || !cow_cache)
 		goto err;
 
 	r = dm_register_target(&ploop_target);
@@ -539,6 +543,7 @@ static int __init dm_ploop_init(void)
 
 	return 0;
 err:
+	kmem_cache_destroy(pio_cache);
 	kmem_cache_destroy(cow_cache);
 	return r;
 }
@@ -546,6 +551,7 @@ static int __init dm_ploop_init(void)
 static void __exit dm_ploop_exit(void)
 {
 	dm_unregister_target(&ploop_target);
+	kmem_cache_destroy(pio_cache);
 	kmem_cache_destroy(cow_cache);
 }
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 78e361566895..ceb30d8efa04 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -284,6 +284,7 @@ struct ploop_cow {
 };
 
 extern bool ignore_signature_disk_in_use;
+extern struct kmem_cache *pio_cache;
 extern struct kmem_cache *cow_cache;
 
 #define rb_root_for_each_md_page(rb_root, md, node)	\
@@ -549,12 +550,12 @@ static inline bool fake_merge_pio(struct pio *pio)
 
 static inline struct pio *alloc_pio(struct ploop *ploop, gfp_t flags)
 {
-	return kmalloc(sizeof(struct pio), flags);
+	return kmem_cache_alloc(pio_cache, flags);
 }
 
 static inline void free_pio(struct ploop *ploop, struct pio *pio)
 {
-	kfree(pio);
+	kmem_cache_free(pio_cache, pio);
 }
 
 extern void md_page_insert(struct ploop *ploop, struct md_page *md);


More information about the Devel mailing list