ITPub博客

首页 > 数据库 > 数据库开发技术 > pg启动过程中的那些事二:初始化PostmasterContext

pg启动过程中的那些事二:初始化PostmasterContext

原创 数据库开发技术 作者:BeiiGang 时间:2011-12-07 22:00:27 0 删除 编辑
写了PostgreSQL启动过程中初始化PostmasterContext的过程、结构等[@more@]

1先上个示意图,看一下函数调用过程梗概,中间略过部分细节



前面标3的是初始化PostmasterContext

初始化PostmasterContext的方法调用流程图

2初始化PostmasterContext的过程

话说main()->…->PostmasterMain()->…->MemoryContextInit()->AllocSetContextCreate()(“->” 表示调用),初始化完TopMemoryContext和ErrorContext,这之后,main()->…->PostmasterMain()->AllocSetContextCreate()初始化PostmasterContext,PostmasterContext是MemoryContext类型的全局变量,定义如下:

MemoryContext PostmasterContext = NULL;

PostmasterContext的类型和TomMemoryContext、ErrorContext是一样的,都是MemoryContext。有了《pg启动过程中的那些事一》垫底,这个写起来就容易了。初始化PostmasterContext的过程和ErrorContext基本上是一样的。所以下面就直接上初始化完以后的结构图了。不过前面只有TomMemoryContext和ErrorContext的内存结构图加上内存空间管理的AllocBlock和AllocChunk,看起来已经让人眼花缭乱了,这里把AllocBlock和AllocChunk相关部分删掉,突出MemoryContext全局变量之间的关系。


PostmasterContext、TomMemoryContext、ErrorContext的结构图

TomMemoryContext的firstchild指向PostmasterContext,PostmasterContext的nextchild指向ErrorContext,形成了树形结构。PostmasterContext、ErrorContext的parent成员指向TomMemoryContext,形成了环。整体上构成了图。

PostmasterContext在AllocBlock和AllocChunk中的位置,见下面示意图,图中红色的那一块就是PostmasterContext,里面的成员和其他细节就不画了,要不然看起来就天下大乱了。



PostmasterContext在内存中的AllocBlock和AllocChunk中的位置

有了《pg启动过程中的那些事一》和这篇文章垫底,再要理解pg中内存分配的机制就容易了。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26509284/viewspace-1056748/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    4
  • 访问量
    3402