[Devel] [PATCH RHEL8 COMMIT] ploop: Allocate piocb from kmem_cache

Konstantin Khorenko khorenko at virtuozzo.com
Tue Dec 10 18:28:44 MSK 2019


The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.2.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.2.6
------>
commit 6df8caaae912d5ab3e79b5c8c4b5865f6f340f42
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Dec 10 18:28:42 2019 +0300

    ploop: Allocate piocb from kmem_cache
    
    Just in the way as plain bios are allocated,
    allocate piocb from kmem_cache, since this
    works better under memory pressure.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c    | 10 ++--------
 drivers/md/dm-ploop-target.c | 10 ++++++++++
 drivers/md/dm-ploop.h        |  8 ++++++++
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 8af8fa836278..e6dcd0c8a530 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -851,12 +851,6 @@ static bool ploop_attach_end_action(struct bio *bio, struct ploop_index_wb *piwb
 	return true;
 }
 
-struct ploop_iocb {
-	struct kiocb iocb;
-	struct bio *bio;
-	atomic_t count;
-};
-
 static void ploop_read_aio_do_completion(struct ploop_iocb *piocb)
 {
 	struct bio *bio = piocb->bio;
@@ -864,7 +858,7 @@ static void ploop_read_aio_do_completion(struct ploop_iocb *piocb)
 	if (!atomic_dec_and_test(&piocb->count))
 		return;
 	bio_endio(bio);
-	kfree(piocb);
+	kmem_cache_free(piocb_cache, piocb);
 }
 
 static void ploop_read_aio_complete(struct kiocb *iocb, long ret, long ret2)
@@ -895,7 +889,7 @@ static void submit_delta_read(struct ploop *ploop, unsigned int level,
 	loff_t pos;
 	int ret;
 
-	piocb = kzalloc(sizeof(*piocb), GFP_NOIO); /* This may be improved */
+	piocb = kmem_cache_zalloc(piocb_cache, GFP_NOIO);
 	if (!piocb) {
 		bio->bi_status = BLK_STS_RESOURCE;
 		bio_endio(bio);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 24f69cc35c5b..904cacade2db 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -12,6 +12,8 @@
 
 #define DM_MSG_PREFIX "ploop"
 
+struct kmem_cache *piocb_cache;
+
 static void inflight_bios_ref_exit0(struct percpu_ref *ref)
 {
 	struct ploop *ploop = container_of(ref, struct ploop,
@@ -303,11 +305,19 @@ static int __init dm_ploop_init(void)
 		return r;
 	}
 
+	piocb_cache = kmem_cache_create("ploop-iocb", sizeof(struct ploop_iocb),
+					0, 0, NULL);
+	if (!piocb_cache) {
+		dm_unregister_target(&ploop_target);
+		return -ENOMEM;
+	}
+
 	return 0;
 }
 
 static void __exit dm_ploop_exit(void)
 {
+	kmem_cache_destroy(piocb_cache);
 	dm_unregister_target(&ploop_target);
 }
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 7c6dfccfb3f5..12c946030905 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -254,6 +254,14 @@ struct dm_ploop_endio_hook {
 	unsigned int ref_index:2;
 };
 
+struct ploop_iocb {
+	struct kiocb iocb;
+	struct bio *bio;
+	atomic_t count;
+};
+
+extern struct kmem_cache *piocb_cache;
+
 static inline bool ploop_is_ro(struct ploop *ploop)
 {
 	return (dm_table_get_mode(ploop->ti->table) & FMODE_WRITE) == 0;



More information about the Devel mailing list