kstrdup_const(9)
β¨ kstrdup_const(9) β¨
okay so bestie, welcome to the Kernel API Manual entry for kstrdup_const β the function that's like "hmm, do I actually need to copy this string, or can I just point at it and save us all some RAM?" π
πΈ NAME πΈ
kstrdup_const β conditionally duplicate an existing const string. yes, conditionally. she's picky. π
π¦ SYNOPSIS π¦
const char * kstrdup_const (const char *s , gfp_t gfp );
π ARGUMENTS π
sβ the string to duplicate. the main character of this whole operation π«Άgfpβ the GFP mask used in thekmalloccall when allocating memory. so basically, how she's allowed to grab memory β¨
β NOTE β
bestie pls read this one π
Strings allocated by kstrdup_const should be freed by kfree_const and must not be passed to krealloc. like, do not. that's not her job. π
π₯ RETURN π₯
Returns the source string if it is in the .rodata section β otherwise it falls back to kstrdup. no cap, that's literally it. π
π SEE ALSO π
Kernel file ./mm/util.c, plus the whole friend group:
kfree_const(9)__kmemdup_nul(9)kstrdup(9)kstrndup(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)memdup_user(9)vmemdup_user(9)strndup_user(9)memdup_user_nul(9)randomize_page(9)__account_locked_vm(9)account_locked_vm(9)__vmalloc_array(9)vmalloc_array(9)__vcalloc(9)vcalloc(9)folio_mapping(9)folio_copy(9)get_cmdline(9)mem_dump_obj(9)compat_set_desc_from_vma(9)__compat_vma_mmap(9)compat_vma_mmap(9)snapshot_page(9)mmap_action_prepare(9)mmap_action_complete(9)folio_pte_batch(9)page_range_contiguous(9)
βΏ and that's the whole page, bestie βΏ this one came from the ./mm source, dated October 2026, and the last little flourish is the kstrdup_const(9) title wave at the end β mwah π go free your strings with kfree_const and stay iconic π§π
π¦ 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