Re: possible dsm bug in dsm_attach()

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: possible dsm bug in dsm_attach()
Date: 2015-03-25 10:11:15
Message-ID: CAA4eK1+NwUJ9ik61yGfZBcN85dQuNEvd38_h1zngCdZrGLGQTQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, May 6, 2014 at 11:15 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
> On Tue, May 6, 2014 at 1:14 PM, Andres Freund <andres(at)2ndquadrant(dot)com>
wrote:
> > On 2014-05-06 08:48:57 -0400, Robert Haas wrote:
> >> On Tue, May 6, 2014 at 8:43 AM, Andres Freund <andres(at)2ndquadrant(dot)com>
wrote:
> >> > The break because of refcnt == 1 doesn't generally seem to be a good
> >> > idea. Why are we bailing if there's *any* segment that's in the
process
> >> > of being removed? I think the check should be there *after* the
> >> > dsm_control->item[i].handle == seg->handle check?
> >>
> >> You are correct. Good catch.
> >
> > Fix attached.
>
> Committed, thanks.
>

dsm_create(Size size, int flags)
{
..
/* Lock the control segment so we can register the new segment. */
LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE);

..
/* Verify that we can support an additional mapping. */
if (nitems >= dsm_control->maxitems)
{
if ((flags & DSM_CREATE_NULL_IF_MAXSEGMENTS) != 0)
{
dsm_impl_op(DSM_OP_DESTROY, seg->handle, 0, &seg->impl_private,
&seg->mapped_address, &seg->mapped_size, WARNING);
if (seg->resowner != NULL)
ResourceOwnerForgetDSM(seg->resowner, seg);
dlist_delete(&seg->node);
pfree(seg);
return NULL;
}
..
}

Is there a reason lock is not released in case we return NULL in above
code?

I am facing an issue in case we need to create many segments for
large inheritance hierarchy. Attached patch fixes the problem for me.

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

Attachment Content-Type Size
release_lock_dsm_v1.patch application/octet-stream 501 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rajeev rastogi 2015-03-25 10:17:25 Re: Parallel Seq Scan
Previous Message Kouhei Kaigai 2015-03-25 10:09:42 Re: Custom/Foreign-Join-APIs (Re: [v9.5] Custom Plan API)