Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNP2e-0003uA-M1 for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2016 18:37:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bNP2d-00087O-FK for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2016 18:37:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bNP1w-0007N5-VH for pgsql-bugs@postgresql.org; Wed, 13 Jul 2016 18:37:09 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bNP1p-0003yq-2O for pgsql-bugs@postgresql.org; Wed, 13 Jul 2016 18:37:07 +0000 Received: by mail-wm0-x22f.google.com with SMTP id o80so82320764wme.1 for ; Wed, 13 Jul 2016 11:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=c6CwU2bWYCagjmx7BSFHYjzdm/wb8lPop/KJo1szb+0=; b=FH4T6fxD+tIl0MmpSANs/WviZz2TqqHRKH0bbTGXgHS+dtV+4iPGxXQriO9IbUkh3+ s4+thiADOMw0Y5WddVko/lqqrnlm6LQ5mA6O9GQ/JXtmA5cEpSwCaLJiM9xNlakheRqu kpyiELUWrh9rGRuDuSd2TbXiN0DPtQMS+coVpB6QmW9rxF0tyO0YxZbO7big9hWsp6Rk hidNfNjiOK/pH/JKErRVgJ72YQ5uN9glQ3JpWxJZjLNIBMv3hRdrao5SzkFElXwMJbP0 HrXrduhtF8gHX1otO5LKPivFh47viEnIHJ/zXlHCvrArHskDBFUFqk/9EpuczYBlwLSG Jr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=c6CwU2bWYCagjmx7BSFHYjzdm/wb8lPop/KJo1szb+0=; b=ReuLYcy9vfFmdFM8xB1PdI4yhd87wBuUKU55GCQf5pF+wLm4urZey1y6edr5aRat6C dSJEXPCDIMV+Fy2dacu/h5tWf32VrSc9kLh9Em/8OibRP24TM6k24do8B7Wsbsvqjfpi UOUHip3eqL0gI/G56/vLpaGhaIx/MPSl9qiWSgDeQ3jrZdz9MawPikuLhbGpgcauhL01 jVERc0Je4SiW3dVN3/gxXzLzZqGQ6U25IGkwR2cCVDteSPaOiS7O9sKEH5rhWdV+Ekb4 741/UefU7ztDdZRQx0I4MjysRut94ZiklMXGVB4Va8VVpVCS2110kQidTZcbEnnRhjaA CYyQ== X-Gm-Message-State: ALyK8tIHy2ZNc8S9MNjTbh5xrdnjy3azZLfA8jqTFnRNJbfPf5saULBI86hZmF4lNUt68vsEjr4K5HRbKCsVIYh29PO7eFsWG5zbt+t7BJIE70b7oVulmflwYehbtvx0pZoOw3gKN5hNO3XD7mw4sp0I71Ovo1W7tbE/pY76ThL/f32N+Pdpdf3+g9sMALZaNqe5cAj7 X-Received: by 10.28.152.5 with SMTP id a5mr12213619wme.76.1468435018727; Wed, 13 Jul 2016 11:36:58 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id sb15sm2145897wjb.3.2016.07.13.11.36.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 11:36:58 -0700 (PDT) Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function To: pgsql-bugs@postgresql.org References: <878txea5b4.fsf@news-spur.riddles.org.uk> <20160706212600.GA649263@alvherre.pgsql> From: Tomas Vondra Message-ID: Date: Wed, 13 Jul 2016 20:36:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 07/06/2016 11:40 PM, Peter Geoghegan wrote: > On Wed, Jul 6, 2016 at 2:26 PM, Alvaro Herrera wrote: >>> So I think this is primarily an artifact of doing so much retail >>> palloc/pfree in a single memory context. >> >> As I recall, this is the main reason Andres stuck the slab cache in >> reorderbuffer. Maybe it'd be worthwhile to implement a different >> MemoryContext tailored to this use case, and remove the slab cache >> stuff. > > I withdraw my remarks on that commit -- I don't think that's what it is now. > > I had luck adding a new child memory context for tuplesort.c in commit > 0011c0091e886b874e485a46ff2c94222ffbf550. This allowed tuplesort.c to > blow away the free list via a new call to MemoryContextReset(). This > didn't even remove *any* pfree() operations in the affected codepath, > but was still quite effective. > > I'm not sure that that's comparable, but it may be an interesting case > that others are not aware of. > I'm not very familiar with the reorderbuffer.c, but my understanding is that it's an object with potentially very long lifetime, doing a lot of interleaved palloc/pfree (or accessing the slab cache). The lifetime of tuplesort is much shorter with clear boundaries, and probably does not need palloc/pfree interleaved that much. The separate memory context would probably fix the pfree issue, but I'm afraid it'd make all pfree() calls pointless useless as AllocSet keeps all pfreed chunks in internal freelists and only releases them at the end. Which means the memory context would allocate memory and then keep it until it's destroyed, meaning the slab limits would be pointless. I do have a few rough ideas how this might be improved, but it's a bit rough at this point. The distinguishing feature of the slab allocator is that all objects have exactly the same size, which makes the "many freelist" idea in AllocSet a bit pointless. (Let's ignore that we use the same context for three different objects for now.) So I'm thinking about adding a new MemoryContext implementation, e.g. SlabMemoryContext, which will only allow allocating pieces with a particular size. Then we can get rid of the AllocSet pieces that deal with freelists, and also make sure we know which blocks contain free chunks so that we can reuse chunks from more full blocks, etc. But I haven't tried coding anything, so maybe it's all stupid. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs