Re: [HACKERS] Parallel bitmap heap scan - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] Parallel bitmap heap scan
Date
Msg-id CA+TgmoZdJbzDd15ZAp2sK3+KATyjk+uK74Ln2FcvmLC_1M1FrQ@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] Parallel bitmap heap scan  (Dilip Kumar <dilipbalaut@gmail.com>)
List pgsql-hackers
(On Tue, Feb 28, 2017 at 10:48 AM, Dilip Kumar <dilipbalaut@gmail.com> wrote:
> 0001- same as previous with some changes for freeing the shared memory stuff.

+    if (--ptbase->refcount == 0)
+        dsa_free(dsa, istate->pagetable);
+
+    if (istate->spages)
+    {
+        ptpages = dsa_get_address(dsa, istate->spages);
+        if (--ptpages->refcount == 0)
+            dsa_free(dsa, istate->spages);
+    }
+    if (istate->schunks)
+    {
+        ptchunks = dsa_get_address(dsa, istate->schunks);
+        if (--ptchunks->refcount == 0)
+            dsa_free(dsa, istate->schunks);
+    }

This doesn't involve any locking, which I think will happen to work
with the current usage pattern but doesn't seem very robust in
general.  I think you either need the refcounts to be protected by a
spinlock, or maybe better, use pg_atomic_uint32 for them.  You want
something like if (pg_atomic_sub_fetch_u32(&refcount, 1) == 0) {
dsa_free(...) }

Otherwise, there's no guarantee it will get freed exactly once.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [HACKERS] PATCH: pageinspect / add page_checksum andbt_page_items(bytea)
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] Parallel bitmap heap scan