ext4_free_data(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… ext4_free_data (kernel API manual, section 9, bestie)

okay so picture this: it's a kernel API manual page, section 9, and the function's whole name is ext4_free_data. That's it, that's the header. Now let's get into it ๐Ÿ’–


โœจ NAME โœจ

ext4_free_data โ€” the girl whose entire job is freeing a list of data blocks. icon, honestly. she takes the blocks out and lets them go ๐Ÿฆ‹


๐ŸŒธ SYNOPSIS ๐ŸŒธ

void ext4_free_data (handle_t *handle , struct inode *inode , struct
buffer_head *this_bh , __le32 *first , __le32 *last );

like literally five arguments, no return value, void as ever. slays quietly ๐Ÿ’…


๐ŸŽ€ ARGUMENTS ๐ŸŽ€

  • handle โ€” the handle for this transaction. your backstage pass for this whole operation ๐ŸŽŸ๏ธ
  • inode โ€” the inode we're dealing with. the main character of this little story ๐Ÿ‘‘
  • this_bh โ€” an indirect buffer_head that contains *first and *last. (yes, the asterisks are load-bearing, this is C, bestie ๐Ÿ˜ญ)
  • first โ€” an array of block numbers ๐Ÿงฎ
  • last โ€” points immediately past the end of that array. not at the last element. past it. classic off-the-end situation ๐Ÿ’€

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so what are we even doing here? We're freeing all the blocks that get referred to from that array (and ngl the numbers in it are stored as little-endian 32-bit, that's just the vibe ๐ŸŒˆ), and we update inode->i_blocks appropriately while we're at it. bookkeeping queen ๐Ÿ’–

Here's the cute part: we accumulate contiguous runs of blocks to free. Conveniently โ€” and I do mean conveniently, this is the good stuff โ€” if these blocks are contiguous, then releasing them at one time will only affect one or two bitmap blocks (plus group descriptor(s) and superblock), and we won't actually use a lot of journal space. efficiency! we love her! โญ lowkey obsessed with how tidy that is.

heads up ๐Ÿซถ: this_bh will be NULL if first and last point into the inode's direct block pointers. so don't panic when you see a NULL there, it's intentional, it's giving "different code path" ๐Ÿ™ˆ

๐ŸŒŸ SEE ALSO ๐ŸŒŸ

Kernel file ./fs/ext4/indirect.c and honestly the whole friend group:

go read them, iykyk ๐Ÿ”ฅ


okay that's the whole page, no cap ๐Ÿ’œ this one came out of ./fs/ext4 โ€” that's the source โ€” and it's dated October 2026, from the Kernel API Manual, periodt. bye bestie, go free some blocks ๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from