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 X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2F9AC433FE for ; Wed, 22 Sep 2021 10:40:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6765A6126A for ; Wed, 22 Sep 2021 10:40:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6765A6126A 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 E4F446B006C; Wed, 22 Sep 2021 06:40:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFEBB6B0072; Wed, 22 Sep 2021 06:40:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CED9F6B0073; Wed, 22 Sep 2021 06:40:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id C04D16B006C for ; Wed, 22 Sep 2021 06:40:12 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 81261181D302B for ; Wed, 22 Sep 2021 10:40:12 +0000 (UTC) X-FDA: 78614864664.25.9254814 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf03.hostedemail.com (Postfix) with ESMTP id 0A45530000B2 for ; Wed, 22 Sep 2021 10:40:11 +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 6A3FC201E0; Wed, 22 Sep 2021 10:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1632307210; 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=4ouO2eiBz7AarOubtUS2HbX5UCqDKCApeMp/QJiTLvY=; b=3NMEjBkMvtW+A2X7Xc7hHTQD/hluqwZwy4jjOPlg20LPPsNteIS2Kq7m6QZzHet7gmEO/w uFEvDnxAbN7rEbFKJ4X8T0WpT4uQ4tY/Al07oqF8lpwJ5V5diHeHLfDdMk8d+bizIDuqlF NS990yzPuDBxCvBAFe1ru8Z0JZxtS2E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1632307210; 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=4ouO2eiBz7AarOubtUS2HbX5UCqDKCApeMp/QJiTLvY=; b=4LgCBbV7tZaZYbDqVSHM92uCu2gu2SmcsFEMjOkGtu/RC2hIujoghoWSPbj2dn+a2uok7S Hoj9AvFbLC1gA7CQ== 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 4B89613D69; Wed, 22 Sep 2021 10:40:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7SFsEQoIS2FFXQAAMHmgww (envelope-from ); Wed, 22 Sep 2021 10:40:10 +0000 Message-ID: Date: Wed, 22 Sep 2021 12:40:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [PATCH 1/3] mm/smaps: Fix shmem pte hole swap calculation 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-2-peterx@redhat.com> From: Vlastimil Babka In-Reply-To: <20210917164756.8586-2-peterx@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0A45530000B2 X-Stat-Signature: 6rj1z9tqcutgz7czrbd558xyo6qu3zqw Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3NMEjBkM; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=4LgCBbV7; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-HE-Tag: 1632307211-297984 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: > The shmem swap calculation on the privately writable mappings are using wrong > parameters as spotted by Vlastimil. Fix them. That's introduced in commit > 48131e03ca4e, when rework shmem_swap_usage to shmem_partial_swap_usage. > > Test program: > > ================== > > void main(void) > { > char *buffer, *p; > int i, fd; > > fd = memfd_create("test", 0); > assert(fd > 0); > > /* isize==2M*3, fill in pages, swap them out */ > ftruncate(fd, SIZE_2M * 3); > buffer = mmap(NULL, SIZE_2M * 3, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); > assert(buffer); > for (i = 0, p = buffer; i < SIZE_2M * 3 / 4096; i++) { > *p = 1; > p += 4096; > } > madvise(buffer, SIZE_2M * 3, MADV_PAGEOUT); > munmap(buffer, SIZE_2M * 3); > > /* > * Remap with private+writtable mappings on partial of the inode (<= 2M*3), > * while the size must also be >= 2M*2 to make sure there's a none pmd so > * smaps_pte_hole will be triggered. > */ > buffer = mmap(NULL, SIZE_2M * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); > printf("pid=%d, buffer=%p\n", getpid(), buffer); > > /* Check /proc/$PID/smap_rollup, should see 4MB swap */ > sleep(1000000); > } > ================== > > Before the patch, smaps_rollup shows <4MB swap and the number will be random > depending on the alignment of the buffer of mmap() allocated. After this > patch, it'll show 4MB. > > Fixes: 48131e03ca4e ("mm, proc: reduce cost of /proc/pid/smaps for unpopulated shmem mappings") Thanks, too bad I didn't spot it when sending that patch :) > Reported-by: Vlastimil Babka > Signed-off-by: Peter Xu Reviewed-by: Vlastimil Babka > --- > fs/proc/task_mmu.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index cf25be3e0321..2197f669e17b 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -478,9 +478,11 @@ static int smaps_pte_hole(unsigned long addr, unsigned long end, > __always_unused int depth, struct mm_walk *walk) > { > struct mem_size_stats *mss = walk->private; > + struct vm_area_struct *vma = walk->vma; > > - mss->swap += shmem_partial_swap_usage( > - walk->vma->vm_file->f_mapping, addr, end); > + mss->swap += shmem_partial_swap_usage(walk->vma->vm_file->f_mapping, > + linear_page_index(vma, addr), > + linear_page_index(vma, end)); > > return 0; > } >