krealloc_node_align(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– krealloc_node_align(9) β€” the kernel API glow-up πŸ¦‹

okay so bestie, welcome to krealloc_node_align, from the Kernel API Manual ✨ this is the realloc-adjacent girly who pops up in section 9 of the man pages, and she's here to reallocate memory for you. The contents will remain unchanged. no cap πŸ’…


✨ SYNOPSIS ✨

void * krealloc_node_align (const void *p , size_t new_size , unsigned
long align , gfp_t flags , int nid );

literally one function, five arguments, main character energy πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • p β€” the object you wanna reallocate memory for 🫢
  • new_size β€” how many bytes of memory are required, tell her exactly what you need
  • align β€” the desired alignment, she wants it aligned, periodt
  • flags β€” the type of memory to allocate
  • nid β€” the NUMA node, or NUMA_NO_NODE if you're not being picky 🌸

🌈 DESCRIPTION 🌈

So here's the tea β˜• if p is NULL, krealloc behaves exactly like kmalloc. iconic behavior honestly.

If new_size is 0 and p is not a NULL pointer, the object pointed to is freed. bye bestie πŸ‘‹

⚠️ Only alignments up to those guaranteed by kmalloc will be honored. Don't come for her with your fancy alignment dreams, she said what she said. Please see Documentation/core-api/memory-allocation.rst for more details πŸ“–

If __GFP_ZERO logic is requested, callers must ensure that β€” starting with the initial memory allocation β€” every subsequent call to this API for the same memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that __GFP_ZERO is not fully honored by this API. fr fr, don't skip a call, she's keeping receipts 😭

When slub_debug_orig_size is off, krealloc only knows about the bucket size of an allocation (but not the exact size it was allocated with) and hence implements the following semantics for shrinking and growing buffers with __GFP_ZERO:

           new             bucket
   0       size             size
   |--------|----------------|
   |  keep  |      zero      |

Otherwise, the original allocation size 'orig_size' could be used to precisely clear the requested size, and the new size will also be stored as the new 'orig_size'. she upgraded and now she remembers everything πŸ’–

In any case, the contents of the object pointed to are preserved up to the lesser of the new and old sizes. the vibe check passes πŸ”₯


⭐ RETURN ⭐

Pointer to the allocated memory 🎁 or NULL in case of error 😭 (we don't talk about the error timeline)


πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./include/linux/slab.h β€” go read her whole friend group:


and that's the whole page bestie, every flag and every reference accounted for, iykyk πŸ’œ

this absolute baddie lives in ./include/linux, and the version she's serving is October 2026 β€” that's the date on the tin, mwah πŸ’‹ πŸŽ€βœ¨πŸŒΈ

πŸ“¦ where this page comes from