kstrdup_const(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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 the kmalloc call 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:


✿ 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