Discussion:
[linux-lvm] Setting readahead for Logical Volumes via udev
David Wittman
2014-05-19 15:58:21 UTC
Permalink
Hey all,

I'm having an issue tuning the readahead value for my Logical Volumes via
udev. In short, I'm trying to create a rule that sets the readahead
attribute for each of my Logical Volumes at boot time or upon the creation
of a new volume. udev seems like the perfect place to do this, but for some
reason or another LVM seems to be overriding these settings.

Here's the udev rule I'm using, followed by an example:

```
# cat /etc/udev/rules.d/83-readahead.rules
# Set the readahead on non-spinning disks to 8kb (16 512b sectors)
ACTION=="add", KERNEL=="dm-*", ATTR{queue/rotational}=="0",
ATTR{bdi/read_ahead_kb}="8"

# lvcreate -L 100G data_fioa -n readahead_test
Logical volume "readahead_test" created

# blockdev --report
RO RA SSZ BSZ StartSec Size Device
rw 256 512 4096 0 107374182400 /dev/dm-0
```

You'll notice above that the readahead is still 256 512-byte sectors. The
same happens upon a reboot of the system. Despite this, I do see
udevd-work[4778]: ATTR
'/sys/devices/virtual/block/dm-1/bdi/read_ahead_kb' writing '8'
/etc/udev/rules.d/83-readahead.rules:3

(Note: this is an earlier log entry; I have since disabled debug logging,
so ignore any inconsistencies here)

With all that said, I am quite certain that the udev rules are correct,
because after running `udevadm trigger`, the readahead values are then set
properly:

```
# udevadm trigger
# blockdev --report
RO RA SSZ BSZ StartSec Size Device
rw 16 512 4096 0 107374182400 /dev/dm-0
```

I've tried tweaking a few of the udev specific values in lvm.conf, to no
avail. Any help or suggestions are appreciated. Here are my system details:

Distro: CentOS 6.4
LVM2 version: lvm2-2.02.98-9.el6_4.3.x86_64
udev version: udev-147-2.46.el6_4.2.x86_64

Thanks,

Dave
Peter Rajnoha
2014-05-20 07:03:06 UTC
Permalink
Post by David Wittman
Hey all,
I'm having an issue tuning the readahead value for my Logical Volumes
via udev. In short, I'm trying to create a rule that sets the readahead
attribute for each of my Logical Volumes at boot time or upon the
creation of a new volume. udev seems like the perfect place to do this,
but for some reason or another LVM seems to be overriding these settings.
```
# cat /etc/udev/rules.d/83-readahead.rules
# Set the readahead on non-spinning disks to 8kb (16 512b sectors)
ACTION=="add", KERNEL=="dm-*", ATTR{queue/rotational}=="0",
ATTR{bdi/read_ahead_kb}="8"
Try ACTION=="change", KERNEL=="dm-*", ENV{DM_ACTIVATION}=="1", ATTR ....

Anyway, there's direct way to set the readahead value using LVM tools with:
lvcreate/lvchange -r/--readahead (see man lvcreate and lvchange for more info).
--
Peter
David Wittman
2014-05-20 15:37:50 UTC
Permalink
Hey Peter,

Thanks for the response. I've previously tried the "change" action, and
adding the specifier for the DM_ACTIVATION environment variable had no
effect. I'm also aware of the capability to set the readahead on a
per-volume basis, but I'm looking for a solution which handles setting
these values at boot time and/or volume creation time.

Dave
Post by Peter Rajnoha
Post by David Wittman
Hey all,
I'm having an issue tuning the readahead value for my Logical Volumes
via udev. In short, I'm trying to create a rule that sets the readahead
attribute for each of my Logical Volumes at boot time or upon the
creation of a new volume. udev seems like the perfect place to do this,
but for some reason or another LVM seems to be overriding these settings.
```
# cat /etc/udev/rules.d/83-readahead.rules
# Set the readahead on non-spinning disks to 8kb (16 512b sectors)
ACTION=="add", KERNEL=="dm-*", ATTR{queue/rotational}=="0",
ATTR{bdi/read_ahead_kb}="8"
Try ACTION=="change", KERNEL=="dm-*", ENV{DM_ACTIVATION}=="1", ATTR ....
lvcreate/lvchange -r/--readahead (see man lvcreate and lvchange for more info).
--
Peter
Marian Csontos
2014-05-22 07:07:49 UTC
Permalink
Post by David Wittman
Hey Peter,
Thanks for the response. I've previously tried the "change" action, and
adding the specifier for the DM_ACTIVATION environment variable had no
effect. I'm also aware of the capability to set the readahead on a
per-volume basis, but I'm looking for a solution which handles setting
these values at boot time and/or volume creation time.
Hi David, may be I do not understand your requirements but the
`--readahead` option does set the parameter at volume creation time and
during boot time.

Seeing you use star in the rules, looks like you want to change default
when new LV is created: there is `readahead` setting in the lvm.conf
file to do that.

-- Martian
David Wittman
2014-05-22 21:37:18 UTC
Permalink
Oh, well that makes more sense than using udev. I wasn't aware that -r
would set the readahead value persistently in the LV metadata. That makes
my life easy.

Thank you both.
Post by Marian Csontos
Post by David Wittman
Hey Peter,
Thanks for the response. I've previously tried the "change" action, and
adding the specifier for the DM_ACTIVATION environment variable had no
effect. I'm also aware of the capability to set the readahead on a
per-volume basis, but I'm looking for a solution which handles setting
these values at boot time and/or volume creation time.
Hi David, may be I do not understand your requirements but the
`--readahead` option does set the parameter at volume creation time and
during boot time.
Seeing you use star in the rules, looks like you want to change default
when new LV is created: there is `readahead` setting in the lvm.conf file
to do that.
-- Martian
Loading...