PostgreSQL Source Code
git master
memnodes.h
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* memnodes.h
4
* POSTGRES memory context node definitions.
5
*
6
*
7
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
9
*
10
* src/include/nodes/memnodes.h
11
*
12
*-------------------------------------------------------------------------
13
*/
14
#ifndef MEMNODES_H
15
#define MEMNODES_H
16
17
#include "
nodes/nodes.h
"
18
19
/*
20
* MemoryContextCounters
21
* Summarization state for MemoryContextStats collection.
22
*
23
* The set of counters in this struct is biased towards AllocSet; if we ever
24
* add any context types that are based on fundamentally different approaches,
25
* we might need more or different counters here. A possible API spec then
26
* would be to print only nonzero counters, but for now we just summarize in
27
* the format historically used by AllocSet.
28
*/
29
typedef
struct
MemoryContextCounters
30
{
31
Size
nblocks
;
/* Total number of malloc blocks */
32
Size
freechunks
;
/* Total number of free chunks */
33
Size
totalspace
;
/* Total bytes requested from malloc */
34
Size
freespace
;
/* The unused portion of totalspace */
35
}
MemoryContextCounters
;
36
37
/*
38
* MemoryContext
39
* A logical context in which memory allocations occur.
40
*
41
* MemoryContext itself is an abstract type that can have multiple
42
* implementations.
43
* The function pointers in MemoryContextMethods define one specific
44
* implementation of MemoryContext --- they are a virtual function table
45
* in C++ terms.
46
*
47
* Node types that are actual implementations of memory contexts must
48
* begin with the same fields as MemoryContextData.
49
*
50
* Note: for largely historical reasons, typedef MemoryContext is a pointer
51
* to the context struct rather than the struct type itself.
52
*/
53
54
typedef
void (*
MemoryStatsPrintFunc
) (
MemoryContext
context,
void
*passthru,
55
const
char
*stats_string);
56
57
typedef
struct
MemoryContextMethods
58
{
59
void
*(*alloc) (
MemoryContext
context,
Size
size);
60
/* call this free_p in case someone #define's free() */
61
void (*free_p) (
MemoryContext
context,
void
*pointer);
62
void
*(*realloc) (
MemoryContext
context,
void
*pointer,
Size
size);
63
void (*reset) (
MemoryContext
context);
64
void (*delete_context) (
MemoryContext
context);
65
Size
(*get_chunk_space) (
MemoryContext
context,
void
*pointer);
66
bool
(*is_empty) (
MemoryContext
context);
67
void (*stats) (
MemoryContext
context,
68
MemoryStatsPrintFunc
printfunc,
void
*passthru,
69
MemoryContextCounters
*totals);
70
#ifdef MEMORY_CONTEXT_CHECKING
71
void (*check) (
MemoryContext
context);
72
#endif
73
}
MemoryContextMethods
;
74
75
76
typedef
struct
MemoryContextData
77
{
78
NodeTag
type
;
/* identifies exact kind of context */
79
/* these two fields are placed here to minimize alignment wastage: */
80
bool
isReset
;
/* T = no space alloced since last reset */
81
bool
allowInCritSection
;
/* allow palloc in critical section */
82
Size
mem_allocated
;
/* track memory allocated for this context */
83
const
MemoryContextMethods
*
methods
;
/* virtual function table */
84
MemoryContext
parent
;
/* NULL if no parent (toplevel context) */
85
MemoryContext
firstchild
;
/* head of linked list of children */
86
MemoryContext
prevchild
;
/* previous child of same parent */
87
MemoryContext
nextchild
;
/* next child of same parent */
88
const
char
*
name
;
/* context name (just for debugging) */
89
const
char
*
ident
;
/* context ID if any (just for debugging) */
90
MemoryContextCallback
*
reset_cbs
;
/* list of reset/delete callbacks */
91
}
MemoryContextData
;
92
93
/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
94
95
96
/*
97
* MemoryContextIsValid
98
* True iff memory context is valid.
99
*
100
* Add new context types to the set accepted by this macro.
101
*/
102
#define MemoryContextIsValid(context) \
103
((context) != NULL && \
104
(IsA((context), AllocSetContext) || \
105
IsA((context), SlabContext) || \
106
IsA((context), GenerationContext)))
107
108
#endif
/* MEMNODES_H */
MemoryContextCounters::nblocks
Size nblocks
Definition:
memnodes.h:31
MemoryContextCounters::freespace
Size freespace
Definition:
memnodes.h:34
MemoryContextData::reset_cbs
MemoryContextCallback * reset_cbs
Definition:
memnodes.h:90
MemoryStatsPrintFunc
void(* MemoryStatsPrintFunc)(MemoryContext context, void *passthru, const char *stats_string)
Definition:
memnodes.h:54
MemoryContextCounters
Definition:
memnodes.h:29
MemoryContextData::methods
const MemoryContextMethods * methods
Definition:
memnodes.h:83
MemoryContextCounters::totalspace
Size totalspace
Definition:
memnodes.h:33
MemoryContextData::allowInCritSection
bool allowInCritSection
Definition:
memnodes.h:81
MemoryContextData::isReset
bool isReset
Definition:
memnodes.h:80
NodeTag
NodeTag
Definition:
nodes.h:26
MemoryContextMethods
Definition:
memnodes.h:57
MemoryContextMethods
struct MemoryContextMethods MemoryContextMethods
MemoryContextData::firstchild
MemoryContext firstchild
Definition:
memnodes.h:85
MemoryContextData::prevchild
MemoryContext prevchild
Definition:
memnodes.h:86
MemoryContextData::ident
const char * ident
Definition:
memnodes.h:89
MemoryContextData
Definition:
memnodes.h:76
nodes.h
Size
size_t Size
Definition:
c.h:528
MemoryContextData::mem_allocated
Size mem_allocated
Definition:
memnodes.h:82
MemoryContextCallback
Definition:
palloc.h:47
MemoryContextCounters
struct MemoryContextCounters MemoryContextCounters
MemoryContextData::parent
MemoryContext parent
Definition:
memnodes.h:84
MemoryContextData::name
const char * name
Definition:
memnodes.h:88
MemoryContextData::nextchild
MemoryContext nextchild
Definition:
memnodes.h:87
bool
unsigned char bool
Definition:
c.h:379
MemoryContextData
struct MemoryContextData MemoryContextData
MemoryContextCounters::freechunks
Size freechunks
Definition:
memnodes.h:32
MemoryContextData::type
NodeTag type
Definition:
memnodes.h:78
src
include
nodes
memnodes.h
Generated on Thu Jan 21 2021 00:13:25 for PostgreSQL Source Code by
1.8.13