[Devel] [PATCH RH8 3/5] ploop: Use mempool to alloc pio

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


Reserve some memory for faster pio allocation.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-target.c |    8 ++++++--
 drivers/md/dm-ploop.h        |    7 ++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 364c48e118f1..4a15767f9bc9 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -27,7 +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;
+static struct kmem_cache *pio_cache;
 struct kmem_cache *cow_cache;
 
 static void ploop_aio_do_completion(struct pio *pio)
@@ -174,6 +174,7 @@ static void ploop_destroy(struct ploop *ploop)
 	WARN_ON(!ploop_empty_htable(ploop->inflight_pios));
 	kfree(ploop->inflight_pios);
 	kfree(ploop->exclusive_pios);
+	mempool_destroy(ploop->pio_pool);
 	kfree(ploop->deltas);
 	kvfree(ploop->holes_bitmap);
 	kvfree(ploop->tracking_bitmap);
@@ -315,13 +316,16 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	if (!ploop)
 		return -ENOMEM;
 
+	ploop->pio_pool = mempool_create_slab_pool(PLOOP_PIO_POOL_SIZE,
+						   pio_cache);
 	ploop->exclusive_pios = kcalloc(PLOOP_HASH_TABLE_SIZE,
 					sizeof(struct hlist_head),
 					GFP_KERNEL);
 	ploop->inflight_pios = kcalloc(PLOOP_HASH_TABLE_SIZE,
 					sizeof(struct hlist_head),
 					GFP_KERNEL);
-	if (!ploop->exclusive_pios || !ploop->inflight_pios) {
+	if (!ploop->pio_pool || !ploop->exclusive_pios ||
+				!ploop->inflight_pios) {
 		ret = -ENOMEM;
 		goto err;
 	}
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index ceb30d8efa04..b5ceacc1a145 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -136,6 +136,8 @@ enum {
 
 struct ploop {
 	struct dm_target *ti;
+#define PLOOP_PIO_POOL_SIZE 256
+	mempool_t *pio_pool;
 
 	struct rb_root bat_entries;
 	struct ploop_delta *deltas;
@@ -284,7 +286,6 @@ 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)	\
@@ -550,12 +551,12 @@ static inline bool fake_merge_pio(struct pio *pio)
 
 static inline struct pio *alloc_pio(struct ploop *ploop, gfp_t flags)
 {
-	return kmem_cache_alloc(pio_cache, flags);
+	return mempool_alloc(ploop->pio_pool, flags);
 }
 
 static inline void free_pio(struct ploop *ploop, struct pio *pio)
 {
-	kmem_cache_free(pio_cache, pio);
+	mempool_free(pio, ploop->pio_pool);
 }
 
 extern void md_page_insert(struct ploop *ploop, struct md_page *md);




More information about the Devel mailing list