From 2be80d271e6d029f7a9e5c1ed9c6a6d0c2785a4d Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Wed, 24 Aug 2011 10:59:50 -0400 Subject: [CRAZY RFC PATCH 4/4] dm: add reserved_rq_based_ios module parameter Allow user to change the number of IOs that are reserved by request-based DM's shared mempools by writing to this file: /sys/module/dm_mod/parameters/reserved_rq_based_ios The reserved IOs (and associated mempools) are established when the first request-based DM device is created. But the mempools' reserved IOs may only be changed if/when the mempools are recreated, e.g. if no multipath devices are in use: echo 256 > /sys/module/dm_mod/parameters/reserved_rq_based_ios multipath -F service multipathd restart [This implementation follows the pattern that Mikulas established for dm-bufio's 'dm_bufio_cache_size'.] Not-Signed-off-by: Mike Snitzer --- drivers/md/dm.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 47 insertions(+), 1 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index d904dd8..91d505f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -218,6 +218,23 @@ static struct kmem_cache *_rq_bio_info_cache; static struct dm_md_mempools *_rq_pools; static DEFINE_MUTEX(_rq_pools_mutex); +/* + * Request-based DM's shared mempools' reserved IOs set by the user + */ +static unsigned reserved_rq_based_ios = 0; + +/* + * A copy of reserved_rq_based_ios because it can change anytime. + * If values disagree, the user has changed reserved_rq_based_ios. + */ +static unsigned reserved_rq_based_ios_latch = 0; + +/* The module parameter */ +module_param(reserved_rq_based_ios, uint, 0644); +MODULE_PARM_DESC(reserved_rq_based_ios, "Reserved IOs in request-based mempools"); + +static void __reserved_request_based_ios_refresh(void); + static int __init local_init(void) { int r = -ENOMEM; @@ -252,7 +269,10 @@ static int __init local_init(void) if (!_major) _major = r; + mutex_lock(&_rq_pools_mutex); _rq_pools = NULL; + __reserved_request_based_ios_refresh(); + mutex_unlock(&_rq_pools_mutex); return 0; @@ -2738,7 +2758,7 @@ static struct dm_md_mempools * __alloc_md_pools(unsigned type, unsigned integrit tio_cache = _tio_cache; break; case DM_TYPE_REQUEST_BASED: - pool_size = RESERVED_REQUEST_BASED_IOS; + pool_size = reserved_rq_based_ios_latch; io_cache = _rq_bio_info_cache; tio_cache = _rq_tio_cache; _rq_pools = pools; @@ -2780,6 +2800,26 @@ free_pools_and_out: return NULL; } +static void __reserved_request_based_ios_refresh(void) +{ + reserved_rq_based_ios_latch = reserved_rq_based_ios; + + /* + * Prevent the compiler from using reserved_rq_based_ios anymore + * because it can change. + */ + barrier(); + + if (!reserved_rq_based_ios_latch) { + /* + * If the user uses "0", it means default. Modify + * reserved_rq_based_ios to report the default to the user. + */ + (void)cmpxchg(&reserved_rq_based_ios, 0, RESERVED_REQUEST_BASED_IOS); + reserved_rq_based_ios_latch = reserved_rq_based_ios; + } +} + struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity) { if (type == DM_TYPE_REQUEST_BASED) { @@ -2790,6 +2830,12 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity) pools = _rq_pools; } else { /* + * Check if reserved_rq_based_ios changed. + */ + if (reserved_rq_based_ios != reserved_rq_based_ios_latch) + __reserved_request_based_ios_refresh(); + + /* * Allocate shared request-based mempools. * Must always allocate integrity pool too. */ -- 1.7.1