From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta20.hihonor.com (mta20.honor.com [81.70.206.69]) (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 1C4893EEAE3; Wed, 27 May 2026 11:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.206.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881213; cv=none; b=FScyZzAFC3zpZhrrG02s0fENF27W/7l3MGHznvaF4cM25Hx2CS5ctJ+Lh6IgbcdtwMoPbtvkEMFsHPA1ONP5syBwPp9lVlL6IZTKPtrb0PETccjlhjOc+ggwcqXdsyOb+n4MR5bEiMpRFheSWT8HVG7AoHhP/TSqQvOL1dcnZB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881213; c=relaxed/simple; bh=sFTjpTy9jS1J6p+gZVpzAXiVY7b1vJQet9M2pL8BGtk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I2iicwBY6BOyqpvzfH9Rl5WRxB+ujV+F8aozjYJHu53xuLkr/oZYwN0n5HRB//1eANwP3UuF2+SZWQnk+Qbwa6g4PnrfjScGwz8Luha/73VFoPtDFDCfTRlTqqn0JnC6QtXFeQEzmvxi+5iWiHC1KijJzKbR2YijMRczNJd+6b4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; arc=none smtp.client-ip=81.70.206.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Received: from TW002-1.hihonor.com (unknown [10.72.0.137]) by mta20.hihonor.com (SkyGuard) with ESMTPS id 4gQRdL5rLWzYkxQN; Wed, 27 May 2026 19:06:30 +0800 (CST) Received: from TA003.hihonor.com (10.72.0.43) by TW002-1.hihonor.com (10.72.0.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Wed, 27 May 2026 19:07:57 +0800 Received: from localhost.localdomain (10.144.18.117) by TA003.hihonor.com (10.72.0.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Wed, 27 May 2026 19:07:56 +0800 From: tao To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , <21cnbao@gmail.com>, , , , Subject: [PATCH 03/15] mm: introduce anon_vma_tree_t for multiple anon_vma topologies Date: Wed, 27 May 2026 19:01:35 +0800 Message-ID: <20260527110147.17815-4-tao.wangtao@honor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260527110147.17815-1-tao.wangtao@honor.com> References: <20260527110147.17815-1-tao.wangtao@honor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: TW006-1.hihonor.com (10.77.215.153) To TA003.hihonor.com (10.72.0.43) Prepare for upcoming ANON_VMA_LAZY support and RCU-based lockless rmap traversal by clearly separating anon_vma topology handling from the anon_rmap semantics. Prepare for supporting multiple anon_vma topologies by introducing lightweight abstractions used by the VMA and rmap code. Introduce anon_vma_tree_t as the type stored in vma->anon_vma: typedef unsigned long anon_vma_tree_t; It represents a tagged pointer encoding a reference to the anon_vma topology. The low bits are reserved as type tags to distinguish different implementations (e.g. regular anon_vma and lazy anon_vma). This keeps the VMA representation compact while allowing the topology to evolve without changing the VMA layout. Signed-off-by: tao --- include/linux/mm_types.h | 3 +++ mm/internal.h | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index a308e2c23b82..5f4961ea1572 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -917,6 +917,9 @@ struct vm_area_desc { struct mmap_action action; }; +/* Tagged pointer stored in vma->anon_vma. Low bits encode anon_vma type. */ +typedef unsigned long anon_vma_tree_t; + /* * This struct describes a virtual memory area. There is one of these * per VM-area/task. A VM area is any part of the process virtual memory diff --git a/mm/internal.h b/mm/internal.h index 5a2ddcf68e0b..76544ad44ff0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -246,6 +246,60 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma) up_read(&anon_vma->root->rwsem); } +/* anon_vma_tree_t APIs */ + +static inline anon_vma_tree_t make_anon_vma_tree(struct anon_vma *anon_vma) +{ + return (anon_vma_tree_t)anon_vma; +} + +static inline struct anon_vma *anon_vma_tree_anon_vma(anon_vma_tree_t anon_tree) +{ + return (struct anon_vma *)anon_tree; +} + +static inline void anon_vma_tree_lock_write(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + anon_vma_lock_write(anon_vma); +} + +static inline int anon_vma_tree_trylock_write(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + return anon_vma_trylock_write(anon_vma); +} + +static inline void anon_vma_tree_unlock_write(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + anon_vma_unlock_write(anon_vma); +} + +static inline void anon_vma_tree_lock_read(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + anon_vma_lock_read(anon_vma); +} + +static inline int anon_vma_tree_trylock_read(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + return anon_vma_trylock_read(anon_vma); +} + +static inline void anon_vma_tree_unlock_read(anon_vma_tree_t anon_tree) +{ + struct anon_vma *anon_vma = anon_vma_tree_anon_vma(anon_tree); + + anon_vma_unlock_read(anon_vma); +} + struct anon_vma *folio_get_anon_vma(const struct folio *folio); /* Operations which modify VMAs. */ -- 2.17.1