Skip to content

Commit

Permalink
Track startup memory for resource group
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Kovalenko committed Aug 23, 2024
1 parent 3567721 commit bb36a62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/backend/utils/mmgr/vmem_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ VmemTracker_RegisterStartupMemory(int64 bytes)
pg_atomic_add_fetch_u32((pg_atomic_uint32 *) segmentVmemChunks,
startupChunks);

selfAddStartupChunks(startupChunks);

/*
* Step 2, check if an OOM error should be raised by allocating 0 chunk.
*/
Expand All @@ -692,6 +694,8 @@ VmemTracker_UnregisterStartupMemory(void)
pg_atomic_sub_fetch_u32((pg_atomic_uint32 *) &MySessionState->sessionVmem,
startupChunks);

selfSubStartupChunks(startupChunks);

trackedBytes -= startupBytes;
trackedVmemChunks -= startupChunks;

Expand Down
20 changes: 20 additions & 0 deletions src/backend/utils/resgroup/resgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,26 @@ selfDetachResGroup(ResGroupData *group, ResGroupSlotData *slot)
selfUnsetGroup();
}

/*
* Add startup memory before a resgroup is assigned. This memory
* will later be added to resgroup via selfAttachResGroup
*/
void
selfAddStartupChunks(int32 chunks)
{
self->memUsage += chunks;
}

/*
* Sub startup memory at cleanup. This memory should already been
* subtracted from a resource group via selfDetachResGroup
*/
void
selfSubStartupChunks(int32 chunks)
{
self->memUsage -= chunks;
}

/*
* Initialize the members of a slot
*/
Expand Down
3 changes: 3 additions & 0 deletions src/include/utils/resgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ extern Oid ResGroupGetGroupIdBySessionId(int sessionId);
extern char *getCpuSetByRole(const char *cpuset);
extern void checkCpuSetByRole(const char *cpuset);

extern void selfAddStartupChunks(int32 chunks);
extern void selfSubStartupChunks(int32 chunks);

#define LOG_RESGROUP_DEBUG(...) \
do {if (Debug_resource_group) elog(__VA_ARGS__); } while(false);

Expand Down

0 comments on commit bb36a62

Please sign in to comment.