mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
Use readahead of underlying device and not default (smaller) one.
When we are stacking LV over device, which has for some reason increased read_ahead (e.g. MD RAID), the read_ahead hint for libdevmapper is wrong (it is zero). If the calculated read_ahead hint is zero, patch uses read_ahead of underlying device (if first segment is PV) when setting DM_READ_AHEAD_MINIMUM_FLAG. Because we are using dev-cache, it also store this value to cache for future use (if several LVs are over one PV, BLKRAGET is called only once for underlying device.) This should fix all the reamining problems with readahead mismatch reported for DM over MD configurations (and similar cases).
This commit is contained in:
parent
a01e55b6ec
commit
d396100278
@ -1,5 +1,6 @@
|
||||
Version 2.02.46 -
|
||||
================================
|
||||
Inherit read ahead from underlying device.
|
||||
Use lock query instead of activate_lv_excl.
|
||||
Enable online resizing of mirrors.
|
||||
Use suspend with flush when device size was changed during table preload.
|
||||
|
@ -469,6 +469,11 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in
|
||||
info->live_table = dminfo.live_table;
|
||||
info->inactive_table = dminfo.inactive_table;
|
||||
|
||||
/*
|
||||
* Cache read ahead value for PV devices now (before possible suspend)
|
||||
*/
|
||||
(void)lv_calculate_readhead(lv);
|
||||
|
||||
if (name)
|
||||
dm_pool_free(cmd->mem, name);
|
||||
|
||||
|
@ -1022,6 +1022,8 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
|
||||
if (read_ahead == DM_READ_AHEAD_AUTO) {
|
||||
/* we need RA at least twice a whole stripe - see the comment in md/raid0.c */
|
||||
read_ahead = max_stripe_size * 2;
|
||||
if (!read_ahead)
|
||||
read_ahead = lv_calculate_readhead(lv);
|
||||
read_ahead_flags = DM_READ_AHEAD_MINIMUM_FLAG;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,7 @@ struct device *dev_create_file(const char *filename, struct device *dev,
|
||||
dev->fd = -1;
|
||||
dev->open_count = 0;
|
||||
dev->block_size = -1;
|
||||
dev->read_ahead = -1;
|
||||
memset(dev->pvid, 0, sizeof(dev->pvid));
|
||||
dm_list_init(&dev->open_list);
|
||||
|
||||
@ -124,6 +125,7 @@ static struct device *_dev_create(dev_t d)
|
||||
dev->fd = -1;
|
||||
dev->open_count = 0;
|
||||
dev->block_size = -1;
|
||||
dev->read_ahead = -1;
|
||||
dev->end = UINT64_C(0);
|
||||
memset(dev->pvid, 0, sizeof(dev->pvid));
|
||||
dm_list_init(&dev->open_list);
|
||||
|
@ -262,6 +262,37 @@ static int _dev_get_size_dev(const struct device *dev, uint64_t *size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
|
||||
{
|
||||
long read_ahead_long;
|
||||
|
||||
if (dev->read_ahead != -1) {
|
||||
*read_ahead = (uint32_t) dev->read_ahead;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!dev_open(dev))
|
||||
return_0;
|
||||
|
||||
if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) {
|
||||
log_sys_error("ioctl BLKRAGET", dev_name(dev));
|
||||
if (!dev_close(dev))
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dev_close(dev))
|
||||
stack;
|
||||
|
||||
*read_ahead = (uint32_t) read_ahead_long;
|
||||
dev->read_ahead = read_ahead_long;
|
||||
|
||||
log_very_verbose("%s: read_ahead is %u sectors",
|
||||
dev_name(dev), *read_ahead);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
* Public functions
|
||||
*---------------------------------------------------------------*/
|
||||
@ -277,6 +308,19 @@ int dev_get_size(const struct device *dev, uint64_t *size)
|
||||
return _dev_get_size_dev(dev, size);
|
||||
}
|
||||
|
||||
int dev_get_read_ahead(struct device *dev, uint32_t *read_ahead)
|
||||
{
|
||||
if (!dev)
|
||||
return 0;
|
||||
|
||||
if (dev->flags & DEV_REGULAR) {
|
||||
*read_ahead = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return _dev_read_ahead_dev(dev, read_ahead);
|
||||
}
|
||||
|
||||
/* FIXME Unused
|
||||
int dev_get_sectsize(struct device *dev, uint32_t *size)
|
||||
{
|
||||
|
@ -40,6 +40,7 @@ struct device {
|
||||
int fd;
|
||||
int open_count;
|
||||
int block_size;
|
||||
int read_ahead;
|
||||
uint32_t flags;
|
||||
uint64_t end;
|
||||
struct dm_list open_list;
|
||||
@ -64,6 +65,7 @@ struct device_area {
|
||||
*/
|
||||
int dev_get_size(const struct device *dev, uint64_t *size);
|
||||
int dev_get_sectsize(struct device *dev, uint32_t *size);
|
||||
int dev_get_read_ahead(struct device *dev, uint32_t *read_ahead);
|
||||
|
||||
/* Use quiet version if device number could change e.g. when opening LV */
|
||||
int dev_open(struct device *dev);
|
||||
|
@ -1414,6 +1414,35 @@ static int _vg_mark_partial_lvs(struct volume_group *vg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Be sure that all PV devices have cached read ahead in dev-cache
|
||||
* Currently it takes read_ahead from first PV segment only
|
||||
*/
|
||||
static int _lv_read_ahead_single(struct logical_volume *lv, void *data)
|
||||
{
|
||||
struct lv_segment *seg = first_seg(lv);
|
||||
uint32_t seg_read_ahead = 0, *read_ahead = data;
|
||||
|
||||
if (seg && seg_type(seg, 0) == AREA_PV)
|
||||
dev_get_read_ahead(seg_pv(seg, 0)->dev, &seg_read_ahead);
|
||||
|
||||
if (seg_read_ahead > *read_ahead)
|
||||
*read_ahead = seg_read_ahead;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t lv_calculate_readhead(const struct logical_volume *lv)
|
||||
{
|
||||
uint32_t read_ahead = 0;
|
||||
|
||||
if (lv->read_ahead == DM_READ_AHEAD_AUTO)
|
||||
_lv_postorder((struct logical_volume *)lv, _lv_read_ahead_single, &read_ahead);
|
||||
|
||||
log_debug("Calculated readahead of LV %s is %u", lv->name, read_ahead);
|
||||
return read_ahead;
|
||||
}
|
||||
|
||||
int vg_validate(struct volume_group *vg)
|
||||
{
|
||||
struct pv_list *pvl, *pvl2;
|
||||
|
@ -344,6 +344,11 @@ struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv);
|
||||
*/
|
||||
unsigned snapshot_count(const struct volume_group *vg);
|
||||
|
||||
/*
|
||||
* Calculate readahead from underlying PV devices
|
||||
*/
|
||||
uint32_t lv_calculate_readhead(const struct logical_volume *lv);
|
||||
|
||||
/*
|
||||
* For internal metadata caching.
|
||||
*/
|
||||
|
@ -43,6 +43,10 @@ lvchange -r 400 "$vg/$lv"
|
||||
check_lvs_ lv_read_ahead 400
|
||||
lvremove -ff "$vg"
|
||||
|
||||
#COMM "read ahead is properly inherited from underlying PV"
|
||||
blockdev --setra 768 $dev1
|
||||
lvcreate -n $lv -L4M $vg $dev1
|
||||
test $(blockdev --getra $G_dev_/$vg/$lv) -eq 768
|
||||
# Check default, active/inactive values for read_ahead / kernel_read_ahead
|
||||
lvcreate -n $lv -l 50%FREE $vg
|
||||
lvchange -an $vg/$lv
|
||||
|
Loading…
Reference in New Issue
Block a user