Linux Kernel中所應用的數據結構及演算法

Basic Data Structures and Algorithms in the Linux kernel

Links are to the source code on github.

    1. Linked listdoubly linked listlock-free linked list.
    2. B+ Trees with comments telling you what you can't find in the textbooks.

      A relatively simple B+Tree implementation. I have written it as a learning exercise to understand how B+Trees work. Turned out to be useful as well.

      ...

      A tricks was used that is not commonly found in textbooks. The lowest values are to the right, not to the left. All used slots within a node are on the left, all unused slots contain NUL values. Most operations simply loop once over all slots and terminate on the first NUL.

    3. Priority sorted lists used for mutexesdrivers, etc.

    4. Red-Black trees are used for scheduling, virtual memory management, to track file descriptors and directory entries,etc.
    5. Interval trees
    6. Radix trees, are used for memory management, NFS related lookups and networking related functionality.

      A common use of the radix tree is to store pointers to struct pages;

    7. Priority heap, which is literally, a textbook implementation, used in the control group system.

      Simple insertion-only static-sized priority heap containing pointers, based on CLR, chapter 7

    8. Hash functions, with a reference to Knuth and to a paper.

      Knuth recommends primes in approximately golden ratio to the maximum integer representable by a machine word for multiplicative hashing. Chuck Lever verified the effectiveness of this technique:

      http://www.citi.umich.edu/techreports/reports/citi-tr-00-1.pdf

      These primes are chosen to be bit-sparse, that is operations on them can use shifts and additions instead of multiplications for machines where multiplications are slow.

    9. Some parts of the code, such as this driver, implement their own hash function.

      hash function using a Rotating Hash algorithm

      Knuth, D. The Art of Computer Programming, Volume 3: Sorting and Searching, Chapter 6.4. Addison Wesley, 1973

    10. Hash tables used to implement inodesfile system integrity checks etc.
    11. Bit arrays, which are used for dealing with flags, interrupts, etc. and are featured in Knuth Vol. 4.

    12. Semaphores and spin locks

    13. Binary search is used for interrupt handlingregister cache lookup, etc.

    14. Binary search with B-trees

    15. Depth first search and variant used in directory configuration.

      Performs a modified depth-first walk of the namespace tree, starting (and ending) at the node specified by start_handle. The callback function is called whenever a node that matches the type parameter is found. If the callback function returns a non-zero value, the search is terminated immediately and this value is returned to the caller.

    16. Breadth first search is used to check correctness of locking at runtime.

    17. Merge sort on linked lists is used for garbage collectionfile system management, etc.

    18. Bubble sort is amazingly implemented too, in a driver library.

    19. Knuth-Morris-Pratt string matching,

      Implements a linear-time string-matching algorithm due to Knuth, Morris, and Pratt [1]. Their algorithm avoids the explicit computation of the transition function DELTA altogether. Its matching time is O(n), for n being length(text), using just an auxiliary function PI[1..m], for m being length(pattern), precomputed from the pattern in time O(m). The array PI allows the transition function DELTA to be computed efficiently "on the fly" as needed. Roughly speaking, for any state "q" = 0,1,...,m and any character "a" in SIGMA, the value PI["q"] contains the information that is independent of "a" and is needed to compute DELTA("q", "a") 2. Since the array PI has only m entries, whereas DELTA has O(m|SIGMA|) entries, we save a factor of |SIGMA| in the preprocessing time by computing PI rather than DELTA.

      [1] Cormen, Leiserson, Rivest, Stein Introdcution to Algorithms, 2nd Edition, MIT Press

      [2] See finite automation theory

    20. Boyer-Moore pattern matching with references and recommendations for when to prefer the alternative.

      Implements Boyer-Moore string matching algorithm:

      [1] A Fast String Searching Algorithm, R.S. Boyer and Moore. Communications of the Association for Computing Machinery, 20(10), 1977, pp. 762-772.http://www.cs.utexas.edu/users/moore/publications/fstrpos.pdf

      [2] Handbook of Exact String Matching Algorithms, Thierry Lecroq, 2004 http://www-igm.univ-mlv.fr/~lecroq/string/string.pdf

      Note: Since Boyer-Moore (BM) performs searches for matchings from right to left, it's still possible that a matching could be spread over multiple blocks, in that case this algorithm won't find any coincidence.

      If you're willing to ensure that such thing won't ever happen, use the Knuth-Pratt-Morris (KMP) implementation instead. In conclusion, choose the proper string search algorithm depending on your setting.

      Say you're using the textsearch infrastructure for filtering, NIDS or
      any similar security focused purpose, then go KMP. Otherwise, if you really care about performance, say you're classifying packets to apply Quality of Service (QoS) policies, and you don't mind about possible matchings spread over multiple fragments, then go BM.

from : http://cstheory.stackexchange.com/questions/19759/core-algorithms-deployed

Linux Kernel中所應用的數據結構及演算法的更多相关文章

  1. Android 怎样在linux kernel 中读写文件

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  2. linux kernel中timer的使用

    linux kernel中timer的使用 http://blog.csdn.net/njuitjf/article/details/16888821 在kernel中如果想周期性的干些什么事情,或者 ...

  3. Linux kernel中常见的宏整理

    0x00 宏的基本知识 // object-like #define 宏名 替换列表 换行符 //function-like #define 宏名 ([标识符列表]) 替换列表 换行符 替换列表和标识 ...

  4. Linux kernel中网络设备的管理

    kernel中使用net_device结构来描述网络设备,这个结构是网络驱动及接口层中最重要的结构.该结构不仅描述了接口方面的信息,还包括硬件信息,致使该结构很大很复杂.通过这个结构,内核在底层的网络 ...

  5. Linux Kernel中获取当前目录方法(undone)

    目录 . 引言 . 基于进程内存镜像信息struct mm_struct获取struct path调用d_path()获取当前进程的"绝对路径" . 基于文件描述符(fd).tas ...

  6. 经典数据结构与算法在经典软件(linux kernel)中的应用

    参考文章:Core Alorgithms deployed linux中的priority search tree数据结构研究 虚拟内存: 1.红黑树,管理与进程关联的vm_area_struct实例 ...

  7. 浅谈Linux Kernel 中循环链表的实现

    前阵子在弄缓存的时候,我们需要将qemu对于磁盘镜像文件写请求串成一个链表,最终将这个链表里面的写请求全部刷回到镜像文件里面,那么我们便需要一个强健,可靠的链表的接口,于是我们仿照Linux 2.4. ...

  8. Linux Kernel 排程機制介紹

    http://loda.hala01.com/2011/12/linux-kernel-%E6%8E%92%E7%A8%8B%E6%A9%9F%E5%88%B6%E4%BB%8B%E7%B4%B9/ ...

  9. linux内核中的GPIO系统之(2):pin control subsystem

    一.前言 在linux2.6内核上工作的嵌入式软件工程师在pin control上都会遇到这样的状况: (1)启动一个新的项目后,需要根据硬件平台的设定进行pin control相关的编码.例如:在b ...

随机推荐

  1. JS的video获取时长,出现问题汇总

    <video id="my_video_1" controls="controls" style=" width: 700px; height: ...

  2. matlab批量修改变量的名称

    使用matlab做实验的时候,保存的文件里面的变量名都是一样的 ,所以希望能够把变量名全部都重命名.我举个个例子,假设我一堆文件,文件名分别是gds1,gds2,gds2,-.. 但是实际上load进 ...

  3. elasticsearch 基础 —— Update By Query API

    Update By Query API 最简单的用法是_update_by_query在不更改源的情况下对索引中的每个文档执行更新.这对于获取新属性或其他一些在线映射更改很有用 .这是API: POS ...

  4. U盘装CENTOS操作系统

    一.制作U盘系统镜像 1).用UltralISO软件打开下载好的ISO文件镜像,“文件”-“打开”,选中下载好的ISO镜像 2)点击“启动”-“写入硬盘镜像”,选中需要写入的U盘(容量最少为8G),点 ...

  5. 前端学习(三十四)对象&模块化(笔记)

    人,工人 //类的定义    function Person(name,age){ //构造函数        //工厂模式        //1.原料        //var obj = new ...

  6. Jmeter --Json Extractor (后置处理器)

    一.使用场景 Json Extractor 后置处理器用在返回格式为json的HTTP请求中, 用来获取返回的json中的某个值.并保存成变量供后面的请求进行调用或者断言等. 二.使用方法 1.创建H ...

  7. BZOJ3227 [sdoi2008]红黑树

    贪心什么的太神仙了( 老老实实dp于是就是沙茶题了 f[i][d][0/1]表示i个节点bh为d当前节点颜色白/黑[好好读题是真.. 转移一下然后就可以打表了( 由于我们发现这玩意很好卡有很好的性质( ...

  8. AGC002[BCDEF]题解

    F是计数于是就做(kan ti jie)了= = B - Box and Ball 模拟一下 每个盒子开一个d表示有的球数 可能存在红球的打个标记 传递一下就行了 #include<cstdio ...

  9. python基础:4.请至少列举5个 PEP8 规范(越多越好)。

    1.变量命名规则: 不能与关键字重名,必须以数字字母下划线组成,且不能以数字开头 2.导包规则: # 推荐这样写 import random import sys # 不推荐这样写 import ra ...

  10. 18.Vim基础指令(自用)——2019年12月13日

    title: vim study date: "2018-12-26 20:17:16" tags: 指令学习 categories: 技术驿站 vim study 2018年12 ...