In-depth analysis of Linux kernel linked list

Source: Internet
Author: User
An in-depth analysis of the Linux operating system kernel linked list-general Linux technology-Linux programming and kernel information. The following is a detailed description. I. Data Structure of linked lists

A linked list is a commonly used data structure for organizing ordered data. It connects a series of data nodes into a data link through a pointer. It is an important implementation method for linear tables. Compared with arrays, the linked list is more dynamic. When creating a linked list, you do not need to know the total amount of data in advance. You can randomly allocate space and efficiently insert or delete data anywhere in the linked list. The overhead of the linked list is mainly the access sequence and the Space Loss of the organizational chain.

Generally, the Linked List data structure should contain at least two domains: data domains and pointer domains. data domains are used to store data and pointer domains are used to establish connections with the next node. According to the organization of the pointer field and the connection form between nodes, the linked list can be divided into single-chain tables, double-chain tables, circular linked lists, and Other types. The following lists the common linked list types:

1. Single-chain table

A single-chain table is the simplest type of linked list. It has only one pointer field pointing to the next node. Therefore, the traversal of a single-chain table can only start from the beginning to the end (usually a NULL pointer).

2. double-stranded table

By designing two pointer fields, the dual-chain table can be traversed in two directions, which is different from the single-chain table. If the dependency between the predecessor and the successor is disrupted, a "binary tree" can be formed "; if the frontend of the first node points to the End Node of the linked list and the successor of the End Node points to the first node (the dotted line in 2), a circular linked list is formed. If more pointer fields are designed, to form a variety of complex tree data structures.

3. Circular linked list

The cyclic linked list feature that the tail node points to the first node. The double-loop linked list has been given in the previous section. It is characterized by any node and any data in the two directions can be found in the linked list. If the precursor pointer is removed, it is a single-loop linked list.

A large amount of linked list structures are used in the Linux kernel to organize data, including the device list and Data Organization in various functional modules. Most of these linked lists are implemented in [include/linux/list. h. The subsequent sections of this article will detail the organization and use of this data structure through examples.

   II. Implementation of the data structure of Linux 2.6 kernel linked list

Although the 2.6 kernel is used as the basis for the explanation, the linked list structure in the 2.4 kernel is actually no different from that in the 2.6 kernel. The difference is that 2.6 expands the data structure of two linked lists: the read copy Update (rcu) and the HASH linked list (hlist ). These two extensions are based on the most basic list structure. Therefore, this article mainly introduces the basic linked list structure, and then briefly introduces rcu and hlist.

The definition of the linked list data structure is very simple (Excerpted from [include/linux/list. h]. All the following code, unless described, is taken from this file ):
CODE: struct list_head {struct list_head * next, * prev ;};
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.