sg_alloc_app...e_from_pages(9)
π
sg_alloc_append_table_from_pages β the Kernel API Manual version, bestie edition π
okay so real talk, this is a page from the Kernel API Manual (yes, the (9) girlies) and it's all about sg_alloc_append_table_from_pages, which is a whole mouthful but honestly kind of iconic once you get it. sit down, grab a strawberry drink π, and let's get into it.
β¨ NAME β¨
sg_alloc_append_table_from_pages β allocate and initialize an append sg table from an array of pages π¦
like, you hand it pages, it hands you a scatterlist table. the way that works?? obsessed.
πΈ SYNOPSIS πΈ
int sg_alloc_append_table_from_pages (struct sg_append_table *sgt_append
, struct page **pages , unsigned int n_pages , unsigned int offset ,
unsigned long size , unsigned int max_segment , unsigned int left_pages
, gfp_t gfp_mask );
eight arguments. EIGHT. she's high maintenance but she delivers π
π ARGUMENTS π
sgt_appendβ the sg append table you're working with, your main character struct πpagesβ a pointer to an array of page pointers, i.e. the pages themselvesn_pagesβ how many pages are chilling in thatpagesarrayoffsetβ how far from the start of the first page the buffer actually beginssizeβ how many bytes are actually valid in the buffer, and yes that's after the offset, don't forget πmax_segmentβ the biggest a single scatterlist element is allowed to be, in bytesleft_pagesβ the pages the caller still has to set after this callgfp_maskβ the GFP allocation mask, the classic π
π DESCRIPTION π
so on the first call, she allocates and initializes an sg table from a list of pages. on any call after that, she just reuses the scatterlist from sgt_append. efficient queen.
contiguous ranges of pages get squashed together into a single scatterlist entry β but only up to the max size you gave her in max_segment. no cap, that's the ceiling.
a user can also pass in an offset for the start, plus a size for how many bytes of valid data live in the buffer that the page array describes.
when you're done with the returned sg table, you release it with sg_free_append_table. don't ghost her, actually free her π«Ά
β RETURN β
0on success π- a negative error on failure π
π₯ NOTES π₯
if this function returns non-0(like, a failure), the caller must callsg_free_append_tableto clean up any leftover allocations. no leaving mess everywhere, that's not the vibe.
also: in the first call (the page literally says "fist" lol, love a typo, but you know what she means π), sgt_append must be initialized.
π SEE ALSO π
kernel file ./lib/scatterlist.c, plus 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_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), extract_iter_to_sg(9)
kisses from ./lib, dated October 2026 β this page said sg_alloc_app...e_from_pages(9) at the top and bottom and honestly the truncation is a whole aesthetic πβ¨
π¦ 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