From 9b6135dca445fa300e8a1da5ed6ee84ab49c4945 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 5 Dec 2007 19:24:32 +0000 Subject: [PATCH] round readahead to multiple of page size in tools --- lib/activate/dev_manager.c | 4 ++-- tools/lvchange.c | 8 ++++++++ tools/lvcreate.c | 12 +++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index e4fd8c479..4c2d2c09f 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -952,10 +952,10 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, max_stripe_size = seg->stripe_size; } - if (read_ahead == DM_READ_AHEAD_AUTO) + if (read_ahead == DM_READ_AHEAD_AUTO) { read_ahead = max_stripe_size; - else read_ahead_flags = DM_READ_AHEAD_MINIMUM_FLAG; + } dm_tree_node_set_read_ahead(dnode, read_ahead, read_ahead_flags); diff --git a/tools/lvchange.c b/tools/lvchange.c index 8f7f2423a..b5075d99b 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -372,6 +372,7 @@ static int lvchange_readahead(struct cmd_context *cmd, struct logical_volume *lv) { unsigned read_ahead = 0; + unsigned pagesize = (unsigned) lvm_getpagesize() >> SECTOR_SHIFT; read_ahead = arg_uint_value(cmd, readahead_ARG, 0); @@ -382,6 +383,13 @@ static int lvchange_readahead(struct cmd_context *cmd, return 0; } + if (read_ahead != DM_READ_AHEAD_AUTO && + read_ahead != DM_READ_AHEAD_NONE && read_ahead % pagesize) { + read_ahead = (read_ahead / pagesize) * pagesize; + log_verbose("Rounding down readahead to %u sectors, a multiple " + "of page size %u.", read_ahead, pagesize); + } + if (lv->read_ahead == read_ahead) { log_error("Read ahead is already %u for \"%s\"", read_ahead, lv->name); diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 241197ef6..958caa6b9 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -333,6 +333,7 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd, int argc, char **argv) { int contiguous; + unsigned pagesize; memset(lp, 0, sizeof(*lp)); @@ -462,8 +463,17 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd, /* * Read ahead. */ - if (arg_count(cmd, readahead_ARG)) + if (arg_count(cmd, readahead_ARG)) { lp->read_ahead = arg_uint_value(cmd, readahead_ARG, 0); + pagesize = lvm_getpagesize() >> SECTOR_SHIFT; + if (lp->read_ahead != DM_READ_AHEAD_AUTO && + lp->read_ahead != DM_READ_AHEAD_NONE && + lp->read_ahead % pagesize) { + lp->read_ahead = (lp->read_ahead / pagesize) * pagesize; + log_verbose("Rounding down readahead to %u sectors, a multiple " + "of page size %u.", lp->read_ahead, pagesize); + } + } /* * Permissions.