Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2087008lqb; Mon, 27 May 2024 07:29:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKdNTnQokj5l5ccM3HlFJ3ecx7ugANdkF+gdFz7jP9uyBq5Hp76QuRvE8HUsYVW8krlXSZPIDC9P19KD2Zn4a18TZJAz7ixCURj6fe9A== X-Google-Smtp-Source: AGHT+IEyYiocZC3aDpYikWvgKoVSkyYXb0voGREyaaVBc9dTHnbrt1tAyJ4y4wJUhd529zzqQLrY X-Received: by 2002:a17:902:e846:b0:1f4:9e85:9d5f with SMTP id d9443c01a7336-1f49e85a1damr28421195ad.19.1716820172008; Mon, 27 May 2024 07:29:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716820171; cv=pass; d=google.com; s=arc-20160816; b=ZTIFUZjUKSSdgt9qxg547EFxrF4ejU1D9/i2dqnTR8p6eK9fnus8tlWa0enNHwAlon zJFGALpKuGAjOrb2P/8LD37/Ut4Oiv8RXWQFY6ijaDf0/PzVng3YirxNTKCiB02DaUj+ 2E29C6Ck0rhHdvtF85xN8BDn6iBOcakNSKozBYOaDZ5MRTdLBc+P7Xvx38iMAVIvU5hz wb373vQGx/KSOnZBXDIInUyhAWb/GAFiQKYZWyRKf2EsirEmBn44TaV8HPTqx4gXKgI9 1d9ghKqN0inOKoVLwRtX/vT5DI9H9chmx3+P84k9nQ4IsJmezRjLzCMRCSZbMKVt/9UG aLXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cG/bHQ4quJa6Sy8Ny8W5KhH3qb/Pwqg5bjhVWAnFcjs=; fh=4qo2wXwF6+wBmVpKt9nE5vXwAOEbbhXPZvwe/C5tp4o=; b=TMyBPjx94fXLq7th5t268Zyc+v2RpNcW4dHGc1SqA61ec/5NbtTg5WTKCEkkIp0Sqr E4kTyTtubWt02L8cV87fnaXz8ij517zc0if5NKJnDH5c7bj+OyqWosxjq9FQkyOM1j4e D94Dr9u6AyeT4X2K7v5yb5igpbW6T/QyJ11P2nxrkjx0gVLu9QFD6pdBcMyEUfUc3sYE i5WGcC5xeg2XefRLcEOfKrR7YZ8RCbk17L4F24xOzhXXjNbASzDCEZKZR1Jx0WosA7F3 I9YWbdutYOF/hSBcsy7vfZa0jAUSzX5gDhYwDjJA8EBtLrZUXRljzhCFPHOJP/8oTyel F6+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c17uarff; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-190864-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f4be9ef80bsi684815ad.405.2024.05.27.07.29.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:29:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190864-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c17uarff; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-190864-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6C3022A5839 for ; Mon, 27 May 2024 14:29:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77DB01802D2; Mon, 27 May 2024 14:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c17uarff" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F01A817F36B for ; Mon, 27 May 2024 14:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819315; cv=none; b=h4MOUcfgk6IUMuvz7cGeWp1Z0fVeIGfK4WmhPxbLbmIdBQi51MePwiS1wQGw5Z8Ta3Gdga1aT2GmptIkZKgZB43MQm9GEWUV/9P9THnblPv7eq8fO1oSUKvCA7Bl4DA6wGtE+oIw4K1GJhBE0aa1g0dO1cHJTvCtL54f2SJMuo8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819315; c=relaxed/simple; bh=TuHCmrWuZwGpoZ5sT8ZAtkpr/leRSP9V4NWCvIzzY08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JWkOO+WUgrV4h4cShbn2EuucPxkMpVzL1e+QS3PAMj++zTm28/CzWotMhIHtGvbn8OdZE55bGvCYxxtqzyVpBko9wAk3AmJaPiXzPioha9Gasy/Q12nS5bSckEcTF2KzToBLiao+ONgLfgNcKz6mtPXQGZzoVUrcS09VvYRFmck= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c17uarff; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716819309; 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=c17uarffuFCXg/QqNYa2aTjQCM+LpsSymliHHPxZ9jLcJ0r5qokrTTH7xldI/Tv/AvXLIQ gnKsFHWGPvJ/thgIwfpBFpdhQ3yAk8zBul2GvdfrVo5eQjmyDLghIUIOynm2496HUu9/MT hsWTgkvm2LrehG6ruDU5ll1dgcUu2d4= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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) -- 2.45.1