Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp608241lqp; Wed, 22 May 2024 14:05:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkqEfiC2J0PBwx7zjFX7dyiDw6nh9Q069v5O1ClnLrS+NVnkYOYSx7mfERFwnVBQUyS9/k2hwoyvJwyZkxiCM7m1zYTWrUMosxUhycfw== X-Google-Smtp-Source: AGHT+IGF/Joq/3XbitAE/NMuVP6fPJsv9Oitt1GuKoGTofBYmsDTQF0K1CoQ/+pwBZonoWPvuGlu X-Received: by 2002:a05:6a21:99a6:b0:1af:6911:7ff4 with SMTP id adf61e73a8af0-1b1f87f7c57mr4139731637.7.1716411951892; Wed, 22 May 2024 14:05:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716411951; cv=pass; d=google.com; s=arc-20160816; b=EqvAZPnGkV5kMkK+Q/uJe/dhuHd5eguD6kY5u3GAz6xc6n3NzHZUfNV/Xd/ko8yYHl tlXxdjl5uMlepskEdkoqRKwvBH4Vhhezq4iYisUwMtAvBR35gND6Pt+ucqn3cs92vEU/ Zrg8JA9sS//Rg1t0tcrMX6pLxs8U/RYfdoxjufOQpo/qkJ/6zffriXFDTGu96gtgRwFP WmhgWDQzbicsZ3z1FDtTsULuknFZ84QM5KeAMUALWaW8v/yvLNnkzNOzzhzhGdMmVqih CiqG8w0iV6I3E5vZXMH/D2QKbyE7MTr7XEnwHYVvjqWFjkO2WpRsCFEe1ksX2n7se43X Jg5Q== 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=bs73/DhQAjKCEOqgI5WjSruY0e+O/eQEazhESJihTfc=; fh=4qo2wXwF6+wBmVpKt9nE5vXwAOEbbhXPZvwe/C5tp4o=; b=KX4TZeSlw4/g2AkA5/SUa0ZPf/tVgiLeskjPMVSWsPA9xxzNnN10xMp5CW6U48GeTw 5Y568a2+Y9onbrcjIOtQFGXHOk7nTBxMNdtqUKIB0dG83+eHM12gjq8RpxK2BPx8tMqP JAdXGsHcOjcvNGRb1PA/Tc4KMEObWXXQjOd6BIXAkeRiXX57QC/9jiXoYQGtWjruVU/Z 0OLxU7Wca1mcHDnNnBRCcBFtSm/tmdrsvPxZOU2/caQo5uqWTh6gBbwKx4HpfLRWx8Qv zGePJkNOsGwv5kiYqNUJ6CQ4RqxHIPuywx9TMGaqiHX0BOPjNKp8mgFpjC7yd6Wu/jko tYNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LhsJd9Qb; 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-186712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63d9ab5b248si726000a12.105.2024.05.22.14.05.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 14:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LhsJd9Qb; 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-186712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186712-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4CDAFB21268 for ; Wed, 22 May 2024 21:05:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 069531482F2; Wed, 22 May 2024 21:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LhsJd9Qb" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 7E706146D46 for ; Wed, 22 May 2024 21:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716411853; cv=none; b=PQHVKPJZRWGIVaH2cscB4H4uk3+tus6CSS9r5hFvkxKYhtRRBwLE4VD6CuGGMMzO43iVhEXE45RPGQ0FbyXX2BuevQqG5grpU+iliv/W0l8sOWNj+YK938Vb3sSHhxDkwXXMvCFiEsHCYIl2oa5RcSKrZ/jfFvdS7hqxq4Wq+54= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716411853; c=relaxed/simple; bh=2+I4E7+1vmTeq+NzomJw1rLPkZCo+eWCc5UNkyJyVFg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cX/oMRJ83YD4L1MxVsSoQg8s/iryLposDP8Rhd3a8A5kdLPOXdiXfjvQYfYKMxelIMu5ScxofThL6UAMJuvrP+4fRz4PI27tb9iJg1+Z7szUHdL9bXqbsEDydfv86v8Dctm1i895LB/7i+zYWkeS6TApWw1SopfpQTPiycD2Hyk= 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=LhsJd9Qb; arc=none smtp.client-ip=170.10.129.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=1716411850; 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=bs73/DhQAjKCEOqgI5WjSruY0e+O/eQEazhESJihTfc=; b=LhsJd9QbkCpmzUyoTqYWnVRq1BtoeiUn1vI6cDCN2pN0DrCXLZP/nZ6HDwzWzPGULu22XI kHPPh3ZZbbZJWNW62Y/x4Z30oPpmfT1vJcYr7vTbA+5/m3W7ocr6bFFYMWaTceSAxbSaMX 1QrsoPLy1hdt1UXGu6LNGilq6wEZSLY= 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-515-HtzN_wyHOzWPGa337eP5gw-1; Wed, 22 May 2024 17:03:50 -0400 X-MC-Unique: HtzN_wyHOzWPGa337eP5gw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 6B0D6185A78E; Wed, 22 May 2024 21:03:50 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2949B7414; Wed, 22 May 2024 21:03:47 +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 RFC 2/6] mm: allow reuse of the lower 16bit of the page type with an actual type Date: Wed, 22 May 2024 23:03:37 +0200 Message-ID: <20240522210341.1030552-3-david@redhat.com> In-Reply-To: <20240522210341.1030552-1-david@redhat.com> References: <20240522210341.1030552-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.5 As long as the owner sets a page type first, we can allow reuse of the lower 16bit! 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 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. Signed-off-by: David Hildenbrand --- include/linux/mm_types.h | 5 +++++ include/linux/page-flags.h | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 532a3030405d..6dae8e15037b 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -168,6 +168,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 16bit 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..ed9ac4b5233d 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -942,17 +942,23 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) * __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and * low bits so that an underflow or overflow of _mapcount won't be * mistaken for a page type value. + * + * The highest bit must always be 1, to make page_has_type() work as expected. */ #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 0x00010080 +#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.0