wbc_detach_inode(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… wbc_detach_inode β€” a Kernel API Manual moment πŸ’…

okay so bestie, welcome to the Kernel API Manual β€” this one is literally about detaching writeback stuff from an inode, and it's more iconic than it sounds. πŸ¦‹βœ¨

🌸 NAME 🌸

wbc_detach_inode β€” disassociate wbc from the inode and perform foreign detection. That's the whole vibe check, periodt. πŸ’–

✨ SYNOPSIS ✨

void wbc_detach_inode (struct writeback_control *wbc );

πŸŽ€ ARGUMENTS πŸŽ€

  • wbc β€” the writeback_control of the just finished writeback. 🫢

πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea: call this after a writeback attempt of an inode finishes, and it undoes wbc_attach_and_unlock_inode. It can be called under any context β€” no cap. ✨

Concurrent write sharing of an inode is expected to be very rare, and memcg only tracks page ownership on a first-use basis, severely confining the usefulness of such sharing. Because of that, cgroup writeback tracks ownership per-inode. While support for concurrent write sharing of an inode is deemed unnecessary, an inode being written to by different cgroups at different points in time is a lot more common. And more importantly, charging only by first-use can too readily lead to grossly incorrect behaviors β€” literally a single foreign page can lead to gigabytes of writeback to be incorrectly attributed. πŸ˜­πŸ’€

To resolve this issue, cgroup writeback detects the majority dirtier of an inode and transfers the ownership to it. To avoid unnecessary oscillation, the detection mechanism keeps track of history and gives out the switch verdict only if the foreign usage pattern is stable over a certain amount of time and/or writeback attempts. πŸ’…

On each writeback attempt, wbc tries to detect the majority writer using the Boyer-Moore majority vote algorithm. In addition to the byte count from the majority voting, it also counts the bytes written for the current wb and the last round's winner wb (max of last round's current wb, the winner from two rounds ago, and the last round's majority candidate). Keeping track of the historical winner helps the algorithm to semi-reliably detect the most active writer even when it's not the absolute majority. πŸ‘‘

Once the winner of the round is determined, whether the winner is foreign or not and how much IO time the round consumed is recorded in inode->i_wb_frn_history. If the amount of recorded foreign IO time is over a certain threshold, the switch verdict is given. πŸŽ€

πŸ‘€ SEE ALSO πŸ‘€

Kernel file ./fs/fs-writeback.c is the home base, and here's the full squad:

xoxo, from ./fs, dated October 2026 β€” wbc_detach_inode(9) is signing off, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from