Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id EA9F417B105B for ; Fri, 11 May 2012 13:49:18 -0300 (ADT) Received: from exprod7og118.obsmtp.com ([64.18.2.8]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SSt1k-0002VZ-KV for pgsql-bugs@postgresql.org; Fri, 11 May 2012 16:49:17 +0000 Received: from mail-lpp01m010-f43.google.com ([209.85.215.43]) (using TLSv1) by exprod7ob118.postini.com ([64.18.6.12]) with SMTP ID DSNKT61C+u79NYtTE3/6Dg/EGfL0oTcxdu6B@postini.com; Fri, 11 May 2012 09:49:12 PDT Received: by lahg1 with SMTP id g1so1707449lah.2 for ; Fri, 11 May 2012 09:48:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=+fAQXAhzj+RmIoj/a7Hfck9SHV5Kwvq/lLaPr65c9aw=; b=blvguD1fXycBTLm7kjZ2BH/qB+sJyzIo82ef/Dtjsz7hp/Db5wcsyUp6yXijBTFNUg 5SEq3KBZls7M6fNrvlXU9dqDwymCnlNlcXsj0ooaRp2Ky6HnFRAG8ESTerwSSXIOekFt JMzIWyYsCtLqCbUggmfdnRaeIc8wdniE1BZf+Otc28IkWDHGIQBTcX55fdOFE3PEGz/7 Qn5T0IFo+/HNwXd1OFmPRFKHSws4B6ElpXvZP+3wfYPLPmpwP9otRK04hSCbQjWiwnBH VhVpxjQ4fAXdEoii63rJuD/VHz529PXz2HI38E8GznbRAgWG0223/RFrMabhAlAmQ3sy erRg== Received: by 10.152.132.166 with SMTP id ov6mr3882728lab.35.1336754936638; Fri, 11 May 2012 09:48:56 -0700 (PDT) Received: from [192.168.1.102] (dsl-hkibrasgw2-ff6cc300-200.dhcp.inet.fi. [88.195.108.200]) by mx.google.com with ESMTPS id gv8sm1070432lab.14.2012.05.11.09.48.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 May 2012 09:48:55 -0700 (PDT) Message-ID: <4FAD42F5.9060706@enterprisedb.com> Date: Fri, 11 May 2012 19:48:53 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.3) Gecko/20120329 Icedove/10.0.3 MIME-Version: 1.0 To: Simon Riggs CC: Ryan Kelly , tom Tom , pgsql-bugs@postgresql.org Subject: Re: BUG #6629: Creating a gist index fails with "too many LWLocks taken" References: <4FA7EC37.5070703@enterprisedb.com> <20120508011540.GA28140@llserver.lakeliving.com> <4FACE4C7.6070306@enterprisedb.com> <4FAD1EC1.2000502@enterprisedb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlxbq8sndThBX96TJguwun59JA4r9Fo2EOLWV2nJ3C99RjfH2SOpGioFged4wWPGv/NZYOz X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201205/68 X-Sequence-Number: 33039 On 11.05.2012 18:18, Simon Riggs wrote: > On 11 May 2012 15:14, Heikki Linnakangas > wrote: >> On 11.05.2012 16:56, Simon Riggs wrote: >>> >>> On 11 May 2012 11:07, Heikki Linnakangas >>> wrote: >>> >>>> I wonder if we should reserve a few of the lwlock "slots" for critical >>>> sections, to make this less likely to happen. Not only in this case, but >>>> in >>>> general. We haven't seen this problem often, but it would be quite >>>> trivial >>>> to reserve a few slots. >>> >>> >>> Why reserve them solely for critical sections? >> >> Because if you run out of lwlocks in a critical section, you get a PANIC. > > Yes, but why reserve them solely for critical sections? If you have an > escape hatch you use it, always Well, no, because a PANIC is much worse than an ERROR. Think of this as a spare oxygen tank while diving, rather than an escape hatch. A spare tank can save your life if you run out of oxygen while ascending, but if you run out of oxygen on the way down, you don't continue going down with just the spare tank. Imagine that you have a process that does something like this: for (i=0; i < 99; i++) LWLockAcquire(foolock[i]) START_CRIT_SECTION(); XLogInsert(...) END_CRIT_SECTION(); What happens at the moment is that XLogInsert hits the limit when it tries to acquire WALInsertLock, so you get a PANIC. If we reserved, say, 5 locks for critical sections, so that you could hold 95 locks while outside a critical section, and 5 more within on, you would get an error earlier, outside the critical section, while acquiring the "foolocks". Or if the number of foolocks acquired was less than 95, you would not get error at all. That avoids the PANIC. You can argue for just raising the limit, but that just moves the problem around. It's still possible to hit the limit within a critical section, and PANIC. Likewise, if we lower the limit, that helps us find the problems earlier in the development cycle, but doesn't change the fact that if you run too close to the edge, you run out of locks within a critical section and PANIC. Of course, nothing stops you from writing (bad) code that acquires a lot of locks within a critical section, in which case you're screwed anyway. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com