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 805 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 1085 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 368 of file pgstat_shmem.c.
References Assert, dshash_release_lock(), PgStatShared_HashEntry::generation, PgStat_EntryRef::generation, 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 244 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 264 of file pgstat_shmem.c.
References Assert, PgStat_LocalState::dsa, dsa_detach(), dsa_release_in_place(), dshash_detach(), pgstat_release_all_entry_refs(), pgStatLocal, PgStat_ShmemControl::raw_dsa_area, PgStat_LocalState::shared_hash, and PgStat_LocalState::shmem.
Referenced by pgstat_shutdown_hook().
void pgstat_drop_all_entries | ( | void | ) |
Definition at line 997 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 892 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, | ||
uint64 | objid | ||
) |
Definition at line 953 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_inj(), pgstat_drop_replslot(), pgstat_execute_transactional_drops(), pgstat_init_function_usage(), and pgstat_shutdown_hook().
|
static |
Definition at line 852 of file pgstat_shmem.c.
References Assert, PgStatShared_HashEntry::body, PgStat_HashKey::dboid, PgStatShared_HashEntry::dropped, dshash_release_lock(), elog, ERROR, InvalidDsaPointer, PgStatShared_HashEntry::key, PgStat_HashKey::kind, PgStat_KindInfo::name, PgStat_HashKey::objid, pg_atomic_read_u32(), pg_atomic_sub_fetch_u32(), pgstat_free_entry(), pgstat_get_kind_info(), 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 106 of file pgstat_shmem.c.
References Assert, dsa_minimum_size(), and MAXALIGN.
Referenced by StatsShmemInit(), and StatsShmemSize().
|
static |
Definition at line 827 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 722 of file pgstat_shmem.c.
References Assert, PgStatShared_HashEntry::dropped, PgStat_EntryRefHashEntry::entry_ref, PgStat_ShmemControl::gc_request_count, PgStatShared_HashEntry::generation, PgStat_EntryRef::generation, i, PgStat_EntryRefHashEntry::key, PgStatShared_Common::magic, PgStat_EntryRef::pending, pg_atomic_read_u32(), 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, | ||
uint64 | objid, | ||
bool | create, | ||
bool * | created_entry | ||
) |
Definition at line 444 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_flush_backend(), pgstat_get_entry_ref_locked(), pgstat_have_entry(), pgstat_prep_pending_entry(), and pgstat_reset_entry().
|
static |
Definition at line 388 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, | ||
uint64 | objid, | ||
bool | nowait | ||
) |
Definition at line 684 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 293 of file pgstat_shmem.c.
References PgStatShared_HashEntry::body, chunk, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_allocate0, dsa_get_address(), PgStatShared_HashEntry::generation, 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 647 of file pgstat_shmem.c.
References PgStatShared_Common::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), and PgStat_EntryRef::shared_stats.
Referenced by injection_stats_flush_cb(), pgstat_database_flush_cb(), pgstat_flush_backend_entry(), 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 663 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 706 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 327 of file pgstat_shmem.c.
References Assert, PgStatShared_HashEntry::body, PgStatShared_HashEntry::dropped, PgStat_LocalState::dsa, dsa_get_address(), PgStatShared_HashEntry::generation, 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 793 of file pgstat_shmem.c.
References Assert, pgstat_release_matching_entry_refs(), and pgStatEntryRefHash.
Referenced by pgstat_detach_shmem().
|
static |
Definition at line 813 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 576 of file pgstat_shmem.c.
References Assert, PgStatShared_HashEntry::dropped, dshash_find(), dshash_release_lock(), elog, ERROR, PgStatShared_HashEntry::generation, PgStat_EntryRef::generation, 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 763 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 700 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(), pgstat_drop_inj(), pgstat_drop_replslot(), pgstat_execute_transactional_drops(), and pgstat_shutdown_hook().
void pgstat_reset_entries_of_kind | ( | PgStat_Kind | kind, |
TimestampTz | ts | ||
) |
Definition at line 1091 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, | ||
uint64 | objid, | ||
TimestampTz | ts | ||
) |
Definition at line 1035 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 1055 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 1097 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 352 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 675 of file pgstat_shmem.c.
References PgStatShared_Common::lock, LWLockRelease(), and PgStat_EntryRef::shared_stats.
Referenced by injection_stats_flush_cb(), pgstat_copy_relation_stats(), pgstat_create_replslot(), pgstat_database_flush_cb(), pgstat_fetch_entry(), pgstat_flush_backend_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 1019 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 156 of file pgstat_shmem.c.
References Assert, ctl, dsa_create_in_place, dsa_detach(), dsa_pin(), dsa_set_size_limit(), dsh_params, dshash_create(), dshash_detach(), dshash_get_hash_table_handle(), PgStat_KindInfo::fixed_amount, idx(), PgStat_KindInfo::init_shmem_cb, IsUnderPostmaster, LWTRANCHE_PGSTATS_DSA, MAXALIGN, pg_atomic_init_u64(), pgstat_dsa_init_size(), pgstat_get_kind_info(), pgstat_is_kind_builtin(), PgStat_Kind, PGSTAT_KIND_CUSTOM_MIN, PGSTAT_KIND_MAX, PGSTAT_KIND_MIN, pgStatLocal, PgStat_KindInfo::shared_ctl_off, PgStat_KindInfo::shared_size, PgStat_LocalState::shmem, ShmemAlloc(), ShmemInitStruct(), and StatsShmemSize().
Referenced by CreateOrAttachShmemStructs().
Size StatsShmemSize | ( | void | ) |
Definition at line 127 of file pgstat_shmem.c.
References add_size(), Assert, PgStat_KindInfo::fixed_amount, MAXALIGN, pgstat_dsa_init_size(), pgstat_get_kind_info(), PgStat_Kind, PGSTAT_KIND_CUSTOM_MAX, PGSTAT_KIND_CUSTOM_MIN, and PgStat_KindInfo::shared_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 82 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 91 of file pgstat_shmem.c.
Referenced by pgstat_setup_memcxt(), and pgstat_setup_shared_refs().
|
static |
Definition at line 83 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 90 of file pgstat_shmem.c.
Referenced by pgstat_get_entry_ref_cached(), and pgstat_setup_memcxt().