i40e_txd_use_count(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ i40e_txd_use_count ✨

okay so bestie, we're in the i40e_txd_use_count(9) page from the Kernel API Manual, and honestly? it's a little math baddie moment and i'm obsessed πŸŽ€

πŸ’– NAME πŸ’–

i40e_txd_use_count β€” estimate the number of descriptors needed for Tx

🌸 SYNOPSIS 🌸

unsigned int i40e_txd_use_count (unsigned int size );

πŸ¦‹ ARGUMENTS πŸ¦‹

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

πŸ”₯ DESCRIPTION πŸ”₯

so here's the tea β˜• β€” because of hardware alignment restrictions (4K alignment), we have to assume that there's no more than 12K of data per descriptor, even though each descriptor can actually take up to 16K - 1 bytes of aligned memory. rude, i know. so the vibe check says: divide by 12K. but bestie... division is slow! 😭 like genuinely not the move.

so instead we decompose the whole operation into shifts and one relatively cheap multiply operation. slay.

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, cute right?)

finally, we add one to round up ✨. and here's the little caveat bestie: because 256 isn't an exact multiple of 3, we'll underestimate near each multiple of 12K. which is actually more accurate for us, 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. main character accuracy, no cap πŸ’€

this would then be implemented as:

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

and since multiplication and division are commutative (periodt πŸ’…), we can reorder operations into:

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

literally the same math but the second one is giving optimized icon behavior πŸ‘‘


⭐ SEE ALSO ⭐

go read them, iykyk 🌈


and that's the whole page babes πŸ“ β€” straight from ./drivers/net/ethernet/intel/i40e, dated October 2026, in the i40e_txd_use_count(9) era. mwah, study it, screenshot it, put it on your fridge πŸ’œπŸ§šβœ¨

πŸ“¦ where this page comes from