Improve monitoring of shared memory allocations - Mailing list pgsql-hackers

From Rahila Syed
Subject Improve monitoring of shared memory allocations
Date
Msg-id CAH2L28vHzRankszhqz7deXURxKncxfirnuW68zD7+hVAqaS5GQ@mail.gmail.com
Whole thread Raw
List pgsql-hackers

Hi,

The 0001* patch improved the accounting for the shared memory allocated for a
hash table during hash_create.
pg_shmem_allocations tracks the memory allocated by ShmemInitStruct, which,
for shared hash tables, only covers memory allocated for the hash  directory
and control structure via ShmemInitHash. The hash segments and  buckets
are allocated using ShmemAllocNoError, which does not attribute the  allocation
to the hash table and also does not add it to ShmemIndex.

Therefore, these allocations are not tracked in pg_shmem_allocations.
To improve this, include the allocation of segments and buckets in the initial
allocation of the shared memory for the hash table, in ShmemInitHash.

This will result in pg_shmem_allocations representing the total size of the initial
hash table, including all the buckets and elements, instead of just the directory
size.

Like ShmemAllocNoError, the shared memory allocated by ShmemAlloc is not
tracked by pg_shmem_allocations.
The 0002* patch replaces most of the calls to ShmemAlloc with ShmemInitStruct
to associate a name with the allocations and ensure that they get tracked by
pg_shmem_allocations.

I observed an improvement in total memory allocation by consolidating initial shared
memory allocations for the hash table. For ex. the allocated size for the LOCK hash
hash_create decreased from 801664 bytes to 799616 bytes. Please find the attached
patches, which I will add to the March Commitfest.

Thank you,
Rahila Syed
Attachment

pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: Licence preamble update
Next
From: jian he
Date:
Subject: bug when apply fast default mechanism for adding new column over domain with default value