Avner Levy
Avner Levy

Reputation: 6741

What are the "rwxp" sections in /proc/pid/smaps (linux)

I have a C++ gcc leaking program with 326 sections like the following

33300000-33500000 rwxp 33300000 00:00 0
Size:              2048 kB
Rss:                620 kB
Shared_Clean:         0 kB
Shared_Dirty:         0 kB
Private_Clean:      244 kB
Private_Dirty:      376 kB

I was wondering what kind of allocation cause additions of 2MB writable code segments to the program. Usually I see such sections which are used as stack memory for threads but they are 10 MB large.

Upvotes: 4

Views: 6119

Answers (3)

Avner Levy
Avner Levy

Reputation: 6741

After more research I've found that the process was allocating large memory chunks using malloc.
But when malloc sees that the required allocation size is too large for the heap (see MMAP_THRESHOLD) it allocates the memory by calling mmap.
At the end of the day it was a regular memory leak, except the allocations were especially large and caused direct mmap calls.

Upvotes: 2

Employed Russian
Employed Russian

Reputation: 213799

Usually I see such sections which are used as stack memory for threads

Yes, it is exceedingly likely that you are leaking threads. You can confirm this by looking in /proc/<pid>/task and checking whether you have 326 threads more than you expect. Alternatively, GDB info thread will also list all threads.

Note: the fact that your stacks are executable means that you don't have GNU_STACK segment in your binary or one of its required shared libraries, which is a generally a bad idea.

but they are 10 MB large.

The size of stack segments depends on current ulimit -s setting, as well as any setrlimit(..., RLIMIT_STAck, ...) or pthread_attr_setstacksize() calls that the application itself may perform.

Upvotes: 3

Arnab Nandy
Arnab Nandy

Reputation: 6712

r = read
w = write
x = execute
s = shared
p = private (copy on write)

Upvotes: 7

Related Questions