学习opengauss内存分配
opengauss使用线程管理
ps -ef|grep gaussdb
ps -Tp pid
[og@opengauss ~]$ ps -ef|grep gauss
og 13752 1 2 12:40 ? 00:00:06 /opt/opengauss/openGauss-server/mppdb_temp_install/bin/gaussdb
og 13956 8654 0 12:44 pts/0 00:00:00 grep --color=auto gauss
[og@opengauss ~]$ ps -Tp 13752
PID SPID TTY TIME CMD
13752 13752 ? 00:00:00 gaussdb
13752 13753 ? 00:00:00 jemalloc_bg_thd
13752 13758 ? 00:00:00 gaussdb
13752 13759 ? 00:00:00 syslogger
13752 13760 ? 00:00:00 alarm
13752 13761 ? 00:00:00 reaper
13752 13785 ? 00:00:00 gaussdb
13752 13786 ? 00:00:00 gaussdb
13752 13787 ? 00:00:00 gaussdb
13752 13789 ? 00:00:00 checkpointer
13752 13790 ? 00:00:00 Spbgwriter
13752 13791 ? 00:00:00 pagewriter
13752 13792 ? 00:00:03 pagewriter
13752 13793 ? 00:00:00 pagewriter
13752 13794 ? 00:00:00 pagewriter
13752 13795 ? 00:00:00 pagewriter
13752 13796 ? 00:00:00 WALwriter
13752 13797 ? 00:00:00 WALwriteraux
13752 13798 ? 00:00:00 AVClauncher
13752 13799 ? 00:00:00 Jobscheduler
13752 13800 ? 00:00:00 asyncundolaunch
13752 13801 ? 00:00:00 globalstats
13752 13802 ? 00:00:00 applylauncher
13752 13803 ? 00:00:00 statscollector
13752 13804 ? 00:00:00 txnsnapcapturer
13752 13805 ? 00:00:00 CfsShrinker
13752 13806 ? 00:00:01 percentworker
13752 13807 ? 00:00:03 ashworker
13752 13808 ? 00:00:01 TrackStmtWorker
13752 13809 ? 00:00:00 auditor
13752 13810 ? 00:00:00 2pccleaner
13752 13811 ? 00:00:00 faultmonitor
13752 13812 ? 00:00:00 WLMworker
13752 13813 ? 00:00:00 WLMmonitor
13752 13814 ? 00:00:00 WLMarbiter
13752 13815 ? 00:00:00 undorecycler
[og@opengauss ~]$
opengauss使用共享内存段
ipcs -m
查看buffer设置
[og@opengauss ogdata]$ grep -v ^# postgresql.conf |grep buffers
shared_buffers = 128MB # min 128kB
bulk_write_ring_size = 2GB # for bulkload, max shared_buffers
cstore_buffers = 32MB #min 16MB
[og@opengauss ogdata]$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0052e2c1 0 og 600 577661256 1
[og@opengauss ogdata]$ echo 577661256/1024/1024 | bc
550
550MB - 128MB - 32MB = 390MB
修改buffers ,查看ipcs -m
#############change shared_buffers to 512MB
grep -v ^# postgresql.conf |grep buffers
shared_buffers = 512MB # min 128kB
bulk_write_ring_size = 2GB # for bulkload, max shared_buffers
cstore_buffers = 32MB #min 16MB
[og@opengauss ~]$ env|grep PGDATA
PGDATA=/opt/opengauss/ogdata
[og@opengauss ~]$ gs_ctl stop
[2024-05-06 12:37:13.745][13420][][gs_ctl]: gs_ctl stopped ,datadir is /opt/opengauss/ogdata
waiting for server to shut down..... done
server stopped
[og@opengauss ~]$ gs_ctl start
[2024-05-06 12:37:19.446][13436][][gs_ctl]: gs_ctl started,datadir is /opt/opengauss/ogdata
[2024-05-06 12:37:19.505][13436][][gs_ctl]: waiting for server to start...
.0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.
[og@opengauss ~]$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0052e2c1 98304 og 600 1805535560 1
[og@opengauss ~]$ echo 1805535560/1024/1024 | bc
1721
[og@opengauss ~]$
[og@opengauss ~]$ echo 1721-512-32|bc
1177
疑问
这1177MB是分配给谁了?
参考
ipci.cpp, opengauss的代码
Size ComputeTotalSizeOfShmem()
{
Size size;
/*
* Size of the openGauss shared-memory block is estimated via
* moderately-accurate estimates for the big hogs, plus 100K for the
* stuff that's too small to bother with estimating.
*
* We take some care during this phase to ensure that the total size
* request doesn't overflow size_t. If this gets through, we don't
* need to be so careful during the actual allocation phase.
*/
size = 100000;
size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt)));
size = add_size(size, BufferShmemSize());
size = add_size(size, ReplicationSlotsShmemSize());
#ifndef ENABLE_MULTIPLE_NODES
size = add_size(size, ReplicationOriginShmemSize());
size = add_size(size, ApplyLauncherShmemSize());
#endif
size = add_size(size, LockShmemSize());
size = add_size(size, PredicateLockShmemSize());
size = add_size(size, ProcGlobalShmemSize());
size = add_size(size, XLOGShmemSize());
size = add_size(size, XLogStatShmemSize());
size = add_size(size, CLOGShmemSize());
size = add_size(size, CSNLOGShmemSize());
size = add_size(size, mul_size(NUM_TWOPHASE_PARTITIONS, TwoPhaseShmemSize()));
size = add_size(size, MultiXactShmemSize());
size = add_size(size, LWLockShmemSize());
size = add_size(size, ProcArrayShmemSize());
size = add_size(size, RingBufferShmemSize());
size = add_size(size, BackendStatusShmemSize());
size = add_size(size, sessionTimeShmemSize());
size = add_size(size, sessionStatShmemSize());
size = add_size(size, sessionMemoryShmemSize());
size = add_size(size, SInvalShmemSize());
size = add_size(size, PMSignalShmemSize());
size = add_size(size, ProcSignalShmemSize());
size = add_size(size, CheckpointerShmemSize());
size = add_size(size, PageWriterShmemSize());
size = add_size(size, AutoVacuumShmemSize());
size = add_size(size, WalSndShmemSize());
size = add_size(size, WalRcvShmemSize());
size = add_size(size, DataSndShmemSize());
size = add_size(size, DataRcvShmemSize());
/* DataSenderQueue, DataWriterQueue has the same size, WalDataWriterQueue is deleted */
size = add_size(size, mul_size(2, DataQueueShmemSize()));
size = add_size(size, CBMShmemSize());
size = add_size(size, HaShmemSize());
size = add_size(size, NotifySignalShmemSize());
size = add_size(size, JobInfoShmemSize());
size = add_size(size, BTreeShmemSize());
size = add_size(size, SyncScanShmemSize());
size = add_size(size, AsyncShmemSize());
size = add_size(size, active_gtt_shared_hash_size());
size = add_size(size, AsyncRollbackHashShmemSize());
size = add_size(size, UndoWorkerShmemSize());
size = add_size(size, TxnSnapCapShmemSize());
size = add_size(size, RbCleanerShmemSize());
#ifdef PGXC
size = add_size(size, NodeTablesShmemSize());
#endif
size = add_size(size, TableSpaceUsageManager::ShmemSize());
size = add_size(size, LsnXlogFlushChkShmemSize());
size = add_size(size, heartbeat_shmem_size());
size = add_size(size, MatviewShmemSize());
#ifndef ENABLE_MULTIPLE_NODES
if(g_instance.attr.attr_storage.dcf_attr.enable_dcf) {
size = add_size(size, DcfContextShmemSize());
}
#endif
size = add_size(size, CalShareStorageCtlSize());
/* freeze the addin request size and include it */
t_thrd.storage_cxt.addin_request_allowed = false;
size = add_size(size, t_thrd.storage_cxt.total_addin_request);
/* might as well round it off to a multiple of a typical page size */
size = add_size(size, 8192 - (size % 8192));
/* pca buffer size */
size = add_size(size, pca_buffer_size());
/* csf shrinker backend shared memory */
size = add_size(size, CfsShrinkerShmemSize());
if (g_instance.attr.attr_storage.dms_attr.enable_ondemand_recovery) {
size = add_size(size, OndemandRecoveryShmemSize());
}
return size;
}
后续debug分析
通过nvim 做debug分析,记录每个函数调用后的size值,
可以看出:
138行,139行增加最大. 分别是:
XLOGShmemSize, XlogStatShmemSize. 大概增加了128M.
为什么这2个函数增加这么多?
应该是postgresql 9.2的代码.