Red Hat Bugzilla – Bug 461481
[5.2] valloc() fails with ENOMEM without trying to use arenas
Last modified: 2016-11-24 11:14:53 EST
Description of problem:
When each thread of a multi-threaded process calls valloc()
individually, valloc() sometimes fails with ENOMEM even if the virtual
memory of the process is available enough.
Version-Release number of selected component:
Red Hat Enterprise Linux Version Number: 5
Release Number: 2
Kernel Version: 2.6.18-92.el5
Related Package Version: glibc-2.5-24
Related Middleware / Application: None
Step to Reproduce:
Execute our reproducer as follows.
1) Extract our tar ball.
$ tar zxf mvalloc-race.tar.gz
2) Compile the reproducer.
$ cd mvalloc
3) Execute a reproducer.
valloc() fails with ENOMEM even if the virtual memory is
The output of the reproducer is as follows.
valloc(4063232) failed, err:12
zsh: 31196 abort (core dumped) ./mvalloc-race-v7
Model: PRIMEQUEST 580
CPU Info: Itanium 2(1.6GHz) x4
Memory Info: 4GB
Hardware Component Information: None
Configuration Info: None
Guest Configuration Info: None
It was tried memalign() instead of valloc() in the reproducer because
specification difference between valloc() and memalign() is not so much,
but this problem does -not- occurred.
The implementation difference between valloc() and memalign() is its
action when _int_memalign() returns NULL. I think this difference
causes this problem. The detail of the action is as follows.
The memalign() checks the return value of _int_memalign(). If
_int_memalign() returns NULL, memalign() tries to get memory from the
main_arena. However, valloc() does not check the return value of
_int_valloc() that is the return value of _int_memalign().
_int_valloc() calls _int_memalign() internally. I think this is the
reason why valloc() fails with ENOMEM, and why memalign() does not fail.
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release. Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products. This request is not yet committed for inclusion in an Update
Created attachment 316081 [details]
proposed patch to fix valloc() to fall back to arena.
I'm attaching a patch fixing valloc() to use arenas areas like memalign() does.
Created attachment 316566 [details]
patch fixing valloc/pvalloc to fall back to arenas
Created attachment 316613 [details]
backport for 2.5-25
Created attachment 316623 [details]
backport for 2.5-24 [RHEL-5.2]
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.