Re: Typo in bufmgr.c that result in waste of memory

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Takashi Horikawa <t-horikawa(at)aj(dot)jp(dot)nec(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Typo in bufmgr.c that result in waste of memory
Date: 2016-02-19 05:20:25
Message-ID: CAA4eK1KVPfSm9Dbbg-c18x5Nw20vjPx1_F2VNLhh92K8jq8Pbg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Feb 19, 2016 at 8:28 AM, Takashi Horikawa <t-horikawa(at)aj(dot)jp(dot)nec(dot)com>
wrote:
>
> Hi all,
>
> I have just found a typo in the source code (not in a comment) of bufmgr.c
> that result in waste of memory. It might be a 'bug' but it does not result
> in any incorrect operation but just results in waste of a few memory
> resource.
>
> As sizeof(PrivateRefCountArray) found in InitBufferPoolAccess() is 64 and
> sizeof(PrivateRefCountEntry) which should be used here is 8, this typo
> produces 56 byte of unused memory area per one PrivateRefCount entry in
the
> hash table. I think this result in not only the waste of memory but also
> reduces the cache hit ratio.
>
> ----
> void
> InitBufferPoolAccess(void)
> {
> HASHCTL hash_ctl;
>
> memset(&PrivateRefCountArray, 0, sizeof(PrivateRefCountArray));
>
> MemSet(&hash_ctl, 0, sizeof(hash_ctl));
> hash_ctl.keysize = sizeof(int32);
> X hash_ctl.entrysize = sizeof(PrivateRefCountArray);
> O hash_ctl.entrysize = sizeof(PrivateRefCountEntry);
>
> PrivateRefCountHash = hash_create("PrivateRefCount", 100, &hash_ctl,
> HASH_ELEM | HASH_BLOBS);
> }
> ----
>

Your proposed change seems right to me.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-02-19 07:33:21 Re: WAL logging problem in 9.4.3?
Previous Message Joshua D. Drake 2016-02-19 04:55:36 Re: Relaxing SSL key permission checks