__bread_gfp(9)
π __bread_gfp β a kernel API manual, but make it cute π
okay so this one lives in the Kernel API Manual (section 9, kernel functions, iykyk) and it's literally called __bread_gfp. yes bestie, bread. it reads a block. we love a carb-loaded syscall-adjacent moment πβ¨
β¨ NAME β¨
__bread_gfp β Read a block. that's it. that's the whole vibe. π«Ά
πΈ SYNOPSIS πΈ
struct buffer_head * __bread_gfp (struct block_device *bdev , sector_t
block , unsigned size , gfp_t gfp );
look at her. four arguments, one struct buffer_head * return, main character energy fr fr π
π ARGUMENTS π
bdevβ The block device to read from. like, where the data actually lives πΎblockβ Block number in units of block size. not bytes, bestie, blocks β don't get it twisted πsizeβ The block size of this device in bytes. πgfpβ Not page allocation flags; see below. β οΈ okay this one's a trap, more on that in a sec
π DESCRIPTION π
π¨ real talk first: You are not expected to call this function. The manpage says it, I'm saying it, we're all saying it. You should use one ofsb_bread,sb_bread_unmovableor__breadinstead. periodt.
So what does she do? Read a specified block, and return the buffer head that refers to it. simple, iconic, done. π¦
Now the gfp tea β β this is where people mess up:
- If
gfpis0, the memory will be allocated using the block device's default GFP flags. - If
gfpis__GFP_MOVABLE, the memory may be allocated from a movable area. π - Do not pass in a complete set of GFP flags. like, I'm begging you. don't. π
And the returned buffer head? It has its refcount increased. so the caller should call brelse when it has finished with the buffer. don't just wander off and leave her hanging, that's so not slay π
β CONTEXT β
May sleep waiting for I/O. π΄ so like, don't call her somewhere you can't nap. she's gonna wait for the disk, it's giving "loading screen but make it kernel" π
π RETURN π
NULLif the block was unreadable. π yeah. she can come back empty-handed. handle it.
π SEE ALSO π
Kernel file ./fs/buffer.c β and honestly the whole friend group:
bio_endio_bh(9)end_buffer_read_sync(9)bh_end_read(9)bh_end_write(9)bh_end_async_write(9)mmb_sync(9)block_dirty_folio(9)mark_buffer_dirty(9)__brelse(9)__bforget(9)bh_submit(9)bdev_getblk(9)block_invalidate_folio(9)clean_bdev_aliases(9)try_to_free_buffers(9)bh_uptodate_or_lock(9)__bh_read(9)__bh_read_batch(9)
that's the whole group chat, no cap π
and that's the page!! π she comes from ./fs, dated October 2026, and she's filed under __bread_gfp(9) β go read a block bestie, but like, through sb_bread or __bread, please, I'm literally asking ππ
π¦ 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