sg_alloc_app...e_from_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 themselves
  • n_pages β€” how many pages are chilling in that pages array
  • offset β€” how far from the start of the first page the buffer actually begins
  • size β€” 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 bytes
  • left_pages β€” the pages the caller still has to set after this call
  • gfp_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 ⭐

  • 0 on success πŸŽ‰
  • a negative error on failure 😭

πŸ”₯ NOTES πŸ”₯

if this function returns non-0 (like, a failure), the caller must call sg_free_append_table to 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