[Devel] [PATCH RH7] ploop: Use kmem_cache for iocb allocation

Kirill Tkhai ktkhai at virtuozzo.com
Mon Jun 1 18:31:23 MSK 2020


This should work better in memory pressure.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/io_kaio.c |    2 +-
 fs/aio.c                      |    6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 7ca3374cce3b..855c1c601eaa 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -810,7 +810,7 @@ kaio_sync_io(struct ploop_io * io, int op, struct page **pages,
 	else
 		bvec = kmalloc(sizeof(*bvec) * nr_pages, GFP_NOIO);
 	if (!bvec) {
-		kfree(iocb);
+		aio_kernel_free(iocb);
 		return -ENOMEM;
 	}
 
diff --git a/fs/aio.c b/fs/aio.c
index 96bebbfb5e58..e260710f8d91 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1546,7 +1546,9 @@ static ssize_t aio_run_iocb(struct kiocb *req, bool compat)
  */
 struct kiocb *aio_kernel_alloc(gfp_t gfp)
 {
-	struct kiocb *iocb = kzalloc(sizeof(struct kiocb), gfp);
+	struct kiocb *iocb;
+
+	iocb = kmem_cache_alloc(kiocb_cachep, gfp);
 	if (iocb)
 		iocb->ki_ctx = (void *)-1;
 	return iocb;
@@ -1555,7 +1557,7 @@ EXPORT_SYMBOL_GPL(aio_kernel_alloc);
 
 void aio_kernel_free(struct kiocb *iocb)
 {
-	kfree(iocb);
+	kmem_cache_free(kiocb_cachep, iocb);
 }
 EXPORT_SYMBOL_GPL(aio_kernel_free);
 




More information about the Devel mailing list