Re: RFC: Proposal: Add NUMA Memory Policy Tunable to glibc malloc implementation
罗春生
luochunsheng@ustc.edu
Tue Aug 5 02:50:12 GMT 2025
Dear Florian,
>I don't see why you need LD_PRELOAD for this. The manual page says that
>set_mempolicy is preserved across fork and execve. For such process
>attributes, we do not provide tunables.
Thank you for your insightful feedback.
My reference to LD_PRELOAD was strictly regarding workaround scenarios where developers might
try to intercept early allocations through malloc hooks before main() executes. For example:
// preload_hack.c
__attribute__((constructor)) void malloc_hook(int size) {
// Attempt to set policy before libc constructors without allocating additional memory
set_mempolicy(MPOL_INTERLEAVE, numa_nodes_mask);
return origin_malloc(size);
}
This approach has known limitations: reentrancy risks during dynamic linking and potential performence issues.
Our proposal aims to provide a standardized alternative to such brittle solutions.
I completely agree with your point about the inheritable nature of set_mempolicy()'s process attributes -
the memory policy persists across execve() and is inherited by child processes (as documented in the manual).
This tunable implementation would affect all memory allocation policies of a process and its children, not just ptmalloc's behavior.
The original proposal addressed a specific timing challenge: critical allocations occurring during the initialization sequence:
ld.so initialization → early malloc calls → first user call to set_mempolicy()
After careful consideration, we realized that might not have a real problem - we may have over-engineered a solution for a non-critical situation.
Thank you for your expert guidance.
Best regards,
Chunsheng Luo
More information about the Libc-alpha
mailing list