extract_iter_to_sg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ extract_iter_to_sg(9) ✨

okay so bestie, this one lives in the Kernel API Manual and it's literally the glow-up your scatterlist has been waiting for πŸ’…

πŸŽ€ NAME πŸŽ€

extract_iter_to_sg β€” extract pages from an iterator and add them to an sglist. no cap, that's the whole vibe πŸ¦‹

🌸 SYNOPSIS 🌸

ssize_t extract_iter_to_sg (struct iov_iter *iter , size_t maxsize ,
       struct sg_table *sgtable , unsigned int sg_max , iov_iter_extraction_t
       extraction_flags );

πŸ’– ARGUMENTS πŸ’–

  • iter β€” the iterator you're extracting from, the main character of this whole operation πŸ‘‘
  • maxsize β€” how much of the iterator to copy, like your portion control but for bytes πŸ“
  • sgtable β€” the scatterlist table that gets filled in, she's the canvas bestie 🎨
  • sg_max β€” the maximum number of elements in sgtable that may be filled, aka the hard limit, respect it πŸ™ˆ
  • extraction_flags β€” flags to qualify the request, the little seasoning on top ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

So what it does: it extracts the page fragments from the given amount of the source iterator and adds them to a scatterlist that refers to all of those bits β€” up to a maximum addition of sg_max elements. slay πŸ’«

Now here's the tea on pinning, and this part matters:

  • The pages referred to by UBUF- and IOVEC-type iterators are extracted and pinned πŸ”₯
  • BVEC-, KVEC-, FOLIOQ- and XARRAY-type are extracted but aren't pinned 🫢
  • DISCARD-type is not supported β€” she's simply not invited to the party πŸ’€
No end mark is placed on the scatterlist; that's left to the caller. yes, that's your job bestie, don't forget 😭

extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be allowed on the pages extracted. fancy, iconic, love that for you 🌈

If it's successful, sgtable->nents is updated to include the number of elements added, and the number of bytes added is returned. meanwhile sgtable->orig_nents is left unaltered β€” untouched, unbothered, living her life πŸ’œ

Also important: the iov_iter_extract_mode function should be used to query how cleanup should be performed. like, please check before you yolo the teardown 🧚


⭐ SEE ALSO ⭐

Kernel file ./lib/scatterlist.c and honestly the whole scatterlist friend group:


that's the whole page, ily, go pin some pages responsibly πŸ’– sourced from ./lib, dated October 2026, and filed under extract_iter_to_sg(9) β€” periodt βœ¨πŸŽ€

πŸ“¦ where this page comes from