Preview

Kernel Data Structures

Good Essays
Open Document
Open Document
3107 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Kernel Data Structures
Kernel Data Structures

Umair Hussain Malik p10-6016 p106016@nu.edu.pk

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 Lists
The 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.

Singly and Doubly Linked Lists
The simplest data structure representing such a linked list might look similar to the following:
/* an element in a linked list */ struct list_element { void *data; struct list_element *next;
};

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 Lists
Normally, 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

You May Also Find These Documents Helpful

  • Satisfactory Essays

    4. When the OS addresses the sectors on a hard drive as one long list of sequential sectors, what is this technology called? LBA…

    • 398 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Nt1430 Unit 2 Discuss

    • 401 Words
    • 2 Pages

    The Linux Standard Base (LSB) is a joint project by several Linux distributions under the organizational structure of the Linux Foundation to standardize the software system structure, including the filesystem hierarchy used in the GNU/Linux operating system. When targeting Linux as a platform, application developers want to have some assurance that the code they write on one Linux distribution will run on other Linux distributions without having to go through extra effort. This matches their experiences on other popular platforms, such as Windows or Mac OS X. In addition, application developers want to ensure that the platform as a whole does not diverge. Even if an application works on today's distributions, will it work on tomorrow's? The LSB workgroup has, as its core goal, to address these two concerns. We publish a standard that describes the minimum set of APIs a distribution must support, in consultation with the major distribution vendors. We also provide tests and tools which measure support for the standard, and enable…

    • 401 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Data Link: The protocol layer that transfers data between adjacent network nodes (The switches and MAC addresses)…

    • 648 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 1 Test Paper

    • 381 Words
    • 2 Pages

    1. Create an insert function that will take nodes and add them up in the binary tree.…

    • 381 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 3 Os

    • 1341 Words
    • 6 Pages

    With multiple processors executing the same or different parts of the kernel, kernel tables and management structures must be managed properly to avoid data corruption or invalid operations.…

    • 1341 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    It 218 Week 4 Checkpoint

    • 290 Words
    • 2 Pages

    A pointer can be defined as a memory address. To further explain this definition, we declared a variable of (name). It will look much like this (int name). Every variable will occupy some memory. Now we will declare another variable to under (int name). This variable will be (int name-1), and now this variable is declared as a pointer to (int name).What makes it a pointer is the fact that (name-1) points towards (int name) in a memory storage sense. Basically the pointer to (int name) is the contents of (int name-1). In simple terms, the pointer is not a variable at all. It is the place a specific variable will store and access its information.…

    • 290 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Structured programming is one of the several different ways in which a programming language can be constructed. "It was originally introduced as a means of getting away from the 'spaghetti' code that was used in the early days and to provide some means by which programmers could more easily follow code written by other programmers." (Hendren, 1998) Structured programming is a procedure-oriented method of designing and coding a program.…

    • 962 Words
    • 4 Pages
    Better Essays
  • Satisfactory Essays

    // FREQUENT SUBTREE MINING ALGORITHM... #include #include #include #include #include #include using namespace std; FILE *fp; int no_of_nodes=0, string_ctr=0, vect_ctr=0, vect_ctr1=0,pos_ctr=0,*pos; struct MyNode { string name; vector children; }*myroot, *myroot1, **tree_pattern, **subtree_pattern; //FUNCTION PROTOTYPES DECLARATION ... static void print_element_names(xmlNode *); static MyNode* preprocess(xmlNode *,MyNode *, int); int printMyNode(MyNode *); void print(MyNode **, int); void print_pos_array(int *,int); int check_child(MyNode *, MyNode *); int main() { xmlDoc *doc = NULL; xmlDoc *doc1 = NULL; xmlNode *root_element = NULL; xmlNode *root_element1 = NULL;…

    • 488 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Pointer and Stack

    • 1257 Words
    • 6 Pages

    Here, type is the pointer's base type; it must be a valid C data type and var-name is the name of the pointer variable. The asterisk * you used to declare a pointer is the same asterisk that you use for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer. Following are the valid pointer declaration:…

    • 1257 Words
    • 6 Pages
    Better Essays
  • Better Essays

    Binary Search Tree

    • 1292 Words
    • 6 Pages

    //Program – Binary Search Tree #include<iostream> using namespace std; class node { public: int data; node *left, *right; node() { left=right=NULL; } node(int val) { left=right=NULL; data=val; } }; class bst { private: node *root; void insertNode(node *&rootptr, node *pnew); void deleteNode(node *&root, int delval); int least(node *rootptr); int max(node *rootptr); void pre(node *rootptr); void post(node *rootptr); void in(node *rootptr); int countinternal(node *rootptr, int &count); void printTree(node *p, int level); int search(node *rootptr, int data); public: bst(); void callsearch(int data); void insertBST(int datain); void deleteBST(int data); void displayin(); void displaypost(); void displaypre(); void count(); void print(); void leastele(); void maxele(); }; bst::bst() { root= NULL; } void bst::print() { printTree(root, 0); }; void bst::callsearch(int data) { search(root, data); } int bst::search(node *rootptr, int data) { if(rootptr==NULL) { cout<<"Data not found"; return 0; } else if(rootptr->data==data) cout<<"Element found"<<endl; else if(data<rootptr->data) search(rootptr->left, data); else search(rootptr->right, data); } void bst::count() { int c=0; cout<<"The number of internal nodes is: "<<countinternal(root, c)<<endl; } int bst::countinternal(node *rootptr,int &count) { if(rootptr!=NULL) { countinternal(rootptr->left, count); if(rootptr->right!=NULL || rootptr->left!=NULL)…

    • 1292 Words
    • 6 Pages
    Better Essays
  • Good Essays

    Array Representation

    • 338 Words
    • 2 Pages

    Heap is implemented as an array, but its operations can be grasped more easily by looking at the binary tree representation. The mapping between the array representation and binary tree representation is unambiguous. The array representation can be achieved by traversing the binary tree in level order.…

    • 338 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    Input and Output Devices

    • 2370 Words
    • 10 Pages

    In computer architecture, the combination of the CPU and main memory (i.e. memory that the CPU can read and write to directly, with individual instructions) is considered the brain of a computer, and from that point of view any transfer of information from or to that combination, for example to or from a disk drive, is considered I/O. The CPU and its supporting circuitry provide memory-mapped I/O that is used in low-level computer programming in the implementation of device drivers. An I/O algorithm is one designed to exploit locality and…

    • 2370 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    Linked list

    • 1308 Words
    • 6 Pages

    • Unary operator sizeof is used to determine the size in bytes of any data…

    • 1308 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    memory layout

    • 3957 Words
    • 16 Pages

    A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.…

    • 3957 Words
    • 16 Pages
    Powerful Essays