【Linux 内核 内存管理】RCU 机制 ③ ( RCU 模式下添加链表项 list_add_rcu 函数 | RCU 模式下删除链表项 list_del_rcu 函数 )
2023-06-13 09:18:05 时间
文章目录
一、RCU 模式下添加链表项 list_add_rcu 函数
在 Linux 源码 linux-5.6.18\include\linux\rculist.h
头文件中定义的就是 RCU 链表的操作 ,
其中定义的
static inline void list_add_rcu(struct list_head *new, struct list_head *head)
函数 , 就是 向 链表中 添加元素 的 函数 ;
list_add_rcu
函数中 , 主要是调用了 __list_add_rcu
函数 ,
在 __list_add_rcu
函数中 , 将新添加的 链表项 添加到了 struct list_head *prev
和 struct list_head *next
两个链表项的中间 ;
list_add_rcu 函数原型 :
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add_rcu(struct list_head *new,
struct list_head *prev, struct list_head *next)
{
if (!__list_add_valid(new, prev, next))
return;
new->next = next;
new->prev = prev;
rcu_assign_pointer(list_next_rcu(prev), new);
next->prev = new;
}
/**
* list_add_rcu - add a new entry to rcu-protected list
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*
* The caller must take whatever precautions are necessary
* (such as holding appropriate locks) to avoid racing
* with another list-mutation primitive, such as list_add_rcu()
* or list_del_rcu(), running on this same list.
* However, it is perfectly legal to run concurrently with
* the _rcu list-traversal primitives, such as
* list_for_each_entry_rcu().
*/
static inline void list_add_rcu(struct list_head *new, struct list_head *head)
{
__list_add_rcu(new, head, head->next);
}
源码路径 : linux-5.6.18\include\linux\rculist.h#105
二、RCU 模式下删除链表项 list_del_rcu 函数
在 Linux 源码 linux-5.6.18\include\linux\rculist.h
头文件中定义的就是 RCU 链表的操作 ,
其中定义的
static inline void list_del_rcu(struct list_head *entry)
函数 , 就是 从 链表中 删除元素 的 函数 ;
list_del_rcu
函数中 , 主要是调用了 __list_del_entry
函数 ,
在 __list_del_entry
函数中 , 又调用了 __list_del
函数 ;
list_del_rcu 函数原型 :
/**
* list_del_rcu - deletes entry from list without re-initialization
* @entry: the element to delete from the list.
*
* Note: list_empty() on entry does not return true after this,
* the entry is in an undefined state. It is useful for RCU based
* lockfree traversal.
*
* In particular, it means that we can not poison the forward
* pointers that may still be used for walking the list.
*
* The caller must take whatever precautions are necessary
* (such as holding appropriate locks) to avoid racing
* with another list-mutation primitive, such as list_del_rcu()
* or list_add_rcu(), running on this same list.
* However, it is perfectly legal to run concurrently with
* the _rcu list-traversal primitives, such as
* list_for_each_entry_rcu().
*
* Note that the caller is not permitted to immediately free
* the newly deleted entry. Instead, either synchronize_rcu()
* or call_rcu() must be used to defer freeing until an RCU
* grace period has elapsed.
*/
static inline void list_del_rcu(struct list_head *entry)
{
__list_del_entry(entry);
entry->prev = LIST_POISON2;
}
static inline void __list_del_entry(struct list_head *entry)
{
if (!__list_del_entry_valid(entry))
return;
__list_del(entry->prev, entry->next);
}
/**
* list_del - deletes entry from list.
* @entry: the element to delete from the list.
* Note: list_empty() on entry does not return true after this, the entry is
* in an undefined state.
*/
static inline void list_del(struct list_head *entry)
{
__list_del_entry(entry);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
}
源码路径 : linux-5.6.18\include\linux\rculist.h#156
相关文章
- Linux:实现链表技术的精彩实例(linux链表实例)
- 分析Linux进程内存使用分析(linux进程所占内存)
- Linux自动化管理内存的能力(linux自动清理内存)
- Linux系统:查看信息与调整设置(linux下查看系统信息)
- Linux端口连通性检测(linux端口连通性)
- Linux下使用Dir命令查看文件目录(linux中dir命令)
- 操作系统探索Linux:学习操作Linux系统(什么叫linux)
- Linux引用计数系统:实现内存回收(linux引用计数)
- 深入探索Linux中的内存使用(linux怎么查看内存)
- Linux运维必备:百余条常用命令(linux常用的运维命令)
- 长度Linux求字符串长度:一种简单方式(linux获取字符串)
- Linux双内存技术:增强系统性能(linux双口ram)
- 查看Linux内存使用情况(查看内存linux)
- 在Linux系统中安装LZMA压缩工具(linux安装lzma)
- Linux系统补丁管理指南(linux补丁管理)
- 怎么办? 解决Linux内存不够问题(linux内存不够)
- 深入探究Linux进程的内存占用情况:原理与实践(linux进程内存占用)
- 内存Linux父子进程共享内存:实现功能的关键(linux父子进程共享)
- 系统使用nmon工具监控Linux系统性能(nmon监控linux)
- Linux系统内存管理析:实现高效与可靠性(linux 内存管理分析)
- Linux下查看系统内存的实用方法(linux 查看系统内存)
- Linux内存清理:提高系统运行效率的不二选择(linux清理内存)
- 如何用Linux系统释放内存空间(linux 内存释放命令)
- Linux系统内存优化,提高系统运行效率(linux内存大小)
- Linux下修改文件夹名的简易操作(修改文件夹名 linux)
- Linux下内存测试工具的探索之旅(linux内存测试工具)