From patchwork Wed May 29 11:18: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: 13678709 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 A0A83C27C44 for ; Wed, 29 May 2024 11:19:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D26096B009C; Wed, 29 May 2024 07:19:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CADA96B009D; Wed, 29 May 2024 07:19:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD9C56B009E; Wed, 29 May 2024 07:19: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 806576B009C for ; Wed, 29 May 2024 07:19:16 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 23CE840905 for ; Wed, 29 May 2024 11:19:16 +0000 (UTC) X-FDA: 82171187112.13.6478464 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 7714740007 for ; Wed, 29 May 2024 11:19:14 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/attSln"; spf=pass (imf27.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=1716981554; a=rsa-sha256; cv=none; b=Dg7pvKnIhLmOA5KoVQ6U/xxHQnAMfzpCp+bb7XjU5U8w1fAQeAeos1pg6gQ7dsHgThw8XB MuxjxhXy55wScAux2SeuZCUEBqZqFVpD/Y598E1A+QOsJ2c3JsXjWKvxE1V40IJy0XsBaF ZYwsJAw6+2lgAGLzGHThMTMwNmbOm28= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="R/attSln"; spf=pass (imf27.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=1716981554; 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=eYW6FgG2O6XV/uk9aR1DRrJWoOUkUVwlSfHnXOiWQ04=; b=C1xjyMwURWCLv2QY5PWcJ7dehbAzn8tZVaEIHfSzM9k7bv5eqi1UCScKY7dfNNULAM2myU C/3gfoIDRIA2zvWJHCYK9NCo3IngSLrMBznH97X699h7kXlD7OsLKN2VnIxiWZCnd+S7AD efqcacLwdsAQLFLmZV/rTOfx4uHus1o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716981553; 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=eYW6FgG2O6XV/uk9aR1DRrJWoOUkUVwlSfHnXOiWQ04=; b=R/attSlnudsGgZD2A123ebGkVnGtr5iW1IvBDndz5zRJQEV6KosbIhnOaZzoWjk7h7SNPU TdL46oXzx25CeVvqm3QimCZkAJJCS0xHlvfhs7zZSVP5bfDCXQpoKSiQRuJWxfWaTpIv9V FOWyufDMIO2WWcCP8d0lH7U13HGlMkU= 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-228-yxWjoKy1OFGlzWoM2RexRg-1; Wed, 29 May 2024 07:19:10 -0400 X-MC-Unique: yxWjoKy1OFGlzWoM2RexRg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 2072480028D; Wed, 29 May 2024 11:19:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B9D6C15BB9; Wed, 29 May 2024 11:19:07 +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 v2 1/6] mm: update _mapcount and page_type documentation Date: Wed, 29 May 2024 13:18:59 +0200 Message-ID: <20240529111904.2069608-2-david@redhat.com> In-Reply-To: <20240529111904.2069608-1-david@redhat.com> References: <20240529111904.2069608-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7714740007 X-Stat-Signature: xkhdppc74sz5uktb1d1nyqp939cuqe4i X-HE-Tag: 1716981554-485542 X-HE-Meta: U2FsdGVkX1+wnAT+zoFOZktXXDM9/F+ptPB/TjlGglQ1YG0eGziWZxUvjyoBPPeMBFoCJVQQkdF71qrm5Ix110+I33fv3u+HW0r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wNEWPWD3YntqlkKjTI1Zz1AArEaAB5+JAH7V3aoxbP+Jespn0pw2aBqNd5l7wSyilpSQdna1ncSQdBQNucuqmTPjolf5ZJx4H87XhB1sNFGOQ 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 3aa1b6889bccf..eebfce8f58bca 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 24323c7d0bd48..dd2ce1b3ec80e 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 + * (page_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 */