sg_split(9)
πΈ sg_split(9) β the Kernel API Manual moment
okay so this is sg_split, from the kernel API manual, and yes bestie the (9) means it's a kernel-internal function, we're in the deep deep. no cap, this one is genuinely useful and also genuinely a little fiddly. let's get into it π
β¨ NAME β¨
sg_split β split a scatterlist into several scatterlists. that's it, that's the vibe. one sg list goes in, several sg lists come out. π
π¦ SYNOPSIS π¦
int sg_split (struct scatterlist *in , const int in_mapped_nents , const
off_t skip , const int nb_splits , const size_t *split_sizes , struct
scatterlist **out , int *out_mapped_nents , gfp_t gfp_mask );
like, look at all those params. main character energy honestly. π
π ARGUMENTS π
okay bestie, let's meet the cast:
inβ the input sg list. the thing we're chopping up. βοΈin_mapped_nentsβ the result of adma_map_sg(in, ...), or0if it's not mapped. so: the count you got back from mapping, or a big fat zero if no mapping happened.skipβ the number of bytes to skip in the input sg list. like scrolling past the intro, but in bytes. πnb_splitsβ the number of desired sg outputs. how many pieces we're making, bestie.split_sizesβ the respective size of each output sg list in bytes. one size per output, in order. πoutβ an array where to store the allocated output sg lists. this is where the magic lands. β¨out_mapped_nentsβ the resulting sg lists mapped number of sg entries. Might beNULLif sglist not already mapped (in_mapped_nents = 0). β οΈ so like, if you didn't map it, passNULLhere, fr fr.gfp_maskβ the allocation flag. the classicgfp_tsituation, you know the drill. π«Ά
π₯ DESCRIPTION π₯
This function splits the input sg list into nb_splits sg lists, which are allocated and stored into out. The in is split into:
out[0], which covers bytes[skip .. skip + split_sizes[0] - 1]ofinout[1], which covers bytes[skip + split_sizes[0] .. skip + split_sizes[0] + split_sizes[1] -1]etc ...
so yeah, each output picks up exactly where the last one left off, offset by skip at the start. mathematically tidy, we love to see it. π§
β οΈ heads up bestie: It will be the caller's duty tokfreeout array members. not mine, not the function's β yours. the allocated output sg lists inoutare your responsibility now. don't be the person who leaks them, i'm begging. π
Returns 0 upon success, or error code. so, 0 = slay, anything else = read the error code and cry a little. π
π SEE ALSO π
Kernel file ./lib/sg_split.c β go read the source, iykyk. that's where the real lore lives. β
okay that's the whole page, bestie! written from the ./lib corner of the kernel, October 2026 edition. go split some scatterlists and remember to kfree ππ«Άπ·
π¦ 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