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

Bug fix: Complete the page writeback immediately if zfs_putpage was called with WB_SYNC_NONE #12776

Closed
wants to merge 1 commit into from

Conversation

shaan1337
Copy link
Contributor

@shaan1337 shaan1337 commented Nov 19, 2021

Motivation and Context

Fixes: #12662

Description

When the kernel occasionally performs a background page writeback, WB_SYNC_NONE is specified as sync mode. Currently it appears that the page stays in the page writeback state until the transaction group is synced which then triggers zfs_putpage_commit_cb and unsets the page writeback bit. This blocks other threads that are doing an msync with MS_SYNC for several seconds until the txg is synced due to the txg timeout.

Given that WB_SYNC_NONE is specified, if I got it correctly, the correct behaviour should be that there is no need for the kernel to wait for the write to be done to stable storage, so in the fix I've completed the callback immediately if WB_SYNC_NONE is specified.

I'm new to the zfs/kernel source and just wanted some feedback to validate if the problem description/solution makes sense before making more progress on it (I still need to test the fix)

How Has This Been Tested?

PR still in draft to validate if the approach is correct.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@@ -3592,7 +3592,9 @@ zfs_putpage(struct inode *ip, struct page *pp, struct writeback_control *wbc)
err = sa_bulk_update(zp->z_sa_hdl, bulk, cnt, tx);

zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, pgoff, pglen, 0,
zfs_putpage_commit_cb, pp);
wbc->sync_mode != WB_SYNC_NONE ? zfs_putpage_commit_cb : NULL,
wbc->sync_mode != WB_SYNC_NONE ? pp : NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Two same checks - maybe just use one usual if?

@shaan1337
Copy link
Contributor Author

shaan1337 commented Nov 22, 2021

I think that the current fix is not good because the other thread doing the msync (with MS_SYNC) will complete immediately instead of waiting for the write to complete (which puts data integrity at risk in case of power loss). Secondly, it also breaks the kernel API semantics - PG_writeback should be set until the write is on stable storage. I'll close this PR and work on an alternate fix.

@shaan1337 shaan1337 closed this Nov 22, 2021
@shaan1337 shaan1337 deleted the fix-zfs-putpage branch November 22, 2021 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

msync occasionally takes several seconds (up to ~15 seconds)
2 participants