devm_get_free_pages(9)
π devm_get_free_pages(9) β like, the whole glow-up
okay bestie, so this is a page straight out of the Kernel API Manual and it's genuinely one of the good ones. it's devm_get_free_pages, and it's the resource-managed version of __get_free_pages. yes, the managed one. the one that cleans up after itself. main character energy fr π
β¨ NAME β¨
devm_get_free_pages β Resource-managed __get_free_pages
like, same page-allocating goodness as the original, except this one remembers to tidy up. we stan π
πΈ SYNOPSIS πΈ
unsigned long devm_get_free_pages (struct device *dev , gfp_t gfp_mask ,
unsigned int order );
three arguments, one unsigned long coming back at you. that's it, that's the whole vibe check β¨
π¦ ARGUMENTS π¦
devβ the Device you're allocating memory for. it's the whole reason the "managed" part works, so don't be weird about it π«Άgfp_maskβ the Allocation gfp flags. yes, all of them. you know what you're doing (hopefully) πorderβ the Allocation size, and it's literally(1 << order)pages. soorder0is one page, and it scales up from there. math is math π
π§ DESCRIPTION π§
okay so, short version: it's a Managed get_free_pages. Memory allocated with this function is automatically freed on driver detach. π
like no cap, you don't have to manually free it β the devres machinery handles it for you. it's giving "I set it up and then I forgot about it and everything was fine." iconic behaviour honestly π
π RETURN π
- Address of allocated memory on success π
0on failure π
that's it. check for the 0, bestie, don't get caught out there π
π₯ SEE ALSO π₯
the whole friend group shows up here, and we love them all:
Kernel file ./drivers/base/devres.c, plus:
__devres_alloc_node(9)devres_for_each_res(9)devres_free(9)devres_add(9)devres_find(9)devres_get(9)devres_remove(9)devres_destroy(9)devres_release(9)devres_release_all(9)devres_open_group(9)devres_close_group(9)devres_remove_group(9)devres_release_group(9)__devm_add_action(9)devm_remove_action_nowarn(9)devm_release_action(9)devm_kmalloc(9)devm_krealloc(9)devm_kstrdup(9)devm_kstrdup_const(9)devm_kvasprintf(9)devm_kasprintf(9)devm_kfree(9)devm_kmemdup(9)devm_kmemdup_const(9)devm_free_pages(9)__devm_alloc_percpu(9)
and that's the page!! π source is ./drivers/base, the manual is the Kernel API Manual, and the date on this little masterpiece is October 2026. go allocate something and let the kernel clean up after you, that's the whole dream fr fr πΈβ¨π
π¦ 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