GithubHelp home page GithubHelp logo

RFE: Better lock handling about shake HOT 2 OPEN

kakra avatar kakra commented on June 24, 2024
RFE: Better lock handling

from shake.

Comments (2)

unbrice avatar unbrice commented on June 24, 2024

Locks in Linux can be "advisory" (user space can ignore them) or "mandatory". Mandatory locks can expire, create responsiveness problems and will go away. Advisory locks are typically ignored by user space programs.
I am not aware of xfs_fsr and btrfs defrag having a way around that. I expect that they take advisory locks, or no lock.

Currently we:

  • Take mandatory lock
  • Copy to temporary throw-away file
  • Copy temporary file back over original file ⚠️
  • Release locks

I propose not to rely just on mandatory locking for safety, and make the mandatory locked section much shorter. Instead I propose to:

  1. Take advisory locks on the file about to be defrag'd.
  2. Create an anonymous file in the same directory with open(..., O_TMPFILE).
  3. Copy the defrag'd file over the temporary like the last copy does currently.
  4. Try taking mandatory locks over the defrag'd file, just in case, but don't fail if they can't be acquired
  5. Use heuristics to check the defrag'd file wasn't changed (atime, mtime, file size, checksum of first and last MB)
  6. Swap temporary file defrag'd file renameat2(..., RENAME_EXCHANGE) ⚠️
  7. Do a last check of heuristics, show a warning message if they don't pass
  8. Release locks

This is better because:

  • If mandatory locks are supported, it's quite safe to assume the atomic exchange can happen before lease-break-time
  • If they are not, software honoring advisory locks are still supported (softwares like Gnome Tracker or other accessing files that are not theirs should honor locks)
  • Other softwares are unlikely to encounter problems since the critical section is short but the worse that can happen is to be left with an older version of the file.

What do you think?

from shake.

unbrice avatar unbrice commented on June 24, 2024

(As I go through the backlog, I see this is quite similar to what @kakra proposed in #13 )

from shake.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.