加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgres中重要的数据结构(三)

发布时间:2020-12-13 17:51:47 所属栏目:百科 来源:网络整理
导读:Postmaster的Shared Memory中的shmem index table 内存结构 已有 1042 次阅读 2010-3-31 12:09 | 个人分类: postgresql | 系统分类: 科研笔记 | 关键词:shmem index table memory postgresql post 我们知道,Postmaster的Shared Memory中的shmem index table

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

已有 1042 次阅读 2010-3-31 12:09 |个人分类:postgresql|系统分类:科研笔记|关键词:shmem index table memory postgresql post

我们知道,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结构初始化为下图:

至此,结束。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读