From patchwork Fri Jun 7 12:23:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689814 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A571CC27C5F for ; Fri, 7 Jun 2024 12:24:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A79A6B0085; Fri, 7 Jun 2024 08:24:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7584E6B0095; Fri, 7 Jun 2024 08:24:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BFEE6B0098; Fri, 7 Jun 2024 08:24:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2A5D66B0085 for ; Fri, 7 Jun 2024 08:24:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1FD4A1C2D01 for ; Fri, 7 Jun 2024 12:24:11 +0000 (UTC) X-FDA: 82204009902.10.9736640 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 745454000B for ; Fri, 7 Jun 2024 12:24:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R8rcyjN0; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763049; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AVo7IPc/OzMgdNcQVcdkp4iZHfQkhLNpmKtGDFarvnM=; b=vIccO8SqSu+vP2cm2E7byUNcvZzLAE/torq87ImUIPQviNNitRaa3FSn/cIhFYePykqqbZ AR5+3Jm0EUPYL/Ak+funapL+FGbvwuTIvNTy/0cLzHDGr/fmICqsQLJsLfLDIsG9ti1pgK JrkCQ+BZhTnCETUEdedo9EGNEbZmyEI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763049; a=rsa-sha256; cv=none; b=aqwNm0042kvQjBQuWuInFQ1ZOaVoNo/uiRHR1AFZRyu6zXmON6cHCFg7Eu1sMZbB3iX7yx APnx2sAN244jtphYvr12zq7DGtNpWQRd7v9DsbRGePmKSfnX6Lfd18iLml/Pj/8/qq2rLb qEobUwQHwITKjSVgcNDvmvFJq9Mqn8M= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=R8rcyjN0; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AVo7IPc/OzMgdNcQVcdkp4iZHfQkhLNpmKtGDFarvnM=; b=R8rcyjN0qjcEVaabi+H7ZIy4UKLTnxs955DKUc0FQSzgg/gOIH/6KH9wCX4GkkGj0EtoKh p57LXJXm/WtpCqvxqMA1N4Rou+oao0S9TNnxdG5Eytjhgqj+60an9BU0pqkjHynEowauHZ U3AgEp6wStqU2u58bJGcf/3rWy/EHfI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-8Lw9Jl3kOiKOKhr_XOiSIg-1; Fri, 07 Jun 2024 08:24:03 -0400 X-MC-Unique: 8Lw9Jl3kOiKOKhr_XOiSIg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 322EA3C025AC; Fri, 7 Jun 2024 12:24:03 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 569D9492BCE; Fri, 7 Jun 2024 12:24:01 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet , "Kirill A . Shutemov" Subject: [PATCH v1 1/6] fs/proc/task_mmu: indicate PM_FILE for PMD-mapped file THP Date: Fri, 7 Jun 2024 14:23:52 +0200 Message-ID: <20240607122357.115423-2-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: in7r758ug7dciwokmwf16uemdhfb1rio X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 745454000B X-HE-Tag: 1717763049-490781 X-HE-Meta: U2FsdGVkX1/X48x/R05f6bSP5VyJ/36JnTo1fg+mDynP0EfmEnGu7Qo+gkFvI/5Z2ZMJVyMzgj+0GZsEvYyH77dZqimrWXYsEKOhPo6E+dSeVyo0T8COMgbjQBFdnB/5OZqu9BBU/dmuoBhSm6HKMlN9PvTiAnUEURxK4GQUTa8Rsoags9QSf+lcvGONfBQee8g+rXseOxZL3u0ZCF9gCjLpGfgLfio3w0bs03yaSiXv4OO+7Frltjq9PelOvZOj9RKjkIzQI8BsXSnx3PwiCDb+8gtgVX2XbJ1Byv+3zIlkHP/IsZUgWJ0PkiklgslZqiaN9Bjn0TWv8Fh/FXMz89f4YpcZKqXd5KGgfEZpDi+XhTa58N1qdolGXeg0AtvxSriOLMx9OYYkGcuRYYkOk9iXuubwaa6Sk587nt5V4jk8Vx/QaSyj6mmm3llkS2eOjvZi/uHoQfi0r2MYJ5FPMw4CRfKh9BYFov6EfLhDLm1GFml5KXXRpucschhpa5SIMo7De8K5bBQU+8y1RcvPNoIF0PVNTR8Ud2pWaAXCnLbOvDlWcbBNXGYyb1FtmafgurCImD2Hlafi7QGXLIqu15EQZX+XewisWJs57C0u3DcryYEmYK70NSmrqBsr5UYAA0fSt2OZd9Q7Et67F5pgo+vxYifptfDsO5eskYZOSl63IS7XIOhP69YsNMgE9UnKmES9gu/OiZND/JNK5jvlREcH4cil0ch3MTzgPLSxCl7/xV6ZRqlCKm5+u73g1GOldV85XkbLEEgIvyr8DvNABtSxIl3n826C5XvKLmPbMdwu633vjQTfG0RzWdWRt1Z1to3LK5U2mjpkl+sVXH5arNwoMkkk+q1ImpdMAhg3kOIa107ErOe08TCjS0D6w+kQ31oheGTaXo4TOshFD7Vj184/In1ECjlJrB2Yn4phLN+iTWeuxYdwNCszkYkA0tO14yZ76OJ55qD1PeAUjzc WHVI9pm6 97RjS+kDaSP1lgHUtPMc/OWhuiMohFYJ3CYDr9ZD6jEwWv1SEJGUNA1IgpP7h47MPLj1W6OAPS4C/M4toxVHuRvs0TQrFJZ8SSBEXAxmUHm7CbbtsfpID6F4BFde8nC//FR+s2qunpqGU2k0v2HyuYQCfRxH09vzaawSHIVnSvQptbINu2HIWur1CZBFG0gTkgfIZRKhDKGrFOwI758YrKi0cZ6BUSxG+1w7/70FErbnf84ewRwxaOfVz0A== 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: List-Subscribe: List-Unsubscribe: Looks like we never taught pagemap_pmd_range() about the existence of PMD-mapped file THPs. Seems to date back to the times when we first added support for non-anon THPs in the form of shmem THP. Fixes: 800d8c63b2e9 ("shmem: add huge pages support") Cc: Kirill A. Shutemov Signed-off-by: David Hildenbrand Acked-by: Kirill A. Shutemov Reviewed-by: Lance Yang Reviewed-by: Oscar Salvador --- fs/proc/task_mmu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5aceb3db7565e..08465b904ced5 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1522,6 +1522,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, } #endif + if (page && !PageAnon(page)) + flags |= PM_FILE; if (page && !migration && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE; From patchwork Fri Jun 7 12:23:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689813 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5499DC27C55 for ; Fri, 7 Jun 2024 12:24:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97A886B0093; Fri, 7 Jun 2024 08:24:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92A496B0095; Fri, 7 Jun 2024 08:24:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CBD56B0098; Fri, 7 Jun 2024 08:24:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5BAE06B0093 for ; Fri, 7 Jun 2024 08:24:11 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E0C87818C7 for ; Fri, 7 Jun 2024 12:24:10 +0000 (UTC) X-FDA: 82204009860.01.19E7AD9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 2E006C001C for ; Fri, 7 Jun 2024 12:24:08 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="h5ym/76T"; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763049; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ovOsFhoeBcVzjRXyHZJ60IBLz8Imu+IZUpS2p2waMJI=; b=QhKROe15cdQL7k/7sYworZ9OXEjlq5h5WD4+MNh+vLkj+WGMFQEfjqmiYlb3b4A11Y9ZSl kHdv0PZwv8FuAeiJXrQ2yCw0zpl0BSna9OvQqmmJORv60WGoQTJnFVzn44nL+H0icPgZjA uhv19nRnVkdRfvSRq86v+YhLRB6MKEE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763049; a=rsa-sha256; cv=none; b=qEbBORjoos55nz7LsVftKvVMX9B4ZABAyrbtr/miaTaSyMs54wW0TfPhJ89xlqqeSMbqJu e5jpGJP/5/eqoA4ce+O90fY+cdFOtTVZXwgHSTmN9kJQOGVu6iXdYCqWeZUdU/iStRYEO8 yTG5MyrHRANM2d4BSEWUVPe/lI2etwo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="h5ym/76T"; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ovOsFhoeBcVzjRXyHZJ60IBLz8Imu+IZUpS2p2waMJI=; b=h5ym/76TXJsV/edPrsvoxZSQN+gSzNmOy3G9eK0fFd7sRKjNMcIiYS57BiI7XWmXDhGNvd bv1rOBn47iI3Dp4dhSNa9qpd0lXZbo81cbgQVReiY1sAHUXmeJscvJyn0vR6OgZ+swcBCX m4zk8YMa916Ghqts4g8koEDkNHbv8KY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-Fs9Zz3hfOzmviTqkwaPypg-1; Fri, 07 Jun 2024 08:24:05 -0400 X-MC-Unique: Fs9Zz3hfOzmviTqkwaPypg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B888A1C05129; Fri, 7 Jun 2024 12:24:04 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A76D492BCD; Fri, 7 Jun 2024 12:24:03 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet Subject: [PATCH v1 2/6] fs/proc/task_mmu: don't indicate PM_MMAP_EXCLUSIVE without PM_PRESENT Date: Fri, 7 Jun 2024 14:23:53 +0200 Message-ID: <20240607122357.115423-3-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2E006C001C X-Rspam-User: X-Stat-Signature: kn955tyridwyhqirykkz3adfjp3zwp6h X-HE-Tag: 1717763048-7922 X-HE-Meta: U2FsdGVkX190oNxdPPdX8LrQuDHNJYtkvv/pm09DL1fXiGWbpD4yWxr+q3nTNeVcTYPvboDyzx/sa2KFYQAcwsDfSjHh6mKNvWsPmHmtdZDoSxU6ag79eF52NFJNWjX1BqJZvJNCvDt2+vLm39vI1Z9TUNI2XwXu88pR5y6fhGpq5hG67HiDddEBmZAhXCOMneymETH3LQCeiqzE/XYR3ylIuHjTdLmFKL4TQ2s4JgLdwshw1bmvA/WbT6mNzJDt3foHrAsD9ePBqec1L2jY+NQm6F+sX9DHOUu+eBmdyhG4cAxBoHK1ZdcekK/kPtNJiLH3gwrSIQLjjqOxOBv+LjYnsBTD+yYvbExcJ6ZZHiWWGFsmx+hkjlmU0qYxtfCIh36S7VQjUBdTigrdf3vqsbJ831M1UL0T3kb5eymaBZ7UDWl4/tjA+U41ziMAAkpx8SKYKIJ4NRHujPpsi/xwbBs8IZMr7CX4pcS30EkRiE4Irw+OzxGU1CejJay/aJrqXIb+hMBf5kPPNI2V5zWfquhRysE4cxDo6oLArPbiR9XtRrJr8qEee3EQ4tuNqBZuGZ/bEJr8F6fdyz9p7aHLTsYZJvNTKC1rTGNCpfeum2WQOFRPXadpWYkuOHLD90r12jGzn0IETJ1QHSKL+qygNT3/Musq8eql/cy/QjofLMKAZNcgmFZsRYwEDd3q71uLJAKpVd7ZWjEFx1mSd2IAzRB1kMC86jqz4jIHBcyxYcD5HmGJkJ5bHpRo7x9nT2uYg64bUYGSN3AGv0ZJZoQtTZSXHzdJ1QeWFpHl6EqOWDg1wUNM8FUAfqRgOFEJTzKb2eYVb6LDEUHW9srCBkNvuLIh77ZJRPPg6qRcQoyabRwS+L+1x2Ccc0+r9mIQaUQpyi4fjioWfy4JuPDwIX9NU5Ar/u7JFKu8q3xOAVwwcFXhwsu1PGJ67iOxKAwBWyUjJGm/UbJ1HDTpvIZzjgw 69Vq1MD7 BRbjENmxGBxpgA9DmFtxnzvn81e7V6iHTMWtWMrxP845fQWQpDTy0t2eaVK45EkfPiI01529qSL4CZsJuYnvtVkHXDupP1aRHu9wxe1XvU3FjlZ/dcUfhRu9jOrqYsdi7P0Yg3vTJRFrrF8ttUSxD7E+JhOmUDY8yMhjopFQQw4sVO2eOBFtgMlXO8q0zngWu/gCQjW1eokvgzZspywVZS2QEUQ== 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: List-Subscribe: List-Unsubscribe: Relying on the mapcount for non-present PTEs that reference pages doesn't make any sense: they are not accounted in the mapcount, so page_mapcount() == 1 won't return the result we actually want to know. While we don't check the mapcount for migration entries already, we could end up checking it for swap, hwpoison, device exclusive, ... entries, which we really shouldn't. There is one exception: device private entries, which we consider fake-present (e.g., incremented the mapcount). But we won't care about that for now for PM_MMAP_EXCLUSIVE, because indicating PM_SWAP for them although they are fake-present already sounds suspiciously wrong. Let's never indicate PM_MMAP_EXCLUSIVE without PM_PRESENT. Signed-off-by: David Hildenbrand Signed-off-by: Oscar Salvador Reviewed-by: Oscar Salvador --- fs/proc/task_mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 08465b904ced5..40e38bc33a9d2 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1415,7 +1415,6 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, { u64 frame = 0, flags = 0; struct page *page = NULL; - bool migration = false; if (pte_present(pte)) { if (pm->show_pfn) @@ -1447,7 +1446,6 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, (offset << MAX_SWAPFILES_SHIFT); } flags |= PM_SWAP; - migration = is_migration_entry(entry); if (is_pfn_swap_entry(entry)) page = pfn_swap_entry_to_page(entry); if (pte_marker_entry_uffd_wp(entry)) @@ -1456,7 +1454,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, if (page && !PageAnon(page)) flags |= PM_FILE; - if (page && !migration && page_mapcount(page) == 1) + if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE; if (vma->vm_flags & VM_SOFTDIRTY) flags |= PM_SOFT_DIRTY; @@ -1473,7 +1471,6 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, pte_t *pte, *orig_pte; int err = 0; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - bool migration = false; ptl = pmd_trans_huge_lock(pmdp, vma); if (ptl) { @@ -1517,14 +1514,13 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, if (pmd_swp_uffd_wp(pmd)) flags |= PM_UFFD_WP; VM_BUG_ON(!is_pmd_migration_entry(pmd)); - migration = is_migration_entry(entry); page = pfn_swap_entry_to_page(entry); } #endif if (page && !PageAnon(page)) flags |= PM_FILE; - if (page && !migration && page_mapcount(page) == 1) + if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE; for (; addr != end; addr += PAGE_SIZE) { From patchwork Fri Jun 7 12:23:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689816 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 326D8C27C5F for ; Fri, 7 Jun 2024 12:24:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70ABE6B009B; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B9F76B009C; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533F76B009D; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 336C26B009B for ; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B22FEA1897 for ; Fri, 7 Jun 2024 12:24:15 +0000 (UTC) X-FDA: 82204010070.26.DFE00AF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 0894B10000A for ; Fri, 7 Jun 2024 12:24:13 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NGxJReQ7; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763054; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yx3Qbyh+Nn+bqmSyWmDh1sWt/uN/FzGydIKvFJPogXs=; b=b7OgUtNMO8EU9FIweMs8rM30YGDXAYYrT9RLvBd40NPL4o0wiO8On+XskOseRFr3CpBhCm LdjKlVGtXGt9wcSmslFoSwZ3zpn/kvyAyWi3BnQ2V/DZIhsGvhteuGq0HytrKth5nJFpEI A9yI8y+MO5B4VTe9Ch0UqopqffxlWUg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763054; a=rsa-sha256; cv=none; b=7M/vHO48odXzucrCGeVUx8k6OenHTkyzxvnrBpmkHL1I/FtwqufvQqGjD7ORJGAJEJbwLQ NwiHru/OS+TKrT/catvk284nLPtkWMe9AtKe08ijzNjGigGHyB3hPWYil2jsUneAn8LhMJ ouSNEMRe87UPEcLBBElGgIjsS5mR1zc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NGxJReQ7; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yx3Qbyh+Nn+bqmSyWmDh1sWt/uN/FzGydIKvFJPogXs=; b=NGxJReQ7qSA7gygIQJUV0d73is1bnUETdCp92xED+fAMCMyhOA8OdulnA82+NB2teddn8t 49jg2tDBjWCHPAWHeN4+IrpZDceVRrG7qUoO2XN8tA8myT6w0Yaruk5c6xF0d2S9xwtGOk M2/P6Zj1thO9Ag6+h57w+jzXcijo+lo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-28-FRJ1tLmeM4SPq5VPjh0mRQ-1; Fri, 07 Jun 2024 08:24:08 -0400 X-MC-Unique: FRJ1tLmeM4SPq5VPjh0mRQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A49BC811E79; Fri, 7 Jun 2024 12:24:07 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0098492BD0; Fri, 7 Jun 2024 12:24:04 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet , "Kirill A . Shutemov" Subject: [PATCH v1 3/6] fs/proc/task_mmu: properly detect PM_MMAP_EXCLUSIVE per page of PMD-mapped THPs Date: Fri, 7 Jun 2024 14:23:54 +0200 Message-ID: <20240607122357.115423-4-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: h9u8jd6bbbwbm37mf7qxwd596xphq9i1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0894B10000A X-HE-Tag: 1717763053-669185 X-HE-Meta: U2FsdGVkX1/e4auVKi828v9Qq0xRohT+5SHB6CjGvKm1LN18ZxL6BbvELW6x9n0Bff2zlE9SzTstNLJxL6eTRFC4swafqKZVFLjHtGfjO3aFkeUhM+DgI8QfNTCoIzISSvlKpc0RFQSHfE1UPQ63qzRlpgul/NwW4k4xzyOrsQA9K3boxHQ9f2B/2ZFxAsZEPezYnlNq2nWM82ThuYZBipG/bzpOCHmXJx1OOtLBN7q5KGProdwH11fnEwo0ONFSwvDef19xO90qZ/4IZh1qjpNHg9FPxkw0fZ39F9lqREWG5yPSuTseiWfKIIb1PbWKmRtRtOT/0UzrHK6M5yYtCDo6cf7Lho6Dd2jI3W0W2/olQR8j8kn8VwS0AMdT7wyr6VaR7IPMif2sU3lIOlk0OwNVcH5rGeDg5HpA/BGPj+6v4mGmr3tCkfyywC0eAjuGnfKyYFHi41F5pV4FhlAOJ9OXqLWudYl5/GirhdoHoJDk8s1HbZYzPNNpabF+SrbOQEqsXz8BGiysEXSAr6MzXpiaDLE3EXV+pPYLkdtH1BycOOXu+7qaGoMbEUBVuWv8Jc/YoyZo6FRcXH4ZLY78O5v/V5G4DWV6V2OHHgSl5ozESKBzsCft0oy3o8jVbkfTWfR6wgpChJpjnxb3t0J4sldI7qTKw59DjIUANPV1K/geB/4RCKztCx/vdcauCdqh3ZZ1Ide7Ijtl6dECe9K9Lv1Fn4Gi3JgquQqMSmTbnMVP+UVMJ1oWqu0M1dW/cN4Jo4AVu7W8Ne0rdjUR6VKGQuHZcPJKyG56vDH8hoRJsSAyG6Yj+0vScevqz1sj/iNEpHbzwKpX2oU1TMmkEXoBqrzm3//lb9TwXe5NXVN93kGor2C3l2y2z+UZW8MafI4PhiPY1Q79B2rvfjSvj35ri18URV8VFAa1ZPcYyuvQ8X1YDI5Oxrx62v75C0ELCdqpLLK1qr6YWLyx9ob6YvF xQP2H7S/ diQaY3R1hl6zq21+Tm7kcmoXUJItOWtuuFqbq7uvQPKLKYTeFqVJJqJr+YJMRbKkA+/Pam1cLKWIkoR/yeWQ1yyVt1BctRjTfyVm2Kw+LCoCo+N9zC8Xm8GTypaHGwtLf/Fm5Jx/ORLF9rwlMyA9Vt3mBfY4diqx+M4CNI4JeuecOOGdT1qGerzuc2I6vp39PExE7BACCeI2beAZuixhTfdV53amDEuoW4ZKplI/mTfbD+qnf0856YF/5MA== 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: List-Subscribe: List-Unsubscribe: We added PM_MMAP_EXCLUSIVE in 2015 via commit 77bb499bb60f ("pagemap: add mmap-exclusive bit for marking pages mapped only here"), when THPs could not be partially mapped and page_mapcount() returned something that was true for all pages of the THP. In 2016, we added support for partially mapping THPs via commit 53f9263baba6 ("mm: rework mapcount accounting to enable 4k mapping of THPs") but missed to determine PM_MMAP_EXCLUSIVE as well per page. Checking page_mapcount() on the head page does not tell the whole story. We should check each individual page. In a future without per-page mapcounts it will be different, but we'll change that to be consistent with PTE-mapped THPs once we deal with that. Fixes: 53f9263baba6 ("mm: rework mapcount accounting to enable 4k mapping of THPs") Cc: Kirill A. Shutemov Signed-off-by: David Hildenbrand Reviewed-by: Oscar Salvador --- 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 40e38bc33a9d2..f427176ce2c34 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1474,6 +1474,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, ptl = pmd_trans_huge_lock(pmdp, vma); if (ptl) { + unsigned int idx = (addr & ~PMD_MASK) >> PAGE_SHIFT; u64 flags = 0, frame = 0; pmd_t pmd = *pmdp; struct page *page = NULL; @@ -1490,8 +1491,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, if (pmd_uffd_wp(pmd)) flags |= PM_UFFD_WP; if (pm->show_pfn) - frame = pmd_pfn(pmd) + - ((addr & ~PMD_MASK) >> PAGE_SHIFT); + frame = pmd_pfn(pmd) + idx; } #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION else if (is_swap_pmd(pmd)) { @@ -1500,11 +1500,9 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, if (pm->show_pfn) { if (is_pfn_swap_entry(entry)) - offset = swp_offset_pfn(entry); + offset = swp_offset_pfn(entry) + idx; else - offset = swp_offset(entry); - offset = offset + - ((addr & ~PMD_MASK) >> PAGE_SHIFT); + offset = swp_offset(entry) + idx; frame = swp_type(entry) | (offset << MAX_SWAPFILES_SHIFT); } @@ -1520,12 +1518,16 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, if (page && !PageAnon(page)) flags |= PM_FILE; - if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) - flags |= PM_MMAP_EXCLUSIVE; - for (; addr != end; addr += PAGE_SIZE) { - pagemap_entry_t pme = make_pme(frame, flags); + for (; addr != end; addr += PAGE_SIZE, idx++) { + unsigned long cur_flags = flags; + pagemap_entry_t pme; + + if (page && (flags & PM_PRESENT) && + page_mapcount(page + idx) == 1) + cur_flags |= PM_MMAP_EXCLUSIVE; + pme = make_pme(frame, cur_flags); err = add_to_pagemap(&pme, pm); if (err) break; From patchwork Fri Jun 7 12:23:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689817 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92BBDC27C53 for ; Fri, 7 Jun 2024 12:24:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E88F76B009C; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE6D26B009D; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C86616B009E; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9CEE06B009C for ; Fri, 7 Jun 2024 08:24:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5059D818D9 for ; Fri, 7 Jun 2024 12:24:16 +0000 (UTC) X-FDA: 82204010112.25.1ABD7EF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id A1976140018 for ; Fri, 7 Jun 2024 12:24:14 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HxrT/ahE"; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763054; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cmTZWHwiI2sG/pKc2jb4R462HpyeqH/IZVxQCS1NoNI=; b=0D1Os9j7lQJm+BWFzoVmPTdTyG9C3UvbvWqo7yyGSVFuMXbOifUCenls3b+UBSads1yxQG s20gUDQzH5pBIsOp6+FlmIEyfRsUkzer/7HC28sEzmmrHofE1HNKlY0m0pEbct6thMBEoK rLk5PBAWfNjFzSsmdOrocndWRPdpLu0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HxrT/ahE"; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763054; a=rsa-sha256; cv=none; b=wyPQrnLOUOxCui1cQhdlWGaVxUVeKSPoWcF+/jHr+kQcypZ092Um2qVpaDztmePUAV0Rgr eDilAi4TG0FXQbp6LBDm/+h6oQjecwIfRc3CWYOqrEnDQxAWammiH6gXv0Re9PUdxcyF8p HjkNYiLbX8PTfxNfbOLqlbsWaGadDaQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cmTZWHwiI2sG/pKc2jb4R462HpyeqH/IZVxQCS1NoNI=; b=HxrT/ahE15jHTfoPIzElX4OYauls5PyyuTclmz0ak0NEVReSmvmWaxK3wUNfIlaB0QgeTe 1SUD3Md8UuSrav791wGVGzV75ulAHR95BnuQnL0OvPQiGIRnNKY20sxsS+D5r/jA1H/lG/ poY00VlHjXe38Ko9IVUB0/ZlBEYAFcM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-338-AAnXGuseOzmHuALWoCvR9w-1; Fri, 07 Jun 2024 08:24:09 -0400 X-MC-Unique: AAnXGuseOzmHuALWoCvR9w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39BE185A5B5; Fri, 7 Jun 2024 12:24:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDC93492BCD; Fri, 7 Jun 2024 12:24:07 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet Subject: [PATCH v1 4/6] fs/proc/task_mmu: account non-present entries as "maybe shared, but no idea how often" Date: Fri, 7 Jun 2024 14:23:55 +0200 Message-ID: <20240607122357.115423-5-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Stat-Signature: dxzst6z7nodmhubuejq7jt761h7skwe7 X-Rspamd-Queue-Id: A1976140018 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717763054-754192 X-HE-Meta: U2FsdGVkX1+uzvuR//6KuKUqGDY2ii6wGF3NNrKrmXP6BhemQsF9mwOvmD0zQmRswkYuYTCKwdSi+Ye0V9s/Wd7eyAsk3o3iJc+dwMU8NvkIoPx3Zt0peo1mfc47PyYxS0ITSiqYhHpWjwYghVZaCHYGOkHcn8rSKur25dpiJiE9YQMgoJLSEjkmlZkks7XPXkeGqtqB8VMomrQcHCqOiDO5FLtPckEX5Hv8TOZqxeoEgFIhH/vcBTTFmF22oKn/e1aXxGkUzq+C1ZRCqX6UsTI0gBWwnrlNt1UPgPk3d7FXdeki4xUVM66L2cAK1li4zN1BxCAC7h4JoFX8wmJA5cvOyTYAEN6omM85M5wecqzkkcCgwCNlzuT8T2CkwP7XBQIpujF/26krl+wGDjOJb5F3F8AXvEPa5MbOAFgkgvn9iPjJzynhpyN8T0dBevUFz0bKKITO0aXl4dNpzH8yHt/b8QfLziTWeMV8+gFu+WwSx2FU9DISUWRhLOX6B7dewPpAvcZh7t7LmmvSLIEZA5dhYRyB+4/j431DtwWJL3UFapnyeiScLQGJaL8/61dIvZtVkOUthMEWCf9NGtNn4O0ptLKv0QPCfIWq9SBghbb0rUQOR4P6xjBKTHoecY0IAYjOITwFW7tur6NCvF3WeSqtv+IEE0NTKCSFCrEP1QHaBE/CMgCmoXATyxIGj0cHEbe6VewrFyXdG8P86eiREzCdFUxSD7kM7ExxvdEXy+YBPS4cNNkI1sx05yyQ90PuTx4RT3b4rOwGtElyNeoyQo+1F+5EZgbQbJnJtr/9FNDiU6TwY6hxTcuk3aYVgIGLlaft1ftlCiQMN3s4ANW2m6i2BknP/LZiH2i5yJK33o9MCqvUMT/BZum+GovtsSUnFr4mwj0jFfUMC+L6CxRO8VDR/CBv/XbvdsGfadSvcQUdIg0427DwbjVjYH2IJdu2Vl20v3lYvCdgojZwJ5p W4bZA68A 1dIZvPOJyQKr3HaBL9R/gAFWh6BUGVWbRGU+O6t5A09NacnTxzacmGPVylojT/AeASWD2Lu0xJh0mBDmtmeX9WpkwpBi3sI+1ckyYsKI3IzdKLxlbQyVZtRcs9ee5NjXvHEZI2C4Uqhvi3vPjyOsbVK2klGkX6X7yyQ+kthQC0cZU33F6o7CqAMnvPN9FmBqZ6ohJyFfh01mYpo9jWpwcU/N5PA== 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: List-Subscribe: List-Unsubscribe: We currently rely on mapcount information for pages referenced by non-present entries to calculate the USS (shared vs. private) and the PSS. However, relying on mapcounts for non-present entries doesn't make any sense. We have to treat such entries as "maybe shared, but no idea how often", implying that they will *not* get accounted towards the USS, and will get fully accounted to the PSS (no idea how often shared). There is one exception: device exclusive entries essentially behave like present entries (e.g., mapcount incremented). In smaps_pmd_entry(), use is_pfn_swap_entry() instead of is_migration_entry(), which should not make a real difference but makes the code look more similar to the PTE variant. While at it, adjust the comments in smaps_account(). Signed-off-by: David Hildenbrand --- fs/proc/task_mmu.c | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f427176ce2c34..67d9b406c7586 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -442,7 +442,7 @@ static void smaps_page_accumulate(struct mem_size_stats *mss, static void smaps_account(struct mem_size_stats *mss, struct page *page, bool compound, bool young, bool dirty, bool locked, - bool migration) + bool present) { struct folio *folio = page_folio(page); int i, nr = compound ? compound_nr(page) : 1; @@ -471,22 +471,27 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, * Then accumulate quantities that may depend on sharing, or that may * differ page-by-page. * - * refcount == 1 guarantees the page is mapped exactly once. - * If any subpage of the compound page mapped with PTE it would elevate - * the refcount. + * refcount == 1 for present entries guarantees that the folio is mapped + * exactly once. For large folios this implies that exactly one + * PTE/PMD/... maps (a part of) this folio. * - * The page_mapcount() is called to get a snapshot of the mapcount. - * Without holding the page lock this snapshot can be slightly wrong as - * we cannot always read the mapcount atomically. It is not safe to - * call page_mapcount() even with PTL held if the page is not mapped, - * especially for migration entries. Treat regular migration entries - * as mapcount == 1. + * Treat all non-present entries (where relying on the mapcount and + * refcount doesn't make sense) as "maybe shared, but not sure how + * often". We treat device private entries as being fake-present. + * + * Note that it would not be safe to read the mapcount especially for + * pages referenced by migration entries, even with the PTL held. */ - if ((folio_ref_count(folio) == 1) || migration) { + if (folio_ref_count(folio) == 1 || !present) { smaps_page_accumulate(mss, folio, size, size << PSS_SHIFT, - dirty, locked, true); + dirty, locked, present); return; } + /* + * The page_mapcount() is called to get a snapshot of the mapcount. + * Without holding the folio lock this snapshot can be slightly wrong as + * we cannot always read the mapcount atomically. + */ for (i = 0; i < nr; i++, page++) { int mapcount = page_mapcount(page); unsigned long pss = PAGE_SIZE << PSS_SHIFT; @@ -531,13 +536,14 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, struct vm_area_struct *vma = walk->vma; bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; - bool migration = false, young = false, dirty = false; + bool present = false, young = false, dirty = false; pte_t ptent = ptep_get(pte); if (pte_present(ptent)) { page = vm_normal_page(vma, addr, ptent); young = pte_young(ptent); dirty = pte_dirty(ptent); + present = true; } else if (is_swap_pte(ptent)) { swp_entry_t swpent = pte_to_swp_entry(ptent); @@ -555,8 +561,8 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, mss->swap_pss += (u64)PAGE_SIZE << PSS_SHIFT; } } else if (is_pfn_swap_entry(swpent)) { - if (is_migration_entry(swpent)) - migration = true; + if (is_device_private_entry(swpent)) + present = true; page = pfn_swap_entry_to_page(swpent); } } else { @@ -567,7 +573,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (!page) return; - smaps_account(mss, page, false, young, dirty, locked, migration); + smaps_account(mss, page, false, young, dirty, locked, present); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -578,18 +584,17 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, struct vm_area_struct *vma = walk->vma; bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; + bool present = false; struct folio *folio; - bool migration = false; if (pmd_present(*pmd)) { page = vm_normal_page_pmd(vma, addr, *pmd); + present = true; } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry = pmd_to_swp_entry(*pmd); - if (is_migration_entry(entry)) { - migration = true; + if (is_pfn_swap_entry(entry)) page = pfn_swap_entry_to_page(entry); - } } if (IS_ERR_OR_NULL(page)) return; @@ -604,7 +609,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, mss->file_thp += HPAGE_PMD_SIZE; smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd), - locked, migration); + locked, present); } #else static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, @@ -732,17 +737,21 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, struct vm_area_struct *vma = walk->vma; pte_t ptent = huge_ptep_get(pte); struct folio *folio = NULL; + bool present = false; if (pte_present(ptent)) { folio = page_folio(pte_page(ptent)); + present = true; } else if (is_swap_pte(ptent)) { swp_entry_t swpent = pte_to_swp_entry(ptent); if (is_pfn_swap_entry(swpent)) folio = pfn_swap_entry_folio(swpent); } + if (folio) { - if (folio_likely_mapped_shared(folio) || + /* We treat non-present entries as "maybe shared". */ + if (!present || folio_likely_mapped_shared(folio) || hugetlb_pmd_shared(pte)) mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); else From patchwork Fri Jun 7 12:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689815 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53AE9C27C55 for ; Fri, 7 Jun 2024 12:24:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D75D76B0098; Fri, 7 Jun 2024 08:24:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFAF36B009B; Fri, 7 Jun 2024 08:24:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4DF46B009C; Fri, 7 Jun 2024 08:24:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 911206B0098 for ; Fri, 7 Jun 2024 08:24:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 42171C18C0 for ; Fri, 7 Jun 2024 12:24:15 +0000 (UTC) X-FDA: 82204010070.21.0B558CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 7380D14001C for ; Fri, 7 Jun 2024 12:24:13 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YpBUm9KA; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763053; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NeGZgl6bcZJYszXPuGofZHugwXu/JCr74XswxhNWa/0=; b=toqJ4mGUE2oiV8R0IdjPThfVpnfVPbdVJgulrMtodDlFjr9qgvlzSRMqfZTl9OHbAJaryK sYm8Wdo4aHbA40saoKMMizwPkIX7byFKKrfr2Nc8AJ87mV5ivJEWDdcE11zp5kg78/mCoA b+S2mB7Dg4H8K9W+pmDMK44+QT2a0Ks= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763053; a=rsa-sha256; cv=none; b=fzpO89vO22PyiM1a2iRnDcihWaDyM7JCSrSH2Cftpcf3xUYIRR5U+IcCtZZ8M1/e0vNErY vTJ9VqhafGiuDXV1lF0xj9uoI3YGLHhiB3oiTArb0hvDj6QJF5fKtgXhunMHxuxdFPLuYW ASXKB+LByYJOTXKe1+2rLo7/3NY3114= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YpBUm9KA; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NeGZgl6bcZJYszXPuGofZHugwXu/JCr74XswxhNWa/0=; b=YpBUm9KA7Pdms+2fdRQjYlU7vdAfVC79xBFWH2VX8dJWrWROP7eanbCIs2Fw7+JALPMp42 MzdIYNjYdGJqJb+GFkmms7vV2lXeaIWw0DO/Je45bkhL1bUKVGOWPqGXc+Unf9TSMIibMx 9NFiZM217uHyuDbSh2tfJ/mnLItLMKk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-PkT7xXgBOK2Dyd-86yhZpg-1; Fri, 07 Jun 2024 08:24:11 -0400 X-MC-Unique: PkT7xXgBOK2Dyd-86yhZpg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00F2E185A780; Fri, 7 Jun 2024 12:24:11 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72622492BCE; Fri, 7 Jun 2024 12:24:09 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet Subject: [PATCH v1 5/6] fs/proc: move page_mapcount() to fs/proc/internal.h Date: Fri, 7 Jun 2024 14:23:56 +0200 Message-ID: <20240607122357.115423-6-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: tf3zi7tyz3mzn68iezxa6gorb6e5azpn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7380D14001C X-HE-Tag: 1717763053-553851 X-HE-Meta: U2FsdGVkX1/HA1WSWg8XpcsFesQwBye6Z0maUyISlqJJIOa2ukOhFFZS/qIhgT6YNCvARGqxbVhnC1NzPveCTpSGCX+3Tx9k9snqgyHmGzyXA+sfV7HScirE3whHv9HXzW6GiQNutKPzZDucVLMEx5NQ1LQR1Cv2KummvmpFGuedNRe5KFgEo76OSntexkg2F+as3sFjeGiWAKQOT4qsAxF8RrG22GoFLGtsHObrjUTJiVB6yPvV2CWQCXcSqHGbyZ5IFThlhV9johtb7Cnc4rebi1zpHRo3G/tNCpkvve0oaPQr0u6nEuSa13y04Hjz7TA811J6YFj+2VyYCxyZZhTeEe0yapxFBbXxsgyAE/RnADMF/lR/97s9INe+wdKAB4uKgHd9+0ywvVhNzeOlRC8gtO3l9Mf+rAF7AivPjTh14ss4wd2wuNYGIxNdL6jzv9FcyhAl4emQicbZL1BENsCrz5nEw34/YP181Bu6Zmtp6QEHb1AUWT2Zx3IobTU6AMqv15X3TtRafVDw8TdvEeACepcn+AoushAIbgV2WR0kKID/oTWq++aFPlicgSfTqWT+3+O5rMnqvcbp9B59jd4nVv+kJGyitJmDEquz3YVsbuTBzDOEmkjMRtPIjyMOiqtDKQnEWMnvPc8dQbrxvYb2I0pveytRZhOj71vjk8QA7U15dRgzXqfwhmF8ofrExiRqhfqpZvJZiH+qPpfaTBgH/t494WxuAtm6n1dNm0INeYN/jcW9NDWoGAOXoOYBLWZkCFUDlL7u7bo77adeazzO3wa/b/kx7rDk6QBlm+Uh07eTAbtRJH1+1N1/3oKr9fFm5ABrFw3QPbv69pEbM4H+HSSJ+/eqw7XPCiXGOjM3RMslp9UJe25YsuwGI8z0FHwu0Nsr1j9EKoipw3+T+zAjmWVNplvXEzM5+tYkEDnkna2J45BJtEJ3ZVUVfHY09TjuxdNURBjv9LJE6Xo x0snW97h r/fBSIXNfzTijGmkj7eGKZWoAa+nMCCZ9+UHtg0O0yypSe7yTDSGhgoFvIdUEJDhLv+7QhOf24OTZXeu0CW0xfx0v+tmZZ6BN0XbSke3tGLkwk7WqI3aSkrNtMmKpmWOUxe4HCciDtWBo6LoTvWnjQdTygMbtDIJ3hql0F316oePobzoly74RTcpbEf8Du75hQGJHUU6O5wddqku/rAWOhD8Fnw== 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: List-Subscribe: List-Unsubscribe: ... and rename it to folio_precise_page_mapcount(). fs/proc is the last remaining user, and that should stay that way. While at it, cleanup kpagecount_read() a bit: there are still some legacy leftovers -- when the interface was introduced it returned the page refcount, but was changed briefly afterwards to return the page mapcount. Further, some simple folio conversion. Once we stop using the per-page mapcounts of large folios, all folio_precise_page_mapcount() users will have to implement an alternative way to achieve what they are trying to achieve, possibly in a less precise way. Signed-off-by: David Hildenbrand --- fs/proc/internal.h | 33 +++++++++++++++++++++++++++++++++ fs/proc/page.c | 21 ++++++++++----------- fs/proc/task_mmu.c | 35 ++++++++++++++++++++++------------- include/linux/mm.h | 27 +-------------------------- 4 files changed, 66 insertions(+), 50 deletions(-) diff --git a/fs/proc/internal.h b/fs/proc/internal.h index a71ac5379584a..a8a8576d8592e 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -13,6 +13,7 @@ #include #include #include +#include struct ctl_table_header; struct mempolicy; @@ -142,6 +143,38 @@ unsigned name_to_int(const struct qstr *qstr); /* Worst case buffer size needed for holding an integer. */ #define PROC_NUMBUF 13 +/** + * folio_precise_page_mapcount() - Number of mappings of this folio page. + * @folio: The folio. + * @page: The page. + * + * The number of present user page table entries that reference this page + * as tracked via the RMAP: either referenced directly (PTE) or as part of + * a larger area that covers this page (e.g., PMD). + * + * Use this function only for the calculation of existing statistics + * (USS, PSS, mapcount_max) and for debugging purposes (/proc/kpagecount). + * + * Do not add new users. + * + * Returns: The number of mappings of this folio page. 0 for + * folios that are not mapped to user space or are not tracked via the RMAP + * (e.g., shared zeropage). + */ +static inline int folio_precise_page_mapcount(struct folio *folio, + struct page *page) +{ + int mapcount = atomic_read(&page->_mapcount) + 1; + + /* Handle page_has_type() pages */ + if (mapcount < PAGE_MAPCOUNT_RESERVE + 1) + mapcount = 0; + if (folio_test_large(folio)) + mapcount += folio_entire_mapcount(folio); + + return mapcount; +} + /* * array.c */ diff --git a/fs/proc/page.c b/fs/proc/page.c index 2fb64bdb64eb1..e8440db8cfbf9 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -37,21 +37,19 @@ static inline unsigned long get_max_dump_pfn(void) #endif } -/* /proc/kpagecount - an array exposing page counts +/* /proc/kpagecount - an array exposing page mapcounts * * Each entry is a u64 representing the corresponding - * physical page count. + * physical page mapcount. */ static ssize_t kpagecount_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { const unsigned long max_dump_pfn = get_max_dump_pfn(); u64 __user *out = (u64 __user *)buf; - struct page *ppage; unsigned long src = *ppos; unsigned long pfn; ssize_t ret = 0; - u64 pcount; pfn = src / KPMSIZE; if (src & KPMMASK || count & KPMMASK) @@ -61,18 +59,19 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src); while (count > 0) { + struct page *page; + u64 mapcount = 0; + /* * TODO: ZONE_DEVICE support requires to identify * memmaps that were actually initialized. */ - ppage = pfn_to_online_page(pfn); - - if (!ppage) - pcount = 0; - else - pcount = page_mapcount(ppage); + page = pfn_to_online_page(pfn); + if (page) + mapcount = folio_precise_page_mapcount(page_folio(page), + page); - if (put_user(pcount, out)) { + if (put_user(mapcount, out)) { ret = -EFAULT; break; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 67d9b406c7586..631371cb80a05 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -488,12 +488,12 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, return; } /* - * The page_mapcount() is called to get a snapshot of the mapcount. - * Without holding the folio lock this snapshot can be slightly wrong as - * we cannot always read the mapcount atomically. + * We obtain a snapshot of the mapcount. Without holding the folio lock + * this snapshot can be slightly wrong as we cannot always read the + * mapcount atomically. */ for (i = 0; i < nr; i++, page++) { - int mapcount = page_mapcount(page); + int mapcount = folio_precise_page_mapcount(folio, page); unsigned long pss = PAGE_SIZE << PSS_SHIFT; if (mapcount >= 2) pss /= mapcount; @@ -1424,6 +1424,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, { u64 frame = 0, flags = 0; struct page *page = NULL; + struct folio *folio; if (pte_present(pte)) { if (pm->show_pfn) @@ -1461,10 +1462,14 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, flags |= PM_UFFD_WP; } - if (page && !PageAnon(page)) - flags |= PM_FILE; - if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) - flags |= PM_MMAP_EXCLUSIVE; + if (page) { + folio = page_folio(page); + if (!folio_test_anon(folio)) + flags |= PM_FILE; + if ((flags & PM_PRESENT) && + folio_precise_page_mapcount(folio, page) == 1) + flags |= PM_MMAP_EXCLUSIVE; + } if (vma->vm_flags & VM_SOFTDIRTY) flags |= PM_SOFT_DIRTY; @@ -1487,6 +1492,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, u64 flags = 0, frame = 0; pmd_t pmd = *pmdp; struct page *page = NULL; + struct folio *folio; if (vma->vm_flags & VM_SOFTDIRTY) flags |= PM_SOFT_DIRTY; @@ -1525,15 +1531,18 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, } #endif - if (page && !PageAnon(page)) - flags |= PM_FILE; + if (page) { + folio = page_folio(page); + if (!folio_test_anon(folio)) + flags |= PM_FILE; + } for (; addr != end; addr += PAGE_SIZE, idx++) { unsigned long cur_flags = flags; pagemap_entry_t pme; - if (page && (flags & PM_PRESENT) && - page_mapcount(page + idx) == 1) + if (folio && (flags & PM_PRESENT) && + folio_precise_page_mapcount(folio, page + idx) == 1) cur_flags |= PM_MMAP_EXCLUSIVE; pme = make_pme(frame, cur_flags); @@ -2572,7 +2581,7 @@ static void gather_stats(struct page *page, struct numa_maps *md, int pte_dirty, unsigned long nr_pages) { struct folio *folio = page_folio(page); - int count = page_mapcount(page); + int count = folio_precise_page_mapcount(folio, page); md->pages += nr_pages; if (pte_dirty || folio_test_dirty(folio)) diff --git a/include/linux/mm.h b/include/linux/mm.h index 04795a5090267..42e3752b5eed5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1197,8 +1197,7 @@ static inline int is_vmalloc_or_module_addr(const void *x) /* * How many times the entire folio is mapped as a single unit (eg by a * PMD or PUD entry). This is probably not what you want, except for - * debugging purposes - it does not include PTE-mapped sub-pages; look - * at folio_mapcount() or page_mapcount() instead. + * debugging purposes or implementation of other core folio_*() primitives. */ static inline int folio_entire_mapcount(const struct folio *folio) { @@ -1206,30 +1205,6 @@ static inline int folio_entire_mapcount(const struct folio *folio) return atomic_read(&folio->_entire_mapcount) + 1; } -/** - * page_mapcount() - Number of times this precise page is mapped. - * @page: The page. - * - * The number of times this page is mapped. If this page is part of - * a large folio, it includes the number of times this page is mapped - * as part of that folio. - * - * Will report 0 for pages which cannot be mapped into userspace, eg - * slab, page tables and similar. - */ -static inline int page_mapcount(struct page *page) -{ - int mapcount = atomic_read(&page->_mapcount) + 1; - - /* Handle page_has_type() pages */ - if (mapcount < PAGE_MAPCOUNT_RESERVE + 1) - mapcount = 0; - if (unlikely(PageCompound(page))) - mapcount += folio_entire_mapcount(page_folio(page)); - - return mapcount; -} - static inline int folio_large_mapcount(const struct folio *folio) { VM_WARN_ON_FOLIO(!folio_test_large(folio), folio); From patchwork Fri Jun 7 12:23:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689818 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE810C27C53 for ; Fri, 7 Jun 2024 12:24:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 758F36B009D; Fri, 7 Jun 2024 08:24:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E7776B009F; Fri, 7 Jun 2024 08:24:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50F066B00A0; Fri, 7 Jun 2024 08:24:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 306756B009D for ; Fri, 7 Jun 2024 08:24:20 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A7DB5403C4 for ; Fri, 7 Jun 2024 12:24:19 +0000 (UTC) X-FDA: 82204010238.21.E565A48 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id F05921C0009 for ; Fri, 7 Jun 2024 12:24:17 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hyWG9H0g; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717763058; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IlZ3OfYfLTtJDLF62yb3XVghB10LN2zpLPX8h3wsziU=; b=U9n+Ma0Z5rtRuVKyBg4Buz4HbaF6z40F5BUW6pz+NVOjuz2HQdGrusKSvVxPceJyyWnsw9 5IosmMb4qwCN7wofg1yaW/3aklohGK3OALRoiW9aWdAPsn08F8AdUqw1gMLEGZS89dywi3 kUaUcsIaBsOaW0QLTYZ/t4ophMVpsro= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hyWG9H0g; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717763058; a=rsa-sha256; cv=none; b=7krIG+1xErSXvR70PUvMBAr022GAevQLQHnn4dyWfu0hjudDaJC6jsb5M8m6N85oAjQ1NQ 5sA85S+tealloVzXFAA6kJo5nZU0809lf8X55XGX162ZG3A9gJrLbVt/MjUWFY1zpQMeZF h1VMUxUkvEIrnS1LweqsEoUdGovdOuA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IlZ3OfYfLTtJDLF62yb3XVghB10LN2zpLPX8h3wsziU=; b=hyWG9H0gxdYi8hYdhy46CwIbZoYiGvu8BryTROQHr+ngKc0MLna7lkoYKpPZJyLu66e+GE z0zGD4Rn65LdF4SotmM5hh3aTO+0Klnkm/LOLYHJRf70i7Kqx8i+nc/cpB0ubd5f11GUkN QVJfTXCgGvSbBers+4zj9fe6JYi3Emk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-Ohcn_-66MiOtK0ykrtlcjQ-1; Fri, 07 Jun 2024 08:24:14 -0400 X-MC-Unique: Ohcn_-66MiOtK0ykrtlcjQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FE221C05129; Fri, 7 Jun 2024 12:24:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A45F492BCD; Fri, 7 Jun 2024 12:24:11 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet Subject: [PATCH v1 6/6] Documentation/admin-guide/mm/pagemap.rst: drop "Using pagemap to do something useful" Date: Fri, 7 Jun 2024 14:23:57 +0200 Message-ID: <20240607122357.115423-7-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Stat-Signature: niyysuajbnpgjr1q7ytkp1ya8x5cfszc X-Rspamd-Queue-Id: F05921C0009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717763057-355104 X-HE-Meta: U2FsdGVkX1+0ceLrFfU/PyUPsYBuZPIn3kdGSYivrExMlCFuSiuOEGTwcEizSvLS2G6szIFA5IfsFNl4vfp8/41Vp3Bj6buj9HGl5LJMj7RrNyxbp2pJLRh7n3JrAD/Hz83BK1OmBEbruF+XJOqlE1khqOGIMyj/ST+nvv11D60ktFUHlbOi+p7Z64QfGF8bRTxpruhYjb3cT2KVIwGQSTi9aV3w8YSEuJFgx7InBo0/vur7fle+hiIAlMEbdylJRZNesjkxoit/62r7Mdn3p2mcn4nz/EuzzTJ6UbEm952ArAtjL27+TwuuZOyodPB4TP6f/NShlWD0oG5gPVsVR36c4jxamCSS7m+7NJGU6Qz/+VHtRNpmQhKPLu6tsvIbC2g+fByYWpvl8+47XHDKdpURXDB4P408gPcDWSVM1Mkwdf3OZeuT5rQiWN3hCw+v3XIesPOL653FOVJR5Xec2yYGFkCdpbiVb9APAoWD1Tcb2GIb2l4HDj/A+ZjeS/tRiZA4b9doZ4/U5BSeeFkgwa8Nrzm8F1BnVRqs5WI+GfMQMxbI/tXE7HXESEyY8tYs9On1SQ8vQ73c/I1ODDgKbM2D541hOFVmfuYyNxiQ2JGPuH/6zHPQNoAQ0Z+7hZ1vY4RbE6LW7Z4hrcYUB71zVDRU9UJ91+gqltu67kPCTWPLCW0c1oFIrTZ0RTK+q3RqEcai+o9HAQso6IQJT+QUZ9K/Sh1lPIDBUHGI+QfJ+kYBOdfU1Or1sF+lXmLy9OxLZb3r+Xokil5X6fUtexJLoJTfaMJxcxe4eGvcB6bzleJWyD75zYl6o1mRlw7EuCX8ZBrnisnQR6HrElLspWxeE4Q7hdADGWjhVwl6IFwGB8D0guYXYBzgUEBrD8N/f2TLmWSOy00UXu8LXh5EV1bxKl86YhRPRFVRmb/y4FvBT3r7Gjbjd7c3qwt6CwLlMl3r6DvFHwpslR/xUHu39Ux SnMV9nP6 VpLRvKwtFnFEq1EpEFZk9N+mYKtZiUCDOAiHiCCq7wXb7bwVrmUnTpXsBGVk25BG/KXs0sX/oqS0geTgeOyhTdfSBL/fSHLtIHnMkAMjHFjIIyUTaYndrYSXLtfj8/PU8FCzK 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: List-Subscribe: List-Unsubscribe: That example was added in 2008. In 2015, we restricted access to the PFNs in the pagemap to CAP_SYS_ADMIN, making that approach quite less usable. It's 2024 now, and using that racy and low-lewel mechanism to calculate the USS should not be considered a good example anymore. /proc/$pid/smaps and /proc/$pid/smaps_rollup can do a much better job without any of that low-level handling. Let's just drop that example. Signed-off-by: David Hildenbrand --- Documentation/admin-guide/mm/pagemap.rst | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst index f5f065c67615d..f2817a8015962 100644 --- a/Documentation/admin-guide/mm/pagemap.rst +++ b/Documentation/admin-guide/mm/pagemap.rst @@ -173,27 +173,6 @@ LRU related page flags The page-types tool in the tools/mm directory can be used to query the above flags. -Using pagemap to do something useful -==================================== - -The general procedure for using pagemap to find out about a process' memory -usage goes like this: - - 1. Read ``/proc/pid/maps`` to determine which parts of the memory space are - mapped to what. - 2. Select the maps you are interested in -- all of them, or a particular - library, or the stack or the heap, etc. - 3. Open ``/proc/pid/pagemap`` and seek to the pages you would like to examine. - 4. Read a u64 for each page from pagemap. - 5. Open ``/proc/kpagecount`` and/or ``/proc/kpageflags``. For each PFN you - just read, seek to that entry in the file, and read the data you want. - -For example, to find the "unique set size" (USS), which is the amount of -memory that a process is using that is not shared with any other process, -you can go through every map in the process, find the PFNs, look those up -in kpagecount, and tally up the number of pages that are only referenced -once. - Exceptions for Shared Memory ============================