Bug 172554 - C++ program with mlockall() is terminating in GCC version 3.4.3 with the error St9bad_alloc
C++ program with mlockall() is terminating in GCC version 3.4.3 with the erro...
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: kernel (Show other bugs)
4.0
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Kernel Maintainer List
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-11-07 01:14 EST by ananth
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-11-07 16:19:02 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description ananth 2005-11-07 01:14:52 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Netscape/8.0.3.1

Description of problem:
Hi 

I am trying to compile and execute the following program

#include <stdio.h>
#include <sys/mman.h>

class CTest {
	int count;
public:
	CTest()
	{
		count = 10;
	}
	~CTest()
	{
		count = 0;
	}
};
main()
{
	
	mlockall(MCL_FUTURE);

	CTest* test = new CTest();

	printf ("Hello World\n");
	munlockall();
}

If I compile the above program using the gcc version 3.2.2 (Red Hat Linux 3.2.2-5 ), and execute the executable, the output is proper as expected.

If I compile the above program using the gcc version 3.4.3 (Red Hat 3.4.3-9.EL4 ), and execute the executable, I am getting the following error
"
terminate called after throwing an instance of 'St9bad_alloc'
what(): St9bad_alloc
Aborted
"

Can anyone had this kind of problem earlier ?? Any solution please..


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.Compile the above program using the G++
2.Execute the ./a.out
3. The application terminated
  

Actual Results:  Program termination

Expected Results:  It should output the message "Hello world" and should come out successfully

Additional info:
Comment 1 Jakub Jelinek 2005-11-07 04:24:38 EST
I can't reproduce this (with gcc-c++-3.4.4-2, but that shouldn't matter).
strace shows:
...
mlockall(MCL_FUTURE)                    = 0
brk(0)                                  = 0x804a000
brk(0x806b000)                          = 0x806b000
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb7fe8000
write(1, "Hello World\n", 12Hello World
)           = 12
munlockall()                            = 0
munmap(0xb7fe8000, 4096)                = 0
exit_group(0)                           = ?

Can you run strace on it?
Comment 2 ananth 2005-11-07 04:56:50 EST
More observation on this problem is:
     1) This problem is coming if I use "new" in the C++ program to allocate 
the memory with MCL_FUTURE flag.
     2) With MCL_FUTURE flag , thread creation using pthread_create() is also 
not success.

     The above problems are not observed in the same G++ version, if I use the 
MCL_CURRENT flag alone.

The strace from the G++ Version (3.4.3 20041212 (Red Hat 3.4.3-9.EL4) is given 
below:


mlockall(MCL_FUTURE)                    = 0
brk(0)                                  = 0x86aa000
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
write(2, "terminate called after throwing "..., 48terminate called after 
throwing an instance of ') = 48
write(2, "St9bad_alloc", 12St9bad_alloc)            = 12
write(2, "\'\n", 2'
)                     = 2
write(2, "  what():  ", 11  what():  )             = 11
write(2, "St9bad_alloc", 12St9bad_alloc)            = 12
write(2, "\n", 1
)                       = 1
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
gettid()                                = 2023
tgkill(2023, 2023, SIGABRT)             = 0
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++

Comment 3 ananth 2005-11-07 04:59:03 EST
More observation on this problem is:
     1) This problem is coming if I use "new" to create the objects and to 
allocate the memory and the memory is locked with MCL_FUTURE flag.
     2) With the memory is locked with MCL_FUTURE flag , thread creation using 
pthread_create() is also not success.

     The above problems are not observed in the same G++ version, if I use the 
MCL_CURRENT flag alone.

The strace from the G++ Version (3.4.3 20041212 (Red Hat 3.4.3-9.EL4) is given 
below:


mlockall(MCL_FUTURE)                    = 0
brk(0)                                  = 0x86aa000
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
brk(0x86cb000)                          = 0x86aa000
mmap2(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -
1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0)
= -1 EAGAIN (Resource temporarily unavailable)
write(2, "terminate called after throwing "..., 48terminate called after 
throwing an instance of ') = 48
write(2, "St9bad_alloc", 12St9bad_alloc)            = 12
write(2, "\'\n", 2'
)                     = 2
write(2, "  what():  ", 11  what():  )             = 11
write(2, "St9bad_alloc", 12St9bad_alloc)            = 12
write(2, "\n", 1
)                       = 1
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
gettid()                                = 2023
tgkill(2023, 2023, SIGABRT)             = 0
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++


Comment 4 Jakub Jelinek 2005-11-07 05:10:52 EST
This shows it has nothing to do with libstdc++ or g++.
The kernel refused to create new mappings, so changing to kernel component.
Are you running as root or as normal user?
EAGAIN from mmap etc. happens e.g. when the process locked memory limit
is exceeded (see ulimit -l).  By default it is 32KB, so it would be no
surprise if allocation of 1MB or 2MB failed.
Comment 5 ananth 2005-11-07 05:23:43 EST
I am executing this program as Normal User.
I tried the same program with root and I am able to execute it successfully.

Thank you
Ananth.

The allocation of memory of size 8 Bytes (2 * character size) using "new" 
itself is failing with Normal User.

Comment 6 Jason Baron 2005-11-07 16:19:02 EST
ok. looks to me like this is working as designed. 

Note You need to log in before you can comment on or make changes to this bug.