1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

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.
This commit is contained in:
Tom Lane
2000-06-28 03:33:33 +00:00
parent b601c8d882
commit 1aebc3618a
74 changed files with 2325 additions and 3296 deletions

View File

@@ -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
/*
* AllocSetContext is our standard implementation of MemoryContext.
*/
typedef struct AllocBlockData *AllocBlock; /* internal to aset.c */
typedef struct AllocChunkData *AllocChunk;
typedef struct AllocSetContext
{
NodeTag type;
MemoryContextMethods method;
AllocSetData setData;
char *name;
OrderedElemData elemData;
} GlobalMemoryData;
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;
/* utils/mcxt.h contains typedef struct GlobalMemoryData *GlobalMemory */
typedef struct MemoryContextData *PortalMemoryContext;
typedef struct PortalVariableMemoryData
{
NodeTag type;
MemoryContextMethods method;
AllocSetData setData;
} *PortalVariableMemory;
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 */

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nodes.h,v 1.69 2000/06/18 22:44:31 tgl Exp $
* $Id: nodes.h,v 1.70 2000/06/28 03:33:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -122,10 +122,7 @@ typedef enum NodeTag
*---------------------
*/
T_MemoryContext = 400,
T_GlobalMemory,
T_PortalMemoryContext,
T_PortalVariableMemory,
T_PortalHeapMemory,
T_AllocSetContext,
/*---------------------
* TAGS FOR VALUE NODES (pg_list.h)