From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E603C433FE for ; Tue, 5 Oct 2021 11:15:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DE54F61251 for ; Tue, 5 Oct 2021 11:15:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DE54F61251 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6F6CD6B006C; Tue, 5 Oct 2021 07:15:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67E9E6B0071; Tue, 5 Oct 2021 07:15:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F8346B0072; Tue, 5 Oct 2021 07:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 39FAB6B006C for ; Tue, 5 Oct 2021 07:15:08 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E73878249980 for ; Tue, 5 Oct 2021 11:15:07 +0000 (UTC) X-FDA: 78662127054.32.C102DB2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf09.hostedemail.com (Postfix) with ESMTP id 351AB3000FE8 for ; Tue, 5 Oct 2021 11:15:07 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0E5942027E; Tue, 5 Oct 2021 11:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1633432506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iXB7Q8sRuEn5IalpujyMPzVx9cKiV7uy8PSeyuhzXA=; b=P6UWVjRA1QJefVXQzGHBE56/zXKTBSG7au+zg1DROwVHfYHSJ/SQ28kzAspfEZuekdKGtf Qz93sGTFcl+SxcbdiKPs7aUR6WBDYDUUWMX8JfuAN07SlBdKbPAOJyryx7/Rx8Dm5bDjMH DgGRIs/nEda1TQjTAa/45A0kjW7hIKc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1633432506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iXB7Q8sRuEn5IalpujyMPzVx9cKiV7uy8PSeyuhzXA=; b=svlCpJ7mOa+0fPKz4EjTmrhBAZpotiFCH5+jOUFqMrLsssMpjPYqvhw5AXijXltYbIMhnP t8mJ78jF4XikC/AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D8F7C13C35; Tue, 5 Oct 2021 11:15:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YNGYM7kzXGGDNgAAMHmgww (envelope-from ); Tue, 05 Oct 2021 11:15:05 +0000 Message-ID: <4bcf5e1d-cd86-319a-889f-782755955e04@suse.cz> Date: Tue, 5 Oct 2021 13:15:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Content-Language: en-US To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , Andrea Arcangeli , Matthew Wilcox References: <20210917164756.8586-1-peterx@redhat.com> <20210917164756.8586-4-peterx@redhat.com> From: Vlastimil Babka Subject: Re: [PATCH 3/3] mm/smaps: Simplify shmem handling of pte holes In-Reply-To: <20210917164756.8586-4-peterx@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 351AB3000FE8 X-Stat-Signature: oq4n7ba31gim54g74woatt37ny5r8qjn Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=P6UWVjRA; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=svlCpJ7m; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam06 X-HE-Tag: 1633432507-288797 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 9/17/21 18:47, Peter Xu wrote: > Firstly, check_shmem_swap variable is actually not necessary, because it's > always set with pte_hole hook; checking each would work. Right... > Meanwhile, the check within smaps_pte_entry is not easy to follow. E.g., > pte_none() check is not needed as "!pte_present && !is_swap_pte" is the same. Seems to be true, indeed. > Since at it, use the pte_hole() helper rather than dup the page cache lookup. pte_hole() is for checking a range and we are calling it for single page, isnt't that causing larger overhead in the end? There's xarray involved, so maybe Matthew will know best. > Still keep the CONFIG_SHMEM part so the code can be optimized to nop for !SHMEM. > > There will be a very slight functional change in smaps_pte_entry(), that for > !SHMEM we'll return early for pte_none (before checking page==NULL), but that's > even nicer. I don't think this is true, 'unlikely(IS_ENABLED(CONFIG_SHMEM))' will be a compile-time constant false and shortcut the rest of the 'if' evaluation thus there will be no page check? Or I misunderstood. > Cc: Hugh Dickins > Cc: Matthew Wilcox > Cc: Vlastimil Babka > Signed-off-by: Peter Xu > --- > fs/proc/task_mmu.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 2197f669e17b..ad667dbc96f5 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -397,7 +397,6 @@ struct mem_size_stats { > u64 pss_shmem; > u64 pss_locked; > u64 swap_pss; > - bool check_shmem_swap; > }; > > static void smaps_page_accumulate(struct mem_size_stats *mss, > @@ -490,6 +489,16 @@ static int smaps_pte_hole(unsigned long addr, unsigned long end, > #define smaps_pte_hole NULL > #endif /* CONFIG_SHMEM */ > > +static void smaps_pte_hole_lookup(unsigned long addr, struct mm_walk *walk) > +{ > +#ifdef CONFIG_SHMEM > + if (walk->ops->pte_hole) { > + /* depth is not used */ > + smaps_pte_hole(addr, addr + PAGE_SIZE, 0, walk); > + } > +#endif > +} > + > static void smaps_pte_entry(pte_t *pte, unsigned long addr, > struct mm_walk *walk) > { > @@ -518,12 +527,8 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, > } > } else if (is_pfn_swap_entry(swpent)) > page = pfn_swap_entry_to_page(swpent); > - } else if (unlikely(IS_ENABLED(CONFIG_SHMEM) && mss->check_shmem_swap > - && pte_none(*pte))) { > - page = xa_load(&vma->vm_file->f_mapping->i_pages, > - linear_page_index(vma, addr)); > - if (xa_is_value(page)) > - mss->swap += PAGE_SIZE; > + } else { > + smaps_pte_hole_lookup(addr, walk); > return; > } > > @@ -737,8 +742,6 @@ static void smap_gather_stats(struct vm_area_struct *vma, > return; > > #ifdef CONFIG_SHMEM > - /* In case of smaps_rollup, reset the value from previous vma */ > - mss->check_shmem_swap = false; > if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) { > /* > * For shared or readonly shmem mappings we know that all > @@ -756,7 +759,6 @@ static void smap_gather_stats(struct vm_area_struct *vma, > !(vma->vm_flags & VM_WRITE))) { > mss->swap += shmem_swapped; > } else { > - mss->check_shmem_swap = true; > ops = &smaps_shmem_walk_ops; > } > } >