From patchwork Fri Sep 17 16:47:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12502779 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 E7CBFC433EF for ; Fri, 17 Sep 2021 17:03:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C19B60F70 for ; Fri, 17 Sep 2021 17:03:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5C19B60F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 001DE6B0073; Fri, 17 Sep 2021 13:03:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECE0D940008; Fri, 17 Sep 2021 13:03:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6F49940007; Fri, 17 Sep 2021 13:03:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id C56276B0073 for ; Fri, 17 Sep 2021 13:03:48 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7AC013A8D2 for ; Fri, 17 Sep 2021 17:03:48 +0000 (UTC) X-FDA: 78597687336.27.B2AB132 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf16.hostedemail.com (Postfix) with ESMTP id E6B48F408C5C for ; Fri, 17 Sep 2021 16:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631897282; h=from:from:reply-to:subject:subject: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=grUUg8VAspODuuKM93nZK+6Ve54OZS2pE6wnY0B0Xh4=; b=Jw9XuKahRM6i12XuAhKZTwronY7JciyooHFiG7Revb3ZS7PTEdrYr7h/tM/kWGA0vb+mXl 23Ui6+rQLl0eIY2vv+ZveUc9U8gQRi9H5JWQwsolmy4itkN8csmM0K6yNb7xk2eEeF8BL1 kq2OSr/Ci1Q1dABbPh/yKt2kCsXT/5s= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-153-fmfZcC4GPIqSAsw_0zgAkg-1; Fri, 17 Sep 2021 12:48:01 -0400 X-MC-Unique: fmfZcC4GPIqSAsw_0zgAkg-1 Received: by mail-qt1-f198.google.com with SMTP id d20-20020ac81194000000b002a53ffbd04dso52437282qtj.12 for ; Fri, 17 Sep 2021 09:48:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=grUUg8VAspODuuKM93nZK+6Ve54OZS2pE6wnY0B0Xh4=; b=KhDDIshoCq69gfAYYpoCTFhzNrRMYUu6mxf8ktdewfoNKqVF+W5MMddkEHGpG35hT4 waSQO87Bg9KXHLv8XbrMyY+6qbOXGmGKcJGYKXHxF5m3F9OSaAgB5/pFlFtmXuBTP1Z6 PRVxM8Ht96u2Oh7LypVpXd6xXy1HV8AKmbgingN1huFtGRtYsRdVA5hW8tC2C0h80Mqi uiEqb7C6yPh3YLCfOotjYIAKbOwu0CGDVLBSPhLSK4hRkbFidVmZdUwn9xEEQ3ctG0b/ nHGhx/XO5ClOtapZyaJyOr/O1QGD/EksEKsdh4BiNt53s5dKjGB/WIRsleTJwthoBHG8 z6pQ== X-Gm-Message-State: AOAM5328S9xM6s1q/512lrWCIyVeHZ6I8/WL9Wu6/9FenIG22bRgGDe0 eG6bEYTIrfQo5KxC8Eia2/UUkl3svYUyyKta00L1vYnQjYq8CvqsOVNk1kTqWceUdk6lVmxz5dD UZt+M9C7rElYr+4GF7KePnXH4O4PD4iI1KenWIzztHmlTXBoN2pWgcHN3jzGQ X-Received: by 2002:a37:a883:: with SMTP id r125mr11301946qke.408.1631897280502; Fri, 17 Sep 2021 09:48:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqphWd+Tlov8LMwfi4vrThplMRTxmltW9/KJp77jBhawRfzds+2s8yAR92mY6VZ+JYJoRaqg== X-Received: by 2002:a37:a883:: with SMTP id r125mr11301917qke.408.1631897280218; Fri, 17 Sep 2021 09:48:00 -0700 (PDT) Received: from t490s.phub.net.cable.rogers.com ([2607:fea8:56a2:9100::d35a]) by smtp.gmail.com with ESMTPSA id t26sm4898057qkm.0.2021.09.17.09.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 09:47:59 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Vlastimil Babka , Andrew Morton , Hugh Dickins , Andrea Arcangeli , peterx@redhat.com, Matthew Wilcox Subject: [PATCH 1/3] mm/smaps: Fix shmem pte hole swap calculation Date: Fri, 17 Sep 2021 12:47:54 -0400 Message-Id: <20210917164756.8586-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917164756.8586-1-peterx@redhat.com> References: <20210917164756.8586-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: weq7m13mnwbmd1w48kx5g87e4u5oui9a Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jw9XuKah; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf16.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E6B48F408C5C X-HE-Tag: 1631897282-614127 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: 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") 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; } From patchwork Fri Sep 17 16:47:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12502809 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 75800C433EF for ; Fri, 17 Sep 2021 17:20:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 18A5561212 for ; Fri, 17 Sep 2021 17:20:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 18A5561212 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A9DB66B0072; Fri, 17 Sep 2021 13:20:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4D336B0073; Fri, 17 Sep 2021 13:20:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 914E3900002; Fri, 17 Sep 2021 13:20:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 7ED806B0072 for ; Fri, 17 Sep 2021 13:20:14 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 43DE318512000 for ; Fri, 17 Sep 2021 17:20:14 +0000 (UTC) X-FDA: 78597728748.40.541A9C3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf16.hostedemail.com (Postfix) with ESMTP id C4F52F40B05A for ; Fri, 17 Sep 2021 16:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631897284; h=from:from:reply-to:subject:subject: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=4hCdvDjRviIL22W5JADBBQycRMaHOvY6mSdPWhIlWZU=; b=JdKxIIaxcCQH0zK0PYTA1iqhIyOkRFobas7p2iahC+X2J9c7gXYuCpc5/gwpo+6zLtdC1q hqjfZdrGRBXv1D42fFbbLbwCkQe/KBz0egCuBryud8ZFEX9Yc7+DkbQwuzoENWKNy06dQZ fmiaQlLZgv02KHY0Rd+RGBPa0x1Yaic= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-343-xcNldY8BPmeOg1JgH-9Pvg-1; Fri, 17 Sep 2021 12:48:03 -0400 X-MC-Unique: xcNldY8BPmeOg1JgH-9Pvg-1 Received: by mail-qv1-f71.google.com with SMTP id ci14-20020a056214054e00b0037a75ff56f9so92068305qvb.23 for ; Fri, 17 Sep 2021 09:48:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4hCdvDjRviIL22W5JADBBQycRMaHOvY6mSdPWhIlWZU=; b=iJZ1NdGTihZgSpg75t2zx7uLVFNVD7rYgoDQ92NErt1/mYV20xPSdWLgU7kIhUFiQQ DaTLRT6WsUAkTF5VOCUusTO8xnPKRx1cAD7Sq5/SDQG5+66oHyNmPsfDkxTzX9ebowQN 2n0efkaKKcclnuPRmwWZiupV0azvRhUMH5tdHgxzMlZD++jMCBec3ch45Fx+5vcMWMSi fH/vAtwai/smRmMViHqrqTh49pY0Hgftx/E6e05KK92iVkZXQPlW302NzFrLZOCiNbWT TZmGa1gIwcsKropsaPz+xeMQ+io99BSa3/XneDKTu3JTCci/ih2dzxK5guAL2Xqqtt9N wZfw== X-Gm-Message-State: AOAM532JDssR+rcj+HRzyyLjjTUGmO2CAJnxrpnx/YN35HS3tOFJwGnM ss4+w7X49Hs0aDKOTlDOsozuWlBFLLdgYvv1cK2ksAXplcoGJT3CWX90gBSQOw2Yp1sSLA15NWj zUaopJuPKfe+owUn7HaYmxJJLGgrji92jQjT+2vA7a/3hgaw98FLWqgJV321Z X-Received: by 2002:aed:3004:: with SMTP id 4mr11017163qte.407.1631897282540; Fri, 17 Sep 2021 09:48:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZWVxwXPHBVDYEfR49AslQcsKewHkeBvsRTypxwBGT/QQhAZPTJ0bzyrPxFClD91GIRnLm8A== X-Received: by 2002:aed:3004:: with SMTP id 4mr11017137qte.407.1631897282257; Fri, 17 Sep 2021 09:48:02 -0700 (PDT) Received: from t490s.phub.net.cable.rogers.com ([2607:fea8:56a2:9100::d35a]) by smtp.gmail.com with ESMTPSA id t26sm4898057qkm.0.2021.09.17.09.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 09:48:01 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Vlastimil Babka , Andrew Morton , Hugh Dickins , Andrea Arcangeli , peterx@redhat.com, Matthew Wilcox Subject: [PATCH 2/3] mm/smaps: Use vma->vm_pgoff directly when counting partial swap Date: Fri, 17 Sep 2021 12:47:55 -0400 Message-Id: <20210917164756.8586-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917164756.8586-1-peterx@redhat.com> References: <20210917164756.8586-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C4F52F40B05A X-Stat-Signature: bynq5rfj5crpbnkursiqbxfgincum4f5 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JdKxIIax; spf=none (imf16.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1631897284-946162 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: As it's trying to cover the whole vma anyways, use direct vm_pgoff value and vma_pages() rather than linear_page_index. Cc: Vlastimil Babka Cc: Hugh Dickins Signed-off-by: Peter Xu Reviewed-by: Vlastimil Babka --- mm/shmem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 96ccf6e941aa..d2620db8c938 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -856,9 +856,8 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma) return swapped << PAGE_SHIFT; /* Here comes the more involved part */ - return shmem_partial_swap_usage(mapping, - linear_page_index(vma, vma->vm_start), - linear_page_index(vma, vma->vm_end)); + return shmem_partial_swap_usage(mapping, vma->vm_pgoff, + vma->vm_pgoff + vma_pages(vma)); } /* From patchwork Fri Sep 17 16:47:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12502811 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 80DE9C433F5 for ; Fri, 17 Sep 2021 17:24:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 278D9610E9 for ; Fri, 17 Sep 2021 17:24:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 278D9610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8C5C6900002; Fri, 17 Sep 2021 13:24:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 873B36B0073; Fri, 17 Sep 2021 13:24:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 762A5900002; Fri, 17 Sep 2021 13:24:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 547BE6B0072 for ; Fri, 17 Sep 2021 13:24:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 14DC154CB5 for ; Fri, 17 Sep 2021 17:24:39 +0000 (UTC) X-FDA: 78597739878.08.1D36511 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf24.hostedemail.com (Postfix) with ESMTP id B9FE9B421697 for ; Fri, 17 Sep 2021 16:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631897286; h=from:from:reply-to:subject:subject: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=PhwkRZZomqS7IRkM943StXbgZUJTllJV3QENdXcVkKA=; b=L3tPH0byyyQfCZcdeW8gN4QQHYOUXq6UDSQAUE5IBNa07BWdhVVfhHjvujpmA5rbq62oVk 6hZHumlF1tXFrl7/zCcf5x1WYE4BWCSvM8huLWXB1YkyqOGAx4EwzhmcrK/HrOgx9jKRPq 0FJhxAYLyoE9LxTUIoiVn2SPmQfmC5g= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-JICU8WGzOLav_UfQ9DFEYg-1; Fri, 17 Sep 2021 12:48:05 -0400 X-MC-Unique: JICU8WGzOLav_UfQ9DFEYg-1 Received: by mail-qv1-f72.google.com with SMTP id ib9-20020a0562141c8900b003671c3a1243so92263809qvb.21 for ; Fri, 17 Sep 2021 09:48:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PhwkRZZomqS7IRkM943StXbgZUJTllJV3QENdXcVkKA=; b=uzQs7LFdCx/RSzCUbMEN/0OiSwL+o7NK6z90nsVyhWE0HS1dr77hKv12aRKvD6sP5x Ip/MzAupI3/dD2VrMXyOIYNt75MFa06I1LqwScjWoUr3Yu8MK+qjgHf82FiSZAmWCAcC ddpqy6U5GbhG8RKRz7MuaI770trKpsCWhvOkJkWZqKCC5TjKfWxgRCJPvrAs4KUODvZ6 VqffejEQJn3IXjzosR2i7GBlVJ7dpUte5zZN1za5XmYmwLVPthOR0/Y92jnhgRO6wjJp AP4g5D6JhO7U0swMal7wpq73yZwmJZy0SAd0lbicnrzAq83CWzdkywMWen5smm/yy7bC fPjQ== X-Gm-Message-State: AOAM530IfbAX8DJOYEdOMV4DCjXKtRwqDmLT25xdbehiqhihygbct3GU X3+XG4xeXMUXsQivulhkqXRekt9Kpe4WtJPEejYBNnzp3fwYzqqOEQv9L58G3DdR69zeyHbDz4D IrdQWNnWnyqxrhBnPp6ER6Sgr7MVo7ikQChujdvgGZ8VrUfYnnlNJebdBYVGw X-Received: by 2002:ac8:44aa:: with SMTP id a10mr11380285qto.63.1631897284445; Fri, 17 Sep 2021 09:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1nXcUZuUXlV6357X6Rp9A+NjJOAP7ILOrMrY0DUvD6B4OVjkMZ8OBuC+G4k8LXezyzfvUjQ== X-Received: by 2002:ac8:44aa:: with SMTP id a10mr11380251qto.63.1631897284165; Fri, 17 Sep 2021 09:48:04 -0700 (PDT) Received: from t490s.phub.net.cable.rogers.com ([2607:fea8:56a2:9100::d35a]) by smtp.gmail.com with ESMTPSA id t26sm4898057qkm.0.2021.09.17.09.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Sep 2021 09:48:03 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Vlastimil Babka , Andrew Morton , Hugh Dickins , Andrea Arcangeli , peterx@redhat.com, Matthew Wilcox Subject: [PATCH 3/3] mm/smaps: Simplify shmem handling of pte holes Date: Fri, 17 Sep 2021 12:47:56 -0400 Message-Id: <20210917164756.8586-4-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210917164756.8586-1-peterx@redhat.com> References: <20210917164756.8586-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B9FE9B421697 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L3tPH0by; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf24.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: ims1aw4xrdp373chw9t5ogben843cypr X-HE-Tag: 1631897286-249591 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: Firstly, check_shmem_swap variable is actually not necessary, because it's always set with pte_hole hook; checking each would work. 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. Since at it, use the pte_hole() helper rather than dup the page cache lookup. 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. 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; } }