From patchwork Mon May 27 14:14: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: 13675408 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 43C4CC25B74 for ; Mon, 27 May 2024 14:15:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1C8E6B0098; Mon, 27 May 2024 10:15:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD116B0099; Mon, 27 May 2024 10:15:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A947E6B009A; Mon, 27 May 2024 10:15:13 -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 8DD806B0098 for ; Mon, 27 May 2024 10:15:13 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3059941521 for ; Mon, 27 May 2024 14:15:13 +0000 (UTC) X-FDA: 82164372906.05.B3B2819 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 A1D0B1A0025 for ; Mon, 27 May 2024 14:15:11 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cnnWOlxR; 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=1716819311; 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=fI7k3N6P8qJ4FuS4bDw6lNsnGteHRLAJN+b2iNRt+tE=; b=t4DXo+7ooocxcA295Uf1ydO3oqtRImuGy4KlQiiMEbWfR8zCfioWV0UzHrgSDhWVrtGtLy TILDW5bdijH0QQvw8RjAmOCpyWPThTxoYzbQT+IEjlu6wZMrEyFZPy15LIF+LEWKd+r4TD KYTiZeR2MV1zi4Gw6SN2+aJ/8kJFOKs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cnnWOlxR; 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=1716819311; a=rsa-sha256; cv=none; b=u9yC/aEYpnXH9cBnjXLCPbTgLDQCEnwpbE1qrswgnX1VyviXGvDLk5BvnYCTun3jcsjKc9 UQVpybFhRegfWODdT5oGbPm1751vtFK+YRuof2KM7Yat53jZ9HAiueUQJmEGfxEDEHklP5 uf6PC0TlXpEMBzApcewhGeqDClsqnuQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716819311; 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=fI7k3N6P8qJ4FuS4bDw6lNsnGteHRLAJN+b2iNRt+tE=; b=cnnWOlxRhK2XTGBkMAwbkn8/24KarkDsBnn2LA/rOyrWhtX92rIjA+TVpaHlaXm24/RHqx Vn0NOmYkxBwCklK3RnxiDWuDCDyFdE4uZu0KFAQTiFbCbe/6h+U2y4XvX/GoQDiiu4IH3S khW6RXBlTlpSNjw5UJW427vu6CB/ayo= 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-550-kXZuQwgiNe2ZxgXhztVTPw-1; Mon, 27 May 2024 10:15:03 -0400 X-MC-Unique: kXZuQwgiNe2ZxgXhztVTPw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 CA8BD8029E1; Mon, 27 May 2024 14:15:02 +0000 (UTC) Received: from t490s.redhat.com (unknown [10.39.192.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0613A1C0654B; Mon, 27 May 2024 14:15:00 +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 v1 1/6] mm: update _mapcount and page_type documentation Date: Mon, 27 May 2024 16:14:49 +0200 Message-ID: <20240527141454.113132-2-david@redhat.com> In-Reply-To: <20240527141454.113132-1-david@redhat.com> References: <20240527141454.113132-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Queue-Id: A1D0B1A0025 X-Stat-Signature: pqxdc4byh7b7fxcprek9ni9yya83nidw X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1716819311-391340 X-HE-Meta: U2FsdGVkX1/G6cz2liywVRaRZFhk++irkyEwaq0pIPcISas/71gabRiRMRicW5Tv/dUFE89FScKwzALethqDXrCSH+d+hG0WGw7ZvAv2TYaLF27+l5dJPZbz0fEuUOaM12ep7GwCH69NGQGUA0f1adoNXXeyi53cQrFNz23UwLLYvFhKpLhDHIuPHAeW9cdJIHl6wOYcc5D5wpEAMs2K+Oo1Mg+kJCLuTbm9hTyphXWuZLm8HQJcqlbU82JcSUbcdk3Byj6QSBG5cHYpVyXUgRzyEoQKECpnbcCzY/jc/iRFm+UQuZTRCDKVnrHh3TY3pyT8P4j4RjS14N8GZi5ASXxl21pTV8XLv/9uFosnRfXOu/3CoYp6jYUzr6RVQJSrT6U2jMn4R3voqm71xRrHK821i8rr3o8ICGLZQ0YLDqktt1tZ6SvZ2HW0yk2pEbAH8Fh9Er4iWSJ+ssnthQ/OKX8LDcP0t+Y5NnGfjeO7CuW687XLIQXF+hHTH5cwD+J/f251cW0xtSwoTL3h747lX6mM7k/nesBN/Dk9gJ4TIXcABFFXu9fUyQq+mgeA+cUuDyzdl34Sc+jAMWkcgXwDo8a6ddMo6723iARrJ6H37tPpRZL6u4oKjCRtt1WCXhq00hW9LOvMamW8B9HxAIdDQtZXMu8kmGfqsK7pzfhHqZrn4VcTWGarM+aomNrcPZBNlhoLUlTSR+DD0HD5GP4XDSyP5efnBRtgcIsHPzrCGwyvcOd890kZFE82/RSDze/t2wK2j71mF847f+TGIKz/pNmNAaVd9ql+QIwQVfZWtyvufPOY6A422rHmhsZUBcTo0yoqAdGW8wBqKsi+lEOj1h9bpiHxXga8+0PeLj/YdzFwMqPjS5QT9u9eeyxuXP1GdDV5IZSHUSL5osay7gdtB3e0eVGDXDrQAVEj1oLrWXVdh47SfKBoX25H4cwO1YvI+xMEhxfTUz/DxtBZ4PN Bmr5Iy6T Fa76hRYhxn6XfEVxW3XYVkjm9jEiR5ClUCFJO6MRyAw6z0Cg= 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. Move "page_type" before "mapcount", to make it clearer what typed folios are. Signed-off-by: David Hildenbrand --- include/linux/mm.h | 5 ----- include/linux/mm_types.h | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 16 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..6b2aeba792c4 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,18 +150,26 @@ 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 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. */ - atomic_t _mapcount; + unsigned int page_type; /* - * 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 pages that are 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). */ - unsigned int page_type; + atomic_t _mapcount; }; /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */