extract_iter_to_sg(9)
β¨ 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 insgtablethat 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:
sg_nents(9),sg_nents_for_len(9),sg_nents_for_dma(9),sg_last(9)sg_init_table(9),sg_init_one(9)__sg_free_table(9),sg_free_append_table(9),sg_free_table(9)__sg_alloc_table(9),sg_alloc_table(9),sg_alloc_append_table_from_pages(9),sg_alloc_table_from_pages_segment(9)sgl_alloc_order(9),sgl_alloc(9),sgl_free_n_order(9),sgl_free_order(9),sgl_free(9)sg_miter_start(9),sg_miter_skip(9),sg_miter_next(9),sg_miter_stop(9)sg_copy_buffer(9),sg_copy_from_buffer(9),sg_copy_to_buffer(9),sg_pcopy_from_buffer(9),sg_pcopy_to_buffer(9),sg_zero_buffer(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms