SlideShare uma empresa Scribd logo
1 de 11
Linux Kernel Data Structure
Task list – It’s a circular doubly linked list. Each
entry contains a structure (task_struct).
Each structure contains detailed information about
corresponding process and a task list node. The
node contains previous and next pointer only).
Macros to Initialize / manipulate Task list:
 container_of(ptr, type, member) - Returns the
parent structure containing a list_Head (circular
doubly linked list node).
 LIST_HEAD_INIT - Initialize the task list node
embedded in the task_struct.
Linux Kernel Data Structure
Macros to Initialize / manipulate Task list:
 list_for_each_entry(pos, head, member) – Traverse given list
 list_for_each_entry_safe(pos, n, head, member) – safe
against entry removal while traversing the list
 list_for_each_entry_reverse(pos, head, member) – Traverse
given list backward
 list_for_each_entry_reverse_safe(pos, n, head, member) safe against entry removal while traversing the list backward
 list_for_each_entry_safe_continue (pos, n, head, member)
- safe against entry removal while continuing after current
point
pos: pointer type to use as a loop cursor.
n: pointer type to store next pointer.
head: the head for your list (struct list_head *head)
member: the name of the list_struct (struct list_head *list)
Linux Kernel Data Structure
Functions to Initialize/manipulate Task list:
 list_add(struct list_head *new, struct list_head
*head) - add a node to given list
 list_add_tail( struct list_head *new, struct
list_head *head) - add the new node to the list

immediately before the head node
 list_del(struct list_head *entry) – delete a node
from the list
 list_del_init(struct list_head *entry) – delete a
node from a linked list and reinitialize the
given list head
Linux Kernel Data Structure
Functions to Initialize/manipulate Task list:
 list_move(struct list_head *list, struct list_head *head) –
Remove the node from the list and add the node after head
node in the given list.
 list_move_tail list_move(struct list_head *list, struct
list_head *head) ) – Remove the node from the list and add
the node add the node before head node in the given list.
 list_empty(struct list_head *head) – verify if list is empty
 list_splice(struct list_head *list, struct list_head *head) –
Join two lists
 list_splice_init(struct list_head *list, struct list_head *head)
– Join two lists and initialize first list
Linux Kernel Data Structure
Kfifo - Generic Queue used by Linux kernel
Functions to Initialize/manipulate Queue:
 int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t
gfp_mask) – creates a queue and initializes with “size” bytes
 void kfifo_init(struct kfifo *fifo, void *buffer, unsigned int
size)- creates a queue and initializes with “size” bytes from
the memory pointed by buffer
 static inline bool kfifo_initialized(struct kfifo *fifo) – verify if
queue is initialized
 unsigned int kfifo_in(struct kfifo *fifo, const void *from,
unsigned int len) – add data of size “len” from memory
pointed to by “from pointer” to queue
Linux Kernel Data Structure
Functions to Initialize/manipulate Queue:
 unsigned unsigned int kfifo_out(struct kfifo *fifo,
void *to, unsigned int len)– remove from queue
data of size “len” and copy to memory pointed by “to
pointer” from queue
 unsigned int kfifo_out_peek(struct kfifo *fifo, void
*to, unsigned int len, unsigned offset) – peek data
within the queue without removing it
 static inline void kfifo_reset(struct kfifo *fifo) –
remove entire contents of queue
 static inline void kfifo_reset_out(struct kfifo *fifo) –
does not remove entire contents of queue
Linux Kernel Data Structure
Functions to Initialize/manipulate Queue:
 int kfifo_is_empty(struct kfifo *fifo) – verify if queue
is empty
 int kfifo_is_full (struct kfifo *fifo) - verify if queue is
full
 static inline unsigned int kfifo_len(struct kfifo *fifo)
– returns queue size
 unsigned int kfifo_avail(struct kfifo *fifo) – returns
no of bytes available in the queue
 void kfifo_free(struct kfifo *fifo) – free memory
allocated to queue using kfifo_alloc()
Linux Kernel Data Structure
IDR – It is the map implementation of Linux . Struct idr
is used for mapping user-space UIDs to their
associated kernel data structure
Functions to Initialize/manipulate IDR:
void idr_init(struct idr *idp)- initialize Map (idr)
Allocating a new UID (create a new map entry) 2 steps:
1. int idr_pre_get(struct idr *idp, gfp_t gfp_mask) Resizes the backing tree
2. int idr_get_new(struct idr *idp, void *ptr, int *id)Uses the idr pointed at by idp to allocate a new UID and
associate it with the pointer ptr
Linux Kernel Data Structure
Functions to Initialize/manipulate Queue:
void *idr_find(struct idr *idp, int id)– look up a
UID
void idr_remove(struct idr *idp, int id) Remove a UID from an idr
void idr_remove_all(struct idr *idp) – remove
all entries from idr
void idr_destroy(struct idr *idp) - Destroy entire
idr
Linux Kernel Data Structure
Rbtree (red-black tree) – It is the Linux’s
implementation of (semi) Balanced Binary search tree.
It is useful for inserting and searching efficiently.
prio_tree (PST) - It is the Linux’s implementation of
radix priority search tree which is a mix of heap and
radix trees.
It is useful for storing intervals.
e.g. consider a vma as a closed interval of file pages
[offset_begin, offset_end], and store all vmas that map
a file in a PST.
Thank You
• Your suggestions and comments are always
welcome.
• Please send me your feedback at
a_s_sinha@yahoo.com

Mais conteúdo relacionado

Mais procurados

The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
hugo lu
 

Mais procurados (20)

twlkh-linux-vsyscall-and-vdso
twlkh-linux-vsyscall-and-vdsotwlkh-linux-vsyscall-and-vdso
twlkh-linux-vsyscall-and-vdso
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
writing self-modifying code and utilizing advanced assembly techniques
writing self-modifying code and utilizing advanced assembly techniqueswriting self-modifying code and utilizing advanced assembly techniques
writing self-modifying code and utilizing advanced assembly techniques
 
Tensorflow lite for microcontroller
Tensorflow lite for microcontrollerTensorflow lite for microcontroller
Tensorflow lite for microcontroller
 
Pwning in c++ (basic)
Pwning in c++ (basic)Pwning in c++ (basic)
Pwning in c++ (basic)
 
4章 Linuxカーネル - 割り込み・例外 5
4章 Linuxカーネル - 割り込み・例外 54章 Linuxカーネル - 割り込み・例外 5
4章 Linuxカーネル - 割り込み・例外 5
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Sockets and Socket-Buffer
Sockets and Socket-BufferSockets and Socket-Buffer
Sockets and Socket-Buffer
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
Injection on Steroids: Codeless code injection and 0-day techniques
Injection on Steroids: Codeless code injection and 0-day techniquesInjection on Steroids: Codeless code injection and 0-day techniques
Injection on Steroids: Codeless code injection and 0-day techniques
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
 
eBPF/XDP
eBPF/XDP eBPF/XDP
eBPF/XDP
 
Comprendre les scripts shell auto-extractible
Comprendre les scripts shell auto-extractibleComprendre les scripts shell auto-extractible
Comprendre les scripts shell auto-extractible
 

Destaque

Uma visão do mundo rails campus party 2011 - fabio akita
Uma visão do mundo rails   campus party 2011 - fabio akitaUma visão do mundo rails   campus party 2011 - fabio akita
Uma visão do mundo rails campus party 2011 - fabio akita
Campus Party Brasil
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 

Destaque (20)

Data Structures for Text Editors
Data Structures for Text EditorsData Structures for Text Editors
Data Structures for Text Editors
 
Capturando pacotes de rede no kernelspace
Capturando pacotes de rede no kernelspaceCapturando pacotes de rede no kernelspace
Capturando pacotes de rede no kernelspace
 
Linux下Poll和Epoll内核源码剖析
Linux下Poll和Epoll内核源码剖析Linux下Poll和Epoll内核源码剖析
Linux下Poll和Epoll内核源码剖析
 
Uma visão do mundo rails campus party 2011 - fabio akita
Uma visão do mundo rails   campus party 2011 - fabio akitaUma visão do mundo rails   campus party 2011 - fabio akita
Uma visão do mundo rails campus party 2011 - fabio akita
 
Open Source Systems Performance
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems Performance
 
Epoll - from the kernel side
Epoll -  from the kernel sideEpoll -  from the kernel side
Epoll - from the kernel side
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
 
Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 

Semelhante a Data Structures used in Linux kernel

Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 
1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf
ivylinvaydak64229
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
shahidqamar17
 

Semelhante a Data Structures used in Linux kernel (20)

Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
Linux
LinuxLinux
Linux
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
LinkedDoublyLists.ppt
LinkedDoublyLists.pptLinkedDoublyLists.ppt
LinkedDoublyLists.ppt
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 

Mais de assinha

Mais de assinha (10)

Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
 
SNMP AT a GLANCE
SNMP AT a GLANCESNMP AT a GLANCE
SNMP AT a GLANCE
 
Layer3protocols
Layer3protocolsLayer3protocols
Layer3protocols
 
Umts explained
Umts explainedUmts explained
Umts explained
 
Architectural patterns part 4
Architectural patterns part 4Architectural patterns part 4
Architectural patterns part 4
 
Architectural patterns part 3
Architectural patterns part 3Architectural patterns part 3
Architectural patterns part 3
 
Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patterns
 
Architectural patterns part 1
Architectural patterns part 1Architectural patterns part 1
Architectural patterns part 1
 
E nodeb handover procedure
E nodeb handover procedureE nodeb handover procedure
E nodeb handover procedure
 
Initial LTE call Setup Flow
Initial LTE call Setup FlowInitial LTE call Setup Flow
Initial LTE call Setup Flow
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Data Structures used in Linux kernel

  • 1. Linux Kernel Data Structure Task list – It’s a circular doubly linked list. Each entry contains a structure (task_struct). Each structure contains detailed information about corresponding process and a task list node. The node contains previous and next pointer only). Macros to Initialize / manipulate Task list:  container_of(ptr, type, member) - Returns the parent structure containing a list_Head (circular doubly linked list node).  LIST_HEAD_INIT - Initialize the task list node embedded in the task_struct.
  • 2. Linux Kernel Data Structure Macros to Initialize / manipulate Task list:  list_for_each_entry(pos, head, member) – Traverse given list  list_for_each_entry_safe(pos, n, head, member) – safe against entry removal while traversing the list  list_for_each_entry_reverse(pos, head, member) – Traverse given list backward  list_for_each_entry_reverse_safe(pos, n, head, member) safe against entry removal while traversing the list backward  list_for_each_entry_safe_continue (pos, n, head, member) - safe against entry removal while continuing after current point pos: pointer type to use as a loop cursor. n: pointer type to store next pointer. head: the head for your list (struct list_head *head) member: the name of the list_struct (struct list_head *list)
  • 3. Linux Kernel Data Structure Functions to Initialize/manipulate Task list:  list_add(struct list_head *new, struct list_head *head) - add a node to given list  list_add_tail( struct list_head *new, struct list_head *head) - add the new node to the list immediately before the head node  list_del(struct list_head *entry) – delete a node from the list  list_del_init(struct list_head *entry) – delete a node from a linked list and reinitialize the given list head
  • 4. Linux Kernel Data Structure Functions to Initialize/manipulate Task list:  list_move(struct list_head *list, struct list_head *head) – Remove the node from the list and add the node after head node in the given list.  list_move_tail list_move(struct list_head *list, struct list_head *head) ) – Remove the node from the list and add the node add the node before head node in the given list.  list_empty(struct list_head *head) – verify if list is empty  list_splice(struct list_head *list, struct list_head *head) – Join two lists  list_splice_init(struct list_head *list, struct list_head *head) – Join two lists and initialize first list
  • 5. Linux Kernel Data Structure Kfifo - Generic Queue used by Linux kernel Functions to Initialize/manipulate Queue:  int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask) – creates a queue and initializes with “size” bytes  void kfifo_init(struct kfifo *fifo, void *buffer, unsigned int size)- creates a queue and initializes with “size” bytes from the memory pointed by buffer  static inline bool kfifo_initialized(struct kfifo *fifo) – verify if queue is initialized  unsigned int kfifo_in(struct kfifo *fifo, const void *from, unsigned int len) – add data of size “len” from memory pointed to by “from pointer” to queue
  • 6. Linux Kernel Data Structure Functions to Initialize/manipulate Queue:  unsigned unsigned int kfifo_out(struct kfifo *fifo, void *to, unsigned int len)– remove from queue data of size “len” and copy to memory pointed by “to pointer” from queue  unsigned int kfifo_out_peek(struct kfifo *fifo, void *to, unsigned int len, unsigned offset) – peek data within the queue without removing it  static inline void kfifo_reset(struct kfifo *fifo) – remove entire contents of queue  static inline void kfifo_reset_out(struct kfifo *fifo) – does not remove entire contents of queue
  • 7. Linux Kernel Data Structure Functions to Initialize/manipulate Queue:  int kfifo_is_empty(struct kfifo *fifo) – verify if queue is empty  int kfifo_is_full (struct kfifo *fifo) - verify if queue is full  static inline unsigned int kfifo_len(struct kfifo *fifo) – returns queue size  unsigned int kfifo_avail(struct kfifo *fifo) – returns no of bytes available in the queue  void kfifo_free(struct kfifo *fifo) – free memory allocated to queue using kfifo_alloc()
  • 8. Linux Kernel Data Structure IDR – It is the map implementation of Linux . Struct idr is used for mapping user-space UIDs to their associated kernel data structure Functions to Initialize/manipulate IDR: void idr_init(struct idr *idp)- initialize Map (idr) Allocating a new UID (create a new map entry) 2 steps: 1. int idr_pre_get(struct idr *idp, gfp_t gfp_mask) Resizes the backing tree 2. int idr_get_new(struct idr *idp, void *ptr, int *id)Uses the idr pointed at by idp to allocate a new UID and associate it with the pointer ptr
  • 9. Linux Kernel Data Structure Functions to Initialize/manipulate Queue: void *idr_find(struct idr *idp, int id)– look up a UID void idr_remove(struct idr *idp, int id) Remove a UID from an idr void idr_remove_all(struct idr *idp) – remove all entries from idr void idr_destroy(struct idr *idp) - Destroy entire idr
  • 10. Linux Kernel Data Structure Rbtree (red-black tree) – It is the Linux’s implementation of (semi) Balanced Binary search tree. It is useful for inserting and searching efficiently. prio_tree (PST) - It is the Linux’s implementation of radix priority search tree which is a mix of heap and radix trees. It is useful for storing intervals. e.g. consider a vma as a closed interval of file pages [offset_begin, offset_end], and store all vmas that map a file in a PST.
  • 11. Thank You • Your suggestions and comments are always welcome. • Please send me your feedback at a_s_sinha@yahoo.com