一张图深度解析 Linux 共享内存的内核实现
扬帆 sailing_9806#163.com
http://blog.csdn.net/sailor_8318/article/details/39484747
(本原创文章发表于 扬帆 的个人 blog,未经本人许可,不得用于商业用途。任何个人、媒
体、其他网站不得私自抄袭;网络媒体转载请注明出处,增加原文链接,否则属于侵权行为。
如有任何问题,请留言或者发邮件给 sailing_9806#163.com)
【摘要】本文首先介绍了众所周知的共享内存用户态 API,然后介绍了相关的内核主要数据
结构,并逐一分析了 shmget、shmat、数据访问、shmdt 的内核实现及数据结构之间的动态
关系,从数据的关联图即可一窥共享内存的实现机制。
【关键字】共享内存,shmat, smget, mmap,shmid_kernel
1 功能........................................................................................................................................... 2
2 示例代码 ................................................................................................................................... 2
3 主要数据结构及其关系 ........................................................................................................... 5
3.1 ipc_params .................................................................................................................... 5
3.2 shmid_kernel ................................................................................................................. 6
3.3 kern_ipc_perm .............................................................................................................. 6
3.4 shm_file_data ................................................................................................................ 7
3.5 shm_file_operations ..................................................................................................... 7
3.6 shm_vm_ops ................................................................................................................. 7
3.7 ipc_ops .......................................................................................................................... 7
3.8 数据结构之间的关系 ................................................................................................... 8
4 创建 or 打开 share memory ..................................................................................................... 9
4.1 主流程 ........................................................................................................................... 9
4.2 Shmget ........................................................................................................................ 10
4.3 ipcget_public ............................................................................................................... 10
4.4 newseg ........................................................................................................................ 11
4.5 shmem_file_setup....................................................................................................... 12
4.6 alloc_file ...................................................................................................................... 13
4.7 用户态信息 ................................................................................................................. 13
5 attach 到 share memory ......................................................................................................... 14
5.1 主流程 ......................................................................................................................... 14
5.2 do_shmat .................................................................................................................... 16
5.3 shm_mmap ................................................................................................................. 17
5.4 shmem_mmap ............................................................................................................ 17
5.5 shm_open ................................................................................................................... 18
评论9
最新资源