From patchwork Thu Aug 29 16:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13783480 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 4CC6CC87FCB for ; Thu, 29 Aug 2024 16:59:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D33176B00AA; Thu, 29 Aug 2024 12:59:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1B26B00AC; Thu, 29 Aug 2024 12:59:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83796B00AD; Thu, 29 Aug 2024 12:59:17 -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 919B76B00AA for ; Thu, 29 Aug 2024 12:59:17 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4FF5BAA24D for ; Thu, 29 Aug 2024 16:59:17 +0000 (UTC) X-FDA: 82505893554.03.FF4E35E 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 9C06F1C001B for ; Thu, 29 Aug 2024 16:59:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JlaYG4gg; 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=1724950710; a=rsa-sha256; cv=none; b=w3kekuZS/RTDkGPTrd5qzMDxMrLnfXts68Vnn8jEm1Th9HSLK/EtdY//feIZEEJ6JJC6C7 q6DIeUx0B5gFLBqUQ43yt5JfHZZK+KJMzbq+Fgy4oQ0gL0ddaQf5hO/vVMu6r8EfdiuzXi hyFk7HXGXemsaftScTIa+EFzzQlBU9o= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JlaYG4gg; 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=1724950710; 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=MiGCooKskvY1haSoDErYW63CNhCWGlypowkYLoi/78c=; b=4MPmDWhO1hI6TYKkIyTHWJHIN2hREPjodyIGlem226ddnsfw7kaF5Rh0xbhn4c3U/r2ann tvba99WZnKKCPxm+RSuhgz5e3FMN8mBmzIbRjjLWHN8QINJchQFhpNRbKSljvActOUBaYU 9fxL88Z/Qd68woJPzJ60A0b/c6irAEM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724950755; 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=MiGCooKskvY1haSoDErYW63CNhCWGlypowkYLoi/78c=; b=JlaYG4ggMiutZJ6H3Un4SXHxPC9ict6ee9mC22M+8KWxaa/pT67o/trsfeaWk9dm5XRAip q+1f9iqMmcR2SU5/840eeFcbWnQGBCoVo+/ZQVH5mtZUNA9r/iqBJ3Q8/QsZmMMVI8UnTz p2l0peQtI3hsgdMb7iAc0N7MLor8Ed8= Received: from mx-prod-mc-02.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-169-8aXbFsVPOVG-1DFlGxFIdw-1; Thu, 29 Aug 2024 12:59:11 -0400 X-MC-Unique: 8aXbFsVPOVG-1DFlGxFIdw-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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6AE9218BC2D7; Thu, 29 Aug 2024 16:59:08 +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 A5CBF1955F21; Thu, 29 Aug 2024 16:59:00 +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 15/17] fs/proc/task_mmu: remove per-page mapcount dependency for "mapmax" (CONFIG_NO_PAGE_MAPCOUNT) Date: Thu, 29 Aug 2024 18:56:18 +0200 Message-ID: <20240829165627.2256514-16-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-Stat-Signature: t7ccsqigf3ztuhhxqtgsxzkt79gcp5mx X-Rspamd-Queue-Id: 9C06F1C001B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724950755-258858 X-HE-Meta: U2FsdGVkX1+wTt9Zhht0dhYdBiDyspL22VJNKgtvyLuYqPYSM8wBzPq9EZY9VGWovPh3IQEXiqLW9UneRpPIOh7nIUOPUDnjib9L7w14yOrVpqUBIOiL17TZl5RR8Lm8ixRtHKPyOgtNuVgp+DMv1pNT4Fw3ENjtvCAHpEvQxQQWNirfv+aHRdRrEO9xXLyQddZflKQZgoLMy/Fm1nYPoIsQhEc7OMRnbEZhXQYFWJchVB353t5c9NeZIUA9dsq09RV/cvVVxnop6GQYkUvIA5jSCbdj+OnGiOkzccH5tKIXyC60QRGn7y46m651pCJrooovDpui/uETDqTur6v0WyC+KozXrZkcxLFuGki2IWG4rrAR+X7gmLwU8mkQ35PEduq7zP/P9o/odDUXZVGZqUH6hnB3/ZE8XwJwFPz0lGbl0Qqw+7PYIVJUvg/RPhzYT7+ffb1R98VsTctRA6kMCpSY8Ps63jkO1i2Keo5J8NMbOSO/U2SnYSkdI+v2vuRqF0Xr0SEcKc/LGppKAHakvs78xuXW7BOvoUYVAB3pmNqwOXnfQrUMM33tUkt0+Fu8ZcmRa7GOPsIh0IkVqpwm+Nv5ns2nQqcx4YmFXuijSFzRiM+QIWXrdhQ3vKBPXOtrrZAQCs8/WJdLLepQL3Chq/g/5awbH3GtUGqIKPan2TT9bCM014zmuaBacnTgNhrRWEQvcsXrWd3AIc7zCoFe/v9J00a20JO5EStyOIu7Bce49mzUIIVPNsX0ECCUUd0YrNptXVwohOOptjtrkKQsR4Ijcd1JV9PDgXNeMFkQvn+7SMBBWsJaW4MDKwtcm2Xo59Ews6aUGhKUffIktm3fL1W6KwRGV+ANSRoqD8k/1uOzMXZ5yTRyOh/c6Li+IWJkWZFBl2NYQujye1qo75zjlkwR4IgtaUL7C/Pad/gv+0aeTvBvHAnk5h2RZgAUmvmL3krK4OnwZlEYZcJt7HK TzWah3RC GjTliTPPrzJtm662vY/LhUWcJ12crwgTkJHv9Fg1fVZoUBFEokAc3WbphCLNEIUmidO3DFp/3kinQTTMqukV4o/RGgLDDbMXEQBECYwhStPWQr2ladgURu5Uc51qjZUUHmTevBrnfi4TfU/bqcQmd2IkQ5N4JpG2qQ3v0+kCVmab8Y59ZmPgQ5/gMO5TNdn8rpDdwihSDXzCoQ5Z5fP0qfeBK8j0Rf73/3G8cKX/G6SC1jyKZVRa3NhGqaTVUlZh1FLePVB3gXiDRheVnJgso/4cSU8nRVq/ZYrk+IZtSbJIsvCeECmz48ysdywO/A8J4eQdB74KB747qGE0LDwzGVjgKidKObn3UW2JGRWWSo1u27hthK8e9V6afZA== 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. For calculating "mapmax", we now use the average per-page mapcount in a large folio instead of the per-page mapcount. For hugetlb folios and folios that are not partially mapped into MMs, there is no change. Likely, this change will not matter much in practice, and an alternative might be to simple remove this stat with CONFIG_NO_PAGE_MAPCOUNT. However, there might be value to it, so let's keep it like that and document the behavior. Signed-off-by: David Hildenbrand --- Documentation/filesystems/proc.rst | 5 +++++ fs/proc/task_mmu.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index e834779d96115..bed03e77c0f91 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -684,6 +684,11 @@ Where: node locality page counters (N0 == node0, N1 == node1, ...) and the kernel page size, in KB, that is backing the mapping up. +Note that some kernel configurations do not track the precise number of times +a page part of a larger allocation (e.g., THP) is mapped. In these +configurations, "mapmax" might corresponds to the average number of mappings +per page in such a larger allocation instead. + 1.2 Kernel data --------------- diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f35a63c4b7c7a..3d9fe99346478 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2872,7 +2872,13 @@ 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 = folio_precise_page_mapcount(folio, page); + int count; + +#ifdef CONFIG_PAGE_MAPCOUNT + count = folio_precise_page_mapcount(folio, page); +#else + count = min_t(int, folio_average_page_mapcount(folio), 1); +#endif md->pages += nr_pages; if (pte_dirty || folio_test_dirty(folio))