Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1thzSc-009gGC-IG for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 23:14:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1thzRb-001lYa-Gs for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 23:13:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1thzRb-001lYR-7G for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 23:13:31 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1thzRZ-000L04-2E for pgsql-hackers@postgresql.org; Tue, 11 Feb 2025 23:13:31 +0000 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5744725401A7; Tue, 11 Feb 2025 18:13:28 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Tue, 11 Feb 2025 18:13:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1739315608; x=1739402008; bh=jXMfmKcN4A nPWhTBGuaMzGha74Y90AYPmQGGxgEkKkc=; b=CLiyEXPTcQ2T5HiC+qLnJmbVlD sFT/pfDU1vGDUfdXD3MtheYC16qpmAoPzCGlefc1q63wauDLYKmS9JC/W2dl2sgX 0VtYJW8e/KaM6pQv/6cQyQTVTLZFW4pjtItkUMG8neAtrx2cSq7V42GL3y2WY5QM S329yFqPZ9nmvN7klkGOu2ro/tat1aAKyXLlbIpch1nVGxVNaQTj6mltNrrPmLC6 LpFCl0CH9CQy1Le8bQJWkdyyz0DHIu6QsbE11wK52qcIzuIJ9fgufmnC9wkdSSNI /j2EwYJwGU/qn+7Xby9Q55LrB9zrdksd8Xy2D077hp8JfdMR+nAZdrcdnWyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1739315608; x=1739402008; bh=jXMfmKcN4AnPWhTBGuaMzGha74Y90AYPmQG GxgEkKkc=; b=LGJAE50FFgRZG2qv3xp3ctex8Kv/K0dVnvZ2Z+eHD//W/GEA/xq nV+7bLGxQJYSoGCcFF+1Bghx8Bdm8cmo/vmUZM+08USpb7rCqTtJRaeRWaXaoJwR IveG8HRM9BvFj7nj9/QpZL1nLLka41zCqQSoodOVfi5xKhBe/L5+Lkz+Cd9UlBy5 5f9URN06QVflzmGQZNaRqTajLWgvEcL5CAtqTrfEpJaj/5JQnYs7hGchpTkDlfMk dVlfNjyxDXNp1OdZztRJvG/zadvX39eL0iCb1Wd5grSGI07pBMVtwCyfoyKyoJDJ nitzATl+oyGt5/M94eZVxe6qXBtK54KL4bw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegvddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdfstddttddv necuhfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgrii gvlhdruggvqeenucggtffrrghtthgvrhhnpeeffffgledvffegtdevlefgtdeggffhvdek gfegteeiveejkeetudelveejhfeugeenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghr tghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphhoshhtghhrvg hssehjvghlthgvfhdrnhhlpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphho shhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrd hushdprhgtphhtthhopehtohhmrghssehvohhnughrrgdrmhgv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Feb 2025 18:13:27 -0500 (EST) Date: Tue, 11 Feb 2025 18:13:26 -0500 From: Andres Freund To: Tom Lane Cc: Tomas Vondra , Jelte Fennema-Nio , PostgreSQL-development Subject: Re: Bump soft open file limit (RLIMIT_NOFILE) to hard limit on startup Message-ID: References: <3203865.1739301613@sss.pgh.pa.us> <94798ef1-0f13-416a-983a-88447e434a7f@vondra.me> <7u7dbn6s2i6bf3hjzkbqaexj2bpoblqxwbkffbetl4rjv6dcom@s2uickjc5z53> <3216369.1739308717@sss.pgh.pa.us> <3226911.1739314539@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3226911.1739314539@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-02-11 17:55:39 -0500, Tom Lane wrote: > Andres Freund writes: > > So the issue would actually be that we're currently doing set_max_safe_fds() > > too late, not too early :/ > > Well, we'd rather set_max_safe_fds happen after semaphore creation, > so that it doesn't have to be explicitly aware of whether semaphores > consume FDs. Could we have it be aware of how many FDs *will be* > needed for io_uring, but postpone creation of those until after we > jack up RLIMIT_NOFILE? Yes, that should be fairly trivial to do. It'd require a call from postmaster into the aio subsystem, after set_max_safe_fds() is done, but I think that'd be ok. I'd be inclined to not make that a general mechanism for now. > I guess the other way would be to have two rounds of RLIMIT_NOFILE > adjustment, before and after shmem creation. That seems ugly but > shouldn't be very time-consuming. Yea, something like that could also work. At some point I was playing with calling AcquireExternalFD() the appropriate number of times during shmem reservation. That turned out to work badly right now, because it relies on max_safe_fds() being set *and* insists on numExternalFDs < max_safe_fds / 3. One way to deal with this would be for AcquireExternalFD() to first increase the rlimit, if necessary and possible, then start to close LRU files and only then fail. Arguably that'd have the advantage of e.g. postgres_fdw not stomping quite so hard on VFDs, because we'd first increase the limit. Of course it'd also mean we'd increase the limit more often. But I don't think it's particularly expensive. Greetings, Andres Freund