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 1uwfbN-0065Bw-B5 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Sep 2025 11:36:33 +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 1uwfbJ-0077zl-PR for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Sep 2025 11:36:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uwfbJ-0077zd-Fp for pgsql-hackers@lists.postgresql.org; Thu, 11 Sep 2025 11:36:29 +0000 Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uwfbG-001peg-2E for pgsql-hackers@lists.postgresql.org; Thu, 11 Sep 2025 11:36:28 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4cMwVm2lblz9tQ3; Thu, 11 Sep 2025 13:36:16 +0200 (CEST) Date: Thu, 11 Sep 2025 13:36:14 +0200 From: Christoph Berg To: Tomas Vondra Cc: Bertrand Drouvot , Andres Freund , Tomas Vondra , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Introduce pg_shmem_allocations_numa view Message-ID: References: <132f85de-75c8-4e21-b875-b806596c9214@vondra.me> <64e8ec11-6bb8-488b-abfc-8e67324a03fa@vondra.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wIOga72bHU5UUpAV" Content-Disposition: inline In-Reply-To: <64e8ec11-6bb8-488b-abfc-8e67324a03fa@vondra.me> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --wIOga72bHU5UUpAV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Re: Tomas Vondra > Thanks! Pushed, with both adjustments (link to kernel thread, adding the > commit hash). The PG18 Debian package is still carrying the contrib complement of this patch (see attachment). Should that be addressed before 18.0? Christoph --wIOga72bHU5UUpAV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=move-pages32 Work around a Linux bug in move_pages In 32-bit mode on 64-bit kernels, move_pages() does not correctly advance to the next chunk. Work around by not asking for more than 16 pages at once so move_pages() internal loop is not executed more than once. https://www.postgresql.org/message-id/flat/a3a4fe3d-1a80-4e03-aa8e-150ee15f6c35%40vondra.me#6abe7eaa802b5b07bb70cc3229e63a9f https://marc.info/?l=linux-mm&m=175077821909222&w=2 --- a/contrib/pg_buffercache/pg_buffercache_pages.c +++ b/contrib/pg_buffercache/pg_buffercache_pages.c @@ -390,8 +390,15 @@ pg_buffercache_numa_pages(PG_FUNCTION_AR memset(os_page_status, 0xff, sizeof(int) * os_page_count); /* Query NUMA status for all the pointers */ - if (pg_numa_query_pages(0, os_page_count, os_page_ptrs, os_page_status) == -1) - elog(ERROR, "failed NUMA pages inquiry: %m"); +#define NUMA_QUERY_CHUNK_SIZE 16 /* has to be <= DO_PAGES_STAT_CHUNK_NR (do_pages_stat())*/ + for (uint64 chunk_start = 0; chunk_start < os_page_count; chunk_start += NUMA_QUERY_CHUNK_SIZE) { + uint64 chunk_size = Min(NUMA_QUERY_CHUNK_SIZE, os_page_count - chunk_start); + + if (pg_numa_query_pages(0, chunk_size, &os_page_ptrs[chunk_start], + &os_page_status[chunk_start]) == -1) + elog(ERROR, "failed NUMA pages inquiry status: %m"); + } +#undef NUMA_QUERY_CHUNK_SIZE /* Initialize the multi-call context, load entries about buffers */ --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -689,8 +689,15 @@ pg_get_shmem_allocations_numa(PG_FUNCTIO CHECK_FOR_INTERRUPTS(); } - if (pg_numa_query_pages(0, shm_ent_page_count, page_ptrs, pages_status) == -1) - elog(ERROR, "failed NUMA pages inquiry status: %m"); +#define NUMA_QUERY_CHUNK_SIZE 16 /* has to be <= DO_PAGES_STAT_CHUNK_NR (do_pages_stat())*/ + for (uint64 chunk_start = 0; chunk_start < shm_ent_page_count; chunk_start += NUMA_QUERY_CHUNK_SIZE) { + uint64 chunk_size = Min(NUMA_QUERY_CHUNK_SIZE, shm_ent_page_count - chunk_start); + + if (pg_numa_query_pages(0, chunk_size, &page_ptrs[chunk_start], + &pages_status[chunk_start]) == -1) + elog(ERROR, "failed NUMA pages inquiry status: %m"); + } +#undef NUMA_QUERY_CHUNK_SIZE /* Count number of NUMA nodes used for this shared memory entry */ memset(nodes, 0, sizeof(Size) * (max_nodes + 1)); --wIOga72bHU5UUpAV--