博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Radix Tree in Linux Kernel
阅读量:7095 次
发布时间:2019-06-28

本文共 2949 字,大约阅读时间需要 9 分钟。

hot3.png

1. Common Introduction to Radix Tree

(mainly from wiki)

In , a tree (also patricia trie or radix trie or compact prefix tree) is a space-optimized where each node with only one child is merged with its child.

()

 

They find particular application in the area of , where the ability to contain large ranges of values with a few exceptions is particularly suited to the hierarchical organization of . (also, the hierarchical organization of page addresses in page cache!)

 

Donald R. Morrison first described what he called "Patricia trees" in 1968; the name comes from the PATRICIA, which stands for "Practical Algorithm To Retrieve Information Coded In Alphanumeric".

 

Radix trees also share the disadvantages of tries, however: as they can only be applied to strings of elements or elements with an efficiently reversible mapping () to strings, they lack the full generality of balanced search trees, which apply to any data type with a .

 

2. Radix Tree in Linux Kernel

Problem: In Linux, file can be quite large, even a few terabytes. When accessing the file, the page cache may become filled with so many pages of the file that sequentially scanning all of them would be too time-consuming.

Goal: Perform page cache searching efficiently

Method: Linux 2.6 makes use of a large set of search trees, one for each page cache. These trees are radix trees.

 

A Linux radix tree is a mechanism by which a (pointer) value can be associated with a (long) integer key. It is reasonably efficient in terms of storage, and is quite quick on lookups.

The address_space structure used to keep track of backing store contains a radix tree which tracks in-core pages tied to that mapping. Among other things, this tree allows the memory management code to quickly find pages which are dirty or under writeback.

In radix tree, the equivalent of the linear address is the page’s index.

In a 32-bit architecture, the height of this radix tree never exceeds 6, that is 2+6+6+6+6+6. The corresponding slot numbers are: 4, 64, 64, 64, 64, 64.

 

If the highest index of a radix tree is smaller than the page index of a page to be added, then the kernel increases the tree height correspondingly.

 

data structures

 

struct address_space {	struct radix_tree_root	page_tree;	/* radix tree of all pages */};/* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */struct radix_tree_root {	unsigned int		height;	gfp_t			gfp_mask;	struct radix_tree_node	*rnode;};struct radix_tree_node {	unsigned int	height;		/* Height from the bottom */	unsigned int	count;	struct rcu_head	rcu_head;	void		*slots[RADIX_TREE_MAP_SIZE];	unsigned long	tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS];};/* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */struct radix_tree_root {	unsigned int		height;	gfp_t			gfp_mask;	struct radix_tree_node	*rnode;};struct radix_tree_path {	struct radix_tree_node *node;	int offset;};

 

3. References

 

转载于:https://my.oschina.net/u/158589/blog/61887

你可能感兴趣的文章
C/C++踩坑记录(二)一段有趣的常量字符串
查看>>
GDI+ 学习记录(2): 画笔线帽 - Cap
查看>>
一张表里的多个字段值 取自 字典表里的text 的查询
查看>>
golang tcp socket
查看>>
特么的程序员励志故事(小IT职员在北京5年买了500W的房子)
查看>>
全选和反选 checkbox
查看>>
wget
查看>>
Linux设置用户登录提示
查看>>
js metro仿win8卡片效果
查看>>
Samba服务器的配置 , nfs配置解析
查看>>
我的友情链接
查看>>
document.body属性
查看>>
c++ 广义表
查看>>
esxi中虚拟机中GTX1070
查看>>
docker
查看>>
vc char * 转换为 LPCTSTR的方法
查看>>
Spring(一)——总体介绍
查看>>
select count(*)和select count(1)的区别
查看>>
Spring AOP实现对redis统一管理 (注解方式)
查看>>
在XenServer 6.0中设置自动启动虚拟机
查看>>