bio_alloc_clone(9)
π bio_alloc_clone β Kernel API Manual, section 9
okay so bestie, welcome to bio_alloc_clone(9) from the Kernel API Manual (yes, section 9, we're in kernel-dev territory now π). This is the one where you make a brand-new bio that's a total clone of another one and they share the same biovec situation. It's giving "twins but they share a closet" energy. Let's get into it β¨
β¨ SYNOPSIS β¨
struct bio * bio_alloc_clone (struct block_device *bdev , struct bio
*bio_src , gfp_t gfp , struct bio_set *bs );
literally one function call, four arguments, and a struct bio * coming back at you π«Ά
πΈ ARGUMENTS πΈ
bdevβ theblock_deviceyou're cloning onto. this is the destination vibe π¦bio_srcβ thebioyou're cloning from. your source material, your blueprint, your blueprint-bio πgfpβ the allocation priority. like, how hard should we be trying to get memory rn π€bsβ thebio_setyou're allocating out of. that's the pool, bestie πββοΈ
π DESCRIPTION π
So what actually happens? You allocate a new bio, and it's a clone of bio_src. β
Here's the part that matters (highkey important, ngl): this reuses the bio_vecs that bio_src->bi_io_vec points to β it does not copy them, it shares them. It also clones the iterator that's pointing at the current position inside them π―
And now the ownership bit, listen up because this is the whole thing fr fr:
The caller owns the returned bio, but not thebio_vecs. And you must make sure the bio is freed before the memory pointed to bybio_Src->bi_io_vecs. Like, that's the rule. Break it and things get real bad real fast π
so: you own the bio π«΅, you do not own the vecs π ββοΈ, and free order is not optional, it's the law periodt β¨
π¦ SEE ALSO π¦
Kernel file ./block/bio.c, plus this whole iconic little squad of friends π―ββοΈ:
bio_reset(9)bio_reuse(9)bio_chain(9)bio_chain_and_submit(9)bio_alloc_bioset(9)bio_kmalloc(9)bio_truncate(9)guard_bio_eod(9)bio_put(9)bio_init_clone(9)bio_full(9)__bio_add_page(9)bio_add_virt_nofail(9)bio_add_page(9)bio_add_folio(9)bio_add_vmalloc_chunk(9)bio_add_vmalloc(9)bio_iov_iter_get_pages(9)bio_iov_iter_bounce(9)bio_iov_iter_unbounce(9)bio_await(9)submit_bio_wait(9)bdev_rw_virt(9)bio_copy_data(9)bio_endio(9)bio_split(9)bio_trim(9)bioset_init(9)
anyway that's the whole page, ily, go free your bios in the right order π
sign-off szn: this one lives in ./block, and it's dated October 2026 β so yeah, future-dated manpage, main character energy only πβπ«Ά
π¦ 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