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 1uChlN-0019dj-1S for pgsql-general@arkaria.postgresql.org; Wed, 07 May 2025 16:36:53 +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 1uChlK-00F6PD-HI for pgsql-general@arkaria.postgresql.org; Wed, 07 May 2025 16:36:50 +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 1uChlK-00F6P5-37 for pgsql-general@lists.postgresql.org; Wed, 07 May 2025 16:36:50 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uChlH-000f20-05 for pgsql-general@lists.postgresql.org; Wed, 07 May 2025 16:36:49 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5fbf29d0ff1so51240a12.0 for ; Wed, 07 May 2025 09:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746635807; x=1747240607; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zFnZkB8DbersAZuC0zoryUzjJqlnfsnHPyQE/6QEdIY=; b=KF0xfy2l+VHFJOaradRI76TO1TDiYq+EMM7Vg0iNlcGKJY9a/7h6DVcmwTONaLEWXO AMGmGpBdX3wEyyr4bpqR1nEj8nlT/HDuXrzUmsW4vFfQHwQS0AY1f21fVdKCC0qXuy15 Rxm6G35+hkkxAPqWCWC0EUNhvz+hb9YwNIeSSAjafAWlG3vPtJ/gw/uSog1lqvYAB0pz M9hB2OsSSLQfv3eSKDgHqctDJENpjmXPc7+iXqWP54A/rV1MXgmV7yXxaIt8Tp9s1HC6 92kqzvOjfu6gstQCKw9RauqHyEaVfegcSuV9w6pdr/PebVUjlgbi6hVfOwYPaYOm7HyK OO+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746635807; x=1747240607; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zFnZkB8DbersAZuC0zoryUzjJqlnfsnHPyQE/6QEdIY=; b=hxmdF5WqShfI6aEvEq4ji1Z1g8r+CRCt9ArQNXd2dvsTVBipLu3Hq1qed0GUKXJTji JDrQRh2O92UN5Zi5FmK7zXJlvtL8OHqdZqFGgXtIstdxJOqjO3Lhd1lG0zashclIWW76 WXvPU0DQi3VXAjp9Gb8i79X348UbbbP5gTq+QRnmwW8IqMWeRe0/u2pmMR2FS6DlGjJd poRHd9sMvghhsZy1BTwTR67fwdbwqWlfYZ6T5SzSctyvoWL3fD3b0UDcop9rgUyN7Yg7 WNudpQPAe0KVfedK32wAGs2+gcUG32C/st55LcqCb4DzoNKUpBnGCp/7st5QcE/qlHD2 ltGQ== X-Gm-Message-State: AOJu0Yy6hp9CHnc3TmPKIz0ymFhABBqGFQ2w0Vlv/StEng4ULUH+HyCB 3CcSLdUje435Li0MJ0wIONNHDJfjzQK7EEvGx7Zh9Zr2NxZ4IS8Qr70Ea84vMCu4Us/XC+dusoZ R3Y+dscuhg/xcOXmXmFZBvCGg+6g= X-Gm-Gg: ASbGncscUTsJ3KKgzje367f4BE9Zb2bzEinIuhNm9pdaC7m0C530027/E3irRt3NZ9k BqTbi+PlYuY3Otk7WvS1odqSsPguTxJbwRi/CQ2XWHYEoZkHPOVEhgOoEymGdTVeb5t1WMXPnRQ zs7uo9KZ5/diR/3IOjUVkpWi0= X-Google-Smtp-Source: AGHT+IHbddQKNX0xiTeFP1gqGWydifoWcrZZyI5rr/JVzvNWQqkO/kTMOlaoJWXGOKiwW3fovkLV3wvqKI1gvmaC0Ek= X-Received: by 2002:a05:6402:4488:b0:5fb:da2a:52a4 with SMTP id 4fb4d7f45d1cf-5fbe9e139bamr2841435a12.15.1746635806465; Wed, 07 May 2025 09:36:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bogdan Siara Date: Wed, 7 May 2025 18:36:20 +0200 X-Gm-Features: ATxdqUGDYlSoU-bjALXlh1ZFG5w2wpQ_kFECXhGqbjEUbjksTrA8nLvorjGJqy8 Message-ID: Subject: Re: huge_pages=on cause could not map anonymous shared memory: Cannot allocate memory To: Alicja Kucharczyk Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000cbe3ec06348e560e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cbe3ec06348e560e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Alicja, Thanks for your advice, now postgresql works fine with 'huge_pages=3Don'. Regards Bogdan =C5=9Br., 7 maj 2025 o 14:17 Alicja Kucharczyk napisa=C5=82(a): > Hi Bogdan, > The root cause here is that the number of huge pages you've configured > (vm.nr_hugepages =3D 980) is not sufficient. > Each huge page on your system is 2=E2=80=AFMB in size, so 980 pages give = you > roughly 1.96=E2=80=AFGB of memory (980 =C3=97 2=E2=80=AFMB). However, Pos= tgreSQL is clearly > requesting about 2.2=E2=80=AFGB of shared memory (specifically, 220410675= 2 bytes as > shown in the error message you provided), which exceeds what's available > through huge pages. > > That=E2=80=99s why PostgreSQL fails to start when huge_pages =3D on - it = requires > the entire shared memory segment to come from huge pages and refuses to > fall back to regular ones. > > Earlier, you had the huge_pages setting commented out, which means > PostgreSQL used the default value: huge_pages =3D try. In that mode, it f= irst > attempts to use huge pages, but if that fails (like in your case due to > insufficient allocation), it falls back to standard memory pages =E2=80= =94 which is > why the instance started without issues then. > > To fix the issue, you should increase vm.nr_hugepages to at least 1100 to > fully cover the shared memory request (you can go a bit higher to be safe > and then reduce it as described in the article I'm pasting the link to). > > Also, a side note: max_connections =3D 1000 is quite high for an instance > with 8=E2=80=AFGB of RAM and only 2 vCPUs. Even if huge pages are properl= y > allocated, such a high number of connections can lead to performance > issues. You might want to consider lowering it or using a connection pool= er > like PgBouncer. > > If you=E2=80=99d like to understand how huge pages work in PostgreSQL, in= cluding > how to calculate memory needs and configure the OS properly, I wrote a > detailed article some time ago (still valid). It=E2=80=99s in Polish, whi= ch I > assume is fine for you: > https://linuxpolska.com/pl/baza-wiedzy/blog/postgres-pamieci-ram-tipstric= ks/ > > best regards, > Alicja Kucharczyk > >> --000000000000cbe3ec06348e560e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Alicja,
Thanks for your advice, now postgresql work= s fine with 'huge_pages=3Don'.
Regards
Bogdan

=C5=9Br., 7 maj 2025 o 14:17=C2=A0Alicja Kucharcz= yk <zaledwie10minut@gmail.c= om> napisa=C5=82(a):
Hi Bogdan,
The root cause here = is that the number of huge pages you've configured (vm.nr_hugepages =3D= 980) is not sufficient.
Each huge page on your system is 2=E2=80=AFMB i= n size, so 980 pages give you roughly 1.96=E2=80=AFGB of memory (980 =C3=97= 2=E2=80=AFMB). However, PostgreSQL is clearly requesting about 2.2=E2=80= =AFGB of shared memory (specifically, 2204106752 bytes as shown in the erro= r message you provided), which exceeds what's available through huge pa= ges.

That=E2=80=99s why PostgreSQL fails to start when huge_pages = =3D on - it requires the entire shared memory segment to come from huge pag= es and refuses to fall back to regular ones.

Earlier, you had the hu= ge_pages setting commented out, which means PostgreSQL used the default val= ue: huge_pages =3D try. In that mode, it first attempts to use huge pages, = but if that fails (like in your case due to insufficient allocation), it fa= lls back to standard memory pages =E2=80=94 which is why the instance start= ed without issues then.

To fix the issue, you should increase vm.nr_= hugepages to at least 1100 to fully cover the shared memory request (you ca= n go a bit higher to be safe and then reduce it as described in the article= I'm pasting the link to).

Also, a side note: max_connections = =3D 1000 is quite high for an instance with 8=E2=80=AFGB of RAM and only 2 = vCPUs. Even if huge pages are properly allocated, such a high number of con= nections can lead to performance issues. You might want to consider lowerin= g it or using a connection pooler like PgBouncer.

If you=E2=80=99d l= ike to understand how huge pages work in PostgreSQL, including how to calcu= late memory needs and configure the OS properly, I wrote a detailed article= some time ago (still valid). It=E2=80=99s in Polish, which I assume is fin= e for you: https://linuxpolska.com/pl/baza-= wiedzy/blog/postgres-pamieci-ram-tipstricks/

b= est regards,
Alicja Kucharczyk
--000000000000cbe3ec06348e560e--