From patchwork Wed May 22 21:03:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13671078 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 71E99C25B78 for ; Wed, 22 May 2024 21:03:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 053626B0093; Wed, 22 May 2024 17:03:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 003BA6B0095; Wed, 22 May 2024 17:03:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE6A46B0096; Wed, 22 May 2024 17:03:57 -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 BE73C6B0093 for ; Wed, 22 May 2024 17:03:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3896A164CDE for ; Wed, 22 May 2024 21:03:57 +0000 (UTC) X-FDA: 82147258914.10.85540AC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 83B784001E for ; Wed, 22 May 2024 21:03:54 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HkD7xvPo; spf=pass (imf04.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716411834; a=rsa-sha256; cv=none; b=uw4x29+/LKKWp+Agz96xboqweSKKm/a8B+1FYv4/qA6ckUV2s3Y2ORCakG48OJvSQPXjvW U98630aD804b1s0RZU2NFFoh629wh7OxguLknwJWiSNogrFJXJHYDzreM1jUjGFRUfsZRG tTAJNwpG8W3g3o0LfIxax7UoQQZVIsc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HkD7xvPo; spf=pass (imf04.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=1716411834; 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=02LYfptPkP3NVWI/Y1/skwE/AqJ4JQacKiY+62xb+tg=; b=CYjq++YSOO/tBz1RbMYRGlmkZMBHm1r9z45B/uYtYjU1tjDg4afcG+Fx77j4E2v6vCUlHc kehTTTeyrnQIl823dnnh3Pc6oRjZer+ebxwFYaiUNoifY+FrXecyoJSz2sAneuG4TvT1qP h8pHR+JFxyNroIDavags6w4nCCXfBCI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716411833; 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=02LYfptPkP3NVWI/Y1/skwE/AqJ4JQacKiY+62xb+tg=; b=HkD7xvPoadeiytz857EaTNYmZWnh9Tq6j4tML/NmY8JXV4bp5wzkDyD4aB+Q8Is5kpV6Kc W4+cJEqILe1XWNrMA0Fdb1Eem3W7lnhJTdXMiKVnHsGaOQ2nLkNbt07bz7/tSgNIxXcr3e BXXaDChLzx8m1ekMXptB2gOqsMAwQbw= 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-30-cKasN1UEODSQMPyfVtjrrA-1; Wed, 22 May 2024 17:03:48 -0400 X-MC-Unique: cKasN1UEODSQMPyfVtjrrA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 BC5A729AA3B8; Wed, 22 May 2024 21:03:47 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61F1F28E2; Wed, 22 May 2024 21:03:45 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Mike Rapoport , Minchan Kim , Sergey Senozhatsky , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH RFC 1/6] mm: update _mapcount and page_type documentation Date: Wed, 22 May 2024 23:03:36 +0200 Message-ID: <20240522210341.1030552-2-david@redhat.com> In-Reply-To: <20240522210341.1030552-1-david@redhat.com> References: <20240522210341.1030552-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Queue-Id: 83B784001E X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: tt1jtwrz3tcrumc779fej59jo3pxhgj1 X-HE-Tag: 1716411834-870364 X-HE-Meta: U2FsdGVkX19yi4/gsXp3MkZAdz6xpSUgmWMg+hBFjCOlDSYfk2UsvPTcg5apebewRh6jbyLXdDzzItfCNtLib+znlOuWReNTSEOYz/q60SF9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QM04NJe9z1QNT9BRKE8mVCBAY4c06kEOn0b/Pg0MDbfui+5I6Q8hqbgvXNtXGOOm+YYyBPzS7PTGmUkFV1mDV+O8v3n7mCdAWo 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 make it clearer that _mapcount must no longer be used for own purposes, and how _mapcount and page_type behaves nowadays (also in the context of hugetlb folios, which are typed folios that will be mapped to user space). Move the documentation regarding "-1" over from page_mapcount_reset(), which we will remove next. Signed-off-by: David Hildenbrand --- include/linux/mm.h | 5 ----- include/linux/mm_types.h | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9849dfda44d4..018e7c0265ca 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1206,11 +1206,6 @@ static inline int folio_entire_mapcount(const struct folio *folio) return atomic_read(&folio->_entire_mapcount) + 1; } -/* - * The atomic page->_mapcount, starts from -1: so that transitions - * both from it and to it can be tracked, using atomic_inc_and_test - * and atomic_add_negative(-1). - */ static inline void page_mapcount_reset(struct page *page) { atomic_set(&(page)->_mapcount, -1); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 24323c7d0bd4..532a3030405d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -46,9 +46,7 @@ struct mem_cgroup; * which is guaranteed to be aligned. If you use the same storage as * page->mapping, you must restore it to NULL before freeing the page. * - * If your page will not be mapped to userspace, you can also use the four - * bytes in the mapcount union, but you must call page_mapcount_reset() - * before freeing it. + * The mapcount field must not be used for own purposes. * * If you want to use the refcount field, it must be used in such a way * that other CPUs temporarily incrementing and then decrementing the @@ -152,16 +150,24 @@ struct page { union { /* This union is 4 bytes in size. */ /* - * If the page can be mapped to userspace, encodes the number - * of times this page is referenced by a page table. + * For pages part of non-typed folios for which mappings are + * tracked via the RMAP, encodes the number of times this page + * is directly referenced by a page table. + * + * Note that the mapcount is always initialized to -1, so that + * transitions both from it and to it can be tracked, using + * atomic_inc_and_test() and atomic_add_negative(-1). */ atomic_t _mapcount; /* - * If the page is neither PageSlab nor mappable to userspace, - * the value stored here may help determine what this page - * is used for. See page-flags.h for a list of page types - * which are currently stored here. + * For head pages of typed folios, the value stored here + * allows for determining what this page is used for. The + * tail pages of typed folios will not store a type + * (mapcount == -1). + * + * See page-flags.h for a list of page types which are currently + * stored here. */ unsigned int page_type; };