Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the memory consumption grows when using more threads on Linux? (C++)

Program:

I created a C++ calculation program for high volume of data, which could be run on 1 or more threads. (via config file)

The program environment is the following: C++, OpenMp, Redhat-x64, malloc/free

Results on Linux:

  • When I run it on 1 thread, process size is 177 MB.
  • When I run it on 2 threads, process size is 317 MB.
  • When I run it on 4 threads, process size is 600 MB.

Results on Windows:

  • Process size still the same regardless the number of threads used, 110MB.

Question:

Why does the memory consumption grows when using more threads on Linux?

like image 864
Axel Borja Avatar asked Sep 01 '26 06:09

Axel Borja


2 Answers

A fair guess is that delete in Linux will cache released memory for future new requests, just as it does on Windows, but Linux has a cache per thread whereas Windows has a cache per process.

(More accurately, it would be the C++ runtime library that determines how such a cache works).

like image 196
MSalters Avatar answered Sep 03 '26 20:09

MSalters


Use /proc/<PID>/maps, or better pmap(1), to figure out where the pages go.

like image 31
Nikolai Fetissov Avatar answered Sep 03 '26 20:09

Nikolai Fetissov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!