From patchwork Tue Apr 9 19:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623119 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 31547CD1299 for ; Tue, 9 Apr 2024 19:24:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FB456B0095; Tue, 9 Apr 2024 15:24:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9836D6B0096; Tue, 9 Apr 2024 15:24:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 826326B0098; Tue, 9 Apr 2024 15:24:12 -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 608766B0095 for ; Tue, 9 Apr 2024 15:24:12 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2BFBF80575 for ; Tue, 9 Apr 2024 19:24:12 +0000 (UTC) X-FDA: 81990969144.18.106712C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 6983D20018 for ; Tue, 9 Apr 2024 19:24:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZHSftwi9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690650; 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=xg0rO/waZOgQmZDoxFOYF0uFGKk6lZboizK7nff+LmE=; b=pBEsH8xv9dOcZ80ixBx3+bDIFaItn3yOhX5kmv3hW7VSZr8jDKQZPHJ1BM1KTHbMA02PAN DsKhuOl+P6psb3eGRP7727TYJ3vC6fIBij9Rbr4I1v3trJpDYL+O6IhN7xLsRDBvEeCI/s VAaHBTvBJ0FSj1d+cEILx0ItpVq3Ytk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZHSftwi9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690650; a=rsa-sha256; cv=none; b=8SNeAteu/hCHBGAj412aheBlilGeAkJtH57eGLz2BhM6m6/++jsMVvfDz5A7bMNJPjOn8k DdVg/Q9aJdmz7MkoZlzK8FdBnsItZQB70W2iuYyqdrD+0tg+36KC24Md2xZBQz0ir44vSD dwscF3Il/yr7+r60qtTaLdR2XpciI1Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690649; 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=xg0rO/waZOgQmZDoxFOYF0uFGKk6lZboizK7nff+LmE=; b=ZHSftwi9tCSU7OBRmZHYJZjWPiIa/XFj1ekDyCpXL9raHOq9vjrbW6k1uAmRWtNEziwYj9 aCt6T7+JFAmv1WjzsON1vrPF3RB7THcPhOyjrHRhviz/BlGnJYhiio2JBLKhwGHVSBHdSB V6JjMlwXcKiKetLstEUBnBQcXI9Y5n4= 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-575-RAOsmv4mOp6g3iCo6gpvAQ-1; Tue, 09 Apr 2024 15:24:06 -0400 X-MC-Unique: RAOsmv4mOp6g3iCo6gpvAQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 24D511887313; Tue, 9 Apr 2024 19:23:48 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CD4540AE783; Tue, 9 Apr 2024 19:23:32 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 01/18] mm: allow for detecting underflows with page_mapcount() again Date: Tue, 9 Apr 2024 21:22:44 +0200 Message-ID: <20240409192301.907377-2-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 6983D20018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uehjkd4eef9wfeqn67ayf8f3cphyhw9r X-HE-Tag: 1712690650-217079 X-HE-Meta: U2FsdGVkX19ka4cotuwQPZdhc+Ig967PwlFvyNgkvm/AAvqxesanykhLmeI+hejn1a5iLhrHC5q6JB4oSgFbhy4IIH2u5qZ4zrOz2vxMx2DpTBvSFVD3/el7g3+CgCuqZUZlRGXggRxJblK5ZYdzbbIQ5ilrspzQwG0i+Rvz5J0TXXtgA2+HZZmi789MGVF4HmWmY7CiBIPnoGSzrViZMA2BxM9e7gbLmlWVGBkcnQ1Bbx1tHwt1oXa1YTm+ueFDMQUYbGSww/wlMRfTUrGJaL/WFuMcqDrdZEPktSWqv5zUecFkLuEKuhFPeJz6+Kzu2JQsvtFy63yHXxFUE11L0N9y0fk0H+htVt/xSsBJweoFlsZm5i5SWmmqmoRuI/NcDozatTdySQIa8XYNY0NAZni5yKOPbO0q035jq7NivrwN2EJwp0bvXLOut5i39849gyrB4eEl6scbTYq0PS8TJj+jYuNuuLzIz+Ieu9CB5RcOyO9byGN2YaxZogZ1Pa4c+DBpqGfo9d9njJZyn7aVUQOVKWyIfLpKpnHP+FsZ4/P8k9J2JIx1Jh/muaeDHOSyzRptmLM9v4ZIuJ/+CIL3AnlmBVur/YTouKEpnGqErb2jrpfqif49nShPrzl+F2n7P/QzH9YX45nKAeFW2BIS9GTWKonckW/3GMdMolYND045ETsIDXatiw+38tT3GTg7qsaRwYr+R8oL7eNH3wECXnXYcOmv4BIpfv8LimRF1qQMDuZlombDOX3PFxrQP0G4rIhPBBzMa/Kp0O36SJFq6nKXGj6kSzH/nk+CwXT3i9Q5+YyeVaxqPIV5S0ZiX+l3i1Px9BVMMzz2f3LsjMQwCYqJ5XfOe/o94/Vz/ZgURF6WCI5dgmZT789a9fHJo9kJgvcTT/K0usQ5M0zF5y6EuJYkDwC4WBjI42D8k9CWZJ/DFZ5bl9PJGYgmgMV/fWYJ 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: Commit 53277bcf126d ("mm: support page_mapcount() on page_has_type() pages") made it impossible to detect mapcount underflows by treating any negative raw mapcount value as a mapcount of 0. We perform such underflow checks in zap_present_folio_ptes() and zap_huge_pmd(), which would currently no longer trigger. Let's check against PAGE_MAPCOUNT_RESERVE instead by using page_type_has_type(), like page_has_type() would, so we can still catch some underflows. Fixes: 53277bcf126d ("mm: support page_mapcount() on page_has_type() pages") Signed-off-by: David Hildenbrand --- include/linux/mm.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ef34cf54c14f..0fb8a40f82dd 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1229,11 +1229,10 @@ static inline void page_mapcount_reset(struct page *page) */ static inline int page_mapcount(struct page *page) { - int mapcount = atomic_read(&page->_mapcount) + 1; + int mapcount = atomic_read(&page->_mapcount); /* Handle page_has_type() pages */ - if (mapcount < 0) - mapcount = 0; + mapcount = page_type_has_type(mapcount) ? 0 : mapcount + 1; if (unlikely(PageCompound(page))) mapcount += folio_entire_mapcount(page_folio(page)); From patchwork Tue Apr 9 19:22:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623118 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 C9945CD128A for ; Tue, 9 Apr 2024 19:24:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 678B46B008C; Tue, 9 Apr 2024 15:24:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6285A6B0093; Tue, 9 Apr 2024 15:24:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 516CA6B0095; Tue, 9 Apr 2024 15:24:10 -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 2FD086B008C for ; Tue, 9 Apr 2024 15:24:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 92CCBA0569 for ; Tue, 9 Apr 2024 19:24:07 +0000 (UTC) X-FDA: 81990968934.07.C583253 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id E7D17160017 for ; Tue, 9 Apr 2024 19:24:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HbQ8J0GV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690646; 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=omUW48lRIosbAMPj8czTvBZpGDzoyoLuJmkkL5iPx/s=; b=GaJ+WLNBFW5A8IKlgpEfvxfnIDQM5O/Lk+BSoBUnyrqjvG193SD+hibbY3N2lkGRofXan+ Ydt3fh7bzwwpqiwjz5EcZ1c1kdDuEGnnkAhisIjHd3pBwPu3ZRT/mp9rUo3rhrkTmmkyuG SFBOO2/B9eQb6PvMGiO+NbKRMCVTVUY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HbQ8J0GV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690646; a=rsa-sha256; cv=none; b=Sa84EiugOFXl2auS5b85BmM4xHKWTnHyTufJBhc7l0YkF2fr1doa1TJOEFCBFIVIRJVMf9 5oBse5HOvv967NwN9zmmES5F+E6k5vBPWq7NRwqG3xPM3/qGim2RS3dtyBk76SVulc99Xc NzEXZZSlBzssXBiAKhmTwmucC8TLV7s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690645; 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=omUW48lRIosbAMPj8czTvBZpGDzoyoLuJmkkL5iPx/s=; b=HbQ8J0GVQ8w2hxM+l8xHn5f/aM3NCN/vVYt1YDiia6yh7QE1MQIbBw+wR4ugI2dOXoN/gz l94dlY053kZ6Ytb+O+HzXC8gu7FS/wmcAewPTAJjcFVoL0cGoNjN/FV9v6n/Uq/W2n910y Fz/RF4T0+y65GsyBL2zg7g0pRXNVG+8= 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-312-_0ZSgaEpNaK-itip1P_sGw-1; Tue, 09 Apr 2024 15:24:01 -0400 X-MC-Unique: _0ZSgaEpNaK-itip1P_sGw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 DE82338000A3; Tue, 9 Apr 2024 19:23:59 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D8CB40AE78D; Tue, 9 Apr 2024 19:23:48 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 02/18] mm/rmap: always inline anon/file rmap duplication of a single PTE Date: Tue, 9 Apr 2024 21:22:45 +0200 Message-ID: <20240409192301.907377-3-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: E7D17160017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: n8m4t9ibrf487ib4cfoakc7ofsk34z8f X-HE-Tag: 1712690645-839801 X-HE-Meta: U2FsdGVkX1852oMa9BzhwJchXYWlVVmIjiTo6sH+f24VTOA4RGnzJaAYRq0ofChlQbOFQRtQ2cFOkZ7/Wl6nRdcTLdqoEt3Q+N0OEaed+5zKK3L+kAlQnsKIzpoZEXdzPTQnOwZHg1cKQ8Bxw6q9ebcjDrLqmEA88FDlzRbwk7Yf4nFig5bvjTk5F6Yx1zMMqhnbwGQ22NjX+NZz1NeNYLw9a9j33x3YQVcwmIBj3DQ5zq+rNlq7a8vZ1dXLwa+pDeKJ/7H46A/M0H/i5JOJiaWlsMyizLPyjuPKXxmanTfbBhd1nkr0haK+Ign3C7aCl21mP1YXVUJrtUNADJXZ67fCIDWrtxxNzKhmFBRkDp8/j2bj2bA4YIzhgcIUuj25Psn442aKVOJBD1j2qeTlPv6Twa4yUgtIrlVCQtCg+jIiVfdsJn6akATGLkCaQh8l3cPm+6a5Tko7NSstg3WYW1II3DBF0Bbr8dB93cynDkjH5flCoZhtZUGY3PG6WI89oaMv66YoZkEhfayJS1X2YXwYtvhIy5aKJ0zQPgg81ul6IsWDvCFaSZduX2gH1Dqdwft7/azdOCuhT73J1CINb2weQMdRQV5fSsLB0yYtD1a1VDXy3XMbICMJ078OGOv/15TtHNiY6FD79A7ZHPETVjqMbDLqo6UE998p/nViEWNRIkbuOwIOX9F8Z0UQBSzVURKWBIReVygXP+ycJGxKrdlKUPE+NlhZ0UZlSwHeuA6pCl+tJHmiSFxry3VTtckQmpa3ncIfxzSzHeCjO3uFVTfNEZNAkZUS0cVIzSIRJ54ogcleObbCmrwpE2QOhbxquTscqiAK9WbqM120rqDPFB6fUOjnJN96696chD00SltRG8PlQRNfiaqBDBM30ND7VJSN1baudrXCPt05zj7R+RByuYQ3CO25d+UupQ3l0E0lsLjhjDW1tL6+k7Us1pXuUfved6H0RiZFnI9EPy0 MFYeslFG /u+S1YqftZx9zDf+lUVxlWDcpVuQUpUvGHjnaquflc/xzFmHwgEgmdKMzCg7KlOdxiyZ8dg5eSPLL7CnHTXhA3qrGchFLDSlWOaWa/45Fv99S37+KWHcHUcRzyxxz/zYxsdiurRZAAfCHd2Dt5Mc9NRMxqM7pgq2dWUeckg6SSQ8Vfwo= 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: As we grow the code, the compiler might make stupid decisions and unnecessarily degrade fork() performance. Let's make sure to always inline functions that operate on a single PTE so the compiler will always optimize out the loop and avoid a function call. This is a preparation for maintining a total mapcount for large folios. Signed-off-by: David Hildenbrand Reviewed-by: Yin Fengwei --- include/linux/rmap.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 9bf9324214fc..9549d78928bb 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -347,8 +347,12 @@ static inline void folio_dup_file_rmap_ptes(struct folio *folio, { __folio_dup_file_rmap(folio, page, nr_pages, RMAP_LEVEL_PTE); } -#define folio_dup_file_rmap_pte(folio, page) \ - folio_dup_file_rmap_ptes(folio, page, 1) + +static __always_inline void folio_dup_file_rmap_pte(struct folio *folio, + struct page *page) +{ + __folio_dup_file_rmap(folio, page, 1, RMAP_LEVEL_PTE); +} /** * folio_dup_file_rmap_pmd - duplicate a PMD mapping of a page range of a folio @@ -448,8 +452,13 @@ static inline int folio_try_dup_anon_rmap_ptes(struct folio *folio, return __folio_try_dup_anon_rmap(folio, page, nr_pages, src_vma, RMAP_LEVEL_PTE); } -#define folio_try_dup_anon_rmap_pte(folio, page, vma) \ - folio_try_dup_anon_rmap_ptes(folio, page, 1, vma) + +static __always_inline int folio_try_dup_anon_rmap_pte(struct folio *folio, + struct page *page, struct vm_area_struct *src_vma) +{ + return __folio_try_dup_anon_rmap(folio, page, 1, src_vma, + RMAP_LEVEL_PTE); +} /** * folio_try_dup_anon_rmap_pmd - try duplicating a PMD mapping of a page range From patchwork Tue Apr 9 19:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623120 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 8FF2BC67861 for ; Tue, 9 Apr 2024 19:24:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 232A16B0098; Tue, 9 Apr 2024 15:24:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BB5B6B0099; Tue, 9 Apr 2024 15:24:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00DD86B009A; Tue, 9 Apr 2024 15:24:16 -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 D66416B0098 for ; Tue, 9 Apr 2024 15:24:16 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7501DA0DCB for ; Tue, 9 Apr 2024 19:24:16 +0000 (UTC) X-FDA: 81990969312.20.F9D333D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C51C1A0016 for ; Tue, 9 Apr 2024 19:24:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cR4Nt0zU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690654; 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=DanfdMkK2y8X/5UQWi5wxydKuxMzBBZcoNekt2NzNQo=; b=q95xjLDeYSeNlqDv4IPkVa6lFo7YwEyGmQ0RBPIRiNyjXV7iJWb8j0x6hj903sAWgP4Abj fL9UQZOQefoMv/b06IAfkiSzzxxSWA6pt+51uRLqY0QLPpPBl7tH9D5CbDmD/CKpJvpRqK iu9vsEb6cdN8rGFihuxRur1lQsR9TD0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cR4Nt0zU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690654; a=rsa-sha256; cv=none; b=1wzlPXHLq0KxAN8J//64JHguIpwG78RERgKIhDy68xqZk8uXv9irijcX0bRRiDq6SNvvpM tRNArd99wsZhPK7BD/n+sLTIwnnvrwOuIgGzvCNoTrRWJlToK2vtrQKTws2R2NfTMzYlgv 2zgxCQHxBdMItbU6BtEfQLABcOgzUYc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690653; 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=DanfdMkK2y8X/5UQWi5wxydKuxMzBBZcoNekt2NzNQo=; b=cR4Nt0zU9mOStfjO1xhb+ffD7bEhX68DET43WdhVOV0xItKGkNnoQ533mXO9Gpr1Dcx+L0 8fIIxmELZvhu7G+rYd4uAqyyDrWRb+2iecM8ZKXPLKHNa0v6jCUDmZqSh1KJjyDiO0wK45 2NR/lFcnVW2Bzb02W6IzUcXRHZHBpm0= 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-140-eJSj8LVjMUGt1dEE8jgGSA-1; Tue, 09 Apr 2024 15:24:08 -0400 X-MC-Unique: eJSj8LVjMUGt1dEE8jgGSA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 E743E806604; Tue, 9 Apr 2024 19:24:06 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CAAC40B4982; Tue, 9 Apr 2024 19:24:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 03/18] mm/rmap: add fast-path for small folios when adding/removing/duplicating Date: Tue, 9 Apr 2024 21:22:46 +0200 Message-ID: <20240409192301.907377-4-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 4C51C1A0016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 93qdyq3q7gemt3wmkcytmozquj5mt8e9 X-HE-Tag: 1712690654-824703 X-HE-Meta: U2FsdGVkX18t9n19zhFccy6ih/2H0x/I3e2Mjfu1z0khI2KTruzISXFbYGMCrxOvlVEVSuSF6jHEQhvUWf+9TbBM4a2iVu8Goe4RdQtsb9ZCTxOwNn4x3DJZnO+ED7F2+H2aq9T/zxStvVMah7+wiWo+sStFBhDQOxKSdK3aY21opzgBi+VOPo7dzQzfSKTewX0Y7sKujbDrzcrF+QPRdEOLvqDutccl6cu9GT8sopEjPQGwmLX1NAdwXK0jJB43ub3TWxidFR8qLKB/pBm847I4w0BctrvymV4uBB4c6WCWBariqUfABQloBHK/dEIupr4c7WCYluy9Gvta8s8b2Md8eFRfR2uLvrWd9EXqDlSaPJS8wpEUcNGbwdDI9qDCw24U7DQ/br7NuZXqVi0WMJQbxilSY5l2N0SXQwsUDWZ2ape5XfwGFbwHdhBUwsNpWhTYqt3LzeILI1mhMaFSKSatxEzpz1vL94CT0JyZrLPh4ALGUX6A/OWw/Lnf+aWEf5zTVhAmKuYt+WYaWEssslLMHSBbEbVmRKl+mbeFjeHvaQRcEG+H+fpWB7IHRTJkSOYlfLVo+TDNvTLY8cO+BPnP/q1r2iLVRgsoaijUUnDFVmXdRvi50jOvkFdpq8Cug23QuJyEM2cbpHgUn1AbwkeKHHghhJ9MdCN60Ri4RmAOOkYpndVqdUFQfyN18oSHMHwVtIUlICvyVCqUd8eNjE2I7TKzXGv8NE0tg+5IO+2hh3WoaQLh+DQv3gUf83zryMC6hpCwtlfGZGnVbmtnA3jx04bN0XJ2+ib7Q1+pT2U3s5FfuVw5DfgnrENJtZjuIXeD9TC9tXiAgP399t2v6f47/nXuxmWc7EvNl4c3TtrJhuZXADJpKatOFNp3I2YY50z6TwMvywMsQ+AM7EriRZUsAnLFEp/1WKQLR5Yh2cz4TPdBHNRgrFiemgjyUcXNEGgXcy7T26Cvz9q6yVz 7FFyFesy 0Baz0LaD9t6h/kq+3n80qlI0YRLobrlrkHO1pLH8PVFu9STYafrCgtCpudY3VZjWclohsMa1w2Hzkhk039wYGbGeBx94gHhW8j3gv0rPtaTWxoeK1IXD8+H0SVjGLmJ+IaTteepo1dWb3qy9yhXSeF03sZa2P5YqbgM75DtG8bxuzld4= 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 add a fast-path for small folios to all relevant rmap functions. Note that only RMAP_LEVEL_PTE applies. This is a preparation for tracking the mapcount of large folios in a single value. Signed-off-by: David Hildenbrand Reviewed-by: Yin Fengwei --- include/linux/rmap.h | 13 +++++++++++++ mm/rmap.c | 26 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 9549d78928bb..327f1ca5a487 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -322,6 +322,11 @@ static __always_inline void __folio_dup_file_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + atomic_inc(&page->_mapcount); + break; + } + do { atomic_inc(&page->_mapcount); } while (page++, --nr_pages > 0); @@ -405,6 +410,14 @@ static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio, if (PageAnonExclusive(page + i)) return -EBUSY; } + + if (!folio_test_large(folio)) { + if (PageAnonExclusive(page)) + ClearPageAnonExclusive(page); + atomic_inc(&page->_mapcount); + break; + } + do { if (PageAnonExclusive(page)) ClearPageAnonExclusive(page); diff --git a/mm/rmap.c b/mm/rmap.c index 56b313aa2ebf..4bde6d60db6c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1172,15 +1172,18 @@ static __always_inline unsigned int __folio_add_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + nr = atomic_inc_and_test(&page->_mapcount); + break; + } + do { first = atomic_inc_and_test(&page->_mapcount); - if (first && folio_test_large(folio)) { + if (first) { first = atomic_inc_return_relaxed(mapped); - first = (first < ENTIRELY_MAPPED); + if (first < ENTIRELY_MAPPED) + nr++; } - - if (first) - nr++; } while (page++, --nr_pages > 0); break; case RMAP_LEVEL_PMD: @@ -1514,15 +1517,18 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + nr = atomic_add_negative(-1, &page->_mapcount); + break; + } + do { last = atomic_add_negative(-1, &page->_mapcount); - if (last && folio_test_large(folio)) { + if (last) { last = atomic_dec_return_relaxed(mapped); - last = (last < ENTIRELY_MAPPED); + if (last < ENTIRELY_MAPPED) + nr++; } - - if (last) - nr++; } while (page++, --nr_pages > 0); break; case RMAP_LEVEL_PMD: From patchwork Tue Apr 9 19:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623121 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 AE22AC67861 for ; Tue, 9 Apr 2024 19:24:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 408066B009A; Tue, 9 Apr 2024 15:24:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B72E6B009B; Tue, 9 Apr 2024 15:24:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2582E6B009C; Tue, 9 Apr 2024 15:24:36 -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 035956B009A for ; Tue, 9 Apr 2024 15:24:35 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1F38D140182 for ; Tue, 9 Apr 2024 19:24:34 +0000 (UTC) X-FDA: 81990970068.06.CF5DC75 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 400384000F for ; Tue, 9 Apr 2024 19:24:32 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gvS5lACJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690672; 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=sssR1z2Cns5/cDlwFg0C+rTVPaBVC9TbP1UmPuFLGM8=; b=uXHOYk1ExrfZBSpg2RNk0m0MLLFRDrgkV9Od6e9iPA1N1ccO8j0t5DdwXWONpiMLcUcyEi V3yofMpgPasJRtuftNJhOEWdHNjltYdtFb0FJuhW+KzLSEbBKz6zL5VakVfPfBdES99qNe 8Rt6SSum3I/GDJT01J89uhJiyv20HM4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gvS5lACJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690672; a=rsa-sha256; cv=none; b=VvjMtEqjMFy3P8T8kvKquNNRdps4onBt5GjYioACsSQt4eKmn6TQAkDul8mSCwOozficYC q677mHf2ZJw0+F2s2jZozsxgoWSWb1heCS+e8IclY2lZsJkAt6A5RlopaID8vAh4IHOb+6 G9e3kFQOECC4LvLMiZ5yxXCXwIQQ8ts= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690671; 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=sssR1z2Cns5/cDlwFg0C+rTVPaBVC9TbP1UmPuFLGM8=; b=gvS5lACJZdZpqZfNiE3gaqr/mcHpJ+XqP1aG4HpkfbuibyHPsy7u3EbBFZcv8HhBPAEdXT dM/OwrymA6tZlQVPquCgICU3salU+sz9ZmNeIsCspvsYTdUQAq2RZtS59hRdV1cV7jXcTw Im7KV92wDNgH2cndby3YdEwUgp6lTjo= 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-16-tXAOl0sKNr2RokYkQkyf6Q-1; Tue, 09 Apr 2024 15:24:23 -0400 X-MC-Unique: tXAOl0sKNr2RokYkQkyf6Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A202A3C025AD; Tue, 9 Apr 2024 19:24:22 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3405E40B4980; Tue, 9 Apr 2024 19:24:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 04/18] mm: track mapcount of large folios in single value Date: Tue, 9 Apr 2024 21:22:47 +0200 Message-ID: <20240409192301.907377-5-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 400384000F X-Stat-Signature: hec5dfh53xwadx3ur416t8xxqjyj3w6h X-HE-Tag: 1712690672-203581 X-HE-Meta: U2FsdGVkX1+kDN59MODF7lGjUMfqHxkxvimMKAtdbkLKIkOn0RkdXxcQ5kwcwoAyNvos8gP9APS9RMNrWi90qUf1OdBNx2ka1sNj2d1pPFXUOMZ0bMHpeNYCTHd0OBJJNQCnhTLvMM3BAyhIJ5oIFQfMHS15wvx25F8h3lx1XkMR1Od7JUGhDXbzAkehTzLVq8yb7MAw2T9xWEByzsDMTafQ3MNTuzzoeCEHdgkGT1ZAb5RBo+LAtgO6TuoyjhqbUKJZHcC8h48T6gvBLYtXxpHudW4KaNvcaV6S4WOm9RM/+0JnFKiQUNVWOOQU/9fh5HYjH+IvLYRsUFAj/HWzDgbv8RDwjdhujG/GK/AudBISQkeMbXTWt2PAcMzzaLiK3IgKs85ftYGVtOWGB+BJAnHSV3sDQCyctD4O0Mx7EmdWiOZVzRaqzN6+XKDYA12vX3OTlmMVQnoey9h9EfiIZbJGCLQTVM42v5orl7RhVvYGruxg105anNu8wLlrq63Fydpg6JiulA7IAWypQxdcmbWTVZzf+Qrc6OpWcrLHnxGd9/yjdUyoVAbo/whZlTOT1YRXb+ldmwB07C6hBz4e2OfqpowiujDQMBZhjG/MqYO47f0otn4dy8nLOurPFh0kQOoBBn+cYCZrCS2P2L2tgMA5qOex8qNM2xLgI8Hv8F/OzokeGcJKRIemk8LlljAfuTwP+4Wljm4T6aO4ECUCbPQgPZvyTAV00lqXOhI0jCNFysLFsnpOjUo/wKoxC88jmJXetFU8ZM2Ez2yX2cWgTV4Bd3jnuax8TsAyao9JbipYd9sCfB+cLgXKwsL6lfwsuzBRuT2mtyihUOJjEmFJwDFWg8BsiFz4IqYnk7RivgPZRZ7ExMx5eQOaaMAwt0L52kFYdeD2jEXRZc9ZNTN5mFsv6PTzyeOtgdNT27O9V9GSiULSnCmtSKwvIgjMjJHioOkDR/21kUExNIoMuO7 RFJe+84p g1YOfc+XTWV1h01zxLrh/YN+CFeqwHpgTTPNU4nN1WGj0A6u6gX+rq64BAMC8gJ2B/O0+DB2DhVHDXlycTxgktYDTuf6TUI6Eu+l3/U1Dau277q6Bi6PQ3VSO3CorlbAvAED5EPHYMpnWBY74iQo6sbMRoSnWVX9koN4UNAkDxw67ZLE= 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 track the mapcount of large folios in a single value. The mapcount of a large folio currently corresponds to the sum of the entire mapcount and all page mapcounts. This sum is what we actually want to know in folio_mapcount() and it is also sufficient for implementing folio_mapped(). With PTE-mapped THP becoming more important and more widely used, we want to avoid looping over all pages of a folio just to obtain the mapcount of large folios. The comment "In the common case, avoid the loop when no pages mapped by PTE" in folio_total_mapcount() does no longer hold for mTHP that are always mapped by PTE. Further, we are planning on using folio_mapcount() more frequently, and might even want to remove page mapcounts for large folios in some kernel configs. Therefore, allow for reading the mapcount of large folios efficiently and atomically without looping over any pages. Maintain the mapcount also for hugetlb pages for simplicity. Use the new mapcount to implement folio_mapcount() and folio_mapped(). Make page_mapped() simply call folio_mapped(). We can now get rid of folio_large_is_mapped(). _nr_pages_mapped is now only used in rmap code and for debugging purposes. Keep folio_nr_pages_mapped() around, but document that its use should be limited to rmap internals and debugging purposes. This change implies one additional atomic add/sub whenever mapping/unmapping (parts of) a large folio. As we now batch RMAP operations for PTE-mapped THP during fork(), during unmap/zap, and when PTE-remapping a PMD-mapped THP, and we adjust the large mapcount for a PTE batch only once, the added overhead in the common case is small. Only when unmapping individual pages of a large folio (e.g., during COW), the overhead might be bigger in comparison, but it's essentially one additional atomic operation. Note that before the new mapcount would overflow, already our refcount would overflow: each mapping requires a folio reference. Extend the focumentation of folio_mapcount(). Signed-off-by: David Hildenbrand Reviewed-by: Yin Fengwei --- Documentation/mm/transhuge.rst | 12 +++++----- include/linux/mm.h | 44 ++++++++++++++++------------------ include/linux/mm_types.h | 5 ++-- include/linux/rmap.h | 10 ++++++++ mm/debug.c | 3 ++- mm/hugetlb.c | 4 ++-- mm/internal.h | 3 +++ mm/khugepaged.c | 2 +- mm/page_alloc.c | 4 ++++ mm/rmap.c | 34 +++++++++----------------- 10 files changed, 62 insertions(+), 59 deletions(-) diff --git a/Documentation/mm/transhuge.rst b/Documentation/mm/transhuge.rst index 93c9239b9ebe..1ba0ad63246c 100644 --- a/Documentation/mm/transhuge.rst +++ b/Documentation/mm/transhuge.rst @@ -116,14 +116,14 @@ pages: succeeds on tail pages. - map/unmap of a PMD entry for the whole THP increment/decrement - folio->_entire_mapcount and also increment/decrement - folio->_nr_pages_mapped by ENTIRELY_MAPPED when _entire_mapcount - goes from -1 to 0 or 0 to -1. + folio->_entire_mapcount, increment/decrement folio->_large_mapcount + and also increment/decrement folio->_nr_pages_mapped by ENTIRELY_MAPPED + when _entire_mapcount goes from -1 to 0 or 0 to -1. - map/unmap of individual pages with PTE entry increment/decrement - page->_mapcount and also increment/decrement folio->_nr_pages_mapped - when page->_mapcount goes from -1 to 0 or 0 to -1 as this counts - the number of pages mapped by PTE. + page->_mapcount, increment/decrement folio->_large_mapcount and also + increment/decrement folio->_nr_pages_mapped when page->_mapcount goes + from -1 to 0 or 0 to -1 as this counts the number of pages mapped by PTE. split_huge_page internally has to distribute the refcounts in the head page to the tail pages before clearing all PG_head/tail bits from the page diff --git a/include/linux/mm.h b/include/linux/mm.h index 0fb8a40f82dd..1862a216af15 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1239,16 +1239,26 @@ static inline int page_mapcount(struct page *page) return mapcount; } -int folio_total_mapcount(const struct folio *folio); +static inline int folio_large_mapcount(const struct folio *folio) +{ + VM_WARN_ON_FOLIO(!folio_test_large(folio), folio); + return atomic_read(&folio->_large_mapcount) + 1; +} /** - * folio_mapcount() - Calculate the number of mappings of this folio. + * folio_mapcount() - Number of mappings of this folio. * @folio: The folio. * - * A large folio tracks both how many times the entire folio is mapped, - * and how many times each individual page in the folio is mapped. - * This function calculates the total number of times the folio is - * mapped. + * The folio mapcount corresponds to the number of present user page table + * entries that reference any part of a folio. Each such present user page + * table entry must be paired with exactly on folio reference. + * + * For ordindary folios, each user page table entry (PTE/PMD/PUD/...) counts + * exactly once. + * + * For hugetlb folios, each abstracted "hugetlb" user page table entry that + * references the entire folio counts exactly once, even when such special + * page table entries are comprised of multiple ordinary page table entries. * * Return: The number of times this folio is mapped. */ @@ -1256,17 +1266,7 @@ static inline int folio_mapcount(const struct folio *folio) { if (likely(!folio_test_large(folio))) return atomic_read(&folio->_mapcount) + 1; - return folio_total_mapcount(folio); -} - -static inline bool folio_large_is_mapped(const struct folio *folio) -{ - /* - * Reading _entire_mapcount below could be omitted if hugetlb - * participated in incrementing nr_pages_mapped when compound mapped. - */ - return atomic_read(&folio->_nr_pages_mapped) > 0 || - atomic_read(&folio->_entire_mapcount) >= 0; + return folio_large_mapcount(folio); } /** @@ -1275,11 +1275,9 @@ static inline bool folio_large_is_mapped(const struct folio *folio) * * Return: True if any page in this folio is referenced by user page tables. */ -static inline bool folio_mapped(struct folio *folio) +static inline bool folio_mapped(const struct folio *folio) { - if (likely(!folio_test_large(folio))) - return atomic_read(&folio->_mapcount) >= 0; - return folio_large_is_mapped(folio); + return folio_mapcount(folio) >= 1; } /* @@ -1289,9 +1287,7 @@ static inline bool folio_mapped(struct folio *folio) */ static inline bool page_mapped(const struct page *page) { - if (likely(!PageCompound(page))) - return atomic_read(&page->_mapcount) >= 0; - return folio_large_is_mapped(page_folio(page)); + return folio_mapped(page_folio(page)); } static inline struct page *virt_to_head_page(const void *x) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 4260c595a79d..c432add95913 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -289,7 +289,8 @@ typedef struct { * @virtual: Virtual address in the kernel direct map. * @_last_cpupid: IDs of last CPU and last process that accessed the folio. * @_entire_mapcount: Do not use directly, call folio_entire_mapcount(). - * @_nr_pages_mapped: Do not use directly, call folio_mapcount(). + * @_large_mapcount: Do not use directly, call folio_mapcount(). + * @_nr_pages_mapped: Do not use outside of rmap and debug code. * @_pincount: Do not use directly, call folio_maybe_dma_pinned(). * @_folio_nr_pages: Do not use directly, call folio_nr_pages(). * @_hugetlb_subpool: Do not use directly, use accessor in hugetlb.h. @@ -348,8 +349,8 @@ struct folio { struct { unsigned long _flags_1; unsigned long _head_1; - unsigned long _folio_avail; /* public: */ + atomic_t _large_mapcount; atomic_t _entire_mapcount; atomic_t _nr_pages_mapped; atomic_t _pincount; diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 327f1ca5a487..0f906dc6d280 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -273,6 +273,7 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, ClearPageAnonExclusive(&folio->page); } atomic_inc(&folio->_entire_mapcount); + atomic_inc(&folio->_large_mapcount); return 0; } @@ -306,6 +307,7 @@ static inline void hugetlb_add_file_rmap(struct folio *folio) VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); + atomic_inc(&folio->_large_mapcount); } static inline void hugetlb_remove_rmap(struct folio *folio) @@ -313,11 +315,14 @@ static inline void hugetlb_remove_rmap(struct folio *folio) VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); atomic_dec(&folio->_entire_mapcount); + atomic_dec(&folio->_large_mapcount); } static __always_inline void __folio_dup_file_rmap(struct folio *folio, struct page *page, int nr_pages, enum rmap_level level) { + const int orig_nr_pages = nr_pages; + __folio_rmap_sanity_checks(folio, page, nr_pages, level); switch (level) { @@ -330,9 +335,11 @@ static __always_inline void __folio_dup_file_rmap(struct folio *folio, do { atomic_inc(&page->_mapcount); } while (page++, --nr_pages > 0); + atomic_add(orig_nr_pages, &folio->_large_mapcount); break; case RMAP_LEVEL_PMD: atomic_inc(&folio->_entire_mapcount); + atomic_inc(&folio->_large_mapcount); break; } } @@ -382,6 +389,7 @@ static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio, struct page *page, int nr_pages, struct vm_area_struct *src_vma, enum rmap_level level) { + const int orig_nr_pages = nr_pages; bool maybe_pinned; int i; @@ -423,6 +431,7 @@ static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio, ClearPageAnonExclusive(page); atomic_inc(&page->_mapcount); } while (page++, --nr_pages > 0); + atomic_add(orig_nr_pages, &folio->_large_mapcount); break; case RMAP_LEVEL_PMD: if (PageAnonExclusive(page)) { @@ -431,6 +440,7 @@ static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio, ClearPageAnonExclusive(page); } atomic_inc(&folio->_entire_mapcount); + atomic_inc(&folio->_large_mapcount); break; } return 0; diff --git a/mm/debug.c b/mm/debug.c index b71186f1fb0b..d064db42af54 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -68,8 +68,9 @@ static void __dump_folio(struct folio *folio, struct page *page, folio_ref_count(folio), mapcount, mapping, folio->index + idx, pfn); if (folio_test_large(folio)) { - pr_warn("head: order:%u entire_mapcount:%d nr_pages_mapped:%d pincount:%d\n", + pr_warn("head: order:%u mapcount:%d entire_mapcount:%d nr_pages_mapped:%d pincount:%d\n", folio_order(folio), + folio_mapcount(folio), folio_entire_mapcount(folio), folio_nr_pages_mapped(folio), atomic_read(&folio->_pincount)); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 454900c84b30..a8536349de13 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1517,7 +1517,7 @@ static void __destroy_compound_gigantic_folio(struct folio *folio, struct page *p; atomic_set(&folio->_entire_mapcount, 0); - atomic_set(&folio->_nr_pages_mapped, 0); + atomic_set(&folio->_large_mapcount, 0); atomic_set(&folio->_pincount, 0); for (i = 1; i < nr_pages; i++) { @@ -2120,7 +2120,7 @@ static bool __prep_compound_gigantic_folio(struct folio *folio, /* we rely on prep_new_hugetlb_folio to set the hugetlb flag */ folio_set_order(folio, order); atomic_set(&folio->_entire_mapcount, -1); - atomic_set(&folio->_nr_pages_mapped, 0); + atomic_set(&folio->_large_mapcount, -1); atomic_set(&folio->_pincount, 0); return true; diff --git a/mm/internal.h b/mm/internal.h index 9d3250b4a08a..51fa6246769c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -72,6 +72,8 @@ void page_writeback_init(void); /* * How many individual pages have an elevated _mapcount. Excludes * the folio's entire_mapcount. + * + * Don't use this function outside of debugging code. */ static inline int folio_nr_pages_mapped(const struct folio *folio) { @@ -610,6 +612,7 @@ static inline void prep_compound_head(struct page *page, unsigned int order) struct folio *folio = (struct folio *)page; folio_set_order(folio, order); + atomic_set(&folio->_large_mapcount, -1); atomic_set(&folio->_entire_mapcount, -1); atomic_set(&folio->_nr_pages_mapped, 0); atomic_set(&folio->_pincount, 0); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 89e2624fb3ff..2f73d2aa9ae8 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1358,7 +1358,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * Check if the page has any GUP (or other external) pins. * * Here the check may be racy: - * it may see total_mapcount > refcount in some cases? + * it may see folio_mapcount() > folio_ref_count(). * But such case is ephemeral we could always retry collapse * later. However it may report false positive if the page * has excessive GUP pins (i.e. 512). Anyway the same check diff --git a/mm/page_alloc.c b/mm/page_alloc.c index adbb7e6e0c72..393366d4a704 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -941,6 +941,10 @@ static int free_tail_page_prepare(struct page *head_page, struct page *page) bad_page(page, "nonzero entire_mapcount"); goto out; } + if (unlikely(folio_large_mapcount(folio))) { + bad_page(page, "nonzero large_mapcount"); + goto out; + } if (unlikely(atomic_read(&folio->_nr_pages_mapped))) { bad_page(page, "nonzero nr_pages_mapped"); goto out; diff --git a/mm/rmap.c b/mm/rmap.c index 4bde6d60db6c..2608c40dffad 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1138,34 +1138,12 @@ int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff, return page_vma_mkclean_one(&pvmw); } -int folio_total_mapcount(const struct folio *folio) -{ - int mapcount = folio_entire_mapcount(folio); - int nr_pages; - int i; - - /* In the common case, avoid the loop when no pages mapped by PTE */ - if (folio_nr_pages_mapped(folio) == 0) - return mapcount; - /* - * Add all the PTE mappings of those pages mapped by PTE. - * Limit the loop to folio_nr_pages_mapped()? - * Perhaps: given all the raciness, that may be a good or a bad idea. - */ - nr_pages = folio_nr_pages(folio); - for (i = 0; i < nr_pages; i++) - mapcount += atomic_read(&folio_page(folio, i)->_mapcount); - - /* But each of those _mapcounts was based on -1 */ - mapcount += nr_pages; - return mapcount; -} - static __always_inline unsigned int __folio_add_rmap(struct folio *folio, struct page *page, int nr_pages, enum rmap_level level, int *nr_pmdmapped) { atomic_t *mapped = &folio->_nr_pages_mapped; + const int orig_nr_pages = nr_pages; int first, nr = 0; __folio_rmap_sanity_checks(folio, page, nr_pages, level); @@ -1185,6 +1163,7 @@ static __always_inline unsigned int __folio_add_rmap(struct folio *folio, nr++; } } while (page++, --nr_pages > 0); + atomic_add(orig_nr_pages, &folio->_large_mapcount); break; case RMAP_LEVEL_PMD: first = atomic_inc_and_test(&folio->_entire_mapcount); @@ -1201,6 +1180,7 @@ static __always_inline unsigned int __folio_add_rmap(struct folio *folio, nr = 0; } } + atomic_inc(&folio->_large_mapcount); break; } return nr; @@ -1436,10 +1416,14 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, SetPageAnonExclusive(page); } + /* increment count (starts at -1) */ + atomic_set(&folio->_large_mapcount, nr - 1); atomic_set(&folio->_nr_pages_mapped, nr); } else { /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0); + /* increment count (starts at -1) */ + atomic_set(&folio->_large_mapcount, 0); atomic_set(&folio->_nr_pages_mapped, ENTIRELY_MAPPED); SetPageAnonExclusive(&folio->page); __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr); @@ -1522,6 +1506,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, break; } + atomic_sub(nr_pages, &folio->_large_mapcount); do { last = atomic_add_negative(-1, &page->_mapcount); if (last) { @@ -1532,6 +1517,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, } while (page++, --nr_pages > 0); break; case RMAP_LEVEL_PMD: + atomic_dec(&folio->_large_mapcount); last = atomic_add_negative(-1, &folio->_entire_mapcount); if (last) { nr = atomic_sub_return_relaxed(ENTIRELY_MAPPED, mapped); @@ -2714,6 +2700,7 @@ void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); + atomic_inc(&folio->_large_mapcount); if (flags & RMAP_EXCLUSIVE) SetPageAnonExclusive(&folio->page); VM_WARN_ON_FOLIO(folio_entire_mapcount(folio) > 1 && @@ -2728,6 +2715,7 @@ void hugetlb_add_new_anon_rmap(struct folio *folio, BUG_ON(address < vma->vm_start || address >= vma->vm_end); /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0); + atomic_set(&folio->_large_mapcount, 0); folio_clear_hugetlb_restore_reserve(folio); __folio_set_anon(folio, vma, address, true); SetPageAnonExclusive(&folio->page); From patchwork Tue Apr 9 19:22:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623122 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 3314BC67861 for ; Tue, 9 Apr 2024 19:24:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1DF36B009C; Tue, 9 Apr 2024 15:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF5406B009D; Tue, 9 Apr 2024 15:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABCEC6B009E; Tue, 9 Apr 2024 15:24:44 -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 8CF776B009C for ; Tue, 9 Apr 2024 15:24:44 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5E4CDA0520 for ; Tue, 9 Apr 2024 19:24:44 +0000 (UTC) X-FDA: 81990970488.22.65AEBCD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 9EE881C001B for ; Tue, 9 Apr 2024 19:24:42 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dtJf3PMj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690682; a=rsa-sha256; cv=none; b=8EdHN/9o/PRgeQn0tKf0YgcBF6yIgHKXVVMiB5AAxPVNP6O9dN7DdVVIPyGEEmhHSp+1jz wjAzQnkhYQ7uM701TY+ArU3JL4KLbIFp3IaIf+AH5mcAdtt7oiIBeyNx/0/lPhp+GsmS89 HE3rg5OHq3H8cuQzgulPIb/Q2O8k9J8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dtJf3PMj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690682; 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=Uy2oRB9rRnFFfSxz/BmLFL5vpaMUgfQlIINZ/k73n3E=; b=o3U3jKjgJtcRoxif2nyrVH2HXrO1PfVEf4sgCB+VJVTX5EiVlJkMzmNmK/JqgZCICJKKlm vXMAAYiXWvWQxP2Lqu/gbIq/zAMnZksCdHqO0NdL6mFL26ZUvJFWU1emTHnti4aOzk9VSb hOHHoNiU10fdqBTvmV/tlP9hkgz8KRk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690682; 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=Uy2oRB9rRnFFfSxz/BmLFL5vpaMUgfQlIINZ/k73n3E=; b=dtJf3PMjv3+mkwEe37uNcgN5b9xzFYM5gwZWcnsY6ZXKakdk83cN8eEMzvbRDVRewZda1U msEjlHQy1wnVbxMJj4Kxj0cGi+88ymYhSfKRPiGRKeqvJgBHqwgNtYpRpfE51PrMIQ8OT9 95q2uuhpAQaBHZ0fJFhYhQrhukPwTEE= 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-294-y1kOx-irPBuEYteLZHDYxQ-1; Tue, 09 Apr 2024 15:24:35 -0400 X-MC-Unique: y1kOx-irPBuEYteLZHDYxQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 8046C380009F; Tue, 9 Apr 2024 19:24:33 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1167E40B4979; Tue, 9 Apr 2024 19:24:22 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 05/18] mm: improve folio_likely_mapped_shared() using the mapcount of large folios Date: Tue, 9 Apr 2024 21:22:48 +0200 Message-ID: <20240409192301.907377-6-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9EE881C001B X-Stat-Signature: bcqcsrhhi4moi9z6iagmcnqofijxukwj X-HE-Tag: 1712690682-292842 X-HE-Meta: U2FsdGVkX18N5ePqHEXoCrGHh60YQagCT4JRvVjVURxDniaJ5TSzCjag8ZRTWG47DvhpRSe4pZdQVEVQcHzOJFQHOGWJE90BFOQeSs7wCLpYDU5seW0FQTfmDcJ5Mj7Nhh33bOf2PExbUoZ70OagcuROi1Z5s/dQbr5G4Qw1YiwAx4Vlq/vJnnmEMuuqRBSBpIGpdp9unbZEwpF3T3f4kkrPqNLzQ1KnoDVQr7ihDJjGjI4KToaC5vX9DymHPScSdNdEH2Fkl02FL6hws2xiXv3jeTfILMop6lbWA6pmftM+WsjTSXJW3MEgU85dB0UZpo2OKDO6n9Xl0d/PQ6r6/x0Z9tv1EayFzxT53oVSJolY1vj3d44CoAmMrppiwKOF1NJ2+soC+81gN/azNlh/H6LcRMI9oZKaHaqtYT9YBalqO7JBgMOzB6NVxClyJG9NfgxLH8eMaKofDhwNmgQy8oCkyNQ64garpX+HDOdXjHjrOxGcLH773021qY3PGHtgtiH2ma4tF1683J+JuhbzVKDVKHWS46+kNiXUrrPUS74KDLJUSIuRRvNw7Q1cs5GIbvqB3w0Z5ZsBvIeusrge1tQzXysuwYEXCwTDT/jyrXUZP5tcDRu4ksgzCH7pbK0pquVUyl9dST5bVhJajfowpppLwAuIfgGHUcVbt/65nKEo17I9SjbpvpLIbRbEvxtuDPdylYw5sCuSzJoAULeafXrCMQe+Rdm77TkCkZWrrfvk+qyrcIF+cl9iQHMK11OQz+YTcXZUcSwoOjJUSqcJRKcjgZe5NBXcoqD0L5TCCuxchLV5K6EBBd5CM+z8Vd9WxhTz+pxd0psdaejfwOflyTr8sTUVMiBZCzNgacX1Li5v0xvMWhh82oPNXYTczynSGWNhr1zV1OzShSkDpP97NKlJDfaQVUR+Frewq59yruDPKrwTURtmWmlXj3QvKzUnJsbvSQOCQJTfm18BatY 1SRJHo0A mpItasECDwOwx9mn7BH8YvOCl+JI3SVDDfloqJrivbzMOoJ86LfwqNEI2pVzYq/Ba4S9rEs7S+D9uQS/MguO13XHvXCcLnZ/6CpXvHwWZLohsdCWRmKDMIg1ZlYxpfYsjvePJy5bTo3VjqdhHwQDt7nS8vshW6is4AGXmjoDheuM4vTTk8EvkvCmQWmH2RKw0Ai0XJJYGOoL4zLYy5o7YQLbBgFI+I5YTxf1cg1i/2ijvcTZTdb0IGPxrXUBxjTDFiIlS 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 can now read the mapcount of large folios very efficiently. Use it to improve our handling of partially-mappable folios, falling back to making a guess only in case the folio is not "obviously mapped shared". We can now better detect partially-mappable folios where the first page is not mapped as "mapped shared", reducing "false negatives"; but false negatives are still possible. While at it, fixup a wrong comment (false positive vs. false negative) for KSM folios. Signed-off-by: David Hildenbrand Reviewed-by: Yin Fengwei --- include/linux/mm.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1862a216af15..daf687f0e8e5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2183,7 +2183,7 @@ static inline size_t folio_size(struct folio *folio) * indicate "mapped shared" (false positive) when two VMAs in the same MM * cover the same file range. * #. For (small) KSM folios, the return value can wrongly indicate "mapped - * shared" (false negative), when the folio is mapped multiple times into + * shared" (false positive), when the folio is mapped multiple times into * the same MM. * * Further, this function only considers current page table mappings that @@ -2200,7 +2200,22 @@ static inline size_t folio_size(struct folio *folio) */ static inline bool folio_likely_mapped_shared(struct folio *folio) { - return page_mapcount(folio_page(folio, 0)) > 1; + int mapcount = folio_mapcount(folio); + + /* Only partially-mappable folios require more care. */ + if (!folio_test_large(folio) || unlikely(folio_test_hugetlb(folio))) + return mapcount > 1; + + /* A single mapping implies "mapped exclusively". */ + if (mapcount <= 1) + return false; + + /* If any page is mapped more than once we treat it "mapped shared". */ + if (folio_entire_mapcount(folio) || mapcount > folio_nr_pages(folio)) + return true; + + /* Let's guess based on the first subpage. */ + return atomic_read(&folio->_mapcount) > 0; } #ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE From patchwork Tue Apr 9 19:22:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623123 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 96404CD128A for ; Tue, 9 Apr 2024 19:24:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CF236B009E; Tue, 9 Apr 2024 15:24:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27F6F6B009F; Tue, 9 Apr 2024 15:24:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 146FC6B00A0; Tue, 9 Apr 2024 15:24:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E8EBA6B009E for ; Tue, 9 Apr 2024 15:24:56 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 00EAC1C07B7 for ; Tue, 9 Apr 2024 19:24:52 +0000 (UTC) X-FDA: 81990970866.25.FFF9B11 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 4D5A8140013 for ; Tue, 9 Apr 2024 19:24:51 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JyD2fiHj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690691; 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=kfmOqlR3LeI6JA5XUUI6YoG07vX8W74qIyKiUchjaJU=; b=lZ5oZSEP7CUzjV6mX8iG/BiftMcp100P2v2K+gHykmtbL3/+7dilSD+/ioyjZO8Q7D7qjS cH0XtErEH/R8ufrr15/wXHRDKWwK8jGPfzFHUOZuK3whPJNrFXVoODpjSJEG7jOPC/kgNu TCDRzQomuif1zSNDjfJaEFs2kPyhx8c= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JyD2fiHj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690691; a=rsa-sha256; cv=none; b=G+DQWw/LJdz8aOpGgqp2rVGqQPXZBPPYKWDWYX1UYlO0fExNsKw9fflcCxVvBasKmYqTh/ oGcqE+fsum/YHzOioIfGcdOzGJ7VVY1qljP5HPf71pN8WEGT/tRKddyekg8AKbL+15YWWY ypoILzoD73Z4b/FkZC+LECUIhKxSHqw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690690; 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=kfmOqlR3LeI6JA5XUUI6YoG07vX8W74qIyKiUchjaJU=; b=JyD2fiHjiLQfbwFCydKVWOonHr3AYfBobrYWYGx1t4vQG5pFUih5y/LS7JcFtC7EC8lAC6 UsVpzr1FwWtbAeHv2M8NjGmLyZ9uY5ueafp9t+KokPIBIHW5ss/TmzGEiF63M2H5JQ5nEc dIIBgCgQwbwGLzf7HoiwaCB6MZvITTU= 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-97-N-WWN3PRODGQvvQK2vZjIQ-1; Tue, 09 Apr 2024 15:24:44 -0400 X-MC-Unique: N-WWN3PRODGQvvQK2vZjIQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 B730680B51A; Tue, 9 Apr 2024 19:24:42 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCED040B4979; Tue, 9 Apr 2024 19:24:33 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 06/18] mm: make folio_mapcount() return 0 for small typed folios Date: Tue, 9 Apr 2024 21:22:49 +0200 Message-ID: <20240409192301.907377-7-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 4D5A8140013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3yzk6piwue4pd5m8fqmfibe8bfbyzkex X-HE-Tag: 1712690691-878658 X-HE-Meta: U2FsdGVkX18vgQjtbOZPHjiQRiqweYZ/vQ7AvRzh2GEg7gXIEL9cy5SopOSJfeZ/djBYQ5Tm1HRy00u1b0V8puWBf/pMRT0QpciE24C2KCotagiCiVGyuxSFpW2xVfBuMQsSryGeq0LlVVIwIjZaTQkss7WGw4K8Jgm7oXW+x7Oic/A4948m/MQpP9GSseUKpM/4SFcAf4FPcD6tkj3VX3WBt739kaF1Ymzj4bFn1YWsqy33XmuElAIwomIqkwFyqmJeF+s4CJqPv/30x2FrqfRzjfw0EiSd2oaFCs4UTY/Cx8LA95Wr6MyMNYpzfm+YI/IG/TdoV6NuHe6UXfpnTfNiLbLGQiP8DF/dIn4K1QxyRgFweKfnvGKH2xs1+O+1oHkI6PVeWXQXp4npgHZ3W7O0Uu2AGqmAw7JKN7RpXeTR6/HRuY7JWVy+mu0F8IOPDfsq7IBvz86PNVsoPQ8fwDxrO4ZghUzoOYfet3iX9QTlXvbDp75dvgwAQPOvXmnWpmcEs9yQX/eIp6cTyZd0yhkCe6eOYRtbK9Nj7C88hEs+IG/2696ckOCLC+MYLS35NaJFF486ZF1xfsZjrspm7KyqNupFCt3sVbGIXRhOWF2Au7w+0PQZn2oohwinTlqFLgh+pr6ribd5ykRtTN7PcPmOz+QGigJVf9zl9D5KQs3H+WvqU0zZZp9d1pcTTcIBsvp7BJVeJQcxbYk7UAcMyszTo7wT1JU02bOUDLawd/zoYxvYsCSTrfdbF15O3jMvahpqHftT0zekxCAcGQ62QnBhp17KAwlqSYWmLH/y5fBGEFWadWIP723Lfw/XKCAHMfaE2dWcolLQ4Owo3e4EqDithbfffKwJtrbo8o09ZYj7JPZuhbURX1cV8loW7vB+zcnOy+O+zPX/wgxdKK5o4lDBV1yVIWXxkUt7Kr5b5cYJqxivul9qoJCfywKRbdvIuxXpr/EzHf5lYx8mgz+ MYK7Phiu WhfKVGT/cPhk/z/Jd5KL7e1dddkPyMWcE5P30sktqUyUIdViUkVB1K9ibTt6+tqOgG0ozO/jlWUJ7Ni6lEqAGSokcg2TEVrHnNEg2OJCibrDATP34X4ByJqPCTchHoh0pcQKGBK033f6lX7mzGEybEOFk2rdYpT+efAxq5V4PAhNRcTF/YYET5U0fc95WYG6I4o1dxCPAoiBnwVpmy3gIfUWPF/PhHKlXTCZC 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 already handle it properly for large folios. Let's also return "0" for small typed folios, like page_mapcount() currently would. Consequently, folio_mapcount() will never return negative values for typed folios, but may return negative values for underflows. Signed-off-by: David Hildenbrand Signed-off-by: David Hildenbrand --- include/linux/mm.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index daf687f0e8e5..d453232bba62 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1260,12 +1260,19 @@ static inline int folio_large_mapcount(const struct folio *folio) * references the entire folio counts exactly once, even when such special * page table entries are comprised of multiple ordinary page table entries. * + * Will report 0 for pages which cannot be mapped into userspace, such as + * slab, page tables and similar. + * * Return: The number of times this folio is mapped. */ static inline int folio_mapcount(const struct folio *folio) { - if (likely(!folio_test_large(folio))) - return atomic_read(&folio->_mapcount) + 1; + int mapcount; + + if (likely(!folio_test_large(folio))) { + mapcount = atomic_read(&folio->_mapcount); + return page_type_has_type(mapcount) ? 0 : mapcount + 1; + } return folio_large_mapcount(folio); } From patchwork Tue Apr 9 19:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623124 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 8A674C67861 for ; Tue, 9 Apr 2024 19:25:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20BD86B00A0; Tue, 9 Apr 2024 15:25:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BBED6B00A1; Tue, 9 Apr 2024 15:25:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 084066B00A2; Tue, 9 Apr 2024 15:25:05 -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 DBFF26B00A0 for ; Tue, 9 Apr 2024 15:25:04 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9776FC04E2 for ; Tue, 9 Apr 2024 19:25:04 +0000 (UTC) X-FDA: 81990971328.16.93A4BEB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id E2E2C140015 for ; Tue, 9 Apr 2024 19:25:02 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Mj8euJmy; spf=pass (imf09.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=1712690703; 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=6rnCGH1F82LpMt5YjVvPZTK3t5BGo8uUqDhbNYCO1mM=; b=nP5mrF32YmDaAHjD1kr3QpHTBz7mbuoe1OHnoXk8JkBrfR1vqrFVQVJX8UwTm/T825CJSS kNJyoEH1BFIyrWPZYSCGvVKGFJ5DhI5HGJkeyX7ZwapDh0UBYJ6TCrqbaVaRXvwhoC1it5 iUQQj8/UeoHI57Kr7IY5DVQOPUfhkj4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690703; a=rsa-sha256; cv=none; b=dqJXTrBLf0fnHYNn7L6/tLMsRJr6Zpkq82+XMmMkL4o0qrkJWpODMQNuVJ7TpJtp7BR6pE ifiDdjHdOhkf2EHvsrGEhmpw3GUqL1UYF0pTMBCkIRLMbxsW9fhKgJrOIKWEcaBCm1YTcJ FDkXlP0NCpidBtlD5K6suoQ9u21MJpg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Mj8euJmy; spf=pass (imf09.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=1712690702; 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=6rnCGH1F82LpMt5YjVvPZTK3t5BGo8uUqDhbNYCO1mM=; b=Mj8euJmyRbkqnGtXpMHf65w26Z9md3rt3ifAm+BoSVIrjYQjF6/TWfFWxPaOn/O3w2vUo6 AenTeskHeiXKQMCTVVBG861ko4x+M35IMY9vNL5kIr91Fg82VeXT4va2j8p22Jr6YxvXmj 3Vi/Slmvart/Rh0cNZgL2NHKU7Zq9AM= 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-195-HVcby02FNvy6GQIyoWw54g-1; Tue, 09 Apr 2024 15:24:57 -0400 X-MC-Unique: HVcby02FNvy6GQIyoWw54g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 6D86429AA392; Tue, 9 Apr 2024 19:24:56 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A40740B497A; Tue, 9 Apr 2024 19:24:42 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 07/18] mm/memory: use folio_mapcount() in zap_present_folio_ptes() Date: Tue, 9 Apr 2024 21:22:50 +0200 Message-ID: <20240409192301.907377-8-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: E2E2C140015 X-Rspam-User: X-Stat-Signature: 13tp71epbkzz46q4hju1shiw6newxajo X-Rspamd-Server: rspam03 X-HE-Tag: 1712690702-433325 X-HE-Meta: U2FsdGVkX1/Qltm6ID6lAp8aDQDySbvu8D1uLI3+FWhNywko5/huLN4rP8+Rxsbl1vtVgAi8ebGsev7aeA86jHKWwcDlPVzmC8iISx54tobJ0dguxFZDCc4pm9DgVJR7WSfj7eXKGy+yphbhAGAtVo8GfB2ArxcKLocci6MVxszdtHNWvkaD3G3LO5c5wVybnZCVxTTteHelJJJE9eXKooozfa+5kBQz4suVrSjbcVeWR82EdqdqCeovwCE19oNFIhed68h5LXMEBU5alcTYHJnQcxXlAB32BqN8iKEmPoYb+/ejOJI9tXaUg885vcG2lAFrOSuFCfhhEsRiENrVA3/Uo8QiBoZxQ1yFCZX07Ivay6Ikkn8sKsfhC5ZWpQRahUPqrF35siekBEXqt5ntwAF92js3eFbJuJNi96ahE7kUSJ06febqBkJc52PR9lSl5nwG74m3fv41Rw9LFJNTGw8ewaQjDiFm921OBwbhKs1mg1Txj/rYaJm5EPLK29D/PQWQAD4omI6yfcvCvbMhrjS+D7dmX0Yz0rd+n9zxFs9lMNX0dZS3g6X/7w3rgcjeK/LoPADvYNDYtcSJ1BS+QAfXXXjZSQKnS0Fhl+z50527IA8dnozRDzLsr0JjBN3WXs4u0IRRC0v15uWncpW3x6NUeLKRKgbsrSII2Eq7yN2ejxzjWSWvw2fv1ySrG+HHUScVJBsFStQ9tW254krXrqHXUgEwqJb3Xn0n4/C7777oYSpYWOrTjtHWvWNJIGdqG2GZjzrY8xTNaLtRRMa6sorCPH2tvbn5a+n0ObBYVHaO/PVzslVRSMUiKvuezKoksYzZFP8NZdgYsMPhgZd9ZDc/KNer27MiaRHvri9eOKuPuwkEtXwOV7a2VT+TetVpdq0jy1lrFVs/VlLmVQ8cuUvj6kYoTj9x+CyU83t0Lslr6C5XKM6XeWkUiYotDRQ8w07eqv2rB2VBW3sHM0z h//CWvYR 1Kz91S+aeE/gVGcTTRIeoQKTQot0AsrgTn5OrR+r89ISrwAw2nE6avvgfvJQjxVJ4lCJlgHFpE4Tj8Qucpz0V8+yglMuwGBoch82Ixo8PlLXZEx9wIUdynykJgTSI7GTw/fnBpnWtrTXtWdWnQVvsE+Yfwf734ohVZ0mof/HtuAqjdX25CxHd8I8eyd01ti8RF4wUpTTpIH67AugFjXBV/4jrPGFm0VXWvL3b 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. In zap_present_folio_ptes(), let's simply check the folio mapcount(). If there is some issue, it will underflow at some point either way when unmapping. As indicated already in commit 10ebac4f95e7 ("mm/memory: optimize unmap/zap with PTE-mapped THP"), we already documented "If we ever have a cheap folio_mapcount(), we might just want to check for underflows there.". There is no change for small folios. For large folios, we'll now catch more underflows when batch-unmapping, because instead of only testing the mapcount of the first subpage, we'll test if the folio mapcount underflows. Signed-off-by: David Hildenbrand --- mm/memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 78422d1c7381..178492efb4af 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1502,8 +1502,7 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb, if (!delay_rmap) { folio_remove_rmap_ptes(folio, page, nr, vma); - /* Only sanity-check the first page in a batch. */ - if (unlikely(page_mapcount(page) < 0)) + if (unlikely(folio_mapcount(folio) < 0)) print_bad_pte(vma, addr, ptent, page); } From patchwork Tue Apr 9 19:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623125 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 8BD38C67861 for ; Tue, 9 Apr 2024 19:25:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E5C16B00A2; Tue, 9 Apr 2024 15:25:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 196146B00A3; Tue, 9 Apr 2024 15:25:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05D846B00A4; Tue, 9 Apr 2024 15:25:20 -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 D9AE76B00A2 for ; Tue, 9 Apr 2024 15:25:20 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AAC9E1602B0 for ; Tue, 9 Apr 2024 19:25:20 +0000 (UTC) X-FDA: 81990972000.19.63CAA66 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 1662F40013 for ; Tue, 9 Apr 2024 19:25:18 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="A5/9zM/r"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690719; 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=l2g8VbuF2c0rw+gA2SjXZjA9kizkfkgdJ7YGUNRZUqA=; b=ZwJgPuI9vDw16QX6AYX+n1yM+GoEj9oAnqjLTtVPsRZn0kKG+rppW4Pva6CzquI8hLWwW5 6Gygu4Dly9LsrqJfk3adgB5Xj5zpJVaIsSb9QdNgD4BawgiZWnBwoyIuZXsg1qAB+e9rvK /YPR3dJNBekjgNnYpSo7y6z4+yI7aY8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="A5/9zM/r"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690719; a=rsa-sha256; cv=none; b=NTNVsBdqN7TOzp8fB/hPTjveVj4+YzXoYApSgAex8lAvZzoaYlwYqFKvX0bkFqzklmHZWT tHy9VP7ae7EXOcvlP+9MxJst8x2+S2gK7sCYEXZh8VMvmDK3qtcWj0SlAqGw712JR2hqMT WBY60XLykVqk/WiMcCBVVo2hbDKPxT8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690718; 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=l2g8VbuF2c0rw+gA2SjXZjA9kizkfkgdJ7YGUNRZUqA=; b=A5/9zM/rM7JBKoNLt24FNgKWH++cfxED7fGDqn/iJdK4yEgqQcPq9p26ewUj/RhN9Lpzmu i1YIS8Jh0jmhQ/ApPJ1Pmi3GP4so/XtM4oygFSQG8MHWGUj9wL7sOxvKSEMSdSxjzt35qC P4wjhcLth2ixmeZ6HNcLf5S6uxv0hF8= 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-61-9JpVPi_eMcaHlYj18Lcjpg-1; Tue, 09 Apr 2024 15:25:10 -0400 X-MC-Unique: 9JpVPi_eMcaHlYj18Lcjpg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 9AB78806625; Tue, 9 Apr 2024 19:25:08 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCB3B40B4980; Tue, 9 Apr 2024 19:24:56 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 08/18] mm/huge_memory: use folio_mapcount() in zap_huge_pmd() sanity check Date: Tue, 9 Apr 2024 21:22:51 +0200 Message-ID: <20240409192301.907377-9-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1662F40013 X-Stat-Signature: qjh6471fs19yrhz7bfwd3p96auhwupjg X-Rspam-User: X-HE-Tag: 1712690718-271124 X-HE-Meta: U2FsdGVkX189NOYp0miDr9rX2Akx4PGT0GG2+A9oj39/f1GXck9lIq0LsOjDrrryVG/2z/g58Q4nhl9sTG3JHr8zmYVFgzBtcwUZP6C+toPEfmtmrDS0eyinORndWyIZgT+rCyclo8dGA/wLDUZNASFHhA+DQmHt0U5FgUEbO13h6Ga4s34AhD9qHraBWni2pDJeTtqxlqfx/5rOHwr4h5MZ1Vwx0bGtCMR/EHtYqyEX+edKbeE9VsIqtF/kFIYQoF/nLhgsgoX0sY/i1LsnHY2iGPKbY4F+DEPuDuKzDkblkT3pPeyieNkHTvw2TDEQzhJFwppbGHKXOvEHRpn7fHzik/R6DBb9HQ0Gn4C5+nM17Tx0zbu0ohAL0SsgBlMvoonyV46g8Ptfb4bS+OKeD5MVm2FTJvISDwzXViYXIO18xIvJdkCvNZnrNjRuKcOZLVbLb7ThdSDp5teF9uSyA9SJhoePUJ6fd/cs3KPE1C97ApRJ4+wc9xDgcqXeQqmYMQFUryJnL68q/VLopbRwuR9/Rv6YhYoYrKpgDNsL1+a+tnaakHkRcm+xAEn9leJPTE25F60gLZcSx3HouLiLXkRtLY4CF3as/RpxcR75wAe54V6wDZWmvE5f50UF0HXybPXcXNxcFOkc48/RKH44OudrsmjheVe+XDpyOHOUjJizphjNl6mFqV9iOJtbcFnPo8U28XI72aK3PgAfpcPBOv4TzzbIM6g2q5cyHTcKsQHyU0u6NaP/8U3gU35f58EdQhr4wcyT4ZgO4HSEANR+TNphJ1CYQLWMvtZ78TeZ+iC+DdfK+Gfw7mtGYJIdGqJTnBv9vqMv48dFyIgziXi/1YWOPM6QywAPA8Ef3/90lZaWG1z6ueD4XMBpmXVakjMDc1w0eNYFeZim0Jx58bsjwTTGwRXasTHNsCCU6rZPtnTQYO6rcohrgR4Yilk5z1Ts 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. Let's similarly check for folio_mapcount() underflows instead of page_mapcount() underflows like we do in zap_present_folio_ptes() now. Instead of the VM_BUG_ON(), we should actually be doing something like print_bad_pte(). For now, let's keep it simple and use WARN_ON_ONCE(), performing that check independently of DEBUG_VM. Signed-off-by: David Hildenbrand --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d8d2ed80b0bf..68ac27d229ef 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1851,7 +1851,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, folio = page_folio(page); folio_remove_rmap_pmd(folio, page, vma); - VM_BUG_ON_PAGE(page_mapcount(page) < 0, page); + WARN_ON_ONCE(folio_mapcount(folio) < 0); VM_BUG_ON_PAGE(!PageHead(page), page); } else if (thp_migration_supported()) { swp_entry_t entry; From patchwork Tue Apr 9 19:22: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: 13623126 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 E7BDDC67861 for ; Tue, 9 Apr 2024 19:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B1B36B00A4; Tue, 9 Apr 2024 15:25:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 762AB6B00A5; Tue, 9 Apr 2024 15:25:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 629916B00A6; Tue, 9 Apr 2024 15:25:29 -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 3EBEE6B00A4 for ; Tue, 9 Apr 2024 15:25:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 030EF1C074D for ; Tue, 9 Apr 2024 19:25:28 +0000 (UTC) X-FDA: 81990972378.18.E6B5954 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C7F61A0016 for ; Tue, 9 Apr 2024 19:25:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aE3ERRay; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690727; 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=UDO/LuGyFJsgzNpcvXk5nDcpkN8Vm1hlfEW8fwIXGqY=; b=esraJEOOM23WeDQbNdFr7U6AWZBpIpjm5/5hfpq9xcQXXpEHoX2Sre/e1LK76+wCccJigz /Zp0Xzy3XynRoOpWxuiIaCLWlU6S4JrnBEQbepGy4WAkn4orA8i8OGRJMf/WG5e6pz/fvd ++FU0wRvRnS31dlshBUdp5KXHfao8OM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aE3ERRay; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690727; a=rsa-sha256; cv=none; b=CDLPmujZyWTK8zit/QU9zl6s95MsLBHHxENb+8RMJRZ3HSNca9voUHh/4WelEsuXeR4EJx t7CJ6RYACrjn64hFOEHLI4CoTRm6rmCVxBeBfBhwYMFHtLGCy0Hcccd0afK3+PK6armmoc czAXaRKN3XqVfNfHgIr9+W/pm4mUe5U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690726; 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=UDO/LuGyFJsgzNpcvXk5nDcpkN8Vm1hlfEW8fwIXGqY=; b=aE3ERRayW9PGzqV0JaiCgUhOOYxvfhOWBIfVVTPZiinJ6Tu0vC0LhIQXFi5dc6tJjTtfMN /aYwOLI8f1OyDgDC8WAA6jRa85i3wl1W4taemluK27SE80UW/Y4hLqNMS322ih/ySSS44u BrBcGb0GkYYbPEBoXsM7NzqYqPJ3aUo= 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-79-q_7BzCqOO76DTj4PZpIcDA-1; Tue, 09 Apr 2024 15:25:22 -0400 X-MC-Unique: q_7BzCqOO76DTj4PZpIcDA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 E95FE890524; Tue, 9 Apr 2024 19:25:20 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1E2B40AE784; Tue, 9 Apr 2024 19:25:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 09/18] mm/memory-failure: use folio_mapcount() in hwpoison_user_mappings() Date: Tue, 9 Apr 2024 21:22:52 +0200 Message-ID: <20240409192301.907377-10-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 4C7F61A0016 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5c8e7c8ii1cre738bqy6t1j9yy5ette3 X-HE-Tag: 1712690727-248317 X-HE-Meta: U2FsdGVkX1+1fy8Fvwfk10akjkBPvPrEnSAr3zI4oMtJ/Rs5OHbir8ODIjDV6c+ggUh+7njMcGzMb5Ka8wupK0L8Vl3uotgH8NfQPDNBrrVZvm4cTJm734Sh+YsY4iMcTsQuMskqS3whO53x+FhEo3vzscWv4aKF1AgRbtwaCa1SPb3QAzvVuszTN8+kVspG7OvJiqWWqBfJPFzsVB3PeFEvz0iDxEeVo3DPjuu+7M51ZPynbpKP6lJn7B1XcXdhFCKXe7vKvDr07baTs2zuP7PEhdoanYtnAl/+f7J6TFgF1SVGrnQDXuIj4xwSwzy+Le65DJndJSO3vm6lmlBv4xuUJu1RTdbL2etk1enLSwFumMUbcdtA6wj+iI2NWbqIYw67Ww5JQtqVHwS6S686plF6C67VGmhd+q4pnPWgVGj6TO4324ZoMndYNZhh2XboAdWkc/dFn/2Ul+0U6hajEox6QJys5eMoN/dQ0JibY5jrKzTjeffFw0jgZ/ZuusGAp3gs3mENtMjECRXClVYTmMYfUmWIbxab29RrPPjfSBmBqpbSTf5BJZwyqtcSAv6Ev0axd7pr1dB3pEJ8XV+ffe5TWkRd20ICSRE7RJ00ZL4DFWTp470KAzzek2syKngtRbBoTk5qzU8uYxC5HtP/YDNntrBGmy3KBhCdp2n/EvmB6JNTSLq31r/IhxLReqkfxt5jeukgHhqjY2hqEnKWt/N50KVmGXJGXl38V8fsIiTzwOdY6btBIfWxlrjnTQWHxhLJZl7cXUxMh5CrQSsdchuopjxR+XSE1mf7oZxgLNRR6wXNn370QfCj5iFfpYuhzzcMOwMidhQ+wfkjkNbNvs7OEB2dkx4EiuzKSU3bpKszI60dqfd1qMgoKYgdkQqjPjL4T9os4fcxS2pJd8HOXZIJBF3ELuiVnX/BNiTffiRQ32orHZ9wX4CubNbfgsICwT5sS6TLvhuxYGFP5tE U1GPXdw5 nd1UUgduH2Xj+0Ri0MC3Y/YYyRbueUpLlwULNiJVJ4/TaNLe7H4cDtseDPWRG0RiWRGFsrgo0ADGTGJKa5Pco2ekiD4Vihj82OKoV3RvDYCRSYct/f2XCdL2WytvBRypywz7zj95CHWaNmDLrA63p2Ctbm2c3RxGXhsgQ3ByELxvlZR9+9lZjsoFcLiQJeqsZ8GmzH025/5BoQ1tthwOq3FZ6Dp41b79fkhcp 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. We can only unmap full folios; page_mapped(), which we check here, is translated to folio_mapped() -- based on folio_mapcount(). So let's print the folio mapcount instead. Signed-off-by: David Hildenbrand --- mm/memory-failure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 88359a185c5f..ee2f4b8905ef 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1628,8 +1628,8 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, unmap_success = !page_mapped(p); if (!unmap_success) - pr_err("%#lx: failed to unmap page (mapcount=%d)\n", - pfn, page_mapcount(p)); + pr_err("%#lx: failed to unmap page (folio mapcount=%d)\n", + pfn, folio_mapcount(page_folio(p))); /* * try_to_unmap() might put mlocked page in lru cache, so call From patchwork Tue Apr 9 19:22: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: 13623127 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 05185CD128A for ; Tue, 9 Apr 2024 19:25:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9ADF26B0087; Tue, 9 Apr 2024 15:25:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95DA56B0096; Tue, 9 Apr 2024 15:25:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 825716B00A6; Tue, 9 Apr 2024 15:25:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 646DB6B0087 for ; Tue, 9 Apr 2024 15:25:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2B6821602B0 for ; Tue, 9 Apr 2024 19:25:43 +0000 (UTC) X-FDA: 81990972966.28.5E6EC3D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id A5CDA1A0016 for ; Tue, 9 Apr 2024 19:25:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KJdP6vMQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690741; 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=DDf71sS1dWCd5bf/gEaENI1Rp8VJQ5nXZAI6YpNXJLo=; b=X0KhbvGTfHaaFX6EDhvdQHyxYyOc9/RSfCeynGn6GidiOB2NuEQfv9EuaVls/jwciJtbSn 45xy0OdJevrMXFLVba9pR1VflfoLSdNr6gStXWWUt8IYwPuzaUdYRJuSDnnEiYUBVI/DQA 0R52D51QsXks78UlfVNdYqm+VGMbgAU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KJdP6vMQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690741; a=rsa-sha256; cv=none; b=5XbV+X5qfFNHr6Hho09QN49ZC8SkhDCSuZBTCzQJCR7Y0OmCBicnQdAq9zPTl102O7Pgm0 L4idSnQHBjAqf34QUa8P11hmtwV79ZvAZo1mJkZHF78hEzmVNTBNvVXQpJY+r5VWfkN6Lg kKgHQki2+AyFdZ+y02iQt51jKuvppTk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690741; 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=DDf71sS1dWCd5bf/gEaENI1Rp8VJQ5nXZAI6YpNXJLo=; b=KJdP6vMQy7LR2tMT75htXB+desShi/Gz+q1U3jUSTjtN0egbmnoXPgj64ZIBx2AG3PMJpy WuQRofJdxk7IIuX+WyZqj3hk2xsKi1yRn57LjjDGh5gv9t9VC9VNKahXSloZPpOa7VoV3p 1a+MYFLg4fAHOpQ05K7UOhyXNxWKJj0= 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-538-vMa84eYMNlusTgwrdB_i6w-1; Tue, 09 Apr 2024 15:25:35 -0400 X-MC-Unique: vMa84eYMNlusTgwrdB_i6w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 592A9830ED2; Tue, 9 Apr 2024 19:25:33 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A7E840153AE; Tue, 9 Apr 2024 19:25:21 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 10/18] mm/page_alloc: use folio_mapped() in __alloc_contig_migrate_range() Date: Tue, 9 Apr 2024 21:22:53 +0200 Message-ID: <20240409192301.907377-11-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A5CDA1A0016 X-Stat-Signature: 34u5zn54xgxrfjfmttpgaquh7sny8wpr X-Rspam-User: X-HE-Tag: 1712690741-952025 X-HE-Meta: U2FsdGVkX18avXkeCLfKLrIV+JO+ctpzqPjj+Bz283LB0kFKgixw9HrSDCkDXEM2F66L2NIn6ZyRk1s8GLUmXvOZ0ddsz1PK08Uk/ZeebfoIJDKTNXA9/fFda67N13QHF5B+l/UDVmz0M5Tf7a7NJYbQ7kP+lJaZ2h+mfgsDPfDIEtrTZXi2JZWdOU89spLauGtnlT7f0ZCNyq2pb9N7lC59rnpa/MaAgzj6BBSOKEwqjZnxFPEyoqw+NiQvoU/hcOe27dRMv8Dzzre5re1ACuN4iZ/O4kuMXZImIbcG7fV/K0DmyRacx9cvcGn1U8YsSHgk/IY54gP+3seQS7WHMrGEA5yksB7ftetq/HKlARd0lrAyqGIE0XH+GuUOs9nTUOFMxf4cvCHKIKmKvzIFM3lDlMlBs6+ZIAz0o4kD8lym0jqA8Ct3royLFtQ/Bkt5cR3QIZQYKuQ/7NQpRETkYl2wFg52B+a/j0N2PAFYGaLRxJPCKVEOGldPrYhgiWSLZQy4Gsp//GTT+gglLZWotafdkNh1r/FW8W2VUxzQrX15WJNuasaQsp1fFedi5ulNK+myfpCATXJnNtoSvZlU1PjqTSIyihv3AFI49NuzXyQSNOJSkMTqIARgu1GDMXerlyJ4eig4bg/dC6QN1AzF3ip7AKIB56qXi3MdoWs4rdrhlDjhobvWZkiXY0hNa4BOefarVjHre029yq25vSjVvyKZcTElxCWLqDqAVQSyZwWiRyNPHMSMQGpRJn4qp2q9vYaVNIKLfJPqXTwGQsMZeJfqmyRJ3DsV0kaSDsIKXDlIvlNH4omKJKa1IGZcCnv24VY/9NZDynhcvIkEMl6bvFsFeicsRNtFmn7aTjEtCxUHbvKf3uDoUz3RFSS0oHkZ+43nz/++s6trOhh2MChDbnVssFyXFubxfSkKdzyw2F8SI+imuUWsJv/cZQT5XeKi 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. For tracing purposes, we use page_mapcount() in __alloc_contig_migrate_range(). Adding that mapcount to total_mapped sounds strange: total_migrated and total_reclaimed would count each page only once, not multiple times. But then, isolate_migratepages_range() adds each folio only once to the list. So for large folios, we would query the mapcount of the first page of the folio, which doesn't make too much sense for large folios. Let's simply use folio_mapped() * folio_nr_pages(), which makes more sense as nr_migratepages is also incremented by the number of pages in the folio in case of successful migration. Signed-off-by: David Hildenbrand --- mm/page_alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 393366d4a704..40fc0f60e021 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6389,8 +6389,12 @@ int __alloc_contig_migrate_range(struct compact_control *cc, if (trace_mm_alloc_contig_migrate_range_info_enabled()) { total_reclaimed += nr_reclaimed; - list_for_each_entry(page, &cc->migratepages, lru) - total_mapped += page_mapcount(page); + list_for_each_entry(page, &cc->migratepages, lru) { + struct folio *folio = page_folio(page); + + total_mapped += folio_mapped(folio) * + folio_nr_pages(folio); + } } ret = migrate_pages(&cc->migratepages, alloc_migration_target, From patchwork Tue Apr 9 19:22: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: 13623128 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 4E29BCD128A for ; Tue, 9 Apr 2024 19:25:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE29E6B0082; Tue, 9 Apr 2024 15:25:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C92896B00A8; Tue, 9 Apr 2024 15:25:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B32DB6B00A9; Tue, 9 Apr 2024 15:25:50 -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 8ED5F6B0082 for ; Tue, 9 Apr 2024 15:25:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 55EF4C0522 for ; Tue, 9 Apr 2024 19:25:50 +0000 (UTC) X-FDA: 81990973260.19.8C9EE90 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id A03BB40009 for ; Tue, 9 Apr 2024 19:25:48 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eGRYGrD0; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690748; 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=IN3zVkAYwXXWogoRwDYvxGTLC4K4Gwg+xwqZ7vjK29g=; b=hfUo/BaV0MBNLAVfvUJGP7EVkifS5NFC4gl0VomQI3GIv9cylyiNJh776N5kulq5VJ29Dm 31fw5LeQNRGQSFn2fQZvW5DsD70KjngsJfBaJQHxuLsUlHrMaMFR+4PHz8IVU98Cw+hN3Q OFacMYhTGA1bZnGcZSw+FwpWhlinNJI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eGRYGrD0; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690748; a=rsa-sha256; cv=none; b=JEP/Cem0jNG6eMCJ0jdmKpQkblTtrdg+U7r8+5APz4nFVcxSgEEJA+PxkSLZ+LdoNUlmdO iCbUx2I/GNLqqKDG7KLADrdzYdhKokwx4fP3GkjjgbvVkamRUTsRCKUqWvqXTR8T2E8o5e W0rjQKR5h4ENQgy97an48jdTFK7mTS8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690748; 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=IN3zVkAYwXXWogoRwDYvxGTLC4K4Gwg+xwqZ7vjK29g=; b=eGRYGrD0mix9TbzfmvMEQs0Eat17QablvqmefU5u9sgpWt9VKY+8+d9mVVPUA0qVNvreWw nTQKBKk+SKnW6Xmm8wcD4VguhxUj+RBqOV73yfQBLtBUtRG4JjMfrVP515yRiRP+Tr+W/M 2fq0k2G6xJZYUyriIrQLc1fKwVP91IY= 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-512-p7aYNzngOOiEyTZuHcjUMg-1; Tue, 09 Apr 2024 15:25:44 -0400 X-MC-Unique: p7aYNzngOOiEyTZuHcjUMg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A0997830E7B; Tue, 9 Apr 2024 19:25:43 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD0CF419FA38; Tue, 9 Apr 2024 19:25:33 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 11/18] mm/migrate: use folio_likely_mapped_shared() in add_page_for_migration() Date: Tue, 9 Apr 2024 21:22:54 +0200 Message-ID: <20240409192301.907377-12-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A03BB40009 X-Stat-Signature: rais99hqmfqnnqu1ur63em9amswg6gct X-Rspam-User: X-HE-Tag: 1712690748-535841 X-HE-Meta: U2FsdGVkX1+U2vDBxQhgCyctI7O6PbJn2wuhkG/JDH0yzgj66lhEDQ6sMQi0S50pD8NB6TM3Hc2miwzCiw5A4oGHZaouQYnGIfxVzQS9MNRlhdFhztW64b7uqCT2VqReStjrZNUrRJ6c7cC8j7ds6C0jqxjYDLJDF1vvm8zz5Fk+UC2iDn9Knr02daCn4ufHD1YAWXNI4+nnCwTeFXh3h0jjTLp6v13TvLayKKQZOlfGX2nGmqf8ECRFWf8KwWbWGJ/11CLSY4lPw8k7kET7vE53zcPqj4Rk4GI/kzB+q2CwQnDYUC1T3pi4M/ppmrEOYWDun7usG8PUVlsKIfLxRfo9EsIVqBcZOf5kicyvNuvj1Yporng5uveYuzVp5z+BkuOuoI43XiliPm1cHtYDhRTu9PJOhYfh8S83h+rKCAjput4wKEfMdWL49MTigLnTCNSWHnnFwtBElhmZ7FDucNwkOFsiYXL/bpmSfUpkTBAAqkJk46jEFyy9ok/kGFNtEI8QwwlNIBi/dQ6+fnvT9ui4Ws6Ibi0fPdfKB8qyQOhVAya8SaymJUpwq4OyypZ8aJQE2nX1CaB8J0l6SrH4LXGPE3qtRwcIfy4cKKDutQw0lV37/N7uW9gKzQ90PZckgnni+TtOPfUtiWs+jyTikGQ0sUiWNIAqg9WQhNu9lArPXcsp/hgNR72I+iEcJQDuFF7s12QnoFyvPiDS/xfYZ85pNqedOd9tcx3h56u8FjB75PapOQFW3sG5aVXmlU3WY/+y3xtdAUOxfx9IUZWrPoQeYpCNQd06Ak5eUNDyjrklTUPGc5Uom1NA0B+MtEJlY0RYf/jh9mSmpSHpY5TVT4sj5gqrkqjdVCfDf1JZgH5OUVEQDwMDxz9HbiUpysF75uLCiyuZgh+c6cFR6GJXEWOrfeQnNUrH+hJ+NxMwqvWs7nQH8UcpYydf3SJ/tge+vjGAMVzfrVUWQ/MVun1 xPv5N9We zzwoqH2wNBkGP4OHo4eWSwvhfrsXkSJVfCdpv2+xdKT2iuAxM2go2Sz19RjgOQV85xXGx/yrduBl1/kLJJLr1SOARAqIwOd/H3xkz05oSWD2TomRdUwvk3dT3lJh651/XvSmzt+Fi1Ic5h+107u73wAMiLF80uRNmi+7tC2jR59zQLUyU1VW7bVgGGFSESWRzWcpwka8ePzbvuAiD3UCpk33sc7Dn2u1ZVJ2E 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. In add_page_for_migration(), we actually want to check if the folio is mapped shared, to reject such folios. So let's use folio_likely_mapped_shared() instead. For small folios, fully mapped THP, and hugetlb folios, there is no change. For partially mapped, shared THP, we should now do a better job at rejecting such folios. Signed-off-by: David Hildenbrand --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 285072bca29c..d87ce32645d4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2140,7 +2140,7 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p, goto out_putfolio; err = -EACCES; - if (page_mapcount(page) > 1 && !migrate_all) + if (folio_likely_mapped_shared(folio) && !migrate_all) goto out_putfolio; err = -EBUSY; From patchwork Tue Apr 9 19:22: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: 13623129 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 4FD76CD128A for ; Tue, 9 Apr 2024 19:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D578C6B00AA; Tue, 9 Apr 2024 15:26:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D07B66B00AB; Tue, 9 Apr 2024 15:26:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCF2D6B00AC; Tue, 9 Apr 2024 15:26:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 973896B00AA for ; Tue, 9 Apr 2024 15:26:03 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D5F061A04F3 for ; Tue, 9 Apr 2024 19:26:02 +0000 (UTC) X-FDA: 81990973764.13.BBAE6A0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 2E4FD160017 for ; Tue, 9 Apr 2024 19:26:00 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="NJ/B/XP3"; spf=pass (imf08.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=1712690761; 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=oja6emUhi7xfrQgd9sof78Ea2rpQTjm332kNskpFfoE=; b=IY4DN5B++4gnOcOSuqOYDRCikjBUWmj5HlTMDTrabmdgERcZcggHzCdioij3eTGND3v6q6 qx/G6liBwolZfXi4WI3iEzW4SED1wgJdVoPdBGcGe/BVwM5ElKU/Sxp6oLKgjD11aC0CHj ltL5XHdJU5lsffZpBA05XAqnbCqOD2o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690761; a=rsa-sha256; cv=none; b=xwWcA+pPMzRFmZAacaxlFvZMfOkBm/XmpFvQrXbz7wGTm5k5idoQ4mzDY5wvXm1FJTf+Lz V4FwYYlrXIGid8pYdZbY8dyFGFb2tQCl4TcaWVfcM+F5Qd+iE2lFaonHZSjTLjmVeEhoMO xXF3TB4NLBuQHKKl4Xq3dehhmMNsGHo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="NJ/B/XP3"; spf=pass (imf08.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=1712690760; 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=oja6emUhi7xfrQgd9sof78Ea2rpQTjm332kNskpFfoE=; b=NJ/B/XP3COVCpKvC1knjuut7NMF+3WV481uJFdHoqWl568jyCpFNgMtFRt5xvnbOqUI1I6 Wl/NjRpH2gdfJ12Dt5FO8RkqOsSWbzj7HezzQn+5e5J41UTXPIM1QnJ5WOyrbIhFtouUQ5 EDZF2H40S6x9hBj+Im6ZHNPfZHWoml0= 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-216-euyj5-iiOp6e2NecV838wQ-1; Tue, 09 Apr 2024 15:25:57 -0400 X-MC-Unique: euyj5-iiOp6e2NecV838wQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 262C9800198; Tue, 9 Apr 2024 19:25:56 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B6EB40B497D; Tue, 9 Apr 2024 19:25:43 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 12/18] sh/mm/cache: use folio_mapped() in copy_from_user_page() Date: Tue, 9 Apr 2024 21:22:55 +0200 Message-ID: <20240409192301.907377-13-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 2E4FD160017 X-Rspam-User: X-Stat-Signature: b1pmaeytj13qggm8yd4odbnmgrgzgw73 X-Rspamd-Server: rspam03 X-HE-Tag: 1712690760-192218 X-HE-Meta: U2FsdGVkX1+tWOhmud7SUks4At07ui79s0kAlnnulLWMNTVgbPG0dH7gnz8J08FEM/O3A/OuK37r84rjH1omNBioovMK7a2VIqoxlPSr+9VRCI1WKuIWcUXwkIRGRaBTfgVz54VcX6onbFtFKvcvx9cZgG5V4oDU7wGvivsikxKPiwOY8TOCXCXCoiu+A9sRKZwtoh/WuhNcAVrVnHiMPTU1LlNKuDDosc8V6/r0EgXSGUqSsRZ184Fb7KOiR6+IWAZNrbP4eztbyDX617CvHDiWHyLyRWm21j0whyzdCeyKjkPM4PAfxQ8zzC27irNgUpiWlUr0nJ+DM6QAOe3+3JK/7UsLR00kjXHnkUICvUhbXqPr3EUkiAvMAiqcOn5atXYEZ9vFhQYkGvUSrARFI5Ln2LDvUkRqljFrpY+NOzdTxeUvqP2EaLfruNpQ/t+Va0twxhu/nIJNCjziC9trxH7j5Z0AJvrM1RQvbVTnh++VvWl8i7POEJ6ZMLAz/EdreNToBwsIdIkMjSZTzeugKE5xjHoDWneDVNhUzM9JiIRU7SA9QOzDTiiZ6ndEaq48r4RUTP2xEbXiskltHMDcerZeuLqzTsnbczkQEQBhFLNGtKhSqbEAfr52Zpvc+5Wp5rul12jV59eg6A0P2TAPcq6pWX3n5rMln0da7vIb0GlUtzC10Rf+eRHyBvV8VX2gXpPJQ+GEDvov4tViGQtYomt1+r0mHjWMzTWaEJA1nfmb0wLs+yAlqIlO8xmUsVxC8mSideQuy28dvSqaJvznuU5bNrpDom83jN5tyxryCIacglckDLzCG1qZkGSpbIsgIHBn52cIApBxSzlinNF1qRDYK23h1XsZXgu/t2sXcFRt5K5BADhEp4Bid0lNm/9nDidKXOB3wG2OaxwaHqEWU+gtdqwYT2JhIjsKryZeBw72R4+Kr9obPpqtq4l0V2LB1C9O021c+1Zokh3d+mT Z4ise+iN V/DiyzvfUaNTjsrDn76wIvyzFpg1NRv59c4NI3yoIADgMeHv/5pospHdCNHYc7Q5tU0Evf/K0kAlCoCDQ8UWNfA/fHBpUuIfB8kSPwUb/k+2eh+D6uf7HnvvQTjKaSYWQZp5NE2uuQECRQ+L6WAYDfNobBbSyUgydrwnSm8HpdpQ2zxB/gFqsWHEMNNQqtF++VUaWcFXOYyyu79N0pi2ex49d+Ms2aw/jz04Z 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. We're already using folio_mapped in copy_user_highpage() and copy_to_user_page() for a similar purpose so ... let's also simply use it for copy_from_user_page(). There is no change for small folios. Likely we won't stumble over many large folios on sh in that code either way. Signed-off-by: David Hildenbrand --- arch/sh/mm/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sh/mm/cache.c b/arch/sh/mm/cache.c index 9bcaa5619eab..d8be352e14d2 100644 --- a/arch/sh/mm/cache.c +++ b/arch/sh/mm/cache.c @@ -84,7 +84,7 @@ void copy_from_user_page(struct vm_area_struct *vma, struct page *page, { struct folio *folio = page_folio(page); - if (boot_cpu_data.dcache.n_aliases && page_mapcount(page) && + if (boot_cpu_data.dcache.n_aliases && folio_mapped(folio) && test_bit(PG_dcache_clean, &folio->flags)) { void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK); memcpy(dst, vfrom, len); From patchwork Tue Apr 9 19:22: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: 13623130 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 0DC4FCD1299 for ; Tue, 9 Apr 2024 19:26:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D51F6B00AC; Tue, 9 Apr 2024 15:26:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9856A6B00AD; Tue, 9 Apr 2024 15:26:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84D0C6B00AE; Tue, 9 Apr 2024 15:26:17 -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 6544F6B00AC for ; Tue, 9 Apr 2024 15:26:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 24277A0C9C for ; Tue, 9 Apr 2024 19:26:17 +0000 (UTC) X-FDA: 81990974394.16.F1FFCB4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 7F05940010 for ; Tue, 9 Apr 2024 19:26:15 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aso5oJJ6; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690775; a=rsa-sha256; cv=none; b=YE331oSCVQY/KO3mD1VODOvwbJ/mCjt6Cmo3v594Ur2pVwxVM0F9pwUuGYRzeZBZ14aU/c xRGPnrWX/Stb5C3ogoeWJUCe/UnpdJ3wmKHlSa0xVOQRKNv0VCSP5UDgArEYuyQmY628WX 8cN3mnxfsPSfOUXoJ5SLNQrcrduyXKQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aso5oJJ6; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690775; 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=z56f15PtBl+UvHHvSB3Qx1+Za4NemO81qqaBL/Rijfc=; b=EyqD5VQpQe/hIQcgiML+1+n1DMNsWFhU2RECEdnzAL0sh5bFo1CU41RgUrUjo2WcHz0nFc nZFDYyw1CC3Kq1kkLMllm+c/EBtKRGugjp2wvoHIUgU+96k8mo0++AzE7k/IZtxCNhsQyl WcDYTKu17WEvpGjnTtY3kInDOGEFOcQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690774; 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=z56f15PtBl+UvHHvSB3Qx1+Za4NemO81qqaBL/Rijfc=; b=aso5oJJ6oAQm5N4KHjTiaJiXDbY1WyU1AaAnmAFMBV44XUQMEGzVdfBInPTF6xfTsBKP1s 4heRTHPdGrhocSTQu5Law6h+jDEvkMpzaTIjhoKCWWUCq9xXQOmSXE6HoSXJh5slBAljTo OW2wa4oOJS8xTni83zWXLUhsQStMhvY= 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-14-Ea0Nh1k0ME2JTUIPiSiprg-1; Tue, 09 Apr 2024 15:26:09 -0400 X-MC-Unique: Ea0Nh1k0ME2JTUIPiSiprg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 3DD5B3C3D0CD; Tue, 9 Apr 2024 19:26:08 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B0B440C6DAE; Tue, 9 Apr 2024 19:25:56 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 13/18] mm/filemap: use folio_mapcount() in filemap_unaccount_folio() Date: Tue, 9 Apr 2024 21:22:56 +0200 Message-ID: <20240409192301.907377-14-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7F05940010 X-Stat-Signature: cupm959hwkwtworb3bgtxn1k8t9e8rdi X-HE-Tag: 1712690775-126818 X-HE-Meta: U2FsdGVkX19/aWwZNLhYH518r7/jZU5ebFm6a6F1J7w5jNM1UViVbZMyfcwO2y1K4XCg40S6GG4+MVVcMBlqLJe1uK/kHFzdq0gvNoXuknjmopwmSWFXVsKSgW31D8NCQb/jyJcJ/ScEkWsjmQ4grVn7t+Brg5JI9fOLjoJgMqhgCJty7YAtVijs4w1X81ry0VOCo/QG6alIm5QdmVFTO/tSK87YMc703qvJMimEKdbYcprUXNt1zLwYqIfoygpuu51A2S0soMKzmw7Oe0pchRl4NlCD6YK0CpQqlUIn+RkgYCB3+r/4C+kWi9YRR6NRopPT9rGGZUmtLvdF9Z40a83BSwtFlnlo1JaNHyXHkRBdbCWRnbGMYSHtvBXtMkyKWoefYkHG+zBJI/ostb9Ip0eipdz939g2URvZjizFr/rxashiGLI7USc53E16uGUH3WNd7hgX6WYgh2yEHz0aStsVqiBAeajqf/f7ffbH6/MODlVU0NJVOJArybqkH/XSSNe7u3j5dj9c2NMWI6e+klahGA4UzkdEOcsvraZugovXtj3wLEX21Os9ZWqoB9efjdXSEnUv83fzFlgnQVsoXviKc8IRQSD3xYGbzIEsOiyezeTX+17+93PtzxoT+1xvIj2rP71GjvayCWoRW/9jJWmV1HIHCACgYHNv+ZWkapfKjP+TtWPK4MyIPBNcVTDld5CIomMcWf7gnMESJMXnCX0qjWOwEu8vbLxp7okWAtCQGXJgdrfYIITbSX0x9eYNNDwc7VAkOn5eVtXoF9L8ywP3E3KNjDaFwlbuggURRMhIgQfGKBBi+90PyFCNVVNkL2uW8hwWsOkwu6xKPdjJllr8OhGuUw9YGE67EbQT6T08sxNpPs8Kljz8TRVTylX712e5QzPy+YT9BvDQSg820L2U7lesujS8fJC+wc7sJ0CWapk89w+ROYCEtN2YtQnZQBXCrnA9BrWUoH4ErTu uIhzZP8E FXNBEPjv91KJnvpq1f7/fmme7FBs+ZOr41aen5x4EVEvE48b28cXNDnE7iXHz15UphH+ZBs9BBukhv8h1ynx7iMXXW9vpjNUUHGMPrVFknsGD5NmcHoPYcRTFvzSdedAv013SVNs1MDqb0A7cLmyYOzBMrFCwGaaZM9T/Mdsf/Dx2kXIWZBRBN/WPLIzyFOGk49PLpt8QyxE/CtasO/6dNXQocbh6V3qM7XDu 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. Let's use folio_mapcount() instead of filemap_unaccount_folio(). No functional change intended, because we're only dealing with small folios. Signed-off-by: David Hildenbrand --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index c668e11cd6ef..d4aa82ad5b59 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -168,7 +168,7 @@ static void filemap_unaccount_folio(struct address_space *mapping, add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); if (mapping_exiting(mapping) && !folio_test_large(folio)) { - int mapcount = page_mapcount(&folio->page); + int mapcount = folio_mapcount(folio); if (folio_ref_count(folio) >= mapcount + 2) { /* From patchwork Tue Apr 9 19:22: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: 13623131 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 CA731CD128A for ; Tue, 9 Apr 2024 19:26:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DE176B00AE; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58E356B00AF; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42ED86B00B0; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 256306B00AE for ; Tue, 9 Apr 2024 15:26:24 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C3F6E40553 for ; Tue, 9 Apr 2024 19:26:23 +0000 (UTC) X-FDA: 81990974646.06.A8D8C08 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 219651C000C for ; Tue, 9 Apr 2024 19:26:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PifanRhK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690782; 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=P0NYc9fiw7RbFbzUOP+c9IZVrablCrwSqa05Gf/mEjM=; b=sm+OCUOUxvAfghg1DitF0DaDt4lzNlMHpInBSTEJPUsw7k0XtFSYg9/+Fy3ppJ6MnDJIKV 8nZgDj2bfRn2e33C8as3a8DHyuWY04H1ztAsv1KxQHcOirJK3M857rcAbAsRh6n0dXf4T/ WdcF46910vkMvfk2qp+xUL+rTHuvg9E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PifanRhK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690782; a=rsa-sha256; cv=none; b=pzeDHedZTyJRN2pmy2EHJj2evWArx8yAgeI8uUpJ6m0Uw/LLmw0blDCmPxE2FAsBVqjtCm wFnEbE1P41sfNOQETKVPIZ5CGAB7sDbcjeIXkdNQEuAIi2fLSaUzlHhq+d5UmulxiE7jNd zmXwUERFwnaoRbf1RD7Y0XrmAyEGIRY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690781; 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=P0NYc9fiw7RbFbzUOP+c9IZVrablCrwSqa05Gf/mEjM=; b=PifanRhKtHC+q6DszmwWXFttV97v5KhkTV3r2fI5cE1bRgpmNae5jnjfW/wHKQpPVSY8R5 TwYAbl6uffl9hQjoXa88gEt8mp7ip92TJ5em/WWi4RIpx7sRy14eV8T3Wg8+dQSablh+QT ZZCZrADcXiY+GotAcoIuPBCo7EAg888= 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-227-LSK2VHheNtull5pEDNikGw-1; Tue, 09 Apr 2024 15:26:18 -0400 X-MC-Unique: LSK2VHheNtull5pEDNikGw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 EBA28890521; Tue, 9 Apr 2024 19:26:16 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9815E40B4979; Tue, 9 Apr 2024 19:26:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 14/18] mm/migrate_device: use folio_mapcount() in migrate_vma_check_page() Date: Tue, 9 Apr 2024 21:22:57 +0200 Message-ID: <20240409192301.907377-15-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Stat-Signature: q4cr34udj6quenwj4awgytfhignf7y31 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 219651C000C X-HE-Tag: 1712690781-856174 X-HE-Meta: U2FsdGVkX1+RSEAPiDFdAdFclYRkhZpdNZ579iYVkKx4+YemPgfB14xQlZ0zmqeztFkUiUJFXcd1eCBBCozp6nVmSXbRBwhuHHZvcfq3eIbWYRKvNWPQmERHeIFrRu/b1FyWvBtxPPAbIiwpNIhPTzeGp7tcAjxOlVCBTkkg0W6Zys1AMzi5BdLAEUAE7xjUAvQowS3JCXycKS5Rf8zSXeEIoS+01tUsf2qwcbQqC4PcjyGCKNHD8djVIrTxupnvbY2D7buac/R7FTVo2XY3HQfovF8UfRdrlzuTOhU1PG50v56BKVzOCFaCW5BdEZJklRgKnqHSbuRLLRePBNszfbZl1/pIWfZuVl+Xvs0VIqDTGyKrt6p2ReVQnVsnd4OBcMgbgFmrFlejcCKuTboIpDzAYuGqAv05QEC0lfPPnkyUbVmWgcfSR+yEgEqSQHAL3p4Rgm7/IbhMXEgzepjVwaQhLyzEQijEGBeJPKo7FQafjkckTkbv5M118z6BEQDXE3544qn0aDJ1OUtJaVBDggKKexcYasiY2zBXNcASIWlijf23E6s5jts1mj7jOaBfHKmOT4sa4Swot5rZdtsbKB2sUeOylKAi3idfaDebtI8HFvn4NFImiRO473pYGBJnWwLGwwHkCap1oA+v1Y8+NVM/d/jub2k2+CcnmuHFP9dSCRg3QSKF6TKiAz+I6/OfT67BpGhu1X2062SV2GJSp/6pnOZKlsRbTHjtiwQTuaVcsuiKvUCngstKgWUa71ydLgzWTzWmlVlSVHW/HDrgIln5S12moYZakdXo5tWwiSnm49hk8EjZGbbW0AurDGztcH5UJH7C0wQWvn6XHL7KnykSzbUQssvBgBuN5JM0gsV11xxPE4YR93b16SZcKrCRBenkYIIlT/nip4Li8voULDpms8j7CLphns0kUhn5hCUVn4Z/Nga4WlGqIgUfmAixP+V3Aap1znJSU5eO3/d R5iAWQA+ M15WuI3HUZ8nYUk582fcfqghsGiHpu8yJjfOqS27If4tt9ky2YCHEkYqVTA1K67swXpHQVaCc0fE/IPicfvPlHk/+RXhGXJjbXcRgIro4NhpWOeJFLdrjHh5MHE9HoK5fMDyYpEX8PKRB9UAEzikyrF1wkDMULU5xoQxZ2cuMy2KG9SLpUFRbCOntFvIdIhB9L6eExsxyHkd5LZVhzI/ORKcItFlHtZsbWhGe 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. Let's convert migrate_vma_check_page() to work on a folio internally so we can remove the page_mapcount() usage. Note that we reject any large folios. There is a lot more folio conversion to be had, but that has to wait for another day. No functional change intended. Signed-off-by: David Hildenbrand --- mm/migrate_device.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d40b46ae9d65..b929b450b77c 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -324,6 +324,8 @@ static void migrate_vma_collect(struct migrate_vma *migrate) */ static bool migrate_vma_check_page(struct page *page, struct page *fault_page) { + struct folio *folio = page_folio(page); + /* * One extra ref because caller holds an extra reference, either from * isolate_lru_page() for a regular page, or migrate_vma_collect() for @@ -336,18 +338,18 @@ static bool migrate_vma_check_page(struct page *page, struct page *fault_page) * check them than regular pages, because they can be mapped with a pmd * or with a pte (split pte mapping). */ - if (PageCompound(page)) + if (folio_test_large(folio)) return false; /* Page from ZONE_DEVICE have one extra reference */ - if (is_zone_device_page(page)) + if (folio_is_zone_device(folio)) extra++; /* For file back page */ - if (page_mapping(page)) - extra += 1 + page_has_private(page); + if (folio_mapping(folio)) + extra += 1 + folio_has_private(folio); - if ((page_count(page) - extra) > page_mapcount(page)) + if ((folio_ref_count(folio) - extra) > folio_mapcount(folio)) return false; return true; From patchwork Tue Apr 9 19:22:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623132 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 DA340CD128A for ; Tue, 9 Apr 2024 19:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7171D6B00B0; Tue, 9 Apr 2024 15:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C6E06B00B1; Tue, 9 Apr 2024 15:26:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58E6D6B00B2; Tue, 9 Apr 2024 15:26:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3CC4C6B00B0 for ; Tue, 9 Apr 2024 15:26:35 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 094EBA0C9C for ; Tue, 9 Apr 2024 19:26:35 +0000 (UTC) X-FDA: 81990975150.05.0D179FB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 87DEF40005 for ; Tue, 9 Apr 2024 19:26:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="LEKX/Zbu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690793; 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=NywHbuKGZjP8K2r9cm/m6NcEBx0o+/6jkDGUacCW2cY=; b=Sgk2ctu3ig+bQgJnTfRGyIpnyid+tQUNP9qx92hzbDwj0/ENmiAPJ3UMpAchLOSaHtuWMo rrP16czQQDP1mJK6FQGYuK2nOm90br0tePq7o0XiO1oSLzitGO6irnY5UUjeehrnEYGS2N SXhWwn49/Wf6C92lf7Wn2MSSD1z+dbU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="LEKX/Zbu"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690793; a=rsa-sha256; cv=none; b=bBf1KsQO+qh9uud8u80qFt6XgJ+W7nzq7dSnx66luyaApDjsVUW5H+KfSxGkJfBi3B8vzW +wYeRSe+/VWaFhlbcEtammUGcR7c1kwiq0QYEBb2d8kl7raFUFyuApZ50JYrYskga9QvJW og4/5+tnJE9Xn1RzMLnjW61+BZ17T7s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690792; 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=NywHbuKGZjP8K2r9cm/m6NcEBx0o+/6jkDGUacCW2cY=; b=LEKX/Zbuw+OASiYjzj9CcZ7bGiUReF1ubDdycU++86SYb7+56Awpfb81UEa2bOrx0YHQSN X51nIZvQUqTPVhxdfxKYePrEopu8g7azeD3Y9v5Qa3Zd53DuDg3Qlad0+B0cqeunJZdle9 mqSC7hFv12nnoficICDD1GCigOi6ZIM= 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-695-RFd2M04MNAeCUlOs7BBABg-1; Tue, 09 Apr 2024 15:26:29 -0400 X-MC-Unique: RFd2M04MNAeCUlOs7BBABg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 F246E1C0512F; Tue, 9 Apr 2024 19:26:27 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D11840B497B; Tue, 9 Apr 2024 19:26:17 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 15/18] trace/events/page_ref: trace the raw page mapcount value Date: Tue, 9 Apr 2024 21:22:58 +0200 Message-ID: <20240409192301.907377-16-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Stat-Signature: 39gt4rq3qfn4degfbwi4mgubq7scot19 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 87DEF40005 X-HE-Tag: 1712690793-131580 X-HE-Meta: U2FsdGVkX1+1GWglXbtcwkSmVaQC+JwO9EVSPnN3lVRf57mEPfLBUL1nWvq3ySjr/R50ksibfimAP1OfJSIzrgHOD4lgBy2x8+BpC0gkgvQXpvNgIVDpU5DbVeHhMgqbzQenN/ag+/Y5Uz49qX1IXDXyT9SSLN++pakwE3oWm+zsLwqJlDZuMCZ0kDz4BHCxFCdRYpweKxPy04ZUt6+jA/fIcQuFj8MGLPU7Hp4s1M8/ecpXp1B6Cs7aZlxr49NYjGk9f08NpAJT4tUXCmz/Ii+XSQhlVpE6r9gPhfoSgClsxAql5Q2oqPu+2Y6emcqw/9AwOXevkArsUym/WACYXXVMD5q5K/dD9GkkGGNENpFUBW+smlRKryu0Jt9H+s6o3raybfc1AtkaeMCubK8QxCyP/o0ElXWdjcJnHnNajhu+1oWXP3IKQTXqkexvq3HgJMYRV16NzOZYiFEfNDDLB8mvnvPV5NDAk2FpH5Th12cH/YZ/v3+CTYANkn0ns+UWs1dPT/ZhTWbV6cA8zM2c/DMpIUYoQst5UoAIJ55rHR86rrDv3yvajjIstEAsb35HNrFkEL9meKyxqOm+2wbwGWiMdwTzOeDj31cSgnTY3IO5UrEvDNgmWR6wqcK88DaLJqXi8QBhkJfhXGE3/8bfyPLWTBozc0W5FaP4h+lWOtBeZ+6OMeP1mrETpVHKWdcWdkBwG6vm94f2ams6Wvt/EeHdzX9chwhV2BF6veQNLgwRGcQ0fEVjrARI8CwmsVnbmFQ+5d3/rTVBnapChs8b9ez0c3dSeHjRe3jhKsaeY2knhAuTXihjwhhs03rQwCsWKz5d9Pe1c7tAu0OhJbzCFPsikwX4mfjo62oyx7/ECnKFrk6pADNQ73G231gFy3wE7wBqvpJh5URAZMtbCdtAlt1lkaPrztlzAWWljMRC6trILH35FlZN1ZgcSYShPk2y 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. We already trace raw page->refcount, raw page->flags and raw page->mapping, and don't involve any folios. Let's also trace the raw mapcount value that does not consider the entire mapcount of large folios, and we don't add "1" to it. When dealing with typed folios, this makes a lot more sense. ... and it's for debugging purposes only either way. Signed-off-by: David Hildenbrand --- include/trace/events/page_ref.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/trace/events/page_ref.h b/include/trace/events/page_ref.h index 8a99c1cd417b..fe33a255b7d0 100644 --- a/include/trace/events/page_ref.h +++ b/include/trace/events/page_ref.h @@ -30,7 +30,7 @@ DECLARE_EVENT_CLASS(page_ref_mod_template, __entry->pfn = page_to_pfn(page); __entry->flags = page->flags; __entry->count = page_ref_count(page); - __entry->mapcount = page_mapcount(page); + __entry->mapcount = atomic_read(&page->_mapcount); __entry->mapping = page->mapping; __entry->mt = get_pageblock_migratetype(page); __entry->val = v; @@ -79,7 +79,7 @@ DECLARE_EVENT_CLASS(page_ref_mod_and_test_template, __entry->pfn = page_to_pfn(page); __entry->flags = page->flags; __entry->count = page_ref_count(page); - __entry->mapcount = page_mapcount(page); + __entry->mapcount = atomic_read(&page->_mapcount); __entry->mapping = page->mapping; __entry->mt = get_pageblock_migratetype(page); __entry->val = v; From patchwork Tue Apr 9 19:22:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623133 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 3CC3CCD128A for ; Tue, 9 Apr 2024 19:26:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C46C46B00B2; Tue, 9 Apr 2024 15:26:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF6E36B00B3; Tue, 9 Apr 2024 15:26:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABEB56B00B4; Tue, 9 Apr 2024 15:26:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D0BA6B00B2 for ; Tue, 9 Apr 2024 15:26:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2323380555 for ; Tue, 9 Apr 2024 19:26:51 +0000 (UTC) X-FDA: 81990975822.25.7E6E605 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 65861C0022 for ; Tue, 9 Apr 2024 19:26:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MoZfT7Bb; spf=pass (imf10.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=1712690809; 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=NFT5r3M4f3jd1xpIDzMU21YnNFkRRFHEv0eJ+fAnhKQ=; b=6jGyZrvJZEohZC6wd4aUUxdv4T8Oh9dT08Cz5IslNZz/ZfqZUc+lnI36vP2Oia/jgos0XX HWa3cjqggz9UGbi9yAa8nCBxtICVNngBsS/J3b4MMOOjEghldajt2OwnffvUvIhzcDmAKF B9yXCv3Ov9r936o3vH1IYxUBVmu2WLM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690809; a=rsa-sha256; cv=none; b=Wili4zrIlTubqFC+FI2uSaq7MgDkmN1s9ipkyn8OgRQA+EiItp+ByUUHQwfnrlSyNmA5iS ouVUVIDTRjGWmUTMV54rrL/BvQneRoeeBICvUWO0MGJyiSliegrsTCX2X7XGxTzFGoUegx Kqp312eP/ib/N9FSFsbku6u36AFAWxo= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MoZfT7Bb; spf=pass (imf10.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=1712690808; 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=NFT5r3M4f3jd1xpIDzMU21YnNFkRRFHEv0eJ+fAnhKQ=; b=MoZfT7BbkVFdjihTJtYi5xsmlRFK4ypACmsdUOB2tt8uEgw7UdEz26X3zplCeDMkToEfWz ebvjjRliBDf7F0ZgNDSK3ZGfNed1goz9b6S+pOWl54ULbmdCwxqxpoqju1Sy7TBXnbXbA6 FroTmbvtJxVyfopaGuQ0eedrzAexFT0= 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-654-WsCdNN_cNKiuXalsvr_glg-1; Tue, 09 Apr 2024 15:26:44 -0400 X-MC-Unique: WsCdNN_cNKiuXalsvr_glg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 89ACA811001; Tue, 9 Apr 2024 19:26:40 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BA6940B4979; Tue, 9 Apr 2024 19:26:28 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 16/18] xtensa/mm: convert check_tlb_entry() to sanity check folios Date: Tue, 9 Apr 2024 21:22:59 +0200 Message-ID: <20240409192301.907377-17-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 65861C0022 X-Rspam-User: X-Stat-Signature: zqefgm188d3yisc6jegzhit9smju5ox5 X-Rspamd-Server: rspam03 X-HE-Tag: 1712690809-761381 X-HE-Meta: U2FsdGVkX1/SSqAWnfzTeaIGNfHlxYcKriUQYzbsBlw2oHEwspSY6V/Mys5gb3r3stFV9VT4vncEfqSnUF8U/boN+LOCSrxmNLiIFd1xS5ktKnhnOXS/1LDpFNtPMtGmHtnmcKe+WlcvlwJaTvVI3Ex5BkVX8K8HIBpOZ02JGAmMXXT0iWFQEWXalRxyXeOEKumZip1bzkZtk5m1FDMX4XJC0zPM8ZT8T4jylOpjbiUesKiyvfjEPLfZdSK55M48huL9ezTA96fOXvfSHtE3r5LFxUiyHvPWJv2bNp3slMJP2O/RIudxx1+ALhF6QkXp464dUBz/llg6qRZL7CdKqrIaEFciRa4//ng7V8udjFBJPPO0xNHKS8WXydoNJCU1laksIhSNcCv7GyXamiRCMcdzCcxWW+51JK6tIwY0ae/NowWDPxdg6oruQFTg5xjbvJYxRk1pMCDNC/LeSJmgQgPkyPlhalnvisT6bE/ZV8m4vwjlXcWtp4/8nPdUIBL9lw77dBPrqxoEfS3CS6xSMbp+fhyw52jIuNwZD+4r13IPas+V2RZEpaHtEGgHuS5kG0NfpZBmJ/+SkaYToFsizGj2ZmDbxPbX76VsGXBuJON/4iOFmrL7NNNF1T6IXjScaTgC4yUnoaAbtCv+e4pKbZR8puTCF5x9bza0X4zv3TZB4ifYPLgRVQBvFagYXL5FuzfHYTgxa3WARzYyMdguDgICKmHzoKNq7ER3m9dOrAKXfAHLR8FbtkY5dfAS0VNHDd01S0f7OvLBVWDePr+1/z5dCH1p88UUmFtR+blcHILS3jEK9QvFnJEYFB2NJ5A7+T4sCc0CZVQ7FzdWri0i5atCiw8iHr8xW46wyVPx0MTkvUGOSkKvqa5mpb5JiD1IxPQddZ6QL8J+xtE7iDS4KVY7dQ6WOY31hZDCgVVPIFM2PQB/09ZhU6JYkAcOMy6FZu5Ibqdp7/BvPrmar3u d+acGpQj W4nZ1p4fjnl/WECEqC6ychZ2ZABUoYOaIDgkSjeoWuMQpB2I7R9SPYQROg4jolISKhVfpjIgASh70C7PR2kf1KMKUjiZV/p/450iF4LaUAY6tb+gnQFAqw+RV97StafB6GxNvLLHAwAXRJ3E/t6psUbst9nUlDS0YuuewYZWGlZJyLW0uda8ltAyV53o1mPjXmLBqKwrTgV1DFnSErfnz0VPZkxltPS5CHfGw 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 want to limit the use of page_mapcount() to the places where it is absolutely necessary. So let's convert check_tlb_entry() to perform sanity checks on folios instead of pages. This essentially already happened: page_count() is mapped to folio_ref_count(), and page_mapped() to folio_mapped() internally. However, we would have printed the page_mapount(), which does not really match what page_mapped() would have checked. Let's simply print the folio mapcount to avoid using page_mapcount(). For small folios there is no change. Signed-off-by: David Hildenbrand --- arch/xtensa/mm/tlb.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/xtensa/mm/tlb.c b/arch/xtensa/mm/tlb.c index 4f974b74883c..d8b60d6e50a8 100644 --- a/arch/xtensa/mm/tlb.c +++ b/arch/xtensa/mm/tlb.c @@ -256,12 +256,13 @@ static int check_tlb_entry(unsigned w, unsigned e, bool dtlb) dtlb ? 'D' : 'I', w, e, r0, r1, pte); if (pte == 0 || !pte_present(__pte(pte))) { struct page *p = pfn_to_page(r1 >> PAGE_SHIFT); - pr_err("page refcount: %d, mapcount: %d\n", - page_count(p), - page_mapcount(p)); - if (!page_count(p)) + struct folio *f = page_folio(p); + + pr_err("folio refcount: %d, mapcount: %d\n", + folio_ref_count(f), folio_mapcount(f)); + if (!folio_ref_count(f)) rc |= TLB_INSANE; - else if (page_mapcount(p)) + else if (folio_mapped(f)) rc |= TLB_SUSPICIOUS; } else { rc |= TLB_INSANE; From patchwork Tue Apr 9 19:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623134 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 29AE9C67861 for ; Tue, 9 Apr 2024 19:27:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B845F6B00B3; Tue, 9 Apr 2024 15:26:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B33EE6B00B5; Tue, 9 Apr 2024 15:26:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D4AB6B00B6; Tue, 9 Apr 2024 15:26:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7F0296B00B3 for ; Tue, 9 Apr 2024 15:26:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 525A21C07D0 for ; Tue, 9 Apr 2024 19:26:59 +0000 (UTC) X-FDA: 81990976158.21.9113CCB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 9E015180002 for ; Tue, 9 Apr 2024 19:26:57 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W6KVD8lt; spf=pass (imf06.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=1712690817; 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=9BvBZKQ0eVCGMopeE4n6MDTyBxCnbPUcn/eYDU7e+Xc=; b=VF/afDb0pjOhF9HspZqiR4TfO9S5snbfxQWj6yiInPN7980IkcQpAcsevssnZS0vSb/hbW ie6mnUGtAt9ZGIDiS1wN/7L7k9t4Lq3o0YZktkp/5XuSJl2b6ExsA7pBPAApUt26Uaydni cRt38mo7H5qBtuT841P9WxuW1s1vmyE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690817; a=rsa-sha256; cv=none; b=bMsIaq56cqQjYgSU8rTtbaBu4yRa8pzs1QHP2/C1QFYQL8zU3ecRQSIaIpt26eBoHLRUZr 5G1cKbrlk95YYuBTxNQtPJnE8wSd3TeLPRM3T62+Eq6osLCpJS5wg+/umtE1Ne3g5hDpNg lQxU7iDPQmJsBij/tJ1fYP7S1LwDz6U= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W6KVD8lt; spf=pass (imf06.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=1712690817; 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=9BvBZKQ0eVCGMopeE4n6MDTyBxCnbPUcn/eYDU7e+Xc=; b=W6KVD8ltNPQZnCc0hqsQNI5IfVf7VaX4jrTqB0CIB1zKSgOf9oCL7w4vnKIIv7s1mjxIAv N05jKeisJIEVoYPQsfMPJ+ppjxF6eyjXErVLriVeUWNQSkCGOBuSc9fmSXHU0Mx++JhWCU EMHbG3W72i4WeHIEMqGZNa8bXqvmVPI= 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-183-3faOSIxmOvCIGn74HLebCA-1; Tue, 09 Apr 2024 15:26:53 -0400 X-MC-Unique: 3faOSIxmOvCIGn74HLebCA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 76CA5188ACAA; Tue, 9 Apr 2024 19:26:52 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id C430140B497A; Tue, 9 Apr 2024 19:26:40 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 17/18] mm/debug: print only page mapcount (excluding folio entire mapcount) in __dump_folio() Date: Tue, 9 Apr 2024 21:23:00 +0200 Message-ID: <20240409192301.907377-18-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 9E015180002 X-Rspam-User: X-Stat-Signature: sr9s63a8cuifjx5rcfasncin9qmg19q4 X-Rspamd-Server: rspam03 X-HE-Tag: 1712690817-575760 X-HE-Meta: U2FsdGVkX1+kXB5s6MlE3rhtCq4fPAs91aEfdA4r8lCTKrUOLz92IMkPV1G3TTlk1Zstz0pUCA9Rzsi3fdBHPfWmwTfpw8hCG4m3Phlh/Xp09TCHCfz/K/2LhS+p38K2e8T5B8C1gjsKoSwIorTJE4o0Gzxra7gjCGqGHptMDi5JgU+0P/vmEXYYzFrlng0gEjUfb6utn8ehaoFJqSmQjFefMtH8IUuFT7H+hRWk8WnFMz0XQWSDhwBTNmyQ0OreF745omLSNMbwpBfcY4if/yJwnKeGj49/6WpeZ3mKtku1zR0hVnUGY+gwHMUVOHFb6lVHZgz++ok9zRXIi6lHzgUbZx3cW2ZR3pVOR7c+zRm0WCVYpXL763Y+AIJi502KW/finRGVOuHPrIQ3/uclGhxTNDUkF3DIKs8314xk9kZqNB0bVOeUJYSYYaBUxB9lH/xJcwAiF4eK4DLPxx5HYf9HbfwNJiVh8JaK3L685qurplZAOJ0Y9EJ4bYzaTW1lcVF/z6Wd8fk63gcl3gPJN4S5wz3IR2NRw8wp9iSS+xECt/JG+MpCUTmEkK/PkvsM5UuOVVWRVGUGIvrW80hLlByMXXIrUxP14Vp+iVIr80/vDRpBELVWQfR6SjiYR3zho3DInzepATJDWl0dwnWZqGyAwY3OGYRXScDtJUmwXAkjXc58aFTIu2O5Iktq6+DcGQXgq+3nImK4iowBJ5Lx2eATr8kdDqYIbSBSGm6k8iM1k1+niSILAZa6f93fx2XogvS2bo0rpvAD4AyRttbHfqSY5g3a92DPK7uxQAzZcT2rJbHlqDtbCaTZrqrXHIw/aQasCteMe7CCvSbiw2VXCuwzuv/gIVsaT9WvVgMgCfA7sDz8vJXZp43F7Xwwnks7Zztdx0+lIOEoYP/7vn1/FI5+3jtIExRcuHrBoxPLeXsi6Ff6qjqij8G24ld/wFVm1sD+NftWH4rt10flnHA dBbgCgir mk4VQHAnFgYIq4Dwezlqtts2jl+9Sv0TTLMHTx51gdO+s/U03N+hjL2LmFg7li0GhS+jwlco35r/Xd36UiFZsmvyn5D7xpN0xLR0SwLY3h4OZqhf4y/6xcUdZU97irtOyQYeT8UAuVVD+wHCD7HaTUG/DdvAT9ozE6oXILs94u5JfZNGddVgqIRGSjw8Dtq9fVW4hOupk2besLI8r6eucZtnZT+6dfeK32iyg 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 simplify and only print the page mapcount: we already print the large folio mapcount and the entire folio mapcount for large folios separately; that should be sufficient to figure out what's happening. While at it, print the page mapcount also if it had an underflow, filtering out only typed pages. Signed-off-by: David Hildenbrand --- mm/debug.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index d064db42af54..69e524c3e601 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -55,15 +55,10 @@ static void __dump_folio(struct folio *folio, struct page *page, unsigned long pfn, unsigned long idx) { struct address_space *mapping = folio_mapping(folio); - int mapcount = atomic_read(&page->_mapcount) + 1; + int mapcount = atomic_read(&page->_mapcount); char *type = ""; - /* Open-code page_mapcount() to avoid looking up a stale folio */ - if (mapcount < 0) - mapcount = 0; - if (folio_test_large(folio)) - mapcount += folio_entire_mapcount(folio); - + mapcount = page_type_has_type(mapcount) ? 0 : mapcount + 1; pr_warn("page: refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n", folio_ref_count(folio), mapcount, mapping, folio->index + idx, pfn); From patchwork Tue Apr 9 19:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13623135 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 84AFACD128A for ; Tue, 9 Apr 2024 19:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19B3D6B00B5; Tue, 9 Apr 2024 15:27:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 171346B00B7; Tue, 9 Apr 2024 15:27:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 037F16B00B8; Tue, 9 Apr 2024 15:27:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D7AD46B00B5 for ; Tue, 9 Apr 2024 15:27:18 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A927C160541 for ; Tue, 9 Apr 2024 19:27:18 +0000 (UTC) X-FDA: 81990976956.15.8ED3626 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 013FD1A0008 for ; Tue, 9 Apr 2024 19:27:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Qqjlc9uO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712690837; a=rsa-sha256; cv=none; b=ICME/RwtpUz1+r+bV+c1k90HobmK12DlDFUCbtEG984Ak/YEdPmI6BYHQYj3wefezZAYQ2 Bzwc9ke77VeTM1T235XAILL1Kf+WhnaRwi2v62yyn/HrqIke1wxG+PXNeL7SUVlDuMKFBB 990ovls036G+z3m79Rh4Nf/l/zyvoD8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Qqjlc9uO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712690837; 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=IIAPKUbl/14adNwXxGFYrjBvnjcRb79R1asl7bmu1AM=; b=1sRYicJ8U5cZ1V2pLdlKnh6arm4DJmhWv6CLt3w9qcRVviLuQZlXI7a5mP1s9dzMhIsxzc SsY8bif0QfthEH1v70eylelkyalt1thgvpZr5GyH2vTeOlgER+SqWKvjNyYrsLKyJDYOG4 eh+biIDRRuC/NLWVg7EhVl5Bsf2wEx8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690836; 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=IIAPKUbl/14adNwXxGFYrjBvnjcRb79R1asl7bmu1AM=; b=Qqjlc9uObVNDoVp2u6r+lUync36ccKEqh+xcuZOBYebclTK1KYnBehoEZMccJ+P2VfxXzl pMD4GFLcfYxurKUzQeUpiXEkDN5n1iPiOOaotWKUnkgBz9FMgCHCVKsxVnsSPXKGhW9XkW 0Duh/kZN0COpjIvtwKZDEL0bFnkYps8= 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-629-cPzfINHFMa2e8lR0ggInCw-1; Tue, 09 Apr 2024 15:27:12 -0400 X-MC-Unique: cPzfINHFMa2e8lR0ggInCw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 1A5CC830E7B; Tue, 9 Apr 2024 19:27:11 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9D8740B4980; Tue, 9 Apr 2024 19:26:52 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 18/18] Documentation/admin-guide/cgroup-v1/memory.rst: don't reference page_mapcount() Date: Tue, 9 Apr 2024 21:23:01 +0200 Message-ID: <20240409192301.907377-19-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 013FD1A0008 X-Stat-Signature: dniirisnjdr5nqjmoj6apzanu91t48oy X-HE-Tag: 1712690836-947122 X-HE-Meta: U2FsdGVkX18VL7RXpjiILGmxCdTjmMmgq0wWX4gLFUX5Y2iNzC+/hhjCO1hk6Uff9MyM2hAUWgSynuwKVPWTrfJV7Tnd01sfpFWKBUyreh6VBRJ9rPdzn39KlkPo91zVXMltKCgt7IsdQ+MVGXvUn7Rq4+iE2cEfQrGPJFsa5NL7Pe1ahf+w1dSf9qkMqvGaFjaq/QcTzqXOEub+wIzHbKzrJdes9ulrEl7YsCzCtFDakTk37c7I/YXFiGsUNF+uy+v6FY5foNrbEama0QCiMcdS+15LhJ6WimeaZbGW6gUAdLLBb4jhy5h2o/vpDIUTKQ0wVah56dUxzzKIoy8MaA9sYrMenN3AaEH73O1EtyBpESRO1NX+XQok95SfCtqhVT10xrQm8gKJkwW1MBTa+ziR36YpPLMNAFjjC6VEwDjlHmQKL1bdmZtB0GoRrThuWpft5ORWA3BMl54gW/ronMPMgWKnkEimoM8Qou91D0H1gtJzQkHzQh/pWIR6RbfM3lBOcLc/JdQi08Gx6yPgd6FbgTqoOwoPvJb2a0pW/sJ5OjB+/caAAe3gSd45qD90BpqMvGMY5DzXmw5eLU+pQ1RvkfBKXwH5T0tAXkFufWI5Lgy4caUeISVntccxPb4g/CyM7Q3dL8/Q8cwKdaA0cA6ZTJ8gszUZym8crZ1cJWAiVhO2v0HhfL3yYhWUttAsPi0iO1d2cjubys1yR9FP92QJe4FzsNXni8rN2+rKsLLS4xSgntTTO0N5EK3xghSYVGSn1nAH0nYDWXJtQMZ4CN9GNMpTZIvdNn1F62kEiH2h4PW8B55CgYK1/72D3KZ7vs7dYwdOWkC1Vd5pY1Fg+xaLhqcV4iVIrDQPfXQt+jtsQlYO/kRceWNpLRyvUNmmPLds210Sl+UsWtiVRrAPUls0GH1afJaW48wqCIFmiDttC/gmYHQABonGUKarjPt2ezdp/0F/2F/K94B48Xh e/usPkPM 5YuRodyHYB4K0mWMhQSwNmFjWyRJctywqJWqVAP00WwK4aAKcmfdSjm+Tiiogstxf0Xu6qy/9SmgBBQPmSQj1uKplfXnRQrUr/uFEJGHPDBhMzt5KQvIiMzIqWR/SvSstBkG9OdRjlH/Tf7cSixlXkjzibaZ8IP/XoIattf5Le0w7qh/ypIBq6pVR/kgTSn9L/TRFbrWDPbVvdU/xvz6olj0u/nkFTFHVaGDq 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 stop talking about page_mapcount(). Signed-off-by: David Hildenbrand --- Documentation/admin-guide/cgroup-v1/memory.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v1/memory.rst b/Documentation/admin-guide/cgroup-v1/memory.rst index 46110e6a31bb..9cde26d33843 100644 --- a/Documentation/admin-guide/cgroup-v1/memory.rst +++ b/Documentation/admin-guide/cgroup-v1/memory.rst @@ -802,8 +802,8 @@ a page or a swap can be moved only when it is charged to the task's current | | anonymous pages, file pages (and swaps) in the range mmapped by the task | | | will be moved even if the task hasn't done page fault, i.e. they might | | | not be the task's "RSS", but other task's "RSS" that maps the same file. | -| | And mapcount of the page is ignored (the page can be moved even if | -| | page_mapcount(page) > 1). You must enable Swap Extension (see 2.4) to | +| | The mapcount of the page is ignored (the page can be moved independent | +| | of the mapcount). You must enable Swap Extension (see 2.4) to | | | enable move of swap charges. | +---+--------------------------------------------------------------------------+