---
name: "bio_alloc_bioset"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/bio_alloc_bioset"
---

# bio\_alloc\_bioset(9)

allocate a bio for I/O

## NAME

bio\_alloc\_bioset - allocate a bio for I/O

## SYNOPSIS

**struct bio \* bio\_alloc\_bioset(gfp\_t** *gfp\_mask***, int** *nr\_iovecs***, struct bio\_set \*** *bs***);**

## ARGUMENTS

*gfp\_mask*

the GFP\_ mask given to the slab allocator

*nr\_iovecs*

number of iovecs to pre-allocate

*bs*

the bio\_set to allocate from.

## DESCRIPTION

If *bs* is NULL, uses **kmalloc** to allocate the bio; else the allocation is backed by the *bs*'s mempool.

When *bs* is not NULL, if **\_\_GFP\_DIRECT\_RECLAIM** is set then bio\_alloc will always be able to allocate a bio. This is due to the mempool guarantees. To make this work, callers must never allocate more than 1 bio at a time from this pool. Callers that need to allocate more than 1 bio must always submit the previously allocated bio for IO before attempting to allocate a new one. Failure to do so can cause deadlocks under memory pressure.

Note that when running under **generic\_make\_request** (i.e. any block driver), bios are not submitted until after you return - see the code in **generic\_make\_request** that converts recursion into iteration, to prevent stack overflows.

This would normally mean allocating multiple bios under **generic\_make\_request** would be susceptible to deadlocks, but we have deadlock avoidance code that resubmits any blocked bios from a rescuer thread.

However, we do not guarantee forward progress for allocations from other mempools. Doing multiple allocations from the same mempool under **generic\_make\_request** should be avoided - instead, use bio\_set's front\_pad for per bio allocations.

## RETURN

Pointer to new bio on success, NULL on failure.

## COPYRIGHT
