Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Jul 2016 03:19:13 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Yuri <yuri@rawbw.com>
Cc:        Freebsd hackers list <freebsd-hackers@FreeBSD.org>
Subject:   Re: Why kinfo_getvmmap is sometimes so expensive?
Message-ID:  <20160707001913.GJ38613@kib.kiev.ua>
In-Reply-To: <e6dc27c0-0454-0666-b3e1-887bd116a847@rawbw.com>
References:  <e6dc27c0-0454-0666-b3e1-887bd116a847@rawbw.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jul 06, 2016 at 03:12:59PM -0700, Yuri wrote:
> The function getProcessSizeBytes, calculating the total size of the 
> process, runs once per second. I have two processes of the same kind, 
> but with the different run history.
> 
> Process #1 didn't do much work, its total size is 1.5 GB, google 
> perftools library says that it currently has 1.2GB allocated.
> 
> Process #2 did a lot of work, its total size is 6.9 GB, but most of the 
> used memory was freed, and google perftools library also says that it 
> currently has only 1.2GB allocated.
> 
> Both processes have about 140 lines in /proc/<pid>/map.
> 
> 
> What bothers me is that getProcessSizeBytes run once per second makes 
> process #1 to consume ~0.5% CPU, and process #2 to consume ~14% CPU. 
> When I stop running getProcessSizeBytes, CPU times of both processes go 
> to zero.
> 
> 
> Obviously, google perftools doesn't unmap the memory, and the totals of 
> block sizes in /proc/<pid>/map is much higher for process #2 with about 
> the same block count. But why does this cause 14% of CPU consumption? 
> And why another, similar process that goes through about the same number 
> of blocks only has 0.5% CPU consumption?
To calculate residency count for the process map entries, kernel has to
iterate over all pages.  This operation was somewhat optimized in 10.3
and HEAD, particularly for the large sparce mappings.  But for large populated
mappings there is no other way then to check each page.

You may confirm my hypothesis by setting sysctl
kern.proc_vmmap_skip_resident_count to 0 and see whether the CPU
consumption changed.  Of course, you will not get the resident count
in the returned structure, after the knob is tweaked.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160707001913.GJ38613>