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; } }