mtd_kmalloc_up_to(9)
β¨ mtd_kmalloc_up_to β¨
Okay bestie, welcome to the mtd_kmalloc_up_to(9) page β it's a Kernel API Manual moment, and honestly it's kind of a baddie. Let's get into it π
πΈ NAME πΈ
mtd_kmalloc_up_to β literally just allocate a contiguous buffer up to whatever size you asked for, no cap π
π¦ SYNOPSIS π¦
void * mtd_kmalloc_up_to (const struct mtd_info *mtd , size_t *size );
π ARGUMENTS π
mtdβ the mtd device description object pointer, aka the little descriptor that tells you who this MTD device actually is π«Άsizeβ a pointer to the ideal or maximum size of the allocation. On success, plot twist, it points to the actual allocation size. So it goes in as a wish and comes out as the truth π
π₯ DESCRIPTION π₯
So here's the vibe: this routine attempts to allocate a contiguous kernel buffer up to the specified size, and it does it by backing off the size of the request exponentially until the request succeeds or until the allocation size falls below the system page size. It's giving "I'll take what I can get" energy, and we respect it π
The whole point is that this attempts to make sure it does not adversely impact system performance β so when allocating more than one page, we ask the memory allocator to avoid re-trying, swapping, writing back or performing I/O. Like, please don't do all that, king, just give me the memory π§
Also important, bestie: this function also makes sure that the allocated buffer is aligned to the MTD device's min. I/O unit, i.e. the mtd->writesize value. Alignment ate, fr fr β
This is called, for example by mtd_{read,write} and jffs2_scan_medium, to handle smaller (i.e. degraded) buffer allocations under low- or fragmented-memory situations where such reduced allocations, from a requested ideal, are allowed. Basically when memory is being stingy, we still show up π
Returns a pointer to the allocated buffer on success; otherwise, NULL. That's it, that's the deal π₯
π SEE ALSO π
Kernel file ./drivers/mtd/mtdcore.c, plus this whole iconic lineup:
mtd_wunit_to_pairing_info(9)mtd_pairing_info_to_wunit(9)mtd_pairing_groups(9)add_mtd_device(9)del_mtd_device(9)mtd_device_parse_register(9)mtd_device_unregister(9)register_mtd_user(9)unregister_mtd_user(9)get_mtd_device(9)of_get_mtd_device_by_node(9)get_mtd_device_nm(9)mtd_ooblayout_ecc(9)mtd_ooblayout_free(9)mtd_ooblayout_find_region(9)mtd_ooblayout_find_eccregion(9)mtd_ooblayout_get_bytes(9)mtd_ooblayout_set_bytes(9)mtd_ooblayout_count_bytes(9)mtd_ooblayout_get_eccbytes(9)mtd_ooblayout_set_eccbytes(9)mtd_ooblayout_get_databytes(9)mtd_ooblayout_set_databytes(9)mtd_ooblayout_count_freebytes(9)mtd_ooblayout_count_eccbytes(9)
And that's the whole page, bestie π«Ά this one lives in ./drivers/mtd, dated October 2026, and it's filed under mtd_kmalloc_up_to(9). Go forth and allocate responsibly πβ¨
π¦ 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