From patchwork Thu Aug 29 16:56:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13783479 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 F07BBC87FC3 for ; Thu, 29 Aug 2024 16:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DBA66B00A8; Thu, 29 Aug 2024 12:59:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78A156B00AA; Thu, 29 Aug 2024 12:59:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62B756B00AB; Thu, 29 Aug 2024 12:59:08 -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 41E7B6B00A8 for ; Thu, 29 Aug 2024 12:59:08 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 02973160E0B for ; Thu, 29 Aug 2024 16:59:07 +0000 (UTC) X-FDA: 82505893176.06.6554054 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 5508D40002 for ; Thu, 29 Aug 2024 16:59:06 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KkDCLzPC; spf=pass (imf12.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=1724950627; 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=cKf6dQguD8Od23K0wDaepWW4S0v2e9lLNnYaNj5b1cU=; b=He0sIvalODBBQ5s5m1hqVyu85Z8hiHEMbKBYgMhKnDRGzMEklYdBZqGUHNfpes1ym9rm96 3S32gOdUiP1Nb8qq1H7WYd+YxaW4tLSMvbVRgNqe/rm8FO8jp9BanlvuxVPAZOyIScvXqq xl6nkUV/+w1ZtY4Jjy2ANg/rshEj7T8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KkDCLzPC; spf=pass (imf12.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=1724950627; a=rsa-sha256; cv=none; b=y0zJASoXQ0qjZ4042ecn38vQpAb7jw1VWNLzA4EN/YJxRYrxwSEATyAkSwBOf6x1Wsj4cL vsQU62N7CwpeL+FVmGcWv8QxaY1o/nReimHXD3wpSexxt/qeENJNxqn2Mp2K8wDWA39cfe S8LSGBWnsZuXCJiU80d9aRvl6c6vRT8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724950745; 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=cKf6dQguD8Od23K0wDaepWW4S0v2e9lLNnYaNj5b1cU=; b=KkDCLzPCyOL/ZMZ/mXWWsPZs1vxVQbHb25R4jP5ypgTpktuRS/5TOnVz+tu2v1IsbV/tsB 3kqHeCdZA9Jan651uvdUiIRLF4V1yVh5rPMfQUEoxWzg5dxgpmZQSrUEBJ6X4OBw2cvOsK Hlp3nCuenUulRzRZ7xnGWplMMolrqcY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-ui0rW_eRM6iDl2qZZuTgKA-1; Thu, 29 Aug 2024 12:59:02 -0400 X-MC-Unique: ui0rW_eRM6iDl2qZZuTgKA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3AA1D18F498B; Thu, 29 Aug 2024 16:59:00 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.245]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6ACD61955F66; Thu, 29 Aug 2024 16:58:51 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Tejun Heo , Zefan Li , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jonathan Corbet , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Subject: [PATCH v1 14/17] fs/proc/task_mmu: remove per-page mapcount dependency for PM_MMAP_EXCLUSIVE (CONFIG_NO_PAGE_MAPCOUNT) Date: Thu, 29 Aug 2024 18:56:17 +0200 Message-ID: <20240829165627.2256514-15-david@redhat.com> In-Reply-To: <20240829165627.2256514-1-david@redhat.com> References: <20240829165627.2256514-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5508D40002 X-Stat-Signature: sk516785md3n14zzm68sngdbgounsjms X-Rspam-User: X-HE-Tag: 1724950746-436517 X-HE-Meta: U2FsdGVkX19CThm4MuxGRCSoW91eJLeUKn8jupSc7cl+egTx5NJepxHnMP7DSG5tp6u2jVFC1FtwhWdzWFkPBLcCOdW5Tbo4hNndUkgPkcLCblHJBVBG95U2s+kNUXky/TRtwGwF40fEAZS263TOFJ0BKRy8GyaZGp3L9OkQr/CPqiop5VsbA7p6P9TRxCF4LTOMGbk8m9pZkfqTo/MduNYqdwCYrK/1Cq8MRQdgVRA3yO+bQb2J+Kcdu4+wTAghduGsuTp2D6AJ6ydBykZQPe8UAh9Wzc2d/jcFTG7ZGFTLOghMKvF5UdUeB/5HxYxwD1MG1Acy4aOrHfZbxUuy6pWOUl3A6PY+Djd+zf8+lJjubjDM+YbRo9zXCuq0VGwF4BvZjQRJB7JUfv1vd+FEGLWMovjUYWeQju1aDhhyHRPm/XXaFh8R5SUliQyWLHJFb9z07xHBQKn2ujIGnxeSeicSRxIUmYOxiEN3ONwVEn8KqAOpEg3UAVL82RFgnrtEvvG7/CW0lU7DfIGFl/0bH7YPh9lw1Q0LSxR7ZkyTXCEQk6WHN3ucLVugUqhdnurRpAJA1EcAskN03tNyFzXRa0mzV0fRKiv0OKLiTZSBBgsny27Qi6XVA3Yhs/I64x/2zHU69+ioMRHa6oHlyMI9UMLxql2j1dZsFStvJUdB3rPGtJXdC/8Ew6vpUqZWabZutzMVF0mZ8cI8uZoHf3Uc+Kw3PEvEP1eq6hhhR0W4P2NZ/+YTWLEWT/o914Xeo0gVz4/AefHt4EJxsM8tQKqV7xMpWiukpTBJhfdYZx16v4ySq4M3h/+tmr/ugRug2yFT2vqUIlh3sG/GibQ4omT79Ar4ytjqdIiPBuki6ryq2pcFP0aX5wU7pECqcMDYX6Ws/fHQ399R8Zdqcp/hiF/oHRU9A9La6Ar6wge3eNbc1++TPz4vtUZbPypuXJyjYUy0NYPT9bpUdtIk1KZg/PW Xh+fh94I OFsOoVzwhUCN+5oYbbvw0tgvm/mGttDeU2sxqLbVTvi5ABqBQt8CBhVSVtgW/4WRN+Ax1Zz2k9diBYvom1u9mcMb0POZftvX90LbtMxW7McS0UCsTC7t2fzSM42P80CxgAY40+yy9aYdPPnoa+Zw85d/hSnbNfUXcloYuJwryOjSTrVbNYdk8TvXehEHP9vBxFmBeks676SlykS2kNqY3DYOVkqlxY+Kp/iXoFQ5Dt7eo3vCNztK/SU/rq4PIEPhnz9gzneKlGavBg3B4lYG0D0xM2PjD+frEei1O7OkUb/nOGWQHog2awjj+37kClcHKJEErjv7qCZRsjyQYpCZWl3PCXn/uWpQCqeeWZEirdC01cNAGsL6CRdb36g== 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: Let's implement an alternative when per-page mapcounts in large folios are no longer maintained -- soon with CONFIG_NO_PAGE_MAPCOUNT. PM_MMAP_EXCLUSIVE will now be set if folio_likely_mapped_shared() is true -- when the folio is considered "mapped shared", including when it once was "mapped shared" but no longer is, as documented. This might result in and under-indication of "exclusively mapped", which is considered better than over-indicating it: under-estimating the USS (Unique Set Size) is better than over-estimating it. As an alternative, we could simply remove that flag with CONFIG_NO_PAGE_MAPCOUNT completely, but there might be value to it. So, let's keep it like that and document the behavior. Signed-off-by: David Hildenbrand --- Documentation/admin-guide/mm/pagemap.rst | 9 +++++++++ fs/proc/task_mmu.c | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst index 49590306c61a0..131c86574c39a 100644 --- a/Documentation/admin-guide/mm/pagemap.rst +++ b/Documentation/admin-guide/mm/pagemap.rst @@ -37,6 +37,15 @@ There are four components to pagemap: precisely which pages are mapped (or in swap) and comparing mapped pages between processes. + Note that in some kernel configurations, all pages part of a larger + allocation (e.g., THP) might be considered "mapped shared" if the large + allocation is considered "mapped shared": if not all pages are exclusive to + the same process. Further, some kernel configurations might consider larger + allocations "mapped shared", if they were at one point considered + "mapped shared", even if they would now be considered "exclusively mapped". + Consequently, in these kernel configurations, bit 56 might be set although + the page is actually "exclusively mapped" + Efficient users of this interface will use ``/proc/pid/maps`` to determine which areas of memory are actually mapped and llseek to skip over unmapped regions. diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad7b436b..f35a63c4b7c7a 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -29,6 +29,18 @@ #include #include "internal.h" +#ifdef CONFIG_PAGE_MAPCOUNT +static bool __folio_page_mapped_exclusively(struct folio *folio, struct page *page) +{ + return folio_precise_page_mapcount(folio, page) == 1; +} +#else /* !CONFIG_PAGE_MAPCOUNT */ +static bool __folio_page_mapped_exclusively(struct folio *folio, struct page *page) +{ + return !folio_likely_mapped_shared(folio); +} +#endif /* CONFIG_PAGE_MAPCOUNT */ + #define SEQ_PUT_DEC(str, val) \ seq_put_decimal_ull_width(m, str, (val) << (PAGE_SHIFT-10), 8) void task_mem(struct seq_file *m, struct mm_struct *mm) @@ -1746,7 +1758,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, if (!folio_test_anon(folio)) flags |= PM_FILE; if ((flags & PM_PRESENT) && - folio_precise_page_mapcount(folio, page) == 1) + __folio_page_mapped_exclusively(folio, page)) flags |= PM_MMAP_EXCLUSIVE; } if (vma->vm_flags & VM_SOFTDIRTY) @@ -1821,7 +1833,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, pagemap_entry_t pme; if (folio && (flags & PM_PRESENT) && - folio_precise_page_mapcount(folio, page + idx) == 1) + __folio_page_mapped_exclusively(folio, page)) cur_flags |= PM_MMAP_EXCLUSIVE; pme = make_pme(frame, cur_flags);