Re: [HACKERS] [PATCH] Use MemoryContextAlloc() in the MemoryContextAllocZero() and MemoryContextAllocZeroAligned()

2016-03-12 Thread Tom Lane
Alexander Kuleshov  writes:
> Attached patch simplifies the MemoryContextAllocZero() and
> MemoryContextAllocZeroAligned().

What this does is to de-inline those functions, resulting in an
extra level of function call per allocation.  We had intentionally
inlined them on performance grounds: those things are hot spots in
most workloads.  Do you have any evidence demonstrating that this
doesn't cause a performance hit?

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH] Use MemoryContextAlloc() in the MemoryContextAllocZero() and MemoryContextAllocZeroAligned()

2016-03-12 Thread Michael Paquier
On Sat, Mar 12, 2016 at 8:09 AM, Alexander Kuleshov
 wrote:
> Hello all,
>
> Attached patch simplifies the MemoryContextAllocZero() and
> MemoryContextAllocZeroAligned().
> The MemoryContextAllocZero() and MemoryContextAllocZeroAligned()
> functions does almost the
> same that MemoryContextAlloc() does. Additionally these functions
> fills allocated memory context
> with zeros via MemSetAligned() and MemSetLoop(). Let's call
> MemoryContextAlloc() in these functions
> instead of setting isReset to false, call alloc() callback of the
> context and etc., to prevent code duplication.

This code duplication is on purpose. This is a very hot code path and
we want to avoid the overhead of an extra function call.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] [PATCH] Use MemoryContextAlloc() in the MemoryContextAllocZero() and MemoryContextAllocZeroAligned()

2016-03-11 Thread Alexander Kuleshov
Hello all,

Attached patch simplifies the MemoryContextAllocZero() and
MemoryContextAllocZeroAligned().
The MemoryContextAllocZero() and MemoryContextAllocZeroAligned()
functions does almost the
same that MemoryContextAlloc() does. Additionally these functions
fills allocated memory context
with zeros via MemSetAligned() and MemSetLoop(). Let's call
MemoryContextAlloc() in these functions
instead of setting isReset to false, call alloc() callback of the
context and etc., to prevent code duplication.
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 2bfd364..2845089 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -788,26 +788,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
-	AssertNotInCriticalSection(context);
-
-	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %zu", size);
-
-	context->isReset = false;
-
-	ret = (*context->methods->alloc) (context, size);
-	if (ret == NULL)
-	{
-		MemoryContextStats(TopMemoryContext);
-		ereport(ERROR,
-(errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory"),
- errdetail("Failed on request of size %zu.", size)));
-	}
-
-	VALGRIND_MEMPOOL_ALLOC(context, ret, size);
-
+	ret = MemoryContextAlloc(context, size);
 	MemSetAligned(ret, 0, size);
 
 	return ret;
@@ -825,26 +806,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
 {
 	void	   *ret;
 
-	AssertArg(MemoryContextIsValid(context));
-	AssertNotInCriticalSection(context);
-
-	if (!AllocSizeIsValid(size))
-		elog(ERROR, "invalid memory alloc request size %zu", size);
-
-	context->isReset = false;
-
-	ret = (*context->methods->alloc) (context, size);
-	if (ret == NULL)
-	{
-		MemoryContextStats(TopMemoryContext);
-		ereport(ERROR,
-(errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory"),
- errdetail("Failed on request of size %zu.", size)));
-	}
-
-	VALGRIND_MEMPOOL_ALLOC(context, ret, size);
-
+	ret = MemoryContextAlloc(context, size);
 	MemSetLoop(ret, 0, size);
 
 	return ret;

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers