问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

什么是linux核心数据结构??

发布网友 发布时间:2022-03-17 01:42

我来回答

2个回答

热心网友 时间:2022-03-17 03:12

操作系统可能包含许多关于系统当前状态的信息。当系统发生变化时,这些数据结构必须做相应的改变以反映这些情况。例如,当用户登录进系统时将产生一个新的进程。核心必须创建表示新进程的数据结构,同时 将它和系统中其他进程的数据结构连接在一起。 大多数数据结构存在于物理内存中并只能由核心或者其子系统来访问。数据结构包括数据和指针;还有其他数据结构的地址或者子程序的地址。它们混在一起让Linux核心数据结构看上去非常混乱。尽管可能被几个核心子系统同时用到,每个数据结构都有其专门的用途。理解Linux核心的关键是理解它的数据结构以及Linux核心中操纵这些数据结构的各种函数。本书把Linux核心的 描叙重点放在数据结构上,主要讨论每个核心子系统的算法,完成任务的途径以及对核心数据结构的使用。

2.3.1 连接列表
Linux使用的许多软件工程的技术来连接它的数据结构。在许多场合下,它使用linked或者chained数据结构。 每个数据结构描叙某一事物,比如某个进程或网络设备,核心必须能够访问到所有这些结构。在链表结构中,个根节点指针包含第一个结构的地址,而在每个结构中又包含表中下一个结构的指针。表的最后一项必须是0或者NULL,以表明这是表的尾部。在双向链表中,每个结构包含着指向表中前一结构和后一结构的指针。使用双向链表的好处在于更容易在表的中部添加与删除节点,但需要更多的内存操作。这是一种典型的操作系统开销与CPU循环之间的折中。

2.3.2 散列表
链表用来连接数据结构比较方便,但链表的操作效率不高。如果要搜寻某个特定内容,我们可能不得不遍历整个链表。Linux使用另外一种技术:散列表来提高效率。散列表是指针的数组或向量,指向内存中连续的相邻数据集合。散列表中每个指针元素指向一个独立链表。如果你使用数据结构来描叙村子里的人,则你可以使用年龄作为索引。为了找到某个人的数据,可以在人口散列表中使用年龄作为索引,找到包含此人特定数据的数据结构。但是在村子里有很多人的年龄相同,这样散列表指针变成了一个指向具有相同年龄的人数据链表的指针。搜索这个小链表的速度显然要比搜索整个数据链表快得多。 由于散列表加快了对数据结构的访问速度,Linux经常使用它来实现Caches。Caches是保存经常访问的信息的子集。经常被核心使用的数据结构将被放入Cache中保存。Caches的缺点是比使用和维护单一链表和散列表更复杂。寻找某个数据结构时,如果在Cache中能够找到(这种情况称为cache 命中),这的确很不错。但是如果没有找到,则必须找出它,并且添加到Cache中去。如果Cache空间已经用完则Linux必须决定哪一个结构将从其中抛弃,但是有可能这个要抛弃的数据就是Linux下次要使用的数据。

2.3.3 抽象接口
Linux核心常将其接口抽象出来。接口指一组以特定方式执行的子程序和数据结构的集合。例如,所有的网络设备驱动必须提供对某些特定数据结构进行操作的子程序。通用代码可能会使用底层的某些代码。例如网络层代码是通用的,它得到遵循标准接口的特定设备相关代码的支持。 通常在系统启动时,底层接口向更高层接口注册(Register)自身。这些注册操作包括向链表中加入结构节点。例如,构造进核心的每个文件系统在系统启动时将其自身向核心注册。文件/proc/filesysems中可以看到已经向核心注册过的文件系统。注册数据结构通常包括指向函数的指针,以文件系统注册为例,它向Linux核心注册时必须将那些mount文件系统连接时使用的一些相关函数的地址传入。

参考资料:http://net.fstc.cn/personal/liming/index.asp

热心网友 时间:2022-03-17 04:30

linux核心数据结构
http://www.hlib.cn/article/os/186.asp

此结构用于向核心登记块设备,它还被buffer cache实用。所有此类结构都位于blk_dev数组中。

Struct blk_dev_struct {
void (*request_fn)(void);
struct request * current_request;
struct request plug;
struct tq_struct plug_tq;
};
buffer_head

此结构包含关于buffer cache中一块缓存的信息。

/* bh state bits */
#define BH_Uptodate 0 /* 1 if the buffer contains valid data */
#define BH_Dirty 1 /* 1 if the buffer is dirty */
#define BH_Lock 2 /* 1 if the buffer is locked */
#define BH_Req 3 /* 0 if the buffer has been invalidated */
#define BH_Touched 4 /* 1 if the buffer has been touched (aging) */
#define BH_Has_aged 5 /* 1 if the buffer has been aged (aging) */
#define BH_Protected 6 /* 1 if the buffer is protected */
#define BH_FreeOnIO 7 /* 1 to discard the buffer_head after IO */
struct buffer_head {
/* First cache line: */
unsigned long b_blocknr; /* block number */
kdev_t b_dev; /* device (B_FREE = free) */
kdev_t b_rdev; /* Real device */
unsigned long b_rsector; /* Real buffer location on disk */
struct buffer_head *b_next; /* Hash queue list */
struct buffer_head *b_this_page; /* circular list of buffers in one
page */
/* Second cache line: */
unsigned long b_state; /* buffer state bitmap (above) */
struct buffer_head *b_next_free;
unsigned int b_count; /* users using this block */
unsigned long b_size; /* block size */
/* Non-performance-critical data follows. */
char *b_data; /* pointer to data block */
unsigned int b_list; /* List that this buffer appears */
unsigned long b_flushtime; /* Time when this (dirty) buffer
* should be written */
unsigned long b_lru_time; /* Time when this buffer was
* last used. */
struct wait_queue *b_wait;
struct buffer_head *b_prev; /* doubly linked hash list */
struct buffer_head *b_prev_free; /* doubly linked list of buffers */
struct buffer_head *b_reqnext; /* request queue */
};
device

系统中每个网络设备都用一个设备数据结构来表示。

Struct device
{
/*
* This is the first field of the visible part of this structure
* (I.e. as seen by users in the Space.c file). It is the name
* the interface.
*/
char *name;
/* I/O specific fields */
unsigned long rmem_end; /* shmem recv end */
unsigned long rmem_start; /* shmem recv start */
unsigned long mem_end; /* shared mem end */
unsigned long mem_start; /* shared mem start */
unsigned long base_addr; /* device I/O address */
unsigned char irq; /* device IRQ number */
/* Low-level status flags. */
volatile unsigned char start, /* start an operation */
interrupt; /* interrupt arrived */
unsigned long tbusy; /* transmitter busy */
struct device *next;
/* The device initialization function. Called only once. */
int (*init)(struct device *dev);
/* Some hardware also needs these fields, but they are not part of
the usual set specified in Space.c. */
unsigned char if_port; /* Selectable AUI,TP, */
unsigned char dma; /* DMA channel */
struct enet_statistics* (*get_stats)(struct device *dev);
/*
* This marks the end of the visible part of the structure. All
* fields hereafter are internal to the system, and may change at
* will (read: may be cleaned up at will).
*/
/* These may be needed for future network-power-down code. */
unsigned long trans_start; /* Time (jiffies) of last transmit */
unsigned long last_rx; /* Time of last Rx */
unsigned short flags; /* interface flags (BSD)*/
unsigned short family; /* address family ID */
unsigned short metric; /* routing metric */
unsigned short mtu; /* MTU value */
unsigned short type; /* hardware type */
unsigned short hard_header_len; /* hardware hdr len */
void *priv; /* private data */
/* Interface address info. */
unsigned char broadcast[MAX_ADDR_LEN];
unsigned char pad;
unsigned char dev_addr[MAX_ADDR_LEN];
unsigned char addr_len; /* hardware addr len */
unsigned long pa_addr; /* protocol address */
unsigned long pa_brdaddr; /* protocol broadcast addr*/
unsigned long pa_dstaddr; /* protocol P-P other addr*/
unsigned long pa_mask; /* protocol netmask */
unsigned short pa_alen; /* protocol address len */
struct dev_mc_list *mc_list; /* M'cast mac addrs */
int mc_count; /* No installed mcasts */
struct ip_mc_list *ip_mc_list; /* IP m'cast filter chain */
__u32 tx_queue_len; /* Max frames per queue */
/* For load balancing driver pair support */
unsigned long pkt_queue; /* Packets queued */
struct device *slave; /* Slave device */
struct net_alias_info *alias_info; /* main dev alias info */
struct net_alias *my_alias; /* alias devs */
/* Pointer to the interface buffers. */
struct sk_buff_head buffs[DEV_NUMBUFFS];
/* Pointers to interface service routines. */
int (*open)(struct device *dev);
int (*stop)(struct device *dev);
int (*hard_start_xmit) (struct sk_buff *skb,
struct device *dev);
int (*hard_header) (struct sk_buff *skb,
struct device *dev,
unsigned short type,
void *daddr,
void *saddr,
unsigned len);
int (*rebuild_header)(void *eth,
struct device *dev,
unsigned long raddr,
struct sk_buff *skb);
void (*set_multicast_list)(struct device *dev);
int (*set_mac_address)(struct device *dev,
void *addr);
int (*do_ioctl)(struct device *dev,
struct ifreq *ifr,
int cmd);
int (*set_config)(struct device *dev,
struct ifmap *map);
void (*header_cache_bind)(struct hh_cache **hhp,
struct device *dev,
unsigned short htype,
__u32 daddr);
void (*header_cache_update)(struct hh_cache *hh,
struct device *dev,
unsigned char * haddr);
int (*change_mtu)(struct device *dev,
int new_mtu);
struct iw_statistics* (*get_wireless_stats)(struct device *dev);
};
device_struct

此结构被块设备和字符设备用来向核心登记(包含设备名称以及可对此设备进行的文件操作)。Chrdevs和blkdevs中的每个有效分别表示一个字符设备和块设备。

Struct device_struct {
const char * name;
struct file_operations * fops;
};
file

每个打开的文件、套接口都用此结构表示。

Struct file {
mode_t f_mode;
loff_t f_pos;
unsigned short f_flags;
unsigned short f_count;
unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
struct file *f_next, *f_prev;
int f_owner; /* pid or -pgrp where SIGIO should be sent */
struct inode * f_inode;
struct file_operations * f_op;
unsigned long f_version;
void *private_data; /* needed for tty driver, and maybe others */
};
files_struct

描叙被某进程打开的所有文件。

Struct files_struct {
int count;
fd_set close_on_exec;
fd_set open_fds;
struct file * fd[NR_OPEN];
};
fs_struct
struct fs_struct {
int count;
unsigned short umask;
struct inode * root, * pwd;
};
gendisk

包含关于某个硬盘的信息。用于磁盘初始化与分区检查时。

Struct hd_struct {
long start_sect;
long nr_sects;
};
struct gendisk {
int major; /* major number of driver */
const char *major_name; /* name of major driver */
int minor_shift; /* number of times minor is shifted to get real minor */
int max_p; /* maximum partitions per device */
int max_nr; /* maximum number of real devices */
void (*init)(struct gendisk *);
/* Initialization called before we do our thing */
struct hd_struct *part; /* partition table */
int *sizes; /* device size in blocks, copied to blk_size[] */
int nr_real; /* number of real devices */
void *real_devices; /* internal use */
struct gendisk *next;
};
inode

此VFS inode结构描叙磁盘上一个文件或目录的信息。

Struct inode {
kdev_t I_dev;
unsigned long I_ino;
umode_t I_mode;
nlink_t I_nlink;
uid_t I_uid;
gid_t I_gid;
kdev_t I_rdev;
off_t I_size;
time_t I_atime;
time_t I_mtime;
time_t I_ctime;
unsigned long I_blksize;
unsigned long I_blocks;
unsigned long I_version;
unsigned long I_nrpages;
struct semaphore I_sem;
struct inode_operations *I_op;
struct super_block *I_sb;
struct wait_queue *I_wait;
struct file_lock *I_flock;
struct vm_area_struct *I_mmap;
struct page *I_pages;
struct dquot *I_dquot[MAXQUOTAS];
struct inode *I_next, *I_prev;
struct inode *I_hash_next, *I_hash_prev;
struct inode *I_bound_to, *I_bound_by;
struct inode *I_mount;
unsigned short I_count;
unsigned short I_flags;
unsigned char I_lock;
unsigned char I_dirt;
unsigned char I_pipe;
unsigned char I_sock;
unsigned char I_seek;
unsigned char I_update;
unsigned short I_writecount;
union {
struct pipe_inode_info pipe_I;
struct minix_inode_info minix_I;
struct ext_inode_info ext_I;
struct ext2_inode_info ext2_I;
struct hpfs_inode_info hpfs_I;
struct msdos_inode_info msdos_I;
struct umsdos_inode_info umsdos_I;
struct iso_inode_info isofs_I;
struct nfs_inode_info nfs_I;
struct xiafs_inode_info xiafs_I;
struct sysv_inode_info sysv_I;
struct affs_inode_info affs_I;
struct ufs_inode_info ufs_I;
struct socket socket_I;
void *generic_ip;
} u;
};
ipc_perm

此结构描叙对一个系统V IPC对象的存取权限。

Struct ipc_perm
{
key_t key;
ushort uid; /* owner euid and egid */
ushort gid;
ushort cuid; /* creator euid and egid */
ushort cgid;
ushort mode; /* access modes see mode flags below */
ushort seq; /* sequence number */
};
irqaction

用来描叙系统的中断处理过程。

Struct irqaction {
void (*handler)(int, void *, struct pt_regs *);
unsigned long flags;
unsigned long mask;
const char *name;
void *dev_id;
struct irqaction *next;
};
linux_binfmt

用来表示可被Linux理解的二进

Linux网络代码导读v0.2
http://www.hlib.cn/article/os/192.asp

Linux核心代码分析
http://www.hlib.cn/article/program/1036.asp

LINUX C语言开发简介
http://www.hlib.cn/article/program/1051.asp

Linux下mSQL数据库开发技术
http://www.hlib.cn/article/database/4175.asp

更多linux文章,可站内搜索:
http://www.hlib.cn/search.asp?keyword=linux

参考资料:http://www.0668idc.com/Article/Software/linux/200602/Article_7642_3.html

linux虚拟文件系统的关键数据结构有哪些?

linux虚拟文件系统核心数主要有以下几个数据结构:超级块结构(struct super_block {...} )该结构保存了一个被安装在linux系统上的文件系统的信息。对于基于磁盘的文件系统,该结构一般和保存在磁盘上的"文件系统控制块"对应。也就是说如果是磁盘文件系统,该结构保存的磁盘文件系统的控制信息。inode结构(...

内核树是什么意思?

内核树是操作系统中的一个核心数据结构,它描述了操作系统中所有进程和线程的层级关系。内核树通常是一个多叉树,每个节点代表一个进程或线程,每个节点可以有多个子节点。内核树的根节点是操作系统自身,每个进程和线程都是从根节点开始的子节点,形成了一个树形结构。通过内核树,操作系统可以有效地管理...

linux内核数据结构之kfifo

Linux内核中的kfifo是一个精简且巧妙设计的环形队列,常用于解决生产者和消费者模型中的数据缓冲问题,确保数据处理的高效性。本文将探讨kfifo的数据结构、实现方法以及在并发环境下的使用。在项目开发中,环形缓冲区(ring buffer)作为缓存机制,通过Linux内核的kfifo实现,能够有效降低CPU与内存或磁盘之间的...

什么是linux内核

MutiTask MutiTask 的意思是多任务,代表着 Linux 是一个多任务的操作系统。多任务意味着可以有多个任务同时执行,这里的「同时」可以是并发或并行:对于单核 CPU 时,可以让每个任务执行一小段时间,时间到就切换另外一个任务,从宏观角度看,一段时间内执行了多个任务,这被称为并发。对于多核 CPU ...

ode的抽象概念Linux中Inode的抽象理解linux上in

Inode(Index Node) 是Linux系统文件系统文件系统管理的一种方法。它是文件系统的一种抽象概念,用于管理文件的一组数据结构,它被认为是Linux系统中的核心内容,是整个文件系统的基石。Inode(Index Node)是用来代表单个文件的文件系统中的数据结构,这是一种被引用的特殊文件,不能直接观察或访问。一个...

Linux内核网络分层模型——skb核心操作

Linux内核的网络操作是基于分层设计的,可以形象地比喻为一个数据包的“栈”操作。数据包的形成是通过逐层封装,即所谓的push操作,而解封装则是逐层弹出,即pop操作。核心数据结构sk_buff在这一过程中起到了关键作用。sk_buff操作涉及的步骤包括:首先,通过alloc_skb分配sk_buff结构和数据包缓冲区,...

sk_buff数据结构详解

Linux网络编程中,sk_buff数据结构起着核心作用,它是封装和传递数据的载体。每个网络层都依赖这个结构来存储报头信息、用户数据和内部协调。struct net_device表示网络设备,包含了硬件配置;而struct sock则用于存储套接字的相关网络信息。sk_buff结构体由多个部分组成,包括布局、通用、专用功能和管理函数。

一文秒懂|Linux字符设备驱动

本文旨在快速入门Linux字符设备驱动,带你理解其核心框架和机制。Linux内核的驱动模型包括字符设备驱动、块设备驱动和网络设备驱动,其中字符设备驱动是常见的一种。文章以Kernel 4.19为基础,首先介绍关键数据结构:cdev(字符设备),作为char device的抽象,其主要成员file_operations定义了文件操作接口;dev_...

Android操作系统是基于Linux Kernel是什么意思

kernel(内核):是操作系统最基本的部分,是一个操作系统的核心。是基于硬件的第一层软件扩充,提供操作系统的最基本的功能,是操作系统工作的基础,它负责管理系统的进程、内存、内核体系结构、设备驱动程序、文件和网络系统,决定着系统的性能和稳定。Linux内核:顾名思义即Linux系统的核心,是Linux操作系统...

内存管理:一文读懂Linux内存组织结构及页面布局

7、slab 分配器的结构 详细参考:经典|图解Linux内存性能优化核心思想 8、slab 高速缓存 1) 普通高速缓存 2) 专用高速缓存 9、内核态内存池 1) 基本原理 2) 内核 API 10、用户态内存池 1) C++ 实例 11、DMA 内存 1) 什么是 DMA 2) DMA 信号 out of memory 的时代过去了吗?no,...

linkmap数据结构linux linux内核数据结构 linux内核数据结构框架 程序的核心是数据结构吗 数据结构到底是什么 linux数据结构 linux数据结构map linuxfat数据结构 核心数据结构
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
多特后防四大天王是哪些 iPhoe4还原所有设置后变成语音朗读而且滑屏无法正常使用 金鱼在鱼缸里几天能不会死掉? 金鱼放鱼缸多久合适 金鱼放鱼缸的时间 想学会缅甸语请问大神昆明附近有没有好一点的班? 昆明哪里可以学缅甸语?哪里不贵,哪里有优势? 昆明哪里可以学缅甸语啊?想去学几个月。 要出去缅甸出差一段时间,请问下昆明什么地方有好的缅甸语培训?? 叔叔要去缅甸做生意,帮他找间学校学缅甸语,简单的就行了,只有两个月... 昆明学缅甸语哪里学呀??? 想学几个月,再去一次缅甸。 我的洛奇怎么运行不了 我的macpro是今年七月份买的,怎么免费升级到lion 你说到官网的那个表是什么意思? up to 的用法意义是怎么样的 电脑里的winupdate.exe进程是怎么回事? 医学文献数据库检索网站 京杭大运河的简图怎么画 winscp 如何输入键值 关于系统进程,高手进!!! 2012年新版 Macbook air 听说可以免费把系统更新成山狮的 具体怎么弄啊?求大神指教 你对网传吃小龙虾会得“横纹肌溶解症”此类造谣事件怎么看? 医学英文文献怎么找? 广东东方新特药有限公司怎么样? 怎么把uptodate变成pdf 一打网页就出来这个网站http://secureuptodate.com/是怎么回事? 普通人能下载uptodate吗 如何获得uptodate的账号 win10平板模式怎么切换窗口 win10平板模式怎么切换电脑模式 win10怎么切换平板模式快捷键 win10系统平板模式怎么切换回去 UpToDate数据库怎么样? oppo私密照片怎么打开 oppo手机照片设为私密后怎么查看 如何打开OPPO相片隐藏。? oppo手机照片设为私密后怎么查看? oppo相册里的私密照片怎么找 oppo手机相册里的私密照片怎么找 oppo如何开启私密相册 怎么打开私密相片oppo oppo私密相册怎么打开啊 oppo相册怎么打开私密相册 WPS上怎么画图啊? wps里面怎么画图? WPS画图怎么画 wps文档如何画图形 wps怎么画图 wps文字怎么使用绘图工具 wps如何画图 wps怎么画图形 wps中怎样画图