I have written a program which works on huge set of data. My CPU and OS(Ubuntu) both are 64 bit and I have got 4GB of RAM. Using “top” (%Mem field), I saw that the process’s memory consumption went up to around 87% i.e 3.4+ GB and then it got killed.
I then checked how much memory a process can access using “uname -m” which comes out to be “unlimited”.
Now, since both the OS and CPU are 64 bit and also there exists a swap partition, the OS should have used the virtual memory i.e [ >3.4GB + yGB from swap space ] in total and only if the process required more memory, it should have been killed.
So, I have following ques:
- How much physical memory can a process access theoretically on 64 bit m/c. My answer is 2^48 bytes.
- If less than 2^48 bytes of physical memory exists, then OS should use virtual memory, correct?
- If ans to above ques is YES, then OS should have used SWAP space as well, why did it kill the process w/o even using it. I dont think we have to use some specific system calls which coding our program to make this happen.
Please suggest.
Check with
fileandlddthat your executable is indeed 64 bits.Check also the resource limits. From inside the process, you could use getrlimit system call (and
setrlimitto change them, when possible). From abashshell, tryulimit -a. From azshshell trylimit.Check also that your process indeed eats the memory you believe it does consume. If its pid is 1234 you could try
pmap 1234. From inside the process you could read the/proc/self/mapsor/proc/1234/maps(which you can read from a terminal). There is also the/proc/self/smapsor/proc/1234/smapsand/proc/self/statusor/proc/1234/statusand other files inside your/proc/self/…Check with
freethat you got the memory (and the swap space) you believe. You can add some temporary swap space withswapon /tmp/someswapfile(and usemkswapto initialize it).I was routinely able, a few months (and a couple of years) ago, to run a 7Gb process (a huge
cc1compilation), under Gnu/Linux/Debian/Sid/AMD64, on a machine with 8Gb RAM.And you could try with a tiny test program, which e.g. allocates with
mallocseveral memory chunks of e.g. 32Mb each. Don’t forget to write some bytes inside (at least at each megabyte).standard C++ containers like
std::maporstd::vectorare rumored to consume more memory than what we usually think.Buy more RAM if needed. It is quite cheap these days.