Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp730104lqb; Wed, 29 May 2024 08:56:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5p76WHykxuZiZ84prP3xSoFjE9OLJzz/Stz3Hk50XgeoJ5OLCBCKFkbR0v7k28qVDG8Z1Lw+MN03uhEJyiMN0HYBlhSAONLQMhAU4Mw== X-Google-Smtp-Source: AGHT+IGvUutMHAHin7Dqst8AtD6A8SWYOpZGDpTm9N8veeN5/x3f2Rop7SrTJKi+IpK+l5uIE62m X-Received: by 2002:a17:90b:364a:b0:2b1:b6f:e297 with SMTP id 98e67ed59e1d1-2bf5f715452mr15325122a91.36.1716998211817; Wed, 29 May 2024 08:56:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716998211; cv=pass; d=google.com; s=arc-20160816; b=San5oTtyFyN6rFfm/omZysbtch4U8vBqtzaDmsrkV/SKRqq0omMZ/asBJQ1HFHtYZD w9R3MxWcSPqsxpExfTXTcbmNqoAQQ4iVFxrswwvXynss0gMGfd64TCm+yJqKSmTzkTjv 67cFXzkq7x/bMgRJCrey2wTsBtoY+/NUYYTCH2bXnEhivuW187Zuk3HzopOFCPQvs6pw QFo9Rfr19Tmny0tGD+Hv6VuOfGSBFJfkYW2F6pqXEap+L8TgHsyJ+Fo5541Kp/eHuHw9 GLxStTZjTlh9xpACsT1ZnBGDHUewvmbKNy7LaNDiosmtnr16Iwlu477jaIBg6HcH49yG 9PZw== 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=3dMOK+h64umb2Ww2HIMnnwaYpG06QZyWi58gxbbVwQ8=; fh=oKB3+xUY/AUGL42ltMlOwpteX91P9EZsrULrOPztRoA=; b=Of5bJitB82UVC+4fMZJ5bcI3rq0u+FjjKgzl064T90BKFrKCoZVi9Fz0XigEIkDjub Ugb4Fsa6XjWtAC56MIo80h0ezJqI1x9Xi9lfadhssgWGxM+bhPZyNd/+YZJNOVHVxiM7 TwWMqgzhHWzBAtvVGpYNdRsUrW5srMCuMuZJCuY3iJenYhTr2vR+qQiBMcCzo5tjjdMb zY2nprOIJyJpqEv/4NuV1zPt47Tl1hF43ZQ2jqMpmf0Tbf9GEIkruo6ppO7fleZZQkj/ 3kzAxL0568fOr5axyVFzTzc2luqIrL2rpGPygX5Dbk7veUdD0P7dMPiL+gmtBS0NTTpV +Fpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YP0UQpve; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-194395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c971834si73129425ad.253.2024.05.29.08.56.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 08:56:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YP0UQpve; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-194395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.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 AD014285BAA for ; Wed, 29 May 2024 15:56:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2398021A19; Wed, 29 May 2024 15:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="YP0UQpve" Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CA22180A92 for ; Wed, 29 May 2024 15:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998174; cv=none; b=McxJ6ApfdOsESGBrokp2uAsOogFE1n1WIUsvHMhwF548Rngnw7dyR2b2Qpl/ssZS7eBNU/HzXddMDEppUlf5N4raGGYWQFcE3/QEEF60xXFJP5IPLk0EM+yZ32oTL5i2jw7VJv7kdjve8RL8jkk0LMD5euWemaQlwzC01pNkEKk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998174; c=relaxed/simple; bh=IqLFaT5xdUsd0QyQOBxl0ct08tWkuwCuK9WyVJVmEkk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gEgkYdadRI7byPWjVeL/51N9RryOWVjExTP+FCYZ6l17YgyT9CJsWqxe2BULtiJv/z1RBwUi+ClS8SPoErbJCXlMVHlHLAUq9D3P2tCsbSdxvTVc8/osxq7GwrSVFK9VWvRFFyTlk9ksS6VyEpr0kjXZbJlxOpTFWbiz7DstA+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=YP0UQpve; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=3dMOK +h64umb2Ww2HIMnnwaYpG06QZyWi58gxbbVwQ8=; b=YP0UQpvejOS+fsNjhCsDJ EfWBnufGbRRoqt+o3djgzVYMPcjguMs/Yj+6czMCOHfQlU8M2LTQtAoMZYlYfZuq hjdXd2dKFcLYYcRai5xBucL4/Nhbm90ZXHCrJRoJohRhGGZnLdySBaLJdhnOYIoT Cxf9q2jzix1xa6B36BxMBg= Received: from localhost.localdomain (unknown [124.90.108.240]) by gzga-smtp-mta-g3-4 (Coremail) with SMTP id _____wD33xXqT1dmLAKCBw--.56428S2; Wed, 29 May 2024 23:55:23 +0800 (CST) From: wang wei To: david@redhat.com Cc: 42.hyeyoo@gmail.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, minchan@kernel.org, rppt@kernel.org, senozhatsky@chromium.org, willy@infradead.org, wang wei Subject: Re: [PATCH v1 26] mm allow reuse of the lower 16 bit of the page type with an actual type Date: Wed, 29 May 2024 23:55:20 +0800 Message-Id: <20240529155520.33161-1-a929244872@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240527141454.113132-3-david@redhat.com> References: <20240527141454.113132-3-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-CM-TRANSID:_____wD33xXqT1dmLAKCBw--.56428S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCw43ZF4xKw4UCw4DtrW5ZFb_yoW5GFWrpF 4qkFyYkr48t3y2kw4fKwnxAr17WrsYkFWUC343WrW0yF98Kw1vgF1DKr45X34kurWkAFyY qFZrWw1q934DJw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUVGQDUUUUU= X-CM-SenderInfo: jdzsmjiuuylji6rwjhhfrp/1tbiLgDtpmV4JOd7rgABsv --- > 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 Every PG_XX occupies one bit in my understanding. But why PG_hugetlb occupies two bits? > +#define PG_slab 0x00200000 > > #define PageType(page, flag) \ > ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) -- 2.25.1