[CentOS] top and allocation issues

Thu Mar 3 19:38:52 UTC 2011
Brunner, Brian T. <BBrunner at gai-tronics.com>

centos-bounces at centos.org wrote:
> In a context where exceptions are caught, I ran
> the fragment:
> 
>    cerr << "allocating" << endl;
>    char*    arr[100];
>    for (int jj = 0; jj < 10; ++jj)
>    {
>       cerr << "jj = " << jj << endl;
>       arr[jj] = new char[2,000,000,000]; // This line changed by me to
underscore what you're doing.
>       sleep (30);
>    }
>    sleep (10);
>    for (int jj = 0; jj < 10; ++jj)
>       delete[] arr[jj];
>    cerr << "deleted" << endl;
> 
> The exception was caught with jj = 1, i.e., on the second allocation.
> 
> But on top, I see:
> 
> top - 14:08:46 up  5:21, 10 users,  load average: 0.04, 0.06, 0.08
> Tasks: 158 total,   1 running, 157 sleeping,   0 stopped,   0 zombie
> Cpu(s):  2.7%us,  2.0%sy,  0.0%ni, 94.5%id,  0.6%wa,  0.1%hi,
>  0.1%si,
> 0.0%st
> Mem:   1941908k total,  1231804k used,   710104k free, 138372k buffers
> Swap:  3899384k total,        0k used,  3899384k free, 876020k cached
> 
> and the "710104k free" suggests that I should have failed on the first
> allocation.  Furthermore, the allocation did not alter the values
> in top (except for a little jitter).
> 
> Wherein do I err?

Holy RAMbo, batman!  How many GB of RAM do you intend to allocate?
Once you allocate 2GB like you did, you MUST be running a bigmem or x64
kernel to allocate another 2GB.

You won't see 'new'd memory as "taken" in top(8) because malloc() is a
bug.  Bits are set in a page table, but no memory is actually written
to, and nothing really changes, until the program attempts to write.
What you did was fall off the end of a bit string keeping track of
malloc()'d pages, that's all.

(ps mark, the ++jj or jj++ takes place after the first loops' action,
not before .:. ++jj and jj++ have identical effect).

Insert spiffy .sig here


//me
*******************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed. If you have received this email in error please
notify the system manager. This footnote also confirms that this
email message has been swept for the presence of computer viruses.
www.Hubbell.com - Hubbell Incorporated**