Skip to content
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

Add support for disk cache writeback #6968

Merged
merged 3 commits into from Jan 10, 2022

Conversation

vladikr
Copy link
Member

@vladikr vladikr commented Dec 17, 2021

What this PR does / why we need it:
This is a follow-up PR to #3144
It will allow users to set disk cache mode to writeback

Added Writeback disk cache support

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/S labels Dec 17, 2021
@vladikr
Copy link
Member Author

vladikr commented Dec 17, 2021

/cc @cedbossneo

@kubevirt-bot
Copy link
Contributor

@vladikr: GitHub didn't allow me to request PR reviews from the following users: cedbossneo.

Note that only kubevirt members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @cedbossneo

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@rmohr rmohr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general no issues with this change, I am just wondering if we should somehow make it visible for people that this is a setting which has a higher chance than usual to corrupt your disks.

@davidvossel
Copy link
Member

/cc @davidvossel

@vladikr
Copy link
Member Author

vladikr commented Dec 17, 2021

In general no issues with this change, I am just wondering if we should somehow make it visible for people that this is a setting which has a higher chance than usual to corrupt your disks.

I suppose there is always a risk, but not like the unsafe cache mode that we don't allow in KubeVirt.
iirc, Writethrough is the safest. my understanding is that writeback caches on the host but still requires the guest os to flush which still makes it safe, but I'm not 100% sure :)

I think there are different nuances with each of these cache modes and we can definitely document that. I'll try to find whether there is something written already or reach out to QEMU maintainers.

@vladikr
Copy link
Member Author

vladikr commented Dec 20, 2021

/retest

@vladikr
Copy link
Member Author

vladikr commented Dec 20, 2021

@rmohr Kevin Wolf wrote this to OpenStack back at the time, I'll contact him directly too.
According to this, it's better for us to choose wrteback instead of writethrough when direct I/O is not available.

     The thing that makes 'writethrough' so safe against host crashes is
        that it never keeps data in a "write cache", but it calls fsync()
        after _every_ write. This is also what makes it horribly slow. But
        'cache=none' doesn't do this and therefore doesn't provide this kind
        of safety. The guest OS must explicitly flush the cache in the
        right places to make sure data is safe on the disk. And OSes do
        that.

        So if 'cache=none' is safe enough for you, then 'cache=writeback'
        should be safe enough for you, too -- because both of them have the
        boolean 'cache.writeback=on'. The difference is only in
        'cache.direct', but 'cache.direct=on' only bypasses the host kernel
        page cache and data could still sit in other caches that could be
        present between QEMU and the disk (such as commonly a volatile write
        cache on the disk itself).

@maya-r
Copy link
Contributor

maya-r commented Dec 20, 2021

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 20, 2021
@iholder101
Copy link
Contributor

Out of curiosity - why didn't we have write-back cache mode until now?

@rmohr
Copy link
Member

rmohr commented Dec 22, 2021

@rmohr Kevin Wolf wrote this to OpenStack back at the time, I'll contact him directly too. According to this, it's better for us to choose wrteback instead of writethrough when direct I/O is not available.

     The thing that makes 'writethrough' so safe against host crashes is
        that it never keeps data in a "write cache", but it calls fsync()
        after _every_ write. This is also what makes it horribly slow. But
        'cache=none' doesn't do this and therefore doesn't provide this kind
        of safety. The guest OS must explicitly flush the cache in the
        right places to make sure data is safe on the disk. And OSes do
        that.

        So if 'cache=none' is safe enough for you, then 'cache=writeback'
        should be safe enough for you, too -- because both of them have the
        boolean 'cache.writeback=on'. The difference is only in
        'cache.direct', but 'cache.direct=on' only bypasses the host kernel
        page cache and data could still sit in other caches that could be
        present between QEMU and the disk (such as commonly a volatile write
        cache on the disk itself).

Sounds like this something which we want to choose for the user then if no explicit mode is provided by the user, right?

@vladikr
Copy link
Member Author

vladikr commented Dec 22, 2021

Sounds like this something which we want to choose for the user then if no explicit mode is provided by the user, right?

@rmohr yea, only on filesystems without O_DIRECT. Today we default to writethrough
https://github.com/kubevirt/kubevirt/blob/main/pkg/virt-launcher/virtwrap/converter/converter.go#L414-L425

@vladikr
Copy link
Member Author

vladikr commented Dec 22, 2021

Out of curiosity - why didn't we have write-back cache mode until now?

Previously, the use of the writeback disk cache prevented the VMI from being live migrated. We've decided that migratibility of a workload outweighs the benefits of the writeback cache.
Currently this is not the case.

Copy link
Member

@rmohr rmohr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I would love to see that we also cover migrations in the tests.

@@ -1954,17 +1958,22 @@ var _ = Describe("[sig-compute]Configurations", func() {
Expect(disks[1].Alias.GetName()).To(Equal("ephemeral-disk2"))
Expect(disks[1].Driver.Cache).To(Equal(cacheWritethrough))

By("checking if requested cache 'writeback' has been set")
Expect(disks[2].Alias.GetName()).To(Equal("ephemeral-disk5"))
Expect(disks[2].Driver.Cache).To(Equal(cacheWriteback))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also adjust one migation test to ensure that we can migrate when it is set?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this. That's the only thing I see missing here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good point. Added.

cedbossneo and others added 3 commits January 5, 2022 12:12
Signed-off-by: Cedric Hauber <hauber.c@gmail.com>
Signed-off-by: Vladik Romanovsky <vromanso@redhat.com>
Signed-off-by: Vladik Romanovsky <vromanso@redhat.com>
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 5, 2022
@vladikr
Copy link
Member Author

vladikr commented Jan 5, 2022

/retest

Copy link
Member

@rmohr rmohr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

👍

@@ -528,6 +528,39 @@ var _ = Describe("[Serial][rfe_id:393][crit:high][vendor:cnv-qe@redhat.com][leve
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("should be successfully migrate with a WriteBack disk cache", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/migrate/migrating/

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2022
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rmohr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 10, 2022
@kubevirt-commenter-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants