Kernel Data Structures

As with any large software project, the Linux kernel provides these generic data structures and primitives to encourage code reuse. Kernel developers should use these data structures whenever possible and not “roll your own” solutions. In the following sections, we cover the most useful of these generic data structures, which are the following: * Linked lists

* Queues
* Maps
* Binary trees

Linked ListsThe linked list is the most common data structure in the Linux kernel which, allows the storage and manipulation of a variable number of elements, called the nodes of the list. The elements in a linked list are dynamically created and inserted into the list. This enables the management of a varying number of elements unknown at compile time and each element in the list contains a pointer to the next element. As elements are added to or removed from the list, the pointer to the next node is simply adjusted.

In some linked lists, each element also contains a pointer to the previous element. These lists are called doubly linked lists because they are linked both forward and backward. Linked lists that do not have a pointer to the previous element are called singly linked lists.

A data structure representing a doubly linked list would look similar to this: /* an element in a linked list */
struct list_element {
void *data;/*
struct list_element *next;
struct list_element *prev;
};
Circular Linked ListsNormally, the last element in a linked list has no next element, it is set to point to a special value, such as NULL, to indicate it is the last element in the list. In some linked lists, the last element does not point to a special value. Instead, it points back to the first value. This linked list is called a circular linked list because the list is cyclic. Circular linked lists can come in both doubly and singly linked versions. Although the Linux kernel’s linked list implementation is unique, it is fundamentally a circular doubly linked list. Using this type of linked list provides the greatest flexibility.

Moving Through a Linked ListMovement through a linked list occurs linearly. You visit one element, follow the next pointer, and visit the next element. Rinse and repeat. This is the easiest method of moving through a linked list, and the one for which linked lists are best suited. Linked lists are illsuited for use cases where random access is an important operation. Instead, you use linked lists when iterating over the whole list is important and the dynamic addition and removal of elements is required. In linked list implementations, the first element is often represented by a special pointer—called the head—that enables easy access to the “start” of the list. In a noncircular-linked list, the last element is delineated by its next pointer being NULL. In a circularlinked list, the last element is delineated because it points to the head element. Traversing the list, therefore, occurs linearly through each element from the first to the last. In a doubly linked list, movement can also occur backward, linearly from the last element to the first. Of course, given a specific element in the list, you can iterate backward and forward any number of elements, too. You need not traverse the whole list.

The Linux Kernel’s ImplementationIn comparison to most linked list implementations—including the generic approach described in the previous sections—the Linux kernel’s implementation is unique. Recall from the earlier discussion that data (or a grouping of data, such as a struct) is maintained in a linked list by adding a next (and perhaps a previous) node pointer to the data. For...

You May Also Find These Documents Helpful

...This month is devoted to datastructures. This isn't a computer science course, so let's define a datastructure as a data holder--something that holds whatever data we need while our program executes. Visual BASIC and VBA use two basic datastructures: the array and the collection. This month when I say VB, I also mean VBA.
ARRAYS
Most VB programmers are familiar with the array (figure 1). An array can be single or multidimensional, which means it can have rows and columns. While the array is the most commonly used datastructure, it's not the best choice for at least two reasons. The first is data access. To find something within the array, you have to know exactly what you want. If you knew that, you wouldn't have to look, would you? To search for an item, you must iterate through the array.
[FIGURE 1 OMITTED]
The second reason is that the array must be dimensioned to a known limit. Once set, it's not easy to add an item after that limit is reached. For example, if you have a list of four people, you can't add a fifth person until you resize the array using ReDim or ReDim Preserve. ReDim resizes the array and clears any existing values, while ReDim Preserve resizes and keeps any existing values. Also, the upper limit of the array can't be a dynamic variable. An exception to the dimensioning rule is using an...

...DataStructure
By Romeo Mesina
The basic principle of datastructures is the computer’s ability to organize, retrieve and store data in its specific memory address. Some common types of datastructures that are used in the real world include array, queue, stack, and linked list. Datastructures are designed to manage information to suit particular programming so that it can work appropriately according to its designed purpose. Many algorithms have been developed for the purpose of working with datastructure to sort data more efficiently. As a relevant topic for this report, I will discuss three common types of datastructure to illustrate its use in a real world application.
The first type of datastructure I would like to discuss which is very common in most high level programming languages is the use of stack. A stack is called a last-in first-out (LIFO) datastructure which takes a form of a container that is particularly designed to operate in that circumstance .The elements of the stacks are inserted and remove only from the end of the container. This means that the last thing we added on the top is also the first thing that will get pulled off from the pile. As an example of how stacks works in real life, think...

...Department of Computer Science
COURSE DESCRIPTION
Course Code
CS-203
Course Title
DataStructures
Credit Hours
4
Category
Core
Prerequisite
Knowledge and Experience in Programming Fundamentals and Object Oriented Programming
Expertise in design, implementation, testing, and strong debugging of object-oriented programs.
Inner Classes and Exception Handling
Amis and Objectives
“An apprentice carpenter may want only hammer and saw, but a master craftsman employs many precision tools. Computer programming likewise requires sophisticated tools to cope with complexity of real applications and only practice with these tools will build skill in their use. (Robert L. Kruse DataStructure and Program Design)”. This subject deals to make students convenient in building a memory and time efficient datastructures for the implementation of large-scale (data intensive) computer systems.
Learning Outcomes
Along with many others following are fundamentals learning outcomes for students that are expected through this course
Apply appropriate fundamental datastructures and abstract data types (ADT) such as bags, lists, stacks, queues etc and heaps: min/max heap, min-max heap and some advance hierarchal datastructures like B-Trees: 2-3 tree, 2-3-4 tree and hash tables, and graphs in problem solving.
Apply object-oriented...

...L10: Stacks
UCCD1024 DataStructures
What you will learn today?
 What are stacks?
 Why study stacks?  How to implement stack using linked list?  How to apply the stack concept in application?

This is our emphasis here.
 Read Textbook 1: Chapter 7.
L10: Stack Jan 2013 2
What are stacks?
 It is a special kind of list.  The operations of insert (called push) and delete (called pop) are allowed only at one end (i.e., top).  It has the property of LIFO: Last In First Out.  Less general than list and easier to implement because no insertion and deletion at random locations.
L10: Stack Jan 2013
item4 item3 item2 Take this Insert here item1 one out
without moving other items?
X
without removing item4?
3
X
What you will learn today?
 What are stacks?
 Why study stacks?
 How to implement stack using linked list?  How to apply the stack concept in application?

This is our emphasis here.
L10: Stack Jan 2013
4
Why study stacks?
 A lot of problems have the LIFO characteristics.  With the datastructure of stacks that support LIFO, one can easily create LIFO operations for them.  Problems that need LIFO:  moving a stack of boxes (the removal order is LIFO)
1 2 3 4 5 6
7
L10: Stack Jan 2013
5
Why study stacks?
 A lot of problems have the LIFO characteristics.  With the datastructure of stacks that support...

...students and 3 subjects. The structure should contain 3 subjects and total. 48) Write a program to calculate and print student wise total for 50 students and 3 subjects using pointers. The structure should contain 3 subjects. 49) Write a program to store the information of vehicles use bit fields to store the status information. Assume the vehicle object consists of type, fuel and model member fields. Assume appropriate number of bits for each field. 50) Program for illustration of user defined data types using typedef. 51) Program for illustration of nested structures.
52) Program to add or delete a record of a particular employee based on his code. The structure should contain name, designation, code, salary. Program should also provide the flexibility to update any employees record. 53) Define a structure that represent a complex number (contains two floating point members, called real and imaginary). Write functions to add, subtract, multiply and divide two complex numbers. 54) A company markets Hardware items. Create a structure “hwitem” that stores the title of the item, it’s price, an array of three floats so that it can record the sale in rupees of a particular item for the last three months, category of the item and it’s original equipment manufacturer. Write a short program that provides facility to read N number of items information, append new item, and...

...Lab – Data Analysis and Data Modeling in Visio
Overview
In this lab, we will learn to draw with Microsoft Visio the ERD’s we created in class.
Learning Objectives
Upon completion of this learning unit you should be able to:
▪ Understand the concept of data modeling
▪ Develop business rules
▪ Develop and apply good data naming conventions
▪ Construct simple data models using Entity Relationship Diagrams (ERDs)
▪ Develop entity relationships and define various types of attributes
Lab Goals
Our lab goals are to:
1. Learn to build conceptual models in Microsoft Visio.
2. Create the 5 ERDs from class in Microsoft Visio.
You will accomplish this by drawing the 4 diagrams from the class exercise. You will have to hand in all 4 diagrams by FTPing them to your account space on the IST-S-STUDENTS server and then pasting the url to the diagram in the text boxes for this week’s learning unit assessment.
What you will need to begin
1. A copy of Microsoft Visio 2003 (or higher)
2. The Visio Conceptual Modeling Stencil conceptual modeling.vss (should be with the other files from this week’s lesson)
3. The class exercises from this week (should also be with the other files from week’s lesson.)
Part 1: Getting Ready for Using Microsoft Visio for Conceptual Modeling
Overview
This section will explain how to use Microsoft...

...TYPES OF DATA AND COMPONENTS OF DATASTRUCTURESData types
1. Primitive: is a data type provided by a programming language as a basic building block
2. Composite: is any data type which can be constructed in a program using its programming language's primitive data types and other composite types
3. Abstract: is a mathematical model for a certain class of datastructures that have similar behavior; or for certain data types of one or more programming languages that have similar semantics
TEN COMPONENTS OF DATASTRUCTURE
A. Array
Arrays are one of the simplest and most widely used datastructures in computer programs. Arrays in any programming language all share a few common properties:
• The contents of an array are stored in contiguous memory.
• All of the elements of an array must be of the same type or of a derived type; hence arrays are referred to as homogeneous datastructures.
• Array elements can be directly accessed. With arrays if you know you want to access the ith element, you can simply use one line of code: arrayName[i].
The common operations performed on arrays are:
• Allocation
• Accessing
An array holds several values of the same kind. Accessing the elements is very fast. It may not be...