是否可以通过“CreateSharedMemoryAndSemaphores”方法知道正在分配的内存?

时间:2016-09-21 05:04:33

标签: database postgresql memory-management shared-memory postgresql-9.4

我是数据库和Postgres的新手,我正在分析Postgres在方法“CreateSharedMemoryAndSemaphores”中分配的内存。

类似变量“size”以默认值100000开头,然后添加一堆共享内存,如“SpinlockSemaSize”,“LockShmemSize”等。

有没有办法知道哪个方法为变量添加了多少内存?

    size = 100000;
    size = add_size(size, SpinlockSemaSize());
    size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE,
                                             sizeof(ShmemIndexEnt)));
    size = add_size(size, BufferShmemSize());
    size = add_size(size, LockShmemSize());
    size = add_size(size, PredicateLockShmemSize());
    size = add_size(size, ProcGlobalShmemSize());
    size = add_size(size, XLOGShmemSize());
    size = add_size(size, CLOGShmemSize());
    size = add_size(size, CommitTsShmemSize());
    size = add_size(size, SUBTRANSShmemSize());
    size = add_size(size, TwoPhaseShmemSize());
    size = add_size(size, BackgroundWorkerShmemSize());
    size = add_size(size, MultiXactShmemSize());
    size = add_size(size, LWLockShmemSize());
    size = add_size(size, ProcArrayShmemSize());
    size = add_size(size, BackendStatusShmemSize());
    size = add_size(size, SInvalShmemSize());
    size = add_size(size, PMSignalShmemSize());
    size = add_size(size, ProcSignalShmemSize());
    size = add_size(size, CheckpointerShmemSize());
    size = add_size(size, AutoVacuumShmemSize());

实际代码:https://github.com/postgres/postgres/blob/848ef42bb8c7909c9d7baa38178d4a209906e7c1/src/backend/storage/ipc/ipci.c

1 个答案:

答案 0 :(得分:0)

要确定每行对总数的精确数量,您必须阅读各个函数定义。

但通常到目前为止最大的部分来自

size = add_size(size, BufferShmemSize());

计算共享PostgreSQL页面缓存的共享缓冲区的空间。

BufferShmemSize()中,最重要的贡献来自这一行:

/* size of data pages */
size = add_size(size, mul_size(NBuffers, BLCKSZ));

NBuffers是一个全局变量,包含postgresql.conf参数shared_buffers(PostgreSQL中的GUC用语),BLCKSZ为8192,除非在pg_config.h中手动更改{1}},几乎没有人这样做。