* Paul Eggert: > On 7/22/20 12:13 AM, Florian Weimer wrote: >> I don't think it will work. Try to get an allocation of 4096 bytes with >> 4096 bytes alignment using glibc malloc this way. > > That's just a mental exercise since glibc malloc already has > aligned_alloc, but I took the challenge anyway and found that it's > eminently doable with glibc malloc alone. Run the attached program, > and it should exit with status 0. At least, it works for me.
Ah, 4096 is too small. For large allocations (above the mmap threshold), what happens in the example is that the process VMA limit is eventually exhausted, at which malloc falls back to sbrk, and then the algorithm succeeds. I don't think it's a good idea to trigger ENOMEM, it's certainly not thread-safe. Thanks, Florian