vladon
vladon

Reputation: 8401

Read from /proc/$PID/smaps is slow

We need to monitor memory usage of our high-loaded service every minute by cron.

For this we are reading /proc/PID/smaps and somehow parse it.

But we are encountering timing problems exactly every minute. When monitoring cron is turned off, there is no timing problems.

Only expensive and suspicious operation in our code is that reading of /proc/PID/smaps.

Is there in Linux kernel any lock/mutex/something else while reading smaps?

And is there any other more transparent method to detect memory usage?

Upvotes: 3

Views: 939

Answers (1)

Zhenyu Zhao
Zhenyu Zhao

Reputation: 21

From my study, the cost of read /proc/PID/smaps is correlate with the mem usage the the process. Looks like the kernel is busy to check status of each mem page to generate the content. read smaps cost vs mem usage

"/proc/[pid]/stat" can tell you some info about memory usage like:

          (23) vsize  %lu
                    Virtual memory size in bytes.

          (24) rss  %ld
                    Resident Set Size: number of pages the process has
                    in real memory.  This is just the pages which count
                    toward text, data, or stack space.  This does not
                    include pages which have not been demand-loaded in,
                    or which are swapped out.

Read from this file is fast.

Upvotes: 2

Related Questions