sg_set_folio(9)
π sg_set_folio (kernel API manual, bestie edition)
okay so this is sg_set_folio(9) from the Kernel API Manual, and it's literally the "please stop poking the folio pointer with your bare hands" function π«Ά
β¨ NAME β¨
sg_set_folio β set an sg entry so it points at the given folio π
πΈ SYNOPSIS πΈ
void sg_set_folio (struct scatterlist *sg , struct folio *folio , size_t
len , size_t offset );
π¦ ARGUMENTS π¦
sgβ the SG entry. the main character of this whole operation πfolioβ the folio itself. yes, that folio πlenβ length of the data. how many bytes we're talking about β¨offsetβ offset into the folio. where in the folio we're starting, iykyk πΈ
π DESCRIPTION π
Use this function to set an sg entry pointing at a folio. and like β never assign the folio directly, okay?? π not even once.
why, you ask? because we encode sg table information in the lower bits of the folio pointer. so if you go around assigning it raw, you're lowkey stomping on that encoded info and it will not be slay. the encoding is the whole vibe check here π
when you need to look up the page belonging to an sg entry, see sg_page. that's the one you want for that job, fr fr π§
no cap: this is one of those "use the setter, don't touch the pointer" situations. the function is the gatekeeper and honestly it's giving main character energy π
π SEE ALSO π
Kernel file ./include/linux/scatterlist.h, plus the whole scatterlist friend group π:
sg_next(9)sg_assign_page(9)sg_set_page(9)sg_set_buf(9)sg_chain(9)sg_mark_end(9)sg_unmark_end(9)sg_dma_is_bus_address(9)sg_dma_mark_bus_address(9)sg_dma_unmark_bus_address(9)sg_dma_is_swiotlb(9)sg_dma_mark_swiotlb(9)sg_phys(9)sg_virt(9)sg_init_marker(9)sg_alloc_table_from_pages(9)sg_page_iter_page(9)sg_page_iter_dma_address(9)for_each_sg_page(9)for_each_sg_dma_page(9)for_each_sgtable_page(9)for_each_sgtable_dma_page(9)
π and that's the page!! sourced straight from ./include/linux, dated October 2026 β mwah, go set some folios responsibly, bestie π
β¨π₯
π¦ 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