hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

Postmaster的Shared Memory中的shmem index table 内存结构

已有 8267 次阅读 2010-3-31 12:09 |个人分类:postgresql|系统分类:科研笔记| memory, table, postgresql, shmem

我们知道,Postmaster的Shared Memory中的shmem index table 是一个dynamic hash table,所以理解该hash table初始化时在内存中的结构对于理解postmaster 的shared memory有重要帮助。

调用流程:
PostmasterMain->reset_shared(int)->CreateSharedMemoryAndSemaphores()->InitShmemIndex();
先看PostgreSQL总体内存结构:
在momjian的Inside PostgreSQL Shared Memory http://momjian.us/main/writings/pgsql/inside_shmem.pdf第11页中Shared Memory Creation中,我们可以了解到PostgreSQL总体内存结构:


关于Heap,Stack,Shared Memory的关系和在内存中的位置,请参考我的另外一篇文章:
http://blog.chinaunix.net/u2/81513/showart.php?id=2203403
由于Postgresql对malloc的替换实现palloc,底层仍然采用glib c的malloc调用,所以我们可以得出凡是使用palloc分配的内存都是在heap上的(即采用brk系统调用所申请),也就是上图中的data向下的箭头所指。
关于共享内存的实现,通常是调用os接口mmap()实现。把os中内存页面映射到进程空间中。
pa=mmap(addr, len, prot, flags, fildes, off);
其中addr参数如果为null的话(通常如此),则映射到内存空间的地址由系统设定。由于Postmaster中也是设置的null,故我们不能准确知道shared memory的起始地址。但无妨后面的分析。

调用InitShmemIndex()完之后,Postmaster的内存hash index table结构初始化为下图:




至此,结束。


加我私人微信,交流技术。




https://blog.sciencenet.cn/blog-419883-307647.html

上一篇:使用GDB和DDD调试POSTGRESQL
下一篇:请推荐您觉得不错的网站(收集中...您可以把推荐的网站发到回帖中)
收藏 IP: 223.72.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 09:38

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部