Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 319017 - sys-fs/lvm2-2.02.64 extremely slow shutdown/reboot
Summary: sys-fs/lvm2-2.02.64 extremely slow shutdown/reboot
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: High minor (vote)
Assignee: Robin Johnson
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-09 00:44 UTC by Andreas Klauer
Modified: 2010-06-09 22:41 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
lvm-stop.sh without loops (lvm-stop.sh,879 bytes, text/plain)
2010-05-10 12:23 UTC, Andreas Klauer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Klauer 2010-05-09 00:44:32 UTC
Every time I shutdown or reboot my machine, it spends a long time (minutes) shutting down logical volumes. I've traced this to /lib64/rcscripts/addons/lvm-stop.sh, which calls the various LVM utilies (vgdisplay, lvchange, etc.) several times for every single logical volume. Every call to these utilities takes a few seconds to complete (about 4 seconds in my setup), with several volumes it sums up to minutes.

The script contains this comment:

# If these commands fail it is not currently an issue

If this is true, isn't then lvm-stop.sh completely unnecessary?

Otherwise, I think lvm-stop.sh has room for optimization. I don't think lvdisplay / lvchange have to be called for every single volume. lvchange at the very least happily accepts a list of volumes in one go.

There is a single command that enables all volumes at once (vgchange -a y), this takes only seconds to complete for me, don't the utilities offer something similar for shutdown? If shutdown is really necessary, they should.

I don't see this issue in other distros, though. How do they do it?

I'd be thankful if anyone could shed some light on whether lvm shutdown is actually necessary or not - if it is necessary, I'll see what I can do to optimize the shutdown script and attach the result here...

Reproducible: Always

Steps to Reproduce:
1. Set up LVM on one partition
2. Create 100 or so volumes (can be small)
3. Run lvm-stop.sh and see how long it takes...
Comment 1 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-05-09 23:59:55 UTC
agk:
1.
Can we have an output field for lvs/lvdisplay that gives us the path to the device node, like we get with default lvdisplay?
  --- Logical volume ---
  LV Name                /dev/vg/testcase

2.
Can we get the contents of lv_attr exported as seperate fields? esp. '# open' and read/write status.

andreas:
1.
The first two of the 3 loops I agree we should be able to replace with lvchange -an/vgchange -an.

2.
This should handle the last loop better, to get a list of open LVs:
# lvdisplay -C -o vg_name,lv_name,lv_attr --sep , --nosuffix --noheadings |awk -F, '{gsub(" ","",$0); if($3 ~ /^.....o$/) { printf "%s/%s\n",$1,$2; } }'

However it's not quite perfect, as it's giving out VG/LV, whereas lvdisplay gave out the path to the /dev node.

3.
For the last loop, hoist ROOT_DEVICE out of the loop.
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-05-10 00:00:38 UTC
andreas:
also, why are your calls to the LVM utils so slow? timing them here, I get a range of 90ms-400ms on each call.
Comment 3 Andreas Klauer 2010-05-10 00:53:00 UTC
Dunno, maybe because I'm using LVM on top of cryptsetup and it's actually spanning several PVs. I'll freely admit that my setup is not what you usually get from a 1-click-install, so I'm to blame here as well.

Can you confirm that I understand the lvm-stop.sh correctly:

1st loop shuts down LVs
2nd loop shuts down VGs
3rd loop displays an error message for LVs that could not be shut down?

I'm especially unsure about the 3rd loop.

I don't know if there is a better way to shut down LVs, but I found that lvchange accepts a volume group as argument, to shut down all LVs in that volume group (and print an error for those that can't be shut down).

This works very well for me, as it takes down all LVs instantly. I think I could adapt the lvm-stop.sh accordingly, if you want me to.

Still wondering whether it's necessary to shut them down at all, though. When I'm in a LiveCD, I usually don't, and I haven't seen any ill effects because of this...
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-05-10 01:09:42 UTC
(In reply to comment #3)
> Can you confirm that I understand the lvm-stop.sh correctly:
> 1st loop shuts down LVs
> 2nd loop shuts down VGs
> 3rd loop displays an error message for LVs that could not be shut down?
It's an error message for LVs that are still open.

> I don't know if there is a better way to shut down LVs, but I found that
> lvchange accepts a volume group as argument, to shut down all LVs in that
> volume group (and print an error for those that can't be shut down).
# lvchange -an
# vgchange -an
(notice no argument)

> This works very well for me, as it takes down all LVs instantly. I think I
> could adapt the lvm-stop.sh accordingly, if you want me to.
You're in a good place to test the changes, so yes please. Try the long command I gave for the 3rd loop as well.

> Still wondering whether it's necessary to shut them down at all, though. When
> I'm in a LiveCD, I usually don't, and I haven't seen any ill effects because of
> this...
The shutdown IS required, so that other underneath layers can be shut down (MD-raid is a good case, where you want to note that the array is clean).

CLVM, multipath, iSCSI, lots of other cases weirder than yours :-)
Comment 5 Andreas Klauer 2010-05-10 01:36:27 UTC
lvchange -an actually is what I tried first but doesn't work for me

# lvchange -a n
  Please give logical volume path(s)
  Run `lvchange --help' for more information.

hence the volume group as argument

vgchange unfortunately does not shut down lvs

# vgchange -an
  Can't deactivate volume group "lvm" with 14 open logical volume(s)

Well, maybe it would if no LVs were open anymore, I can't test that at the moment, but the script will have to cope with root on LVM as well, so it's not an option to rely on it either way
Comment 6 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-05-10 01:43:37 UTC
(In reply to comment #5)
> lvchange -an actually is what I tried first but doesn't work for me
> 
> # lvchange -a n
>   Please give logical volume path(s)
>   Run `lvchange --help' for more information.
> 
> hence the volume group as argument
Hmm, ok.

# VG_LIST="$(vgs -o vg_name --nosuffix --noheadings)"
# lvchange -aln ${VG_LIST}
# vgchange -aln 
Comment 7 Andreas Klauer 2010-05-10 12:23:29 UTC
Created attachment 230943 [details]
lvm-stop.sh without loops

So here's a replacement for /lib64/rcscripts/addons/lvm-stop.sh

For most users it should print out this message during shutdown:

Shutting down the Logical Volume Manager
  Shutting Down logical volumes [OK]
  Shutting Down volume groups   [OK]
Finished Shutting down the Logical Volume Manager

For people like me who use root on lvm it looks like this:

Shutting down the Logical Volume Manager
  Shutting Down logical volumes 
  LV lvm/root in use: not deactivating [!!]
  Shutting Down volume groups 
  Can't deactivate volume group "lvm" with 1 open logical volume(s) [!!]
Finished Shutting down the Logical Volume Manager

These error message come directly from the lvchange/vgchange tools. I refrained from reimplementing the 3rd error message loop, for two reasons: 1) I can't find a method that's reasonably fast and 2) I find the original error messages more informative than what I could provide myself in a separate loop.

Total execution time for this lvm-stop.sh on my system is 4 seconds
The original lvm-stop.sh took 820 seconds
Comment 8 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-09 06:33:58 UTC
Ok, tests out good, will be going into 2.02.67-r1
Comment 9 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-09 22:41:41 UTC
InCVS.