[Devel] [PATCH RH8 2/5] ploop: Introduce mem_cache for pio allocation

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jul 21 19:00:19 MSK 2021


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