Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

Started by Bharath Rupireddyalmost 5 years ago14 messages
#1Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
1 attachment(s)

Hi,

We are memset-ting the special space page that's already set to zeros
by PageInit in BloomInitPage, GinInitPage and SpGistInitPage. We have
already removed the memset after PageInit in gistinitpage (see the
comment there). Unless I'm missing something, IMO they are redundant.
I'm attaching a small patch that gets rid of the extra memset calls.

While on it, I removed MAXALIGN(sizeof(SpGistPageOpaqueData)) in
SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special space
data structure.

I didn't see any regression test failure on my dev system with the
attached patch.

Thoughts?

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v1-0001-Remove-extra-memset-in-BloomInitPage-GinInitPage-.patchapplication/octet-stream; name=v1-0001-Remove-extra-memset-in-BloomInitPage-GinInitPage-.patchDownload
From 6facda585f8daca545677e56f7bc5d06dc23cf39 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Mon, 22 Mar 2021 10:13:50 +0530
Subject: [PATCH v1] Remove extra memset in BloomInitPage, GinInitPage and
 SpGistInitPage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We are memset-ting the special space page that's already set to
zeros by PageInit in BloomInitPage, GinInitPage and SpGistInitPage.
We have already removed the memset after PageInit in gistinitpage
(see the comment there).  Unless I'm missing something, IMO they are
redundant. I'm attaching a small patch that gets rid of the extra memset
calls.

While on it, I removed MAXALIGN(sizeof(SpGistPageOpaqueData)) in
SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special
space data structure.
---
 contrib/bloom/blutils.c              | 1 -
 src/backend/access/gin/ginutil.c     | 1 -
 src/backend/access/spgist/spgutils.c | 3 +--
 3 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index 1e505b1da5..754de008d4 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags)
 	PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
 
 	opaque = BloomPageGetOpaque(page);
-	memset(opaque, 0, sizeof(BloomPageOpaqueData));
 	opaque->flags = flags;
 	opaque->bloom_page_id = BLOOM_PAGE_ID;
 }
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index 6b9b04cf42..cdd626ff0a 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize)
 	PageInit(page, pageSize, sizeof(GinPageOpaqueData));
 
 	opaque = GinPageGetOpaque(page);
-	memset(opaque, 0, sizeof(GinPageOpaqueData));
 	opaque->flags = f;
 	opaque->rightlink = InvalidBlockNumber;
 }
diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c
index d8b1815061..1b333f6db1 100644
--- a/src/backend/access/spgist/spgutils.c
+++ b/src/backend/access/spgist/spgutils.c
@@ -541,9 +541,8 @@ SpGistInitPage(Page page, uint16 f)
 {
 	SpGistPageOpaque opaque;
 
-	PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
+	PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
 	opaque = SpGistPageGetOpaque(page);
-	memset(opaque, 0, sizeof(SpGistPageOpaqueData));
 	opaque->flags = f;
 	opaque->spgist_page_id = SPGIST_PAGE_ID;
 }
-- 
2.25.1

#2Mahendra Singh Thalor
mahi6run@gmail.com
In reply to: Bharath Rupireddy (#1)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Mon, 22 Mar 2021 at 10:16, Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

We are memset-ting the special space page that's already set to zeros
by PageInit in BloomInitPage, GinInitPage and SpGistInitPage. We have
already removed the memset after PageInit in gistinitpage (see the
comment there). Unless I'm missing something, IMO they are redundant.
I'm attaching a small patch that gets rid of the extra memset calls.

While on it, I removed MAXALIGN(sizeof(SpGistPageOpaqueData)) in
SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special space
data structure.

I didn't see any regression test failure on my dev system with the
attached patch.

Thoughts?

Your changes look to fine me and I am also not getting any failure. I
think we should back-patch all the branches.

Patch is applying to all the branches(till v95) and there is no failure.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

#3vignesh C
vignesh21@gmail.com
In reply to: Bharath Rupireddy (#1)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Mon, Mar 22, 2021 at 10:16 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

We are memset-ting the special space page that's already set to zeros
by PageInit in BloomInitPage, GinInitPage and SpGistInitPage. We have
already removed the memset after PageInit in gistinitpage (see the
comment there). Unless I'm missing something, IMO they are redundant.
I'm attaching a small patch that gets rid of the extra memset calls.

While on it, I removed MAXALIGN(sizeof(SpGistPageOpaqueData)) in
SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special space
data structure.

I didn't see any regression test failure on my dev system with the
attached patch.

Thoughts?

The changes look fine to me.

Regards,
Vignesh

#4Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: vignesh C (#3)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Sat, Apr 3, 2021 at 3:09 PM vignesh C <vignesh21@gmail.com> wrote:

On Mon, Mar 22, 2021 at 10:16 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

We are memset-ting the special space page that's already set to zeros
by PageInit in BloomInitPage, GinInitPage and SpGistInitPage. We have
already removed the memset after PageInit in gistinitpage (see the
comment there). Unless I'm missing something, IMO they are redundant.
I'm attaching a small patch that gets rid of the extra memset calls.

While on it, I removed MAXALIGN(sizeof(SpGistPageOpaqueData)) in
SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special space
data structure.

I didn't see any regression test failure on my dev system with the
attached patch.

Thoughts?

The changes look fine to me.

Thanks!

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#5Michael Paquier
michael@paquier.xyz
In reply to: Mahendra Singh Thalor (#2)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Mon, Mar 22, 2021 at 10:58:17AM +0530, Mahendra Singh Thalor wrote:

Your changes look to fine me and I am also not getting any failure. I
think we should back-patch all the branches.

Patch is applying to all the branches(till v95) and there is no failure.

Er, no. This is just some duplicated code with no extra effect. I
have no objection to simplify a bit the whole on readability and
consistency grounds (will do so tomorrow), including the removal of
the commented-out memset call in gistinitpage, but this is not
something that should be backpatched.
--
Michael

#6Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Michael Paquier (#5)
1 attachment(s)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Tue, Apr 6, 2021 at 6:09 PM Michael Paquier <michael@paquier.xyz> wrote:

On Mon, Mar 22, 2021 at 10:58:17AM +0530, Mahendra Singh Thalor wrote:

Your changes look to fine me and I am also not getting any failure. I
think we should back-patch all the branches.

Patch is applying to all the branches(till v95) and there is no failure.

Er, no. This is just some duplicated code with no extra effect. I
have no objection to simplify a bit the whole on readability and
consistency grounds (will do so tomorrow), including the removal of
the commented-out memset call in gistinitpage, but this is not
something that should be backpatched.

+1 to not backport this patch because it's not a bug or not even a
critical issue. Having said that removal of these unnecessary memsets
would not only be better for readability and consistency but also can
reduce few extra function call costs(although minimal) while adding
new index pages.

Please find the v3 patch that removed the commented-out memset call in
gistinitpage.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v3-0001-Remove-extra-memset-in-BloomInitPage-GinInitPage-.patchapplication/x-patch; name=v3-0001-Remove-extra-memset-in-BloomInitPage-GinInitPage-.patchDownload
From fe18cdc930933415c02f6eda82fbb1646831ba0a Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Tue, 6 Apr 2021 19:06:51 +0530
Subject: [PATCH v3] Remove extra memset in
 BloomInitPage,GinInitPage,SpGistInitPage

We are memset-ting the special space page that's already set to
zeros by PageInit in BloomInitPage, GinInitPage, SpGistInitPage
and initCachedPage. We have already removed the memset after
PageInit in gistinitpage (see the comment there). It looks like
they are redundant. This patch that gets rid of the extra memset
calls.

While on it, this patch also removed MAXALIGN(sizeof(SpGistPageOpaqueData))
in SpGistInitPage because the PageInit will anyways align the
specialSize. This change is inline with other places (such as
BloomInitPage, brin_page_init GinInitPage, gistinitpage,
_hash_pageinit and so on) where we just pass the size of special
space data structure.

While on it, this patch also removed an unnecessary assignment of
pd_flags to 0 in PageInit as it is anyways being done by MemSet.
---
 contrib/bloom/blinsert.c             | 1 -
 contrib/bloom/blutils.c              | 1 -
 src/backend/access/gin/ginutil.c     | 1 -
 src/backend/access/gist/gistutil.c   | 2 --
 src/backend/access/spgist/spgutils.c | 3 +--
 src/backend/storage/page/bufpage.c   | 2 +-
 6 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index d37ceef753..c34a640d1c 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -63,7 +63,6 @@ flushCachedPage(Relation index, BloomBuildState *buildstate)
 static void
 initCachedPage(BloomBuildState *buildstate)
 {
-	memset(buildstate->data.data, 0, BLCKSZ);
 	BloomInitPage(buildstate->data.data, 0);
 	buildstate->count = 0;
 }
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index 1e505b1da5..754de008d4 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -411,7 +411,6 @@ BloomInitPage(Page page, uint16 flags)
 	PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
 
 	opaque = BloomPageGetOpaque(page);
-	memset(opaque, 0, sizeof(BloomPageOpaqueData));
 	opaque->flags = flags;
 	opaque->bloom_page_id = BLOOM_PAGE_ID;
 }
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index 6b9b04cf42..cdd626ff0a 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -348,7 +348,6 @@ GinInitPage(Page page, uint32 f, Size pageSize)
 	PageInit(page, pageSize, sizeof(GinPageOpaqueData));
 
 	opaque = GinPageGetOpaque(page);
-	memset(opaque, 0, sizeof(GinPageOpaqueData));
 	opaque->flags = f;
 	opaque->rightlink = InvalidBlockNumber;
 }
diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c
index 1ff1bf816f..8dcd53c457 100644
--- a/src/backend/access/gist/gistutil.c
+++ b/src/backend/access/gist/gistutil.c
@@ -761,8 +761,6 @@ gistinitpage(Page page, uint32 f)
 	PageInit(page, pageSize, sizeof(GISTPageOpaqueData));
 
 	opaque = GistPageGetOpaque(page);
-	/* page was already zeroed by PageInit, so this is not needed: */
-	/* memset(&(opaque->nsn), 0, sizeof(GistNSN)); */
 	opaque->rightlink = InvalidBlockNumber;
 	opaque->flags = f;
 	opaque->gist_page_id = GIST_PAGE_ID;
diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c
index 72cbde7e0b..8d99c9b762 100644
--- a/src/backend/access/spgist/spgutils.c
+++ b/src/backend/access/spgist/spgutils.c
@@ -677,9 +677,8 @@ SpGistInitPage(Page page, uint16 f)
 {
 	SpGistPageOpaque opaque;
 
-	PageInit(page, BLCKSZ, MAXALIGN(sizeof(SpGistPageOpaqueData)));
+	PageInit(page, BLCKSZ, sizeof(SpGistPageOpaqueData));
 	opaque = SpGistPageGetOpaque(page);
-	memset(opaque, 0, sizeof(SpGistPageOpaqueData));
 	opaque->flags = f;
 	opaque->spgist_page_id = SPGIST_PAGE_ID;
 }
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index 5d5989c2f5..9f77532a4f 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -51,7 +51,7 @@ PageInit(Page page, Size pageSize, Size specialSize)
 	/* Make sure all fields of page are zero, as well as unused space */
 	MemSet(p, 0, pageSize);
 
-	p->pd_flags = 0;
+	/* p->pd_flags = 0;		done by above MemSet */
 	p->pd_lower = SizeOfPageHeaderData;
 	p->pd_upper = pageSize - specialSize;
 	p->pd_special = pageSize - specialSize;
-- 
2.25.1

#7Mahendra Singh Thalor
mahi6run@gmail.com
In reply to: Bharath Rupireddy (#6)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Tue, 6 Apr 2021 at 19:14, Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Tue, Apr 6, 2021 at 6:09 PM Michael Paquier <michael@paquier.xyz> wrote:

On Mon, Mar 22, 2021 at 10:58:17AM +0530, Mahendra Singh Thalor wrote:

Your changes look to fine me and I am also not getting any failure. I
think we should back-patch all the branches.

Patch is applying to all the branches(till v95) and there is no failure.

Er, no. This is just some duplicated code with no extra effect. I
have no objection to simplify a bit the whole on readability and
consistency grounds (will do so tomorrow), including the removal of
the commented-out memset call in gistinitpage, but this is not
something that should be backpatched.

+1 to not backport this patch because it's not a bug or not even a
critical issue. Having said that removal of these unnecessary memsets
would not only be better for readability and consistency but also can
reduce few extra function call costs(although minimal) while adding
new index pages.

Please find the v3 patch that removed the commented-out memset call in
gistinitpage.

Thanks Bharath for updated patch.

+++ b/src/backend/storage/page/bufpage.c
@@ -51,7 +51,7 @@ PageInit(Page page, Size pageSize, Size specialSize)
     /* Make sure all fields of page are zero, as well as unused space */
     MemSet(p, 0, pageSize);
-    p->pd_flags = 0;
+    /* p->pd_flags = 0;        done by above MemSet */

I think, for readability we can keep old code here or we can remove
new added comment also.

Apart from this, all other changes looks good to me.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

#8Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Mahendra Singh Thalor (#7)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Wed, Apr 7, 2021 at 12:07 AM Mahendra Singh Thalor
<mahi6run@gmail.com> wrote:

+++ b/src/backend/storage/page/bufpage.c
@@ -51,7 +51,7 @@ PageInit(Page page, Size pageSize, Size specialSize)
/* Make sure all fields of page are zero, as well as unused space */
MemSet(p, 0, pageSize);
-    p->pd_flags = 0;
+    /* p->pd_flags = 0;        done by above MemSet */

I think, for readability we can keep old code here or we can remove
new added comment also.

Setting p->pd_flags = 0; is unnecessary and redundant after memsetting
the page to zeros. Also, see the existing code for pd_prune_xid,
similarly I've done that for pd_flags. I think it's okay with /*
p->pd_flags = 0; done by above MemSet */.

Apart from this, all other changes looks good to me.

Thanks for taking a look at the patch.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#9Michael Paquier
michael@paquier.xyz
In reply to: Bharath Rupireddy (#8)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Wed, Apr 07, 2021 at 06:31:19AM +0530, Bharath Rupireddy wrote:

Setting p->pd_flags = 0; is unnecessary and redundant after memsetting
the page to zeros. Also, see the existing code for pd_prune_xid,
similarly I've done that for pd_flags. I think it's okay with /*
p->pd_flags = 0; done by above MemSet */.

Sure, but this one does not hurt much either as-is, so I have left it
out, and applied the rest.
--
Michael

#10Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Michael Paquier (#9)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Wed, Apr 7, 2021 at 11:44 AM Michael Paquier <michael@paquier.xyz> wrote:

On Wed, Apr 07, 2021 at 06:31:19AM +0530, Bharath Rupireddy wrote:

Setting p->pd_flags = 0; is unnecessary and redundant after memsetting
the page to zeros. Also, see the existing code for pd_prune_xid,
similarly I've done that for pd_flags. I think it's okay with /*
p->pd_flags = 0; done by above MemSet */.

Sure, but this one does not hurt much either as-is, so I have left it
out, and applied the rest.

Thanks for pushing the patch.

I wanted to comment out p->pd_flags = 0; in PageInit similar to the
pd_prune_xid just for consistency.
/* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#11Pavel Borisov
pashkin.elfe@gmail.com
In reply to: Bharath Rupireddy (#10)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

ср, 7 апр. 2021 г. в 10:18, Bharath Rupireddy <
bharath.rupireddyforpostgres@gmail.com>:

On Wed, Apr 7, 2021 at 11:44 AM Michael Paquier <michael@paquier.xyz>
wrote:

On Wed, Apr 07, 2021 at 06:31:19AM +0530, Bharath Rupireddy wrote:

Setting p->pd_flags = 0; is unnecessary and redundant after memsetting
the page to zeros. Also, see the existing code for pd_prune_xid,
similarly I've done that for pd_flags. I think it's okay with /*
p->pd_flags = 0; done by above MemSet */.

Sure, but this one does not hurt much either as-is, so I have left it
out, and applied the rest.

Thanks for pushing the patch.

I wanted to comment out p->pd_flags = 0; in PageInit similar to the
pd_prune_xid just for consistency.
/* p->pd_prune_xid = InvalidTransactionId; done by above MemSet
*/

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

I've investigated the commit, and I think there is just one more thing that
can make the page init more even. I propose my very small patch on this in
another discussion branch:
/messages/by-id/CALT9ZEFFq2-n5Lmfg59L6Hm3ZrgCexyhR9eqme7v1jodtXGg1A@mail.gmail.com

If you want, feel free to discuss it and push if consider the change
relevant.

--
Best regards,
Pavel Borisov

Postgres Professional: http://postgrespro.com <http://www.postgrespro.com&gt;

#12Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#10)
1 attachment(s)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Wed, Apr 7, 2021 at 11:47 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Wed, Apr 7, 2021 at 11:44 AM Michael Paquier <michael@paquier.xyz> wrote:

On Wed, Apr 07, 2021 at 06:31:19AM +0530, Bharath Rupireddy wrote:

Setting p->pd_flags = 0; is unnecessary and redundant after memsetting
the page to zeros. Also, see the existing code for pd_prune_xid,
similarly I've done that for pd_flags. I think it's okay with /*
p->pd_flags = 0; done by above MemSet */.

Sure, but this one does not hurt much either as-is, so I have left it
out, and applied the rest.

Thanks for pushing the patch.

I wanted to comment out p->pd_flags = 0; in PageInit similar to the
pd_prune_xid just for consistency.
/* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */

As I said above, just for consistency, I would like to see if the
attached one line patch can be taken, even though it doesn't have any
impact.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachments:

v1-0001-Remove-unnecessary-assignment-of-pd_flags-to-0-in.patchapplication/octet-stream; name=v1-0001-Remove-unnecessary-assignment-of-pd_flags-to-0-in.patchDownload
From c26f68811196dea261337164011ab379e9d583f7 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddy@enterprisedb.com>
Date: Thu, 8 Apr 2021 07:42:36 +0530
Subject: [PATCH v1] Remove unnecessary assignment of pd_flags to 0 in PageInit

---
 src/backend/storage/page/bufpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index b231c438f9..d00fad0f81 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -51,7 +51,7 @@ PageInit(Page page, Size pageSize, Size specialSize)
 	/* Make sure all fields of page are zero, as well as unused space */
 	MemSet(p, 0, pageSize);
 
-	p->pd_flags = 0;
+	/* p->pd_flags = 0;		done by above MemSet */
 	p->pd_lower = SizeOfPageHeaderData;
 	p->pd_upper = pageSize - specialSize;
 	p->pd_special = pageSize - specialSize;
-- 
2.25.1

#13Michael Paquier
michael@paquier.xyz
In reply to: Bharath Rupireddy (#12)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Thu, Apr 08, 2021 at 07:45:25AM +0530, Bharath Rupireddy wrote:

On Wed, Apr 7, 2021 at 11:47 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

I wanted to comment out p->pd_flags = 0; in PageInit similar to the
pd_prune_xid just for consistency.
/* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */

As I said above, just for consistency, I would like to see if the
attached one line patch can be taken, even though it doesn't have any
impact.

FWIW, I tend to prefer the existing style to keep around this code
rather than commenting it out, as one could think to remove it, but I
think that it can be important in terms of code comprehension when
reading the area. So I quite like what 96ef3b8 has undone for
pd_flags, but not much what cc59049 did back in 2007. That's a matter
of taste, really.
--
Michael

#14Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Michael Paquier (#13)
Re: Can we remove extra memset in BloomInitPage, GinInitPage and SpGistInitPage when we have it in PageInit?

On Thu, Apr 8, 2021 at 1:22 PM Michael Paquier <michael@paquier.xyz> wrote:

On Thu, Apr 08, 2021 at 07:45:25AM +0530, Bharath Rupireddy wrote:

On Wed, Apr 7, 2021 at 11:47 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

I wanted to comment out p->pd_flags = 0; in PageInit similar to the
pd_prune_xid just for consistency.
/* p->pd_prune_xid = InvalidTransactionId; done by above MemSet */

As I said above, just for consistency, I would like to see if the
attached one line patch can be taken, even though it doesn't have any
impact.

FWIW, I tend to prefer the existing style to keep around this code
rather than commenting it out, as one could think to remove it, but I
think that it can be important in terms of code comprehension when
reading the area. So I quite like what 96ef3b8 has undone for
pd_flags, but not much what cc59049 did back in 2007. That's a matter
of taste, really.

Thanks! Since the main patch is committed I will go ahead and close
the CF entry.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com