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


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

前面标3的是初始化PostmasterContext

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

 

2初始化PostmasterContext的过程

话说main()->->PostmasterMain()->->MemoryContextInit()->AllocSetContextCreate()-> 表示调用,初始化完TopMemoryContextErrorContext,这之后,main()->->PostmasterMain()->AllocSetContextCreate()初始化PostmasterContextPostmasterContextMemoryContext类型的全局变量,定义如下:

MemoryContext PostmasterContext = NULL;

 

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

 

 


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

PostmasterContextTomMemoryContextErrorContext的结构图

TomMemoryContextfirstchild指向PostmasterContextPostmasterContextnextchild指向ErrorContext,形成了树形结构。PostmasterContextErrorContextparent成员指向TomMemoryContext,形成了环。整体上构成了图。

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

 

 


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

 

 

PostmasterContext在内存中的AllocBlockAllocChunk中的位置

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

 

 

相关文章:

  • 2021-08-14
  • 2021-10-14
  • 2021-05-09
  • 2021-12-30
  • 2021-12-12
  • 2021-04-13
  • 2021-04-11
  • 2021-10-28
猜你喜欢
  • 2021-07-04
  • 2021-08-09
  • 2021-07-01
  • 2021-04-14
  • 2021-10-15
  • 2021-08-02
  • 2021-06-15
相关资源
相似解决方案