From patchwork Mon May 27 14:14: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: 13675410 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 AE687C25B7D for ; Mon, 27 May 2024 14:15:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 259E06B009B; Mon, 27 May 2024 10:15:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 232936B009C; Mon, 27 May 2024 10:15:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01C6F6B009D; Mon, 27 May 2024 10:15:16 -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 D68756B009B for ; Mon, 27 May 2024 10:15:16 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 84B73414C7 for ; Mon, 27 May 2024 14:15:16 +0000 (UTC) X-FDA: 82164373032.20.A868296 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 CA1E840008 for ; Mon, 27 May 2024 14:15:14 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cU8sFxJ3; spf=pass (imf07.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=1716819314; 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=cG/bHQ4quJa6Sy8Ny8W5KhH3qb/Pwqg5bjhVWAnFcjs=; b=xoYUjGOsRNFpUbaknMATxdDmwlk52UbnoX++O7iw+KTTR8U9hAZL5XzvjNYFks3Cw5AGZY WZlAFzCJD3aEeGzgFPpycsAYLs0Sp0JSEvkv+nwxPypZTDVN2HZ/nuuKZqtEsOjmj0Sn1i g/4/JVKxIms8Pt7YKkZ0wbx3FzDraCw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cU8sFxJ3; spf=pass (imf07.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=1716819314; a=rsa-sha256; cv=none; b=AjuRZHKMUFX8WLnXpxHtC396R5xZTTqgvtwfoXakbO1NVcjof4CUswCRNgvMZmPPXorTUm 7WdgO+QgPdhE1EMEM7sbmMK2qxz+ed2dTv2QYX4UzaZ5QNRnxWYDHo5xSa6+H1FHB/W6es QYCbV09Z3bobtRxc/tKzw12oxNDB5pI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716819314; 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=cG/bHQ4quJa6Sy8Ny8W5KhH3qb/Pwqg5bjhVWAnFcjs=; b=cU8sFxJ3VFRar/eyYxHUb6zj1dW4ZyH+b0inXfIjcAFDtIvj3DXD6MSFJWt5Rs4vtBQRbF 789vsAtzDA+0PManU+aOlXVPb4teiSfO/C+Es29HsgySOb+FhJGX61nfGa5fqbFXuaPJAQ RTGlZWx4UEuZIDeoLCD0BMVY4+AFPBA= 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-320-eU3y4psHO9CVn5thPdziNg-1; Mon, 27 May 2024 10:15:05 -0400 X-MC-Unique: eU3y4psHO9CVn5thPdziNg-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 D3E611C0512D; Mon, 27 May 2024 14:15:04 +0000 (UTC) Received: from t490s.redhat.com (unknown [10.39.192.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39E141C00047; Mon, 27 May 2024 14:15:02 +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 2/6] mm: allow reuse of the lower 16 bit of the page type with an actual type Date: Mon, 27 May 2024 16:14:50 +0200 Message-ID: <20240527141454.113132-3-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-Server: rspam05 X-Rspamd-Queue-Id: CA1E840008 X-Stat-Signature: h6sbx5bzpscqcqys15kuk7d6aoqzrxyw X-Rspam-User: X-HE-Tag: 1716819314-473087 X-HE-Meta: U2FsdGVkX1+r7f+N1/a7jB3KCo+nZvGTfyO1/sWFVF8/RfYBwbi9EoEfiwTIHutTYp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7UalSY4ISjJnHqdW8AkdWIFEIRdJHFhaO8PG3GFlb/jTEBfmIRf3Exn/2EwaXiatia5X29JusHTeXfo9BpjmXDaPMTSPcecE3DVtMyuhtixyycPFr4jichUXgw== 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 18 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. Fear of running out of bits for storing the actual type? Actually, we don't need one bit per type, we could store a single value instead. Further, we could likely limit PAGE_TYPE_BASE to a single (highest) bit. Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 5 +++++ include/linux/page-flags.h | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 6b2aeba792c4..598cfedbbfa0 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 104078afe0b1..b43e380ffa0b 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -945,14 +945,18 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) */ #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 +/* + * Reserve 0x0000ffff to catch underflows of _mapcount and + * allow owners that set a type to reuse the lower 16 bit for their own + * purposes. + */ +#define PAGE_MAPCOUNT_RESERVE -65536 +#define PG_buddy 0x00010000 +#define PG_offline 0x00020000 +#define PG_table 0x00040000 +#define PG_guard 0x00080000 +#define PG_hugetlb 0x00100800 +#define PG_slab 0x00200000 #define PageType(page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)