-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shutting down domain takes a long time #5426
Comments
Take a looks at |
@marmarek Looking at the most recent log file for the domain I can see that the log messages report successful shutdown (so it seems) almost immediately after clicking the "Shutdown" button in the Qubes menu. When I click Shutdown and look at the log I immediately see this:
And then it takes ~40 seconds. No further log entries are added, so the log does not really help. Is this ok? Where would I look further? |
|
Your questions lead me to do some more testing:
Shutdown time currently is ~50 seconds in all cases. The first time I noticed the long shutdown is after increasing the private storage by a large amount. But it might be that I did not notice the long shutdown time before during regular shutdown. But I'm certain it used to be a lot faster. If I could pinpoint it to a slow HDD or something this would be fine. I'd just like to see some log where the delay can be seen. Maybe it's a timeout or something. |
Just had look into the oldest xen log file I have, which is from Oct 06. It looks different for shutdown:
The xenbus line is gone in the current log. But then again those changes might be to kernel or xen updates. And the delay is not covered in the log. |
guid.domain.log differs from other domains. It shows:
These log entries seem to be unique to this domain:
Maybe it's just a reporting issue? Somebody not noticing the shutdown already happened? |
Those particular messages are probably unrelated, but I have another idea: during that long shutdown observe output of |
@marmarek
Note how the domain name at some point is replaced by (null) and the time stops. It stays like (null): --ps-d (21.0) for about 8 seconds, then the entry disappears while the domain is still shutting down for many more seconds according to the Qubes Domains list. In my VM I have version 4.0.7 of qubes-libvchan-xen.
Does this shed some light? |
|
Do you see anything in there that looks odd? |
Thanks. I had a (now seemingly incorrect) hunch the issue was that blkdiscard was issuing discards* against thin-volumes hosted on the HDD...but that WD drive is around 10 years old, so it definitely does not support TRIM, so that's not the issue. -Brendan * Qubes issues blkdiscard before lvremove post-shutdown for volatile/snapshot volumes and/or post-VM-delete for deleted VMs. It's good practice, for several reasons, upper layers to notify lower layers that storage is being de-allocated, and lvm does not currently explicitly do so when lvremove is executed. If all layers have pass-down enabled (by default, Qubes doesn't, but many of us enable it), this leads to TRIM requests being issued to the physical storage layer. |
@brendanhoar By explicitly stating the age of this drive you make me wanna do backups more often... |
I made another observation today while trying to reduce the number of Calling Here is the log of calling
@marmarek @brendanhoar How would you interpret this? What exactly is happening there? Some kind of diff being calculated? Which maybe just takes time due to the large amount of data on a slow HDD? |
It looks like discarding the oldest snapshot takes its time. Additionally, I just set the Increasing the @marmarek Does this sound right? Is this supposed to take such a long time? Is there a way to speed this up? |
That makes sense. Issuing DISCARD for the whole 580GB volume indeed can take time. LVM internally handle it too, even if underlying block doesn't support it. Specifically - release blocks from the volume and update internal metadata about those blocks (reference counters etc).
Do you have a specific use case against assumptions in the first point? |
[Edit - I will amend the below after catching up on the previous several posts.] Some interplay of HDD, /etc/lvm/lvm.conf (and cryptsetup options, if being used) may make it possible that the blkdiscard issued before lvremove might be zeroing out the container files (instead of issuing discards, since the backing store is not trim-capable).
Lastly, I wonder if blkdiscard automatically falls back to using zeroout if the volume (real or virtual) does not indicate trim support. That would not be optimal behavior on a thin volume. I may have to go dig out some spinning rust from my closet to do some tests. Brendan PS - my one-ish liner on monitoring discards as they happen: In dom0, Drive 1 will be /dev/sda, etc., it'll also show discards on loops devices as well. |
(Just as a side note, and this could be irrelevant: before I can start the (long-shutdown) AppVM in the second pool I have to start another VM (from the SSD pool) first, OR I have to call Thanks to both of you for helping me out here. |
@marmarek (*) with a physical SATA switch, so no "realy" dual-boot that could be of relevance to the issue |
I wouldn't call it broken. Rather sub-optimal performance.
This rules out my third idea, as you'd still need to wait during shutdown.
I believe this setting applies to non-thin volumes only.
This indeed is relevant for thin volumes, possible values:
|
I have the very same problem discussed here https://groups.google.com/forum/m/#!topic/qubes-users/-ZnZM6rS4hs
|
While shutting down a VM, I observe freezing in other VMs on the same pool as well. During the freeze, A |
I'm using an SSD but I had the same problem and it was only occurred on SanDisk SDSSDXPS480G and not on Samsung SSD 860 EVO. In conclusion, it was solved by changing the discard mode of LVM thin pool from passdown to nopassdown.
This will restore the physical space to the thin pool as in the past, but no TRIM command will be issued to the physical device.
The default "passdown" may cause performance degradation in some cases. |
This sounds like your SSD driver has very poor implementation of "TRIM" operation. "nopassdown" indeed may improve performance in this case, but depending on SSD model, may reduce the disk life time. It is also possible that this disk firmware is stupid enough it won't matter at all besides performance. Hard to tell without doing some extensive tests or analyzing disk firmware. |
At a minimum, Qubes should document possible performance issues under LVM on VM shutdown (during volatile volume/snapshot removals) with both SMR HDs generally and SSDs with poor firmware. Docs should recommend “nopassdown “ in lvm.conf as the workaround, noting the caveats for SSDs above. I was going to recommend exposing this option via the qubes global settings but thinking it through, with all the custom storage layouts out there it might get messy, so that’s probably not a great idea. [I say this all as the instigator (or at least one of them) of adding the blkdiscard invocation to lvm volume removals. I still think the benefits outweigh the other issues.] B |
In case you (or any others reading this) are not already aware, the documentation is a community effort, and everyone is welcome to contribute. (That's how things like this get updated!) So, if you'd like to get involved with the project, this is a great way to do it. You can read more about how to submit documentation changes here: |
Naming VM volumes anything that does not start with |
Thanks! Forgot to mention it... |
Has someone tried using a newer version of libvirt? |
On Thu, Jun 03, 2021 at 10:35:31AM -0700, faerbersteve wrote:
Has someone tried using a newer version of libvirt?
The newer version 7.1 of libvirt contains a fix for a shutdown race which is mentioned in the release notes.
Maybe this solve the issue or part of it.
That sounds like a very different issue. The problem we face here is
happening outside of libvirt.
…--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
|
Would you mind submitting a PR for this? This seems like the best approach until a proper kernel patch can be written. An email to dm-devel would also be great. |
The code is written for R4.0, so perhaps I'll be setting up a new R4.1 testing environment in the coming week. Might take a while... |
It appears like I might not be able to procure enough time anytime soon, so here's the plugin code I had been using at least: https://gist.github.com/iamahuman/a784efbbcadaec508235a10b52cc8baa Sub-tasks for morphing it into something actually merge-able:
|
Is this actually necessary? Using an ioctl will always be more efficient than spawning a process.
I would start with this, as it has no dependencies on any of the other changes. |
Mainly to reduce complexity. However if we keep it, I suppose we shall keep the worker pool as well.
|
I will let @marmarek decide if the complexity is worthwhile. On bleeding-edge kernels, we might be able to get rid of the pool with |
I can confirm that re-installing QubesOS 4.0.4 with BTRFS worked for me to solve this issue. Previously I had QubesOS 4.0.4 with the default LVM-thin. This led to rather slow shutdowns and sometimes temporary GUI freezes when shutting down VMs with data of ~300GB and larger. It typically took 30 sec. up to 2 min, depending on the size. I'm using the SSD Samsung 870 EVO with 4TB, which works fine now with BTRFS. |
I think using |
Confirming that fresh install of 4.1 with BTRFS enabled solves this issue. The instructions on how to select this option during the install setup are detailed here. |
Even if LVM currently doesn't have a dedicated defrag command, wouldn't it still be possible to defragment a volume in a generic way:
This is totally untested and maybe I'm missing something due to lack of familiarity with LVM2 and the lvm_thin driver. |
Hello, with R4.2 things have changed. See also small discussion @ https://forum.qubes-os.org/t/very-slow-shutdown-of-large-vms-in-4-2-even-with-btrfs/23156 |
I guess this means it should still get the |
Qubes OS version
R4.0
Affected component(s) or functionality
Shutting down a domain.
Brief summary
Shutting down one of my domains takes ~40 seconds. Other domains only take ~6 seconds.
To Reproduce
Don't know how to reproduce. Works (not) on my machine:tm:.
Expected behavior
Domain shuts down fast.
Actual behavior
Domain takes ages.
Additional context
My domain has 600 GB private storage. I recently increased the size by ~60 GB, ignoring the advice to increase in steps of 10 GB. I just added 60 GB. Now I don't know if the slow shutdown is since then or if it is since I switched the template from Fedora 28 to Fedora 30 or not related at all. It might also be normal for such a size. Somebody familiar with the inner workings might know if some of those things could matter.
Solutions you've tried
Don't know where to start, which logs to consult or which tools to use.
Any help to get started diagnosing this is appreciated.
The text was updated successfully, but these errors were encountered: