summaryrefslogtreecommitdiff
path: root/src/include/nodes/memnodes.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-06-28 03:33:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-06-28 03:33:33 +0000
commit1aebc3618a0be13451918581ad390ad9a3518702 (patch)
treee8ab228245c43ff086bd8e9d65baf3d1d9a5f96a /src/include/nodes/memnodes.h
parentb601c8d8828ee02ffb195dead82b233b9572fe32 (diff)
downloadpostgresql-1aebc3618a0be13451918581ad390ad9a3518702.tar.gz
First phase of memory management rewrite (see backend/utils/mmgr/README
for details). It doesn't really do that much yet, since there are no short-term memory contexts in the executor, but the infrastructure is in place and long-term contexts are handled reasonably. A few long- standing bugs have been fixed, such as 'VACUUM; anything' in a single query string crashing. Also, out-of-memory is now considered a recoverable ERROR, not FATAL. Eliminate a large amount of crufty, now-dead code in and around memory management. Fix problem with holding off SIGTRAP, SIGSEGV, etc in postmaster and backend startup.
Diffstat (limited to 'src/include/nodes/memnodes.h')
-rw-r--r--src/include/nodes/memnodes.h112
1 files changed, 50 insertions, 62 deletions
diff --git a/src/include/nodes/memnodes.h b/src/include/nodes/memnodes.h
index 08ba967318..abc38e5c60 100644
--- a/src/include/nodes/memnodes.h
+++ b/src/include/nodes/memnodes.h
@@ -7,100 +7,88 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: memnodes.h,v 1.16 2000/01/26 05:58:16 momjian Exp $
+ * $Id: memnodes.h,v 1.17 2000/06/28 03:33:15 tgl Exp $
*
- * XXX the typedefs in this file are different from the other ???nodes.h;
- * they are pointers to structures instead of the structures themselves.
- * If you're wondering, this is plain laziness. I don't want to touch
- * the memory context code which should be revamped altogether some day.
- * - ay 10/94
*-------------------------------------------------------------------------
*/
#ifndef MEMNODES_H
#define MEMNODES_H
-#include "lib/fstack.h"
#include "nodes/nodes.h"
-#include "utils/memutils.h"
/*
* MemoryContext
* A logical context in which memory allocations occur.
*
- * The types of memory contexts can be thought of as members of the
- * following inheritance hierarchy with properties summarized below.
+ * MemoryContext itself is an abstract type that can have multiple
+ * implementations, though for now we have only AllocSetContext.
+ * The function pointers in MemoryContextMethods define one specific
+ * implementation of MemoryContext --- they are a virtual function table
+ * in C++ terms.
*
- * Node
- * |
- * MemoryContext___
- * / \
- * GlobalMemory PortalMemoryContext
- * / \
- * PortalVariableMemory PortalHeapMemory
+ * Node types that are actual implementations of memory contexts must
+ * begin with the same fields as MemoryContext.
*
- * Flushed at Flushed at Checkpoints
- * Transaction Portal
- * Commit Close
- *
- * GlobalMemory n n n
- * PortalVariableMemory n y n
- * PortalHeapMemory y y y
+ * Note: for largely historical reasons, typedef MemoryContext is a pointer
+ * to the context struct rather than the struct type itself.
*/
-typedef struct MemoryContextMethodsData
+typedef struct MemoryContextMethods
{
- Pointer (*alloc) ();
- void (*free_p) (); /* need to use free as a #define, so can't
- * use free */
- Pointer (*realloc) ();
- char *(*getName) ();
- void (*dump) ();
-} *MemoryContextMethods;
+ void *(*alloc) (MemoryContext context, Size size);
+ /* call this free_p in case someone #define's free() */
+ void (*free_p) (MemoryContext context, void *pointer);
+ void *(*realloc) (MemoryContext context, void *pointer, Size size);
+ void (*init) (MemoryContext context);
+ void (*reset) (MemoryContext context);
+ void (*delete) (MemoryContext context);
+ void (*stats) (MemoryContext context);
+} MemoryContextMethods;
+
typedef struct MemoryContextData
{
- NodeTag type;
- MemoryContextMethods method;
+ NodeTag type; /* identifies exact kind of context */
+ MemoryContextMethods *methods; /* virtual function table */
+ MemoryContext parent; /* NULL if no parent (toplevel context) */
+ MemoryContext firstchild; /* head of linked list of children */
+ MemoryContext nextchild; /* next child of same parent */
+ char *name; /* context name (just for debugging) */
} MemoryContextData;
-/* utils/mcxt.h contains typedef struct MemoryContextData *MemoryContext */
+/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
-/* think about doing this right some time but we'll have explicit fields
- for now -ay 10/94 */
-typedef struct GlobalMemoryData
-{
- NodeTag type;
- MemoryContextMethods method;
- AllocSetData setData;
- char *name;
- OrderedElemData elemData;
-} GlobalMemoryData;
-/* utils/mcxt.h contains typedef struct GlobalMemoryData *GlobalMemory */
-
-typedef struct MemoryContextData *PortalMemoryContext;
+/*
+ * AllocSetContext is our standard implementation of MemoryContext.
+ */
+typedef struct AllocBlockData *AllocBlock; /* internal to aset.c */
+typedef struct AllocChunkData *AllocChunk;
-typedef struct PortalVariableMemoryData
+typedef struct AllocSetContext
{
- NodeTag type;
- MemoryContextMethods method;
- AllocSetData setData;
-} *PortalVariableMemory;
+ MemoryContextData header; /* Standard memory-context fields */
+ /* Info about storage allocated in this context: */
+ AllocBlock blocks; /* head of list of blocks in this set */
+#define ALLOCSET_NUM_FREELISTS 8
+ AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */
+ /* Allocation parameters for this context: */
+ Size initBlockSize; /* initial block size */
+ Size maxBlockSize; /* maximum block size */
+ AllocBlock keeper; /* if not NULL, keep this block
+ * over resets */
+} AllocSetContext;
-typedef struct PortalHeapMemoryData
-{
- NodeTag type;
- MemoryContextMethods method;
- Pointer block;
- FixedStackData stackData;
-} *PortalHeapMemory;
/*
* MemoryContextIsValid
* True iff memory context is valid.
+ *
+ * Add new context types to the set accepted by this macro.
*/
#define MemoryContextIsValid(context) \
- (IsA(context,MemoryContext) || IsA(context,GlobalMemory) || \
- IsA(context,PortalVariableMemory) || IsA(context,PortalHeapMemory))
+ ((context) != NULL && \
+ (IsA((context), AllocSetContext)))
+
#endif /* MEMNODES_H */