include/linux/bio.h
Source file repositories/reference/linux-study-clean/include/linux/bio.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/bio.h- Extension
.h- Size
- 19655 bytes
- Lines
- 738
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mempool.hlinux/blk_types.hlinux/uio.h
Detected Declarations
struct queue_limitsstruct folio_iterstruct request_queuestruct bio_liststruct bio_setfunction bio_max_segsfunction bio_flaggedfunction bio_set_flagfunction bio_clear_flagfunction bio_has_datafunction bio_no_advance_iterfunction bio_next_segmentfunction bio_advance_iterfunction bio_advance_iter_singlefunction bio_advancefunction bio_segmentsfunction bio_getfunction bio_cnt_setfunction bio_first_foliofunction bio_next_foliofunction bio_endio_statusfunction bio_io_errorfunction bio_wouldblock_errorfunction bio_iov_vecs_to_allocfunction bio_iov_bounce_nr_vecsfunction bio_init_inlinefunction bio_add_max_vecsfunction bio_release_pagesfunction bio_associate_blkgfunction bio_set_devfunction bio_list_emptyfunction bio_list_initfunction bio_list_sizefunction bio_list_addfunction bio_list_add_headfunction bio_list_mergefunction bio_list_merge_initfunction bio_list_merge_headfunction bio_inc_remainingfunction bioset_initializedfunction bio_clear_polledfunction bio_is_zone_append
Annotated Snippet
struct folio_iter {
struct folio *folio;
size_t offset;
size_t length;
/* private: for use by the iterator */
struct folio *_next;
size_t _seg_count;
int _i;
};
static inline void bio_first_folio(struct folio_iter *fi, struct bio *bio,
int i)
{
struct bio_vec *bvec = bio_first_bvec_all(bio) + i;
if (unlikely(i >= bio->bi_vcnt)) {
fi->folio = NULL;
return;
}
fi->folio = bvec_folio(bvec);
fi->offset = bvec->bv_offset +
PAGE_SIZE * folio_page_idx(fi->folio, bvec->bv_page);
fi->_seg_count = bvec->bv_len;
fi->length = min(folio_size(fi->folio) - fi->offset, fi->_seg_count);
fi->_next = folio_next(fi->folio);
fi->_i = i;
}
static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio)
{
fi->_seg_count -= fi->length;
if (fi->_seg_count) {
fi->folio = fi->_next;
fi->offset = 0;
fi->length = min(folio_size(fi->folio), fi->_seg_count);
fi->_next = folio_next(fi->folio);
} else {
bio_first_folio(fi, bio, fi->_i + 1);
}
}
/**
* bio_for_each_folio_all - Iterate over each folio in a bio.
* @fi: struct folio_iter which is updated for each folio.
* @bio: struct bio to iterate over.
*/
#define bio_for_each_folio_all(fi, bio) \
for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio))
void bio_trim(struct bio *bio, sector_t offset, sector_t size);
extern struct bio *bio_split(struct bio *bio, int sectors,
gfp_t gfp, struct bio_set *bs);
int bio_split_io_at(struct bio *bio, const struct queue_limits *lim,
unsigned *segs, unsigned max_bytes, unsigned len_align);
u8 bio_seg_gap(struct request_queue *q, struct bio *prev, struct bio *next,
u8 gaps_bit);
/**
* bio_next_split - get next @sectors from a bio, splitting if necessary
* @bio: bio to split
* @sectors: number of sectors to split from the front of @bio
* @gfp: gfp mask
* @bs: bio set to allocate from
*
* Return: a bio representing the next @sectors of @bio - if the bio is smaller
* than @sectors, returns the original bio unchanged.
*/
static inline struct bio *bio_next_split(struct bio *bio, int sectors,
gfp_t gfp, struct bio_set *bs)
{
if (sectors >= bio_sectors(bio))
return bio;
return bio_split(bio, sectors, gfp, bs);
}
enum {
BIOSET_NEED_BVECS = BIT(0),
BIOSET_NEED_RESCUER = BIT(1),
BIOSET_PERCPU_CACHE = BIT(2),
};
extern int bioset_init(struct bio_set *, unsigned int, unsigned int, int flags);
extern void bioset_exit(struct bio_set *);
struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
blk_opf_t opf, gfp_t gfp, struct bio_set *bs);
struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask);
extern void bio_put(struct bio *);
Annotation
- Immediate include surface: `linux/mempool.h`, `linux/blk_types.h`, `linux/uio.h`.
- Detected declarations: `struct queue_limits`, `struct folio_iter`, `struct request_queue`, `struct bio_list`, `struct bio_set`, `function bio_max_segs`, `function bio_flagged`, `function bio_set_flag`, `function bio_clear_flag`, `function bio_has_data`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.