From patchwork Wed May 29 11:19: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: 13678710 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 74923C27C43 for ; Wed, 29 May 2024 11:19:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D766B6B009E; Wed, 29 May 2024 07:19:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAE976B009F; Wed, 29 May 2024 07:19:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADBDA6B00A0; Wed, 29 May 2024 07:19:20 -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 86C6D6B009E for ; Wed, 29 May 2024 07:19:20 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14566A09BF for ; Wed, 29 May 2024 11:19:20 +0000 (UTC) X-FDA: 82171187280.29.4C21668 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 3884C40011 for ; Wed, 29 May 2024 11:19:18 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iPIbib+z; 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=1716981558; 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=aDhi0IPu97eWFC0P0dRcSpVPyCoXJ2Cz890fKbkcPeQ=; b=cPOToySLuk3H+Xtw3CQctUS9Ew8/pkhnC1pi32nAMdxQzAX3MWqYFljFgjHQbMBQrTYBeS F28VLwInGY5IbHCvQIBuwFS7mQCmgQjkgfpT68ClsmM0724eBUjdMIpnmzd3KlXaJLbsMd NnC/GW2RNzMU/lRU526F9oCD0WiHnHc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iPIbib+z; 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=1716981558; a=rsa-sha256; cv=none; b=SCKSN6ofeT/xRDyaxMoOUXX45O9++6kv9rMCL50Is7iWO1TzUyxC1EVOqIHOKL2L1k6ocl j0jjP4HZV+1C/KO112oaFJ7cEcPnaUTghOcvUvJD5X5orT/XFGA+uquyqPIAJtI9bJ7mJr nAqc4esR9MkuXkqjscoNG/XGAnxZIbY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716981557; 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=aDhi0IPu97eWFC0P0dRcSpVPyCoXJ2Cz890fKbkcPeQ=; b=iPIbib+zMFoSzC3gzKltmvjBePDoP3YQ9IS98AE17CN7wEuP7o/GGD9q0QdvHgwdzJytrl UHF4X1sOWmxH597GV0Ol3/Y7D4HL859OVo6+uLbgI2vOhdHh8aL4tX78LNCjl1kePN8TvG HMVcXPhBVPG7wLnRvfGdY6VyC8XGb9k= 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-301-x4msqaDFNAKN7DdXTTBhqQ-1; Wed, 29 May 2024 07:19:11 -0400 X-MC-Unique: x4msqaDFNAKN7DdXTTBhqQ-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 3BC6B800169; Wed, 29 May 2024 11:19:11 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5868CC15BB1; Wed, 29 May 2024 11:19:09 +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 2/6] mm: allow reuse of the lower 16 bit of the page type with an actual type Date: Wed, 29 May 2024 13:19:00 +0200 Message-ID: <20240529111904.2069608-3-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-Rspamd-Queue-Id: 3884C40011 X-Stat-Signature: 7ihxiog6fwmbdccwbpjy4mkxsy8sawwd X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1716981558-973715 X-HE-Meta: U2FsdGVkX18FSfvKMa7KjKPar+EWDhh0bB/dOLc3J0K1/SqkWS0cdAXfpThOwS/4ausd/IA0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IzJ0wFy6TVsB3EPt9I7wo5VRjihsOVcUas1XIe5t11KCN6vzSez+BaIPvDTre6Xe5dEJgN+zsKU9MHVBRe/GaQsihECsgVajxUZyQ+uHmjnIgvTm4z4+DryIrZAS7rpc5ia2N4+DFHTj0CmpUH3KUzSZ2p9eVH54= 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 long as the owner sets a page type first, we can allow reuse of the lower 16 bit: sufficient to store an offset into a 64 KiB page, which is the maximum base page size in *common* configurations (ignoring the 256 KiB variant). Restrict it to the head page. We'll use that for zsmalloc next, to set a proper type while still reusing that field to store information (offset into a base page) that cannot go elsewhere for now. Let's reserve the lower 16 bit for that purpose and for catching mapcount underflows, and let's reduce PAGE_TYPE_BASE to a single bit. Note that we will still have to overflow the mapcount quite a lot until we would actually indicate a valid page type. Start handing out the type bits from highest to lowest, to make it clearer how many bits for types we have left. Out of 15 bit we can use for types, we currently use 6. If we run out of bits before we have better typing (e.g., memdesc), we can always investigate storing a value instead [1]. [1] https://lore.kernel.org/all/00ba1dff-7c05-46e8-b0d9-a78ac1cfc198@redhat.com/ Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 5 +++++ include/linux/page-flags.h | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index dd2ce1b3ec80e..791afaf1b1ec3 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -157,6 +157,11 @@ struct page { * * See page-flags.h for a list of page types which are currently * stored here. + * + * Owners of typed folios may reuse the lower 16 bit of the + * head page page_type field after setting the page type, + * but must reset these 16 bit to -1 before clearing the + * page type. */ unsigned int page_type; diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index d1bdbaaccc964..f060db808102c 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -945,15 +945,19 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) * mistaken for a page type value. */ -#define PAGE_TYPE_BASE 0xf0000000 -/* Reserve 0x0000007f to catch underflows of _mapcount */ -#define PAGE_MAPCOUNT_RESERVE -128 -#define PG_buddy 0x00000080 -#define PG_offline 0x00000100 -#define PG_table 0x00000200 -#define PG_guard 0x00000400 -#define PG_hugetlb 0x00000800 -#define PG_slab 0x00001000 +#define PAGE_TYPE_BASE 0x80000000 +/* + * Reserve 0xffff0000 - 0xfffffffe to catch _mapcount underflows and + * allow owners that set a type to reuse the lower 16 bit for their own + * purposes. + */ +#define PG_buddy 0x40000000 +#define PG_offline 0x20000000 +#define PG_table 0x10000000 +#define PG_guard 0x08000000 +#define PG_hugetlb 0x04008000 +#define PG_slab 0x02000000 +#define PAGE_MAPCOUNT_RESERVE (~0x0000ffff) #define PageType(page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)