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

postgres中重要的数据结构(三),第1张

概述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结构初始化为下图:

至此,结束。 总结

以上是内存溢出为你收集整理的postgres中重要的数据结构(三)全部内容,希望文章能够帮你解决postgres中重要的数据结构(三)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1179691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存