Comments (2)
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:
- Take advisory locks on the file about to be defrag'd.
- Create an anonymous file in the same directory with
open(..., O_TMPFILE)
. - Copy the defrag'd file over the temporary like the last copy does currently.
- Try taking mandatory locks over the defrag'd file, just in case, but don't fail if they can't be acquired
- Use heuristics to check the defrag'd file wasn't changed (atime, mtime, file size, checksum of first and last MB)
- Swap temporary file defrag'd file renameat2(..., RENAME_EXCHANGE)
⚠️ - Do a last check of heuristics, show a warning message if they don't pass
- 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.
(As I go through the backlog, I see this is quite similar to what @kakra proposed in #13 )
from shake.
Related Issues (19)
- man page should point out that shake has to be executed as root, neither does the error message HOT 4
- use fiemap instead of fibmap ioctl to support btrfs HOT 1
- Was using a Linux Mint 13/14 LTS Live Boot and was unable to install Shake due to dependencies HOT 2
- RFE: Separate judgement and defrag part into two binaries
- RFE: Reflink the file before rewriting it HOT 1
- RFE: Rename first copy into place for non-hardlinked files HOT 2
- Support for ZFS (open zfs) filesystems HOT 3
- Reformat code HOT 2
- Investigate interactions with realtime file indexers HOT 1
- musl incompatibility due to use of error() from error.h
- You need libattr headers for Shake to build. HOT 2
- PPA not working on newer Ubuntu distros HOT 2
- tmpfile location ? HOT 1
- Update CMakeFiles HOT 1
- Deprecation compilation warnings HOT 1
- Fallback on posix_fallocate if fallocate fail HOT 2
- You need libattr headers for Shake to build HOT 1
- Destroys files if fallocate() is not implemented HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shake.