From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758215AbbKSKFD (ORCPT ); Thu, 19 Nov 2015 05:05:03 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:34338 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757550AbbKSKE6 (ORCPT ); Thu, 19 Nov 2015 05:04:58 -0500 Date: Thu, 19 Nov 2015 11:04:55 +0100 From: Michal Hocko To: Vlastimil Babka Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jerome Marchand , Hugh Dickins , Peter Zijlstra , Oleg Nesterov , linux-api@vger.kernel.org, linux-doc@vger.kernel.org, Konstantin Khlebnikov Subject: Re: [PATCH v5 3/6] mm, proc: reduce cost of /proc/pid/smaps for shmem mappings Message-ID: <20151119100455.GB8494@dhcp22.suse.cz> References: <1447838976-17607-1-git-send-email-vbabka@suse.cz> <1447838976-17607-4-git-send-email-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1447838976-17607-4-git-send-email-vbabka@suse.cz> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 18-11-15 10:29:33, Vlastimil Babka wrote: > The previous patch has improved swap accounting for shmem mapping, which > however made /proc/pid/smaps more expensive for shmem mappings, as we consult > the radix tree for each pte_none entry, so the overal complexity is > O(n*log(n)). > > We can reduce this significantly for mappings that cannot contain COWed pages, > because then we can either use the statistics tha shmem object itself tracks > (if the mapping contains the whole object, or the swap usage of the whole > object is zero), or use the radix tree iterator, which is much more effective > than repeated find_get_entry() calls. > > This patch therefore introduces a function shmem_swap_usage(vma) and makes > /proc/pid/smaps use it when possible. Only for writable private mappings of > shmem objects (i.e. tmpfs files) with the shmem object itself (partially) > swapped outwe have to resort to the find_get_entry() approach. Hopefully > such mappings are relatively uncommon. > > To demonstrate the diference, I have measured this on a process that creates > a 2GB mapping and dirties single pages with a stride of 2MB, and time how long > does it take to cat /proc/pid/smaps of this process 100 times. > > Private writable mapping of a /dev/shm/file (the most complex case): > > real 0m3.831s > user 0m0.180s > sys 0m3.212s > > Shared mapping of an almost full mapping of a partially swapped /dev/shm/file > (which needs to employ the radix tree iterator). > > real 0m1.351s > user 0m0.096s > sys 0m0.768s > > Same, but with /dev/shm/file not swapped (so no radix tree walk needed) > > real 0m0.935s > user 0m0.128s > sys 0m0.344s > > Private anonymous mapping: > > real 0m0.949s > user 0m0.116s > sys 0m0.348s > > The cost is now much closer to the private anonymous mapping case, unless the > shmem mapping is private and writable. > > Signed-off-by: Vlastimil Babka Looks good to me Acked-by: Michal Hocko [...] -- Michal Hocko SUSE Labs