iavf_txd_use_count(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… iavf_txd_use_count(9) πŸ’…

okay so this is a page from the Kernel API Manual bestie, and it's literally about iavf_txd_use_count β€” the little math gremlin that estimates how many descriptors you need for Tx. no cap, it's more fun than it sounds πŸŽ€


✨ NAME ✨

iavf_txd_use_count β€” estimate the number of descriptors needed for Tx πŸ¦‹


🌸 SYNOPSIS 🌸

unsigned int iavf_txd_use_count (unsigned int size );

πŸ’– ARGUMENTS πŸ’–

  • size β€” the transmit request size in bytes. that's it, that's the whole input, she's simple and she knows it πŸ’…

πŸ”₯ DESCRIPTION πŸ”₯

okay so here's the tea β˜• β€” because of hardware alignment restrictions (4K alignment, iconic), we have to assume we can't fit more than 12K of data per descriptor, even though each descriptor can actually take up to 16K - 1 bytes of aligned memory. rude, but fine.

so like, we need to divide by 12K. but division is slow! 😭 and we don't do slow here. instead, we decompose the whole operation into shifts and one relatively cheap multiply operation. slay.

here's the breakdown, step by step, bestie:

  • to divide by 12K, we first divide by 4K, then divide by 3
  • to divide by 4K, shift right by 12 bits
  • to divide by 3, multiply by 85, then divide by 256 (and dividing by 256 is done by shifting right by 8 bits)
  • finally, we add one to round up ⭐

because 256 isn't an exact multiple of 3, we'll underestimate near each multiple of 12K. and honestly? that's actually more accurate, because we have 4K - 1 of wiggle room that we can fit into the last segment 😌 for our purposes this is accurate out to 1M, which is orders of magnitude greater than our largest possible GSO size. iykyk.

this would then be implemented as:

return (((size >> 12) * 85) >> 8) + 1;

and since multiplication and division are commutative (math girlies rise πŸ™Œ), we can reorder operations into:

return ((size * 85) >> 20) + 1;

literally so clean. main character energy fr fr πŸ‘‘


🫢 SEE ALSO 🫢


go read the friends, they're all in the same friend group πŸ’œ

and that's the whole page, bestie!! πŸŽ€ this lil gem lives in ./drivers/net/ethernet/intel/iavf and the version is from October 2026 β€” go off, future manpage πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from