raid5-cache: use a mempool for the metadata block

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>
This commit is contained in:
Christoph Hellwig 2015-12-21 10:51:02 +11:00 committed by NeilBrown
parent c38d29b33b
commit e8deb63810
1 changed files with 12 additions and 2 deletions

View File

@ -77,6 +77,7 @@ struct r5l_log {
struct kmem_cache *io_kc; struct kmem_cache *io_kc;
struct bio_set *bs; struct bio_set *bs;
mempool_t *meta_pool;
struct md_thread *reclaim_thread; struct md_thread *reclaim_thread;
unsigned long reclaim_target; /* number of space that need to be 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); md_error(log->rdev->mddev, log->rdev);
bio_put(bio); bio_put(bio);
__free_page(io->meta_page); mempool_free(io->meta_page, log->meta_pool);
spin_lock_irqsave(&log->io_list_lock, flags); spin_lock_irqsave(&log->io_list_lock, flags);
__r5l_set_io_unit_state(io, IO_UNIT_IO_END); __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); INIT_LIST_HEAD(&io->stripe_list);
io->state = IO_UNIT_RUNNING; 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); block = page_address(io->meta_page);
clear_page(block);
block->magic = cpu_to_le32(R5LOG_MAGIC); block->magic = cpu_to_le32(R5LOG_MAGIC);
block->version = R5LOG_VERSION; block->version = R5LOG_VERSION;
block->seq = cpu_to_le64(log->seq); 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) if (!log->bs)
goto io_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->reclaim_thread = md_register_thread(r5l_reclaim_thread,
log->rdev->mddev, "reclaim"); log->rdev->mddev, "reclaim");
if (!log->reclaim_thread) 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); rcu_assign_pointer(conf->log, log);
return 0; return 0;
error: error:
md_unregister_thread(&log->reclaim_thread); md_unregister_thread(&log->reclaim_thread);
reclaim_thread: reclaim_thread:
mempool_destroy(log->meta_pool);
out_mempool:
bioset_free(log->bs); bioset_free(log->bs);
io_bs: io_bs:
kmem_cache_destroy(log->io_kc); kmem_cache_destroy(log->io_kc);
@ -1200,6 +1209,7 @@ io_kc:
void r5l_exit_log(struct r5l_log *log) void r5l_exit_log(struct r5l_log *log)
{ {
md_unregister_thread(&log->reclaim_thread); md_unregister_thread(&log->reclaim_thread);
mempool_destroy(log->meta_pool);
bioset_free(log->bs); bioset_free(log->bs);
kmem_cache_destroy(log->io_kc); kmem_cache_destroy(log->io_kc);
kfree(log); kfree(log);