Can some throw bright light on Linux Memory Allocation
Sergey Skorokhodov
ucayalyfish at yandex.ru
Thu Aug 7 18:34:09 UTC 2008
Hi,
> Hello,
>
> I have installed Ubuntu on a machine with following
> config.
>
> RAM : 2 GB
> Machine: Intel Core 2 Duo
> OS: Ubuntu 64 bit.
> Disk: 250 GB.
>
>
> I have attached a simple program to test memory allocation on linux
> and something strange is happening.
>
> 1. If I invoke large_memory function then maximum
> size I am allowed is 245GB.
>
> 2. If I use less than 245GB ( say 244 GB) then the
> second stage is also passed. Where from OS is
> allocating 244GB ?
>
> 3. Strange enough, if I use chuck memory, I can
> goto 3817GB before I get segmentation fault.
> ( and buf == NULL is never reached ).
>
> 4. Much more strange, GoogleHeapProfiler, and
> ValGrindHeap profile also add to my uneasiness
> and report that 3817GB allocation is successful.
>
> What is happening ? Please help.
>
I guess that the result of
size_t nb = 1024*1024*1024;
nb *= 255; // 0x3FC0000000
is much larger than the maximal value of size_t on 32-bit systems. So it
is truncated silently to 4 GB. Try
size_t nb = 1024*1024*1024*255;
and you get a warning. C/C++ consider that the programmer knows what
he/she is doing in the former case and keep silent but you can turn some
more rigorous checking on if you like.
Actually, a program is allocated with address space some less that 4 GB
on 32-bit system as some address space is used for memory mapped io and
other hardware needs.
--
Best regards,
Serge
More information about the ubuntu-users
mailing list