Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duNC5-00009B-JS for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Sep 2017 18:24:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1duNC4-0005HW-TA for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Sep 2017 18:24:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duNC4-0005H9-47 for pgsql-hackers@postgresql.org; Tue, 19 Sep 2017 18:24:24 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1duNC0-0004qA-Bn for pgsql-hackers@postgresql.org; Tue, 19 Sep 2017 18:24:23 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B553120FF9; Tue, 19 Sep 2017 14:24:18 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 19 Sep 2017 14:24:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=pm3Voj0t7jCJhhDje+ qpjj46d2S6TEK0wme74lIypTo=; b=H60jOgcsD8qx0ZuOSOPLfIjLr9XI9ux/tJ 2DU1wXdG337CcwLkcDRrhPvtkaAoAFrfFEU5hNq0G/EmZN1xdGeLMxaV4zsKkd8q SpKRFBcFaB3ZmWSZxlT87hqfOEgZT3GhS0Lb69QK5cWBN91SfWLqm9jrS4ivK73l 72/9yoHK1pu+llPRzC9CDyD5MVyPY8vSPSF9z5r4Jpqp/R1/8fImbQF/rOA768g9 ywhWJDD91CyFkhK90En6fAY6mirPKLGe03ahNj5hOncmF6xoa4L4n4JHBTZ1JUk0 GOi0X3awZfgzc1ZCCPg89MLh6xfbfRTWlIw02WGhQFgFn2ZlYhcw== X-ME-Sender: X-Sasl-enc: 6PmSPo07hJbnSi7qDGOHZQK+Pr0g1hRW8dOOg04qvQ0i 1505845458 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 6E0F32444E; Tue, 19 Sep 2017 14:24:18 -0400 (EDT) Date: Tue, 19 Sep 2017 11:24:17 -0700 From: Andres Freund To: Tom Lane Cc: Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup. Message-ID: <20170919182417.mf7xalft7e7veddi@alap3.anarazel.de> References: <20170918103213.nhlmfh5v3qrgoskg@alap3.anarazel.de> <20170918180439.mgxvnbmxzb6br57t@alap3.anarazel.de> <20170919161012.i3j4ugktf2xkr4kb@alap3.anarazel.de> <17513.1505838240@sss.pgh.pa.us> <20170919165111.bsocu7ev2oaox4mx@alap3.anarazel.de> <20170919170821.drrwlt6wcoytlgup@alap3.anarazel.de> <19645.1505841328@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19645.1505841328@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017-09-19 13:15:28 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2017-09-19 13:00:33 -0400, Robert Haas wrote: > >> You mean, in the postmaster? > > > Yes. We try to avoid touch shmem there, but it's not like we're > > succeeding fully. See e.g. the pgstat_get_crashed_backend_activity() > > calls (which do rely on shmem being ok to some extent), pmsignal, > > BackgroundWorkerStateChange(), ... > > Well, the point is to avoid touching data structures that could be > corrupted enough to confuse the postmaster. I don't have any problem with > adding some more functionality to pmsignal, say. Given that we're ok with reading pgstat shared memory entries, I think adding a carefully coded variant of SendProcSignal() should be doable in a safe manner. Something roughly like int PostmasterSendProcSignal(pid_t pid, ProcSignalReason reason) { volatile ProcSignalSlot *slot; /* * As this is running in postmaster, be careful not to dereference * any pointers from shared memory that could be corrupted, and to * not to throw errors. */ for (i = 0; i < NumProcSignalSlots; i++) { slot = &ProcSignalSlots[i]; if (slot->pss_pid == pid) { /* * The note about race conditions in SendProcSignal applies * here, too */ /* Atomically set the proper flag */ slot->pss_signalFlags[reason] = true; /* Send signal */ return kill(pid, SIGUSR1); } } errno = ESRCH; return -1; } As all the memory offsets are computed based on postmaster process-local variables, this should be safe. I'd rather like to avoid a copy of the procsignal infrastructure if we don't need it... Greetings, Andres Freund -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers