mirror of
https://github.com/Zygo/bees.git
synced 2025-07-01 00:02:27 +02:00
context: don't let multiple worker Tasks get stuck on a single extent or inode
When two Tasks attempt to lock the same extent, append the later Task to the earlier Task's post-exec work queue. This will guarantee that all Tasks which attempt to manipulate the same extent will execute sequentially, and free up threads to process other extents. Similarly, if two scanner threads operate on the same inode, any dedupe they perform will lock out other scanner threads in btrfs. Avoid this by serializing Task objects that reference the same file. This does theoretically use an unbounded amount of memory, but in practice a Task that encounters a contended extent or inode quickly stops spawning new Tasks that might increase the queue size, and all Tasks that might contend for the same lock(s) end up on a single FIFO queue. Note that the scope of inode locks is intentionally global, i.e. when an inode is locked, it locks every inode with the same number in every subvol. This avoids significant lock contention and task queue growth when the same inode with the same file extents appear in snapshots. Fixes: https://github.com/Zygo/bees/issues/158 Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
@ -726,7 +726,8 @@ class BeesContext : public enable_shared_from_this<BeesContext> {
|
||||
|
||||
Timer m_total_timer;
|
||||
|
||||
LockSet<uint64_t> m_extent_lock_set;
|
||||
NamedPtr<Exclusion, uint64_t> m_extent_locks;
|
||||
NamedPtr<Exclusion, uint64_t> m_inode_locks;
|
||||
|
||||
mutable mutex m_stop_mutex;
|
||||
condition_variable m_stop_condvar;
|
||||
@ -751,7 +752,7 @@ public:
|
||||
Fd home_fd();
|
||||
string root_path() const { return m_root_path; }
|
||||
|
||||
BeesFileRange scan_forward(const BeesFileRange &bfr);
|
||||
void scan_forward(const BeesFileRange &bfr);
|
||||
|
||||
bool is_root_ro(uint64_t root);
|
||||
BeesRangePair dup_extent(const BeesFileRange &src, const shared_ptr<BeesTempFile> &tmpfile);
|
||||
@ -761,6 +762,8 @@ public:
|
||||
void blacklist_erase(const BeesFileId &fid);
|
||||
bool is_blacklisted(const BeesFileId &fid) const;
|
||||
|
||||
shared_ptr<Exclusion> get_inode_mutex(uint64_t inode);
|
||||
|
||||
BeesResolveAddrResult resolve_addr(BeesAddress addr);
|
||||
void invalidate_addr(BeesAddress addr);
|
||||
|
||||
@ -777,7 +780,6 @@ public:
|
||||
shared_ptr<BeesTempFile> tmpfile();
|
||||
|
||||
const Timer &total_timer() const { return m_total_timer; }
|
||||
LockSet<uint64_t> &extent_lock_set() { return m_extent_lock_set; }
|
||||
};
|
||||
|
||||
class BeesResolver {
|
||||
|
Reference in New Issue
Block a user