PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "pgstat.h"
#include "storage/shmem.h"
#include "utils/memutils.h"
#include "utils/pgstat_internal.h"
#include "lib/simplehash.h"
Go to the source code of this file.
Data Structures | |
struct | PgStat_EntryRefHashEntry |
Macros | |
#define | PGSTAT_ENTRY_REF_HASH_SIZE 128 |
#define | SH_PREFIX pgstat_entry_ref_hash |
#define | SH_ELEMENT_TYPE PgStat_EntryRefHashEntry |
#define | SH_KEY_TYPE PgStat_HashKey |
#define | SH_KEY key |
#define | SH_HASH_KEY(tb, key) pgstat_hash_hash_key(&key, sizeof(PgStat_HashKey), NULL) |
#define | SH_EQUAL(tb, a, b) pgstat_cmp_hash_key(&a, &b, sizeof(PgStat_HashKey), NULL) == 0 |
#define | SH_SCOPE static inline |
#define | SH_DEFINE |
#define | SH_DECLARE |
Typedefs | |
typedef struct PgStat_EntryRefHashEntry | PgStat_EntryRefHashEntry |
typedef bool(* | ReleaseMatchCB) (PgStat_EntryRefHashEntry *, Datum data) |
Variables | |
static const dshash_parameters | dsh_params |
static pgstat_entry_ref_hash_hash * | pgStatEntryRefHash = NULL |
static int | pgStatSharedRefAge = 0 |
static MemoryContext | pgStatSharedRefContext = NULL |
static MemoryContext | pgStatEntryRefHashContext = NULL |
#define PGSTAT_ENTRY_REF_HASH_SIZE 128 |
Definition at line 21 of file pgstat_shmem.c.
#define SH_DECLARE |
Definition at line 43 of file pgstat_shmem.c.
#define SH_DEFINE |
Definition at line 42 of file pgstat_shmem.c.
#define SH_ELEMENT_TYPE PgStat_EntryRefHashEntry |
Definition at line 34 of file pgstat_shmem.c.
#define SH_EQUAL | ( | tb, | |
a, | |||
b | |||
) | pgstat_cmp_hash_key(&a, &b, sizeof(PgStat_HashKey), NULL) == 0 |
Definition at line 39 of file pgstat_shmem.c.
#define SH_HASH_KEY | ( | tb, | |
key | |||
) | pgstat_hash_hash_key(&key, sizeof(PgStat_HashKey), NULL) |
Definition at line 37 of file pgstat_shmem.c.
#define SH_KEY key |
Definition at line 36 of file pgstat_shmem.c.
#define SH_KEY_TYPE PgStat_HashKey |
Definition at line 35 of file pgstat_shmem.c.
#define SH_PREFIX pgstat_entry_ref_hash |
Definition at line 33 of file pgstat_shmem.c.
#define SH_SCOPE static inline |
Definition at line 41 of file pgstat_shmem.c.
typedef struct PgStat_EntryRefHashEntry PgStat_EntryRefHashEntry |
typedef bool(* ReleaseMatchCB) (PgStat_EntryRefHashEntry *, Datum data) |
Definition at line 55 of file pgstat_shmem.c.
|
static |
Definition at line 726 of file pgstat_shmem.c.
References DatumGetObjectId(), PgStat_HashKey::dboid, and PgStat_EntryRefHashEntry::key.
Referenced by pgstat_release_db_entry_refs().
|
static |
Definition at line 983 of file pgstat_shmem.c.
References DatumGetInt32(), PgStatShared_HashEntry::key, and PgStat_HashKey::kind.
Referenced by pgstat_reset_entries_of_kind().
|
static |
Definition at line 322 of file pgstat_shmem.c.
References Assert(), dshash_release_lock(), PgStatShared_Common::magic, pg_atomic_fetch_add_u32(), pg_atomic_read_u32(), pgStatLocal, PgStatShared_HashEntry::refcount, PgStat_EntryRef::shared_entry, PgStat_LocalState::shared_hash, and PgStat_EntryRef::shared_stats.
Referenced by pgstat_get_entry_ref().
void pgstat_attach_shmem | ( | void | ) |
Definition at line 217 of file pgstat_shmem.c.
References Assert(), PgStat_LocalState::dsa, dsa_attach_in_place(), dsa_pin_mapping(), dsh_params, dshash_attach(), PgStat_ShmemControl::hash_handle, MemoryContextSwitchTo(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shared_hash, PgStat_LocalState::shmem, and TopMemoryContext.
Referenced by pgstat_initialize().
void pgstat_detach_shmem | ( | void | ) |
Definition at line 237 of file pgstat_shmem.c.
References Assert(), PgStat_LocalState::dsa, dsa_detach(), dshash_detach(), pgstat_release_all_entry_refs(), pgStatLocal, and PgStat_LocalState::shared_hash.
Referenced by pgstat_shutdown_hook().
void pgstat_drop_all_entries | ( | void | ) |
Definition at line 895 of file pgstat_shmem.c.
References dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), pgstat_drop_entry_internal(), pgstat_request_entry_refs_gc(), pgStatLocal, ps, and PgStat_LocalState::shared_hash.
Referenced by pgstat_reset_after_failure().
|
static |
Definition at line 808 of file pgstat_shmem.c.
References Assert(), PgStat_HashKey::dboid, PgStatShared_HashEntry::dropped, dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), PgStatShared_HashEntry::key, OidIsValid, pgstat_drop_entry_internal(), pgstat_release_db_entry_refs(), pgstat_request_entry_refs_gc(), pgStatLocal, and PgStat_LocalState::shared_hash.
Referenced by pgstat_drop_entry().
bool pgstat_drop_entry | ( | PgStat_Kind | kind, |
Oid | dboid, | ||
Oid | objoid | ||
) |
Definition at line 858 of file pgstat_shmem.c.
References dshash_find(), PgStat_EntryRefHashEntry::entry_ref, PgStat_EntryRefHashEntry::key, sort-test::key, pgstat_drop_database_and_contents(), pgstat_drop_entry_internal(), PGSTAT_KIND_DATABASE, pgstat_release_entry_ref(), pgStatEntryRefHash, pgStatLocal, and PgStat_LocalState::shared_hash.
Referenced by AtEOSubXact_PgStat_DroppedStats(), AtEOXact_PgStat_DroppedStats(), pgstat_drop_replslot(), pgstat_execute_transactional_drops(), and pgstat_init_function_usage().
|
static |
Definition at line 773 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, dshash_release_lock(), elog(), ERROR, InvalidDsaPointer, PgStatShared_HashEntry::key, pg_atomic_sub_fetch_u32(), pgstat_free_entry(), pgStatEntryRefHash, pgStatLocal, PgStatShared_HashEntry::refcount, and PgStat_LocalState::shared_hash.
Referenced by pgstat_drop_all_entries(), pgstat_drop_database_and_contents(), and pgstat_drop_entry().
|
static |
Definition at line 105 of file pgstat_shmem.c.
References Assert(), dsa_minimum_size(), and MAXALIGN.
Referenced by StatsShmemInit(), and StatsShmemSize().
|
static |
Definition at line 748 of file pgstat_shmem.c.
References PgStatShared_HashEntry::body, PgStat_LocalState::dsa, dsa_free(), dshash_delete_current(), dshash_delete_entry(), pgStatLocal, and PgStat_LocalState::shared_hash.
Referenced by pgstat_drop_entry_internal(), and pgstat_release_entry_ref().
|
static |
Definition at line 650 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::dropped, PgStat_EntryRefHashEntry::entry_ref, PgStat_ShmemControl::gc_request_count, i, PgStat_EntryRefHashEntry::key, PgStatShared_Common::magic, PgStat_EntryRef::pending, pg_atomic_read_u64(), pgstat_release_entry_ref(), pgStatEntryRefHash, pgStatLocal, pgStatSharedRefAge, PgStat_EntryRef::shared_entry, PgStat_EntryRef::shared_stats, and PgStat_LocalState::shmem.
Referenced by pgstat_get_entry_ref().
PgStat_EntryRef* pgstat_get_entry_ref | ( | PgStat_Kind | kind, |
Oid | dboid, | ||
Oid | objoid, | ||
bool | create, | ||
bool * | created_entry | ||
) |
Definition at line 397 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), dshash_find(), dshash_find_or_insert(), dshash_release_lock(), PgStat_ShmemControl::is_shutdown, sort-test::key, pgstat_acquire_entry_ref(), pgstat_assert_is_up, pgstat_gc_entry_refs(), pgstat_get_entry_ref_cached(), pgstat_init_entry(), pgstat_need_entry_refs_gc(), pgstat_reinit_entry(), pgstat_release_entry_ref(), pgstat_setup_memcxt(), pgstat_setup_shared_refs(), pgStatLocal, PgStat_LocalState::shared_hash, and PgStat_LocalState::shmem.
Referenced by pgstat_acquire_replslot(), pgstat_create_subscription(), pgstat_create_transactional(), pgstat_fetch_entry(), pgstat_fetch_pending_entry(), pgstat_get_entry_ref_locked(), pgstat_have_entry(), pgstat_prep_pending_entry(), and pgstat_reset_entry().
|
static |
Definition at line 341 of file pgstat_shmem.c.
References Assert(), PgStat_EntryRefHashEntry::entry_ref, sort-test::key, MemoryContextAlloc(), PgStat_EntryRef::pending, pg_atomic_read_u32(), PG_USED_FOR_ASSERTS_ONLY, pgStatEntryRefHash, pgStatSharedRefContext, PgStat_EntryRef::shared_entry, and PgStat_EntryRef::shared_stats.
Referenced by pgstat_get_entry_ref().
PgStat_EntryRef* pgstat_get_entry_ref_locked | ( | PgStat_Kind | kind, |
Oid | dboid, | ||
Oid | objoid, | ||
bool | nowait | ||
) |
Definition at line 612 of file pgstat_shmem.c.
References pgstat_get_entry_ref(), and pgstat_lock_entry().
Referenced by pgstat_copy_relation_stats(), pgstat_create_replslot(), pgstat_report_analyze(), pgstat_report_autovac(), pgstat_report_checksum_failures_in_db(), pgstat_report_replslot(), pgstat_report_vacuum(), and pgstat_reset_database_timestamp().
PgStatShared_Common* pgstat_init_entry | ( | PgStat_Kind | kind, |
PgStatShared_HashEntry * | shhashent | ||
) |
Definition at line 258 of file pgstat_shmem.c.
References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_allocate0, dsa_get_address(), PgStatShared_Common::lock, LWLockInitialize(), LWTRANCHE_PGSTATS_DATA, PgStatShared_Common::magic, pg_atomic_init_u32(), pgstat_get_kind_info(), pgStatLocal, and PgStatShared_HashEntry::refcount.
Referenced by pgstat_get_entry_ref(), and pgstat_read_statsfile().
bool pgstat_lock_entry | ( | PgStat_EntryRef * | entry_ref, |
bool | nowait | ||
) |
Definition at line 575 of file pgstat_shmem.c.
References PgStatShared_Common::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), and PgStat_EntryRef::shared_stats.
Referenced by pgstat_database_flush_cb(), pgstat_function_flush_cb(), pgstat_get_entry_ref_locked(), pgstat_relation_flush_cb(), pgstat_reset_entry(), and pgstat_subscription_flush_cb().
bool pgstat_lock_entry_shared | ( | PgStat_EntryRef * | entry_ref, |
bool | nowait | ||
) |
Definition at line 591 of file pgstat_shmem.c.
References PgStatShared_Common::lock, LW_SHARED, LWLockAcquire(), LWLockConditionalAcquire(), and PgStat_EntryRef::shared_stats.
Referenced by pgstat_fetch_entry().
|
static |
Definition at line 634 of file pgstat_shmem.c.
References Assert(), PgStat_ShmemControl::gc_request_count, pg_atomic_read_u64(), pgStatEntryRefHash, pgStatLocal, pgStatSharedRefAge, and PgStat_LocalState::shmem.
Referenced by pgstat_get_entry_ref().
|
static |
Definition at line 287 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), PgStatShared_Common::magic, pg_atomic_fetch_add_u32(), pgstat_get_entry_data(), pgstat_get_entry_len(), pgStatLocal, and PgStatShared_HashEntry::refcount.
Referenced by pgstat_get_entry_ref().
|
static |
Definition at line 714 of file pgstat_shmem.c.
References Assert(), pgstat_release_matching_entry_refs(), and pgStatEntryRefHash.
Referenced by pgstat_detach_shmem().
|
static |
Definition at line 734 of file pgstat_shmem.c.
References match_db(), ObjectIdGetDatum(), and pgstat_release_matching_entry_refs().
Referenced by pgstat_drop_database_and_contents().
|
static |
Definition at line 521 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::dropped, dshash_find(), elog(), ERROR, PgStatShared_HashEntry::key, sort-test::key, PgStatShared_Common::magic, PgStat_EntryRef::pending, pfree(), pg_atomic_fetch_sub_u32(), pg_atomic_read_u32(), pgstat_delete_pending_entry(), pgstat_free_entry(), pgStatEntryRefHash, pgStatLocal, PgStatShared_HashEntry::refcount, PgStat_EntryRef::shared_entry, PgStat_LocalState::shared_hash, and PgStat_EntryRef::shared_stats.
Referenced by pgstat_drop_entry(), pgstat_gc_entry_refs(), pgstat_get_entry_ref(), and pgstat_release_matching_entry_refs().
|
static |
Definition at line 684 of file pgstat_shmem.c.
References Assert(), PgStat_EntryRefHashEntry::entry_ref, i, PgStat_EntryRefHashEntry::key, pgstat_release_entry_ref(), and pgStatEntryRefHash.
Referenced by pgstat_release_all_entry_refs(), and pgstat_release_db_entry_refs().
void pgstat_request_entry_refs_gc | ( | void | ) |
Definition at line 628 of file pgstat_shmem.c.
References PgStat_ShmemControl::gc_request_count, pg_atomic_fetch_add_u64(), pgStatLocal, and PgStat_LocalState::shmem.
Referenced by AtEOSubXact_PgStat_DroppedStats(), AtEOXact_PgStat_DroppedStats(), pgstat_drop_all_entries(), pgstat_drop_database_and_contents(), and pgstat_execute_transactional_drops().
void pgstat_reset_entries_of_kind | ( | PgStat_Kind | kind, |
TimestampTz | ts | ||
) |
Definition at line 989 of file pgstat_shmem.c.
References Int32GetDatum(), match_kind(), and pgstat_reset_matching_entries().
Referenced by pgstat_reset_of_kind().
void pgstat_reset_entry | ( | PgStat_Kind | kind, |
Oid | dboid, | ||
Oid | objoid, | ||
TimestampTz | ts | ||
) |
Definition at line 933 of file pgstat_shmem.c.
References Assert(), PgStatShared_HashEntry::dropped, pgstat_get_entry_ref(), pgstat_get_kind_info(), pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_EntryRef::shared_entry, shared_stat_reset_contents(), and PgStat_EntryRef::shared_stats.
Referenced by pgstat_create_subscription(), and pgstat_reset().
void pgstat_reset_matching_entries | ( | bool(*)(PgStatShared_HashEntry *, Datum) | do_reset, |
Datum | match_data, | ||
TimestampTz | ts | ||
) |
Definition at line 953 of file pgstat_shmem.c.
References PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), PgStatShared_HashEntry::key, PgStat_HashKey::kind, PgStatShared_Common::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shared_hash, and shared_stat_reset_contents().
Referenced by pgstat_reset_counters(), and pgstat_reset_entries_of_kind().
|
static |
Definition at line 995 of file pgstat_shmem.c.
References ALLOCSET_SMALL_SIZES, AllocSetContextCreate, pgStatEntryRefHashContext, pgStatSharedRefContext, TopMemoryContext, and unlikely.
Referenced by pgstat_get_entry_ref().
|
static |
Definition at line 306 of file pgstat_shmem.c.
References Assert(), PgStat_ShmemControl::gc_request_count, likely, pg_atomic_read_u64(), PGSTAT_ENTRY_REF_HASH_SIZE, pgStatEntryRefHash, pgStatEntryRefHashContext, pgStatLocal, pgStatSharedRefAge, and PgStat_LocalState::shmem.
Referenced by pgstat_get_entry_ref().
void pgstat_unlock_entry | ( | PgStat_EntryRef * | entry_ref | ) |
Definition at line 603 of file pgstat_shmem.c.
References PgStatShared_Common::lock, LWLockRelease(), and PgStat_EntryRef::shared_stats.
Referenced by pgstat_copy_relation_stats(), pgstat_create_replslot(), pgstat_database_flush_cb(), pgstat_fetch_entry(), pgstat_function_flush_cb(), pgstat_relation_flush_cb(), pgstat_report_analyze(), pgstat_report_autovac(), pgstat_report_checksum_failures_in_db(), pgstat_report_replslot(), pgstat_report_vacuum(), pgstat_reset_database_timestamp(), pgstat_reset_entry(), and pgstat_subscription_flush_cb().
|
static |
Definition at line 917 of file pgstat_shmem.c.
References pgstat_get_entry_data(), pgstat_get_entry_len(), pgstat_get_kind_info(), and PgStat_KindInfo::reset_timestamp_cb.
Referenced by pgstat_reset_entry(), and pgstat_reset_matching_entries().
void StatsShmemInit | ( | void | ) |
Definition at line 140 of file pgstat_shmem.c.
References PgStat_ShmemControl::archiver, Assert(), BACKEND_NUM_TYPES, PgStat_ShmemControl::bgwriter, PgStat_ShmemControl::checkpointer, dsa_create_in_place(), dsa_detach(), dsa_pin(), dsa_set_size_limit(), dsh_params, dshash_create(), dshash_detach(), dshash_get_hash_table_handle(), PgStat_ShmemControl::gc_request_count, PgStat_ShmemControl::hash_handle, i, PgStat_ShmemControl::io, IsUnderPostmaster, PgStatShared_Archiver::lock, PgStatShared_BgWriter::lock, PgStatShared_Checkpointer::lock, PgStatShared_SLRU::lock, PgStatShared_Wal::lock, PgStatShared_IO::locks, LWLockInitialize(), LWTRANCHE_PGSTATS_DATA, LWTRANCHE_PGSTATS_DSA, MAXALIGN, pg_atomic_init_u64(), pgstat_dsa_init_size(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shmem, ShmemInitStruct(), PgStat_ShmemControl::slru, StatsShmemSize(), and PgStat_ShmemControl::wal.
Referenced by CreateSharedMemoryAndSemaphores().
Size StatsShmemSize | ( | void | ) |
Definition at line 126 of file pgstat_shmem.c.
References add_size(), MAXALIGN, and pgstat_dsa_init_size().
Referenced by CalculateShmemSize(), and StatsShmemInit().
|
static |
Definition at line 62 of file pgstat_shmem.c.
Referenced by pgstat_attach_shmem(), and StatsShmemInit().
|
static |
Definition at line 81 of file pgstat_shmem.c.
Referenced by pgstat_drop_entry(), pgstat_drop_entry_internal(), pgstat_gc_entry_refs(), pgstat_get_entry_ref_cached(), pgstat_need_entry_refs_gc(), pgstat_release_all_entry_refs(), pgstat_release_entry_ref(), pgstat_release_matching_entry_refs(), and pgstat_setup_shared_refs().
|
static |
Definition at line 90 of file pgstat_shmem.c.
Referenced by pgstat_setup_memcxt(), and pgstat_setup_shared_refs().
|
static |
Definition at line 82 of file pgstat_shmem.c.
Referenced by pgstat_gc_entry_refs(), pgstat_need_entry_refs_gc(), and pgstat_setup_shared_refs().
|
static |
Definition at line 89 of file pgstat_shmem.c.
Referenced by pgstat_get_entry_ref_cached(), and pgstat_setup_memcxt().