From nobody Fri Dec 19 06:15:31 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 726E1267B78 for ; Mon, 24 Feb 2025 16:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740416208; cv=none; b=YznPt2HD48vGugrAjuCqcC4qC0R2uem/tbvW/KYzjXULBPtzTCisHr5VTcV0Ku2K4UHkZkG8EzwkKv5VyMvUGNUVhcRzhDkWtOZ4CgfMyKZjQ9PkGX3aCgaYCVuh/0Mxjh0uFRZNn2o+tKRCS9oHJAwVW1MoDWH6YKUaq1530GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740416208; c=relaxed/simple; bh=y7rnQn4atWG4y4XI5Y3ZUk4Khub4cSbzFIEKIR0LMHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XkqpscOJtM332W+rP0oci+Bq0bGaNQvs4yyPiQ485629fF7WBq0Zk4/gbgzHO/qmwNiCZGC4lfLK6IhcYMYVwVbfp6ey3b9KVUAa7bRbJHKVZVSjf7YXszoMJS7dsySjIjDP4iXC/9cH9rz50VloFzAnWekkf/g5fFn1Kp1t9IY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XdaJyw22; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XdaJyw22" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740416205; 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=qrzeSAQepC6qjgZK5hS618fC1aWLshwTFA4Bvic/TRg=; b=XdaJyw22qn1YI1B67eVRlYv8jfBqTaRUSs5mAZw22xdTKf5jDI3Pj5Yy7Tme9K6NKvlleP OYZZRXvT+hB97Pb/rix9520a7IBVTcJLfv88Ty99dZLiBCgAAFldgih6BVa3d8WbxE/4HU ZDVlcNxTfCQ1ljj/MbMYxBjcTRS1FM8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-lXb5IYKWPS2L1DyIpSNhbw-1; Mon, 24 Feb 2025 11:56:43 -0500 X-MC-Unique: lXb5IYKWPS2L1DyIpSNhbw-1 X-Mimecast-MFC-AGG-ID: lXb5IYKWPS2L1DyIpSNhbw_1740416202 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38f34b3f9f1so3474982f8f.0 for ; Mon, 24 Feb 2025 08:56:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740416202; x=1741021002; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qrzeSAQepC6qjgZK5hS618fC1aWLshwTFA4Bvic/TRg=; b=eD9boOddVgeFDBqGKwqvA4mfY0tpwB/z/SAsiNrbmRV8DH96vvTvWPqZFNrf7VaMr3 b6LhEY5VWCvf8M3s8WMuotamERUVpcQDHLrB7ULtaYyoLdDoxcnaVDy6WlU94KKVwekN e5gDCRY6oHTTn79iGCc1ts6Gm8sZ6fmsk0SogalCQUsm/Jxtag+N0d6pLNEw2X+1yg3n L4cVSJ0MkEoVjMxuPL7MvKj/6H8mhb2P9IiPQ7mvkxG7gS7I+9bNwA9+rUcYqboKJayH tKLt6zoqdeZK9ngOiOhM+lJi19zRoWsAZwYuB0zY3Fb5PSqweZ+rD2mJZ4n1Kyq8QKzH nOPA== X-Gm-Message-State: AOJu0YxogcOoemZNDuu0uu2pznwR96C6c67iGlyTubvy7r4qZng9T43X GbDgmccndE9LoVuADasJAxm+RejY6D47ngGhy/FSIuWtmIqvlJBPqY5Upyxj6jsc/vwTyxQOaKf qE2hFx3EklwJ+gX1ceSN52C3Q2u4yB57HTxWbqJ9Ot7ZJZA8tHAjXkDsbKW1fiQnU70l7WMsw19 Mi8wUc8FwPACYYdTTiMYVQj6TPcZskoUvM3mHPLAT5NZhV X-Gm-Gg: ASbGncvaR6mshtIiKK8pcy8Wd0QA8aGX9OFFz00+VhwGqA5lfwgIUKOjMwZDH4wsaTY 16NrI3RanO63FjAsTHlTwqaH0oFJm7/axyFDudpTMdYC3WPHKGji26bNBZWEni419GaqgJddyVm q1aagq/ofQDAcJ6qBBImkzgB/CpGZ8udt/snsk2D90VobU954RXTXa/3KJNousdyFoPh3nwin9K J12hoXet/CjJiZRM2jDh9GH+qXcowZ62+hsKhod/hXFG0MU9Z34t9+XO7GF8rTxO7bmaU2/1hsq 3ryzXam2nlTmMhr+scpnLpy0GZksoqP3pLKE4dK+Mw== X-Received: by 2002:a5d:588d:0:b0:38f:330a:acbc with SMTP id ffacd0b85a97d-38f6f0c743bmr12450090f8f.54.1740416202255; Mon, 24 Feb 2025 08:56:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHB6f6br0E5FryNlZozgeR2JsRbAfPcg+xWwWdf/YpxK+ukwffc3aXIkqUDyRFtyhNU8GNoFQ== X-Received: by 2002:a5d:588d:0:b0:38f:330a:acbc with SMTP id ffacd0b85a97d-38f6f0c743bmr12450037f8f.54.1740416201773; Mon, 24 Feb 2025 08:56:41 -0800 (PST) Received: from localhost (p4ff234b6.dip0.t-ipconnect.de. [79.242.52.182]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38f259f8602sm32962279f8f.94.2025.02.24.08.56.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Feb 2025 08:56:41 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Tejun Heo , Zefan Li , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Muchun Song , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn Subject: [PATCH v2 17/20] fs/proc/task_mmu: remove per-page mapcount dependency for PM_MMAP_EXCLUSIVE (CONFIG_NO_PAGE_MAPCOUNT) Date: Mon, 24 Feb 2025 17:55:59 +0100 Message-ID: <20250224165603.1434404-18-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224165603.1434404-1-david@redhat.com> References: <20250224165603.1434404-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 11 +++++++++-- 2 files changed, 18 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. =20 + 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 exclusiv= e to + the same process. Further, some kernel configurations might consider la= rger + allocations "mapped shared", if they were at one point considered + "mapped shared", even if they would now be considered "exclusively mapp= ed". + Consequently, in these kernel configurations, bit 56 might be set altho= ugh + 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 2bddcea65cbf1..80839bbf9657f 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1651,6 +1651,13 @@ static int add_to_pagemap(pagemap_entry_t *pme, stru= ct pagemapread *pm) return 0; } =20 +static bool __folio_page_mapped_exclusively(struct folio *folio, struct pa= ge *page) +{ + if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT)) + return folio_precise_page_mapcount(folio, page) =3D=3D 1; + return !folio_maybe_mapped_shared(folio); +} + static int pagemap_pte_hole(unsigned long start, unsigned long end, __always_unused int depth, struct mm_walk *walk) { @@ -1739,7 +1746,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pa= gemapread *pm, if (!folio_test_anon(folio)) flags |=3D PM_FILE; if ((flags & PM_PRESENT) && - folio_precise_page_mapcount(folio, page) =3D=3D 1) + __folio_page_mapped_exclusively(folio, page)) flags |=3D PM_MMAP_EXCLUSIVE; } if (vma->vm_flags & VM_SOFTDIRTY) @@ -1814,7 +1821,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned lo= ng addr, unsigned long end, pagemap_entry_t pme; =20 if (folio && (flags & PM_PRESENT) && - folio_precise_page_mapcount(folio, page + idx) =3D=3D 1) + __folio_page_mapped_exclusively(folio, page)) cur_flags |=3D PM_MMAP_EXCLUSIVE; =20 pme =3D make_pme(frame, cur_flags); --=20 2.48.1