Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
2fd6a44a
Commit
2fd6a44a
authored
Mar 19, 2020
by
Jeff Davis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Specialize MemoryContextMemAllocated()."
This reverts commit
e00912e1
.
parent
2247a1ea
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
77 deletions
+28
-77
src/backend/utils/mmgr/aset.c
src/backend/utils/mmgr/aset.c
+13
-33
src/backend/utils/mmgr/generation.c
src/backend/utils/mmgr/generation.c
+5
-20
src/backend/utils/mmgr/mcxt.c
src/backend/utils/mmgr/mcxt.c
+2
-1
src/backend/utils/mmgr/slab.c
src/backend/utils/mmgr/slab.c
+7
-22
src/include/nodes/memnodes.h
src/include/nodes/memnodes.h
+1
-1
No files found.
src/backend/utils/mmgr/aset.c
View file @
2fd6a44a
...
...
@@ -132,7 +132,6 @@ typedef struct AllocSetContext
Size
maxBlockSize
;
/* maximum block size */
Size
nextBlockSize
;
/* next block size to allocate */
Size
allocChunkLimit
;
/* effective chunk size limit */
Size
memAllocated
;
/* track memory allocated for this context */
AllocBlock
keeper
;
/* keep this block over resets */
/* freelist this context could be put in, or -1 if not a candidate: */
int
freeListIndex
;
/* index in context_freelists[], or -1 */
...
...
@@ -273,7 +272,6 @@ static void *AllocSetRealloc(MemoryContext context, void *pointer, Size size);
static
void
AllocSetReset
(
MemoryContext
context
);
static
void
AllocSetDelete
(
MemoryContext
context
);
static
Size
AllocSetGetChunkSpace
(
MemoryContext
context
,
void
*
pointer
);
static
Size
AllocSetMemAllocated
(
MemoryContext
context
);
static
bool
AllocSetIsEmpty
(
MemoryContext
context
);
static
void
AllocSetStats
(
MemoryContext
context
,
MemoryStatsPrintFunc
printfunc
,
void
*
passthru
,
...
...
@@ -293,7 +291,6 @@ static const MemoryContextMethods AllocSetMethods = {
AllocSetReset
,
AllocSetDelete
,
AllocSetGetChunkSpace
,
AllocSetMemAllocated
,
AllocSetIsEmpty
,
AllocSetStats
#ifdef MEMORY_CONTEXT_CHECKING
...
...
@@ -467,7 +464,8 @@ AllocSetContextCreateInternal(MemoryContext parent,
parent
,
name
);
set
->
memAllocated
=
set
->
keeper
->
endptr
-
((
char
*
)
set
);
((
MemoryContext
)
set
)
->
mem_allocated
=
set
->
keeper
->
endptr
-
((
char
*
)
set
);
return
(
MemoryContext
)
set
;
}
...
...
@@ -557,7 +555,7 @@ AllocSetContextCreateInternal(MemoryContext parent,
parent
,
name
);
set
->
memA
llocated
=
firstBlockSize
;
((
MemoryContext
)
set
)
->
mem_a
llocated
=
firstBlockSize
;
return
(
MemoryContext
)
set
;
}
...
...
@@ -619,7 +617,7 @@ AllocSetReset(MemoryContext context)
else
{
/* Normal case, release the block */
set
->
memA
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
context
->
mem_a
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem
(
block
,
block
->
freeptr
-
((
char
*
)
block
));
...
...
@@ -629,7 +627,7 @@ AllocSetReset(MemoryContext context)
block
=
next
;
}
Assert
(
set
->
memA
llocated
==
keepersize
);
Assert
(
context
->
mem_a
llocated
==
keepersize
);
/* Reset block size allocation sequence, too */
set
->
nextBlockSize
=
set
->
initBlockSize
;
...
...
@@ -705,7 +703,7 @@ AllocSetDelete(MemoryContext context)
AllocBlock
next
=
block
->
next
;
if
(
block
!=
set
->
keeper
)
set
->
memA
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
context
->
mem_a
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem
(
block
,
block
->
freeptr
-
((
char
*
)
block
));
...
...
@@ -717,7 +715,7 @@ AllocSetDelete(MemoryContext context)
block
=
next
;
}
Assert
(
set
->
memA
llocated
==
keepersize
);
Assert
(
context
->
mem_a
llocated
==
keepersize
);
/* Finally, free the context header, including the keeper block */
free
(
set
);
...
...
@@ -760,7 +758,7 @@ AllocSetAlloc(MemoryContext context, Size size)
if
(
block
==
NULL
)
return
NULL
;
set
->
memA
llocated
+=
blksize
;
context
->
mem_a
llocated
+=
blksize
;
block
->
aset
=
set
;
block
->
freeptr
=
block
->
endptr
=
((
char
*
)
block
)
+
blksize
;
...
...
@@ -957,7 +955,7 @@ AllocSetAlloc(MemoryContext context, Size size)
if
(
block
==
NULL
)
return
NULL
;
set
->
memA
llocated
+=
blksize
;
context
->
mem_a
llocated
+=
blksize
;
block
->
aset
=
set
;
block
->
freeptr
=
((
char
*
)
block
)
+
ALLOC_BLOCKHDRSZ
;
...
...
@@ -1060,7 +1058,7 @@ AllocSetFree(MemoryContext context, void *pointer)
if
(
block
->
next
)
block
->
next
->
prev
=
block
->
prev
;
set
->
memA
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
context
->
mem_a
llocated
-=
block
->
endptr
-
((
char
*
)
block
);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem
(
block
,
block
->
freeptr
-
((
char
*
)
block
));
...
...
@@ -1163,8 +1161,8 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
}
/* updated separately, not to underflow when (oldblksize > blksize) */
set
->
memA
llocated
-=
oldblksize
;
set
->
memA
llocated
+=
blksize
;
context
->
mem_a
llocated
-=
oldblksize
;
context
->
mem_a
llocated
+=
blksize
;
block
->
freeptr
=
block
->
endptr
=
((
char
*
)
block
)
+
blksize
;
...
...
@@ -1339,24 +1337,6 @@ AllocSetGetChunkSpace(MemoryContext context, void *pointer)
return
result
;
}
/*
* All memory currently allocated for this context (including fragmentation
* and freed chunks).
*
* Allocation sizes double (up to maxBlockSize), so the current block may
* represent half of the total space allocated to the context. Subtract away
* the free space at the tail of the current block, which may never have been
* touched.
*/
static
Size
AllocSetMemAllocated
(
MemoryContext
context
)
{
AllocSet
set
=
(
AllocSet
)
context
;
AllocBlock
currentBlock
=
set
->
blocks
;
Size
tailSpace
=
currentBlock
->
endptr
-
currentBlock
->
freeptr
;
return
set
->
memAllocated
-
tailSpace
;
}
/*
* AllocSetIsEmpty
* Is an allocset empty of any allocated space?
...
...
@@ -1558,7 +1538,7 @@ AllocSetCheck(MemoryContext context)
name
,
block
);
}
Assert
(
total_allocated
==
set
->
memA
llocated
);
Assert
(
total_allocated
==
context
->
mem_a
llocated
);
}
#endif
/* MEMORY_CONTEXT_CHECKING */
src/backend/utils/mmgr/generation.c
View file @
2fd6a44a
...
...
@@ -61,7 +61,6 @@ typedef struct GenerationContext
/* Generational context parameters */
Size
blockSize
;
/* standard block size */
Size
memAllocated
;
/* track memory allocated for this context */
GenerationBlock
*
block
;
/* current (most recently allocated) block */
dlist_head
blocks
;
/* list of blocks */
...
...
@@ -153,7 +152,6 @@ static void *GenerationRealloc(MemoryContext context, void *pointer, Size size);
static
void
GenerationReset
(
MemoryContext
context
);
static
void
GenerationDelete
(
MemoryContext
context
);
static
Size
GenerationGetChunkSpace
(
MemoryContext
context
,
void
*
pointer
);
static
Size
GenerationMemAllocated
(
MemoryContext
context
);
static
bool
GenerationIsEmpty
(
MemoryContext
context
);
static
void
GenerationStats
(
MemoryContext
context
,
MemoryStatsPrintFunc
printfunc
,
void
*
passthru
,
...
...
@@ -173,7 +171,6 @@ static const MemoryContextMethods GenerationMethods = {
GenerationReset
,
GenerationDelete
,
GenerationGetChunkSpace
,
GenerationMemAllocated
,
GenerationIsEmpty
,
GenerationStats
#ifdef MEMORY_CONTEXT_CHECKING
...
...
@@ -261,7 +258,6 @@ GenerationContextCreate(MemoryContext parent,
/* Fill in GenerationContext-specific header fields */
set
->
blockSize
=
blockSize
;
set
->
memAllocated
=
0
;
set
->
block
=
NULL
;
dlist_init
(
&
set
->
blocks
);
...
...
@@ -301,7 +297,7 @@ GenerationReset(MemoryContext context)
dlist_delete
(
miter
.
cur
);
set
->
memA
llocated
-=
block
->
blksize
;
context
->
mem_a
llocated
-=
block
->
blksize
;
#ifdef CLOBBER_FREED_MEMORY
wipe_mem
(
block
,
block
->
blksize
);
...
...
@@ -358,7 +354,7 @@ GenerationAlloc(MemoryContext context, Size size)
if
(
block
==
NULL
)
return
NULL
;
set
->
memA
llocated
+=
blksize
;
context
->
mem_a
llocated
+=
blksize
;
/* block with a single (used) chunk */
block
->
blksize
=
blksize
;
...
...
@@ -415,7 +411,7 @@ GenerationAlloc(MemoryContext context, Size size)
if
(
block
==
NULL
)
return
NULL
;
set
->
memA
llocated
+=
blksize
;
context
->
mem_a
llocated
+=
blksize
;
block
->
blksize
=
blksize
;
block
->
nchunks
=
0
;
...
...
@@ -532,7 +528,7 @@ GenerationFree(MemoryContext context, void *pointer)
if
(
set
->
block
==
block
)
set
->
block
=
NULL
;
set
->
memA
llocated
-=
block
->
blksize
;
context
->
mem_a
llocated
-=
block
->
blksize
;
free
(
block
);
}
...
...
@@ -670,17 +666,6 @@ GenerationGetChunkSpace(MemoryContext context, void *pointer)
return
result
;
}
/*
* All memory currently allocated for this context (including fragmentation
* and freed chunks).
*/
static
Size
GenerationMemAllocated
(
MemoryContext
context
)
{
GenerationContext
*
set
=
(
GenerationContext
*
)
context
;
return
set
->
memAllocated
;
}
/*
* GenerationIsEmpty
* Is a GenerationContext empty of any allocated space?
...
...
@@ -859,7 +844,7 @@ GenerationCheck(MemoryContext context)
name
,
nfree
,
block
,
block
->
nfree
);
}
Assert
(
total_allocated
==
gen
->
memA
llocated
);
Assert
(
total_allocated
==
context
->
mem_a
llocated
);
}
#endif
/* MEMORY_CONTEXT_CHECKING */
src/backend/utils/mmgr/mcxt.c
View file @
2fd6a44a
...
...
@@ -469,7 +469,7 @@ MemoryContextIsEmpty(MemoryContext context)
Size
MemoryContextMemAllocated
(
MemoryContext
context
,
bool
recurse
)
{
Size
total
=
context
->
me
thods
->
mem_allocated
(
context
)
;
Size
total
=
context
->
me
m_allocated
;
AssertArg
(
MemoryContextIsValid
(
context
));
...
...
@@ -760,6 +760,7 @@ MemoryContextCreate(MemoryContext node,
node
->
methods
=
methods
;
node
->
parent
=
parent
;
node
->
firstchild
=
NULL
;
node
->
mem_allocated
=
0
;
node
->
prevchild
=
NULL
;
node
->
name
=
name
;
node
->
ident
=
NULL
;
...
...
src/backend/utils/mmgr/slab.c
View file @
2fd6a44a
...
...
@@ -67,7 +67,6 @@ typedef struct SlabContext
Size
fullChunkSize
;
/* chunk size including header and alignment */
Size
blockSize
;
/* block size */
Size
headerSize
;
/* allocated size of context header */
Size
memAllocated
;
/* track memory allocated for this context */
int
chunksPerBlock
;
/* number of chunks per block */
int
minFreeChunks
;
/* min number of free chunks in any block */
int
nblocks
;
/* number of blocks allocated */
...
...
@@ -133,7 +132,6 @@ static void *SlabRealloc(MemoryContext context, void *pointer, Size size);
static
void
SlabReset
(
MemoryContext
context
);
static
void
SlabDelete
(
MemoryContext
context
);
static
Size
SlabGetChunkSpace
(
MemoryContext
context
,
void
*
pointer
);
static
Size
SlabMemAllocated
(
MemoryContext
context
);
static
bool
SlabIsEmpty
(
MemoryContext
context
);
static
void
SlabStats
(
MemoryContext
context
,
MemoryStatsPrintFunc
printfunc
,
void
*
passthru
,
...
...
@@ -152,7 +150,6 @@ static const MemoryContextMethods SlabMethods = {
SlabReset
,
SlabDelete
,
SlabGetChunkSpace
,
SlabMemAllocated
,
SlabIsEmpty
,
SlabStats
#ifdef MEMORY_CONTEXT_CHECKING
...
...
@@ -265,7 +262,6 @@ SlabContextCreate(MemoryContext parent,
slab
->
fullChunkSize
=
fullChunkSize
;
slab
->
blockSize
=
blockSize
;
slab
->
headerSize
=
headerSize
;
slab
->
memAllocated
=
0
;
slab
->
chunksPerBlock
=
chunksPerBlock
;
slab
->
minFreeChunks
=
0
;
slab
->
nblocks
=
0
;
...
...
@@ -290,17 +286,6 @@ SlabContextCreate(MemoryContext parent,
return
(
MemoryContext
)
slab
;
}
/*
* All memory currently allocated for this context (including fragmentation
* and freed chunks).
*/
static
Size
SlabMemAllocated
(
MemoryContext
context
)
{
SlabContext
*
slab
=
(
SlabContext
*
)
context
;
return
slab
->
memAllocated
;
}
/*
* SlabReset
* Frees all memory which is allocated in the given set.
...
...
@@ -337,14 +322,14 @@ SlabReset(MemoryContext context)
#endif
free
(
block
);
slab
->
nblocks
--
;
slab
->
memA
llocated
-=
slab
->
blockSize
;
context
->
mem_a
llocated
-=
slab
->
blockSize
;
}
}
slab
->
minFreeChunks
=
0
;
Assert
(
slab
->
nblocks
==
0
);
Assert
(
slab
->
memA
llocated
==
0
);
Assert
(
context
->
mem_a
llocated
==
0
);
}
/*
...
...
@@ -422,7 +407,7 @@ SlabAlloc(MemoryContext context, Size size)
slab
->
minFreeChunks
=
slab
->
chunksPerBlock
;
slab
->
nblocks
+=
1
;
slab
->
memA
llocated
+=
slab
->
blockSize
;
context
->
mem_a
llocated
+=
slab
->
blockSize
;
}
/* grab the block from the freelist (even the new block is there) */
...
...
@@ -516,7 +501,7 @@ SlabAlloc(MemoryContext context, Size size)
SlabAllocInfo
(
slab
,
chunk
);
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
slab
->
memA
llocated
);
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
context
->
mem_a
llocated
);
return
SlabChunkGetPointer
(
chunk
);
}
...
...
@@ -593,13 +578,13 @@ SlabFree(MemoryContext context, void *pointer)
{
free
(
block
);
slab
->
nblocks
--
;
slab
->
memA
llocated
-=
slab
->
blockSize
;
context
->
mem_a
llocated
-=
slab
->
blockSize
;
}
else
dlist_push_head
(
&
slab
->
freelist
[
block
->
nfree
],
&
block
->
node
);
Assert
(
slab
->
nblocks
>=
0
);
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
slab
->
memA
llocated
);
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
context
->
mem_a
llocated
);
}
/*
...
...
@@ -819,7 +804,7 @@ SlabCheck(MemoryContext context)
}
}
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
slab
->
memA
llocated
);
Assert
(
slab
->
nblocks
*
slab
->
blockSize
==
context
->
mem_a
llocated
);
}
#endif
/* MEMORY_CONTEXT_CHECKING */
src/include/nodes/memnodes.h
View file @
2fd6a44a
...
...
@@ -63,7 +63,6 @@ typedef struct MemoryContextMethods
void
(
*
reset
)
(
MemoryContext
context
);
void
(
*
delete_context
)
(
MemoryContext
context
);
Size
(
*
get_chunk_space
)
(
MemoryContext
context
,
void
*
pointer
);
Size
(
*
mem_allocated
)
(
MemoryContext
context
);
bool
(
*
is_empty
)
(
MemoryContext
context
);
void
(
*
stats
)
(
MemoryContext
context
,
MemoryStatsPrintFunc
printfunc
,
void
*
passthru
,
...
...
@@ -80,6 +79,7 @@ typedef struct MemoryContextData
/* these two fields are placed here to minimize alignment wastage: */
bool
isReset
;
/* T = no space alloced since last reset */
bool
allowInCritSection
;
/* allow palloc in critical section */
Size
mem_allocated
;
/* track memory allocated for this context */
const
MemoryContextMethods
*
methods
;
/* virtual function table */
MemoryContext
parent
;
/* NULL if no parent (toplevel context) */
MemoryContext
firstchild
;
/* head of linked list of children */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment