raid5-cache: use a mempool for the metadata block
authorChristoph Hellwig <hch@lst.de>
Sun, 20 Dec 2015 23:51:02 +0000 (10:51 +1100)
committerNeilBrown <neilb@suse.com>
Wed, 6 Jan 2016 00:40:08 +0000 (11:40 +1100)
We only have a limited number in flight, so use a page based mempool.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: NeilBrown <neilb@suse.com>
drivers/md/raid5-cache.c

index 2a644977d90cc948c50527873e46db87ed51f465..fa2d6321f3a4b73e065fdc963828b3e25e168154 100644 (file)
@@ -77,6 +77,7 @@ struct r5l_log {
 
        struct kmem_cache *io_kc;
        struct bio_set *bs;
+       mempool_t *meta_pool;
 
        struct md_thread *reclaim_thread;
        unsigned long reclaim_target;   /* number of space that need to be
@@ -216,7 +217,7 @@ static void r5l_log_endio(struct bio *bio)
                md_error(log->rdev->mddev, log->rdev);
 
        bio_put(bio);
-       __free_page(io->meta_page);
+       mempool_free(io->meta_page, log->meta_pool);
 
        spin_lock_irqsave(&log->io_list_lock, flags);
        __r5l_set_io_unit_state(io, IO_UNIT_IO_END);
@@ -293,8 +294,9 @@ static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log)
        INIT_LIST_HEAD(&io->stripe_list);
        io->state = IO_UNIT_RUNNING;
 
-       io->meta_page = alloc_page(GFP_NOIO | __GFP_NOFAIL | __GFP_ZERO);
+       io->meta_page = mempool_alloc(log->meta_pool, GFP_NOIO);
        block = page_address(io->meta_page);
+       clear_page(block);
        block->magic = cpu_to_le32(R5LOG_MAGIC);
        block->version = R5LOG_VERSION;
        block->seq = cpu_to_le64(log->seq);
@@ -1172,6 +1174,10 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
        if (!log->bs)
                goto io_bs;
 
+       log->meta_pool = mempool_create_page_pool(R5L_POOL_SIZE, 0);
+       if (!log->meta_pool)
+               goto out_mempool;
+
        log->reclaim_thread = md_register_thread(r5l_reclaim_thread,
                                                 log->rdev->mddev, "reclaim");
        if (!log->reclaim_thread)
@@ -1186,9 +1192,12 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
 
        rcu_assign_pointer(conf->log, log);
        return 0;
+
 error:
        md_unregister_thread(&log->reclaim_thread);
 reclaim_thread:
+       mempool_destroy(log->meta_pool);
+out_mempool:
        bioset_free(log->bs);
 io_bs:
        kmem_cache_destroy(log->io_kc);
@@ -1200,6 +1209,7 @@ io_kc:
 void r5l_exit_log(struct r5l_log *log)
 {
        md_unregister_thread(&log->reclaim_thread);
+       mempool_destroy(log->meta_pool);
        bioset_free(log->bs);
        kmem_cache_destroy(log->io_kc);
        kfree(log);