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 1uVCxD-00FMuh-5M for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Jun 2025 17:33:35 +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 1uVCxB-003ab5-7R for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Jun 2025 17:33:33 +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 1uVCxA-003aai-SK for pgsql-hackers@lists.postgresql.org; Fri, 27 Jun 2025 17:33:33 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uVCx8-004RdF-27 for pgsql-hackers@lists.postgresql.org; Fri, 27 Jun 2025 17:33:33 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3a528243636so1500918f8f.3 for ; Fri, 27 Jun 2025 10:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751045608; x=1751650408; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5yLw13QTe7eiaQp/SpYd757UFOAnyxRW+yi8Zf3uZlA=; b=f7TvgR93JcKazm9fjJeGfEDYE+yvM9Kk+reurC+1uH7Uqf6kniyO4XHrH+ePjm65UM dVR6MXtiew3A2cGi2tLtSGQ9GvoxYCTbhLK19NoClJazglshipkg+7AzZE86UI5q3+SI ijJ7GmNQlfnPoyl4X3DPvoQZJgZhdBsrvOgB3i8brAPJXU8LBRbORzA5CcxYoHfxWWJX 8R+h4XkhBXNicGcU7W5OJHcPvkRzzM7uLqfR3uf1PNFAN2Ps8C/+kUlJOsBaJ09zkeQh V9nKORPlpJTqDO9neafN0HLcUHEj2aCDGB702pwSSHtne2AdPc6A5osg4l+rU6BBBRhg O6Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751045608; x=1751650408; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5yLw13QTe7eiaQp/SpYd757UFOAnyxRW+yi8Zf3uZlA=; b=uqc4U7iMOrJAKGmOE7ip6PuzWzs6Cwi4cci0s7rE3itedP8uiIp1mVKx167zfX4T+k WhCxp1i1eCRjnjHvuBJrSnE0J7B96lJ1xWmRjZ3acEZeOwBJ/ApuOkZUJ4SsEBCLJML0 dPQapRsJSm8uHl3xSwr7jewizPpKlzk1nulUcSR1tE2WozydJ3fdBQ+X3STKOi7h12yM O0Wn/bQl/QDX5tpuGLZQ8eyXiip9jdEm9Sts1yQHh96VDi5kmrv1fi2AddFE7yciiBM2 mFPwzYghZM0KsSEnrEVVRiNBsD4XbCF9vm+7v5pDrNeAeIg+on07vFKwnJ6694zTcr+o j7hg== X-Forwarded-Encrypted: i=1; AJvYcCX3qQif6kfacmMXma4lEInBcKyYVt68lOwxn5EpjUTucMPR5xdfOA76aMDE0GWPFhU85ZxgskzUr0vNkpmj@lists.postgresql.org X-Gm-Message-State: AOJu0YzCm+Dxh8vf+hn6Af1n8OhG5gPMfzxlLZjJnLwyWgmtPvEhRwq/ 9x0XipVi6MS8odwSQw05Wxzaln7t7c0MdPZW65N5h7SZwPvcf1+wRBTxuXTv1w== X-Gm-Gg: ASbGncvJdjr/Z+Y7ngk4N0YAA2f3lrdVsTx3UFBRN3ZoM+unucbzZIplIm/n6MAKMmL XlKJaFwGEe5vnfd6r+LFfUE2J2BaFA4FJVKPyCDKwCxYSPWwMVrx27oohisYsDS+DgLm5crOaNj XGMLMelwlXuua5wicWz0XRGp1HuBmZZ6oQrgZZpkXFaVWxNk+XWGMyIlxd2J3j0o5Cxyjs2a92+ l3IjRH/Z/y6s6pvKGw5sJLxIpWYLrkfiL6ynE0IfxZVKsK42pnapvDpwb1nq4kw0PHbBrllyvXM FFvKUxRlfWFONWJ51AIQSWi6R0s7QtEPAZgMp7Y0LNpFhIJDk2PVMbcV7xPWmxGnLmpyTVghcep LMJcW3WibS1cdN+vC/NlWZdaOvzYoLqwoJAFvFkOHt+rcx7Uqk3UTfcDw3Hizdu8aANfxdZLml8 U3weWNGXDdEg6yYl14Jw== X-Google-Smtp-Source: AGHT+IHfItv1BmiPt2T5UGhuw7o3owEQ/eX1gGaE2ilphUTr06zDIcn8hgGpzuQZQDmopHwkstyW3w== X-Received: by 2002:a5d:4d11:0:b0:3a5:51a3:3a2 with SMTP id ffacd0b85a97d-3a90038ac3dmr3713778f8f.45.1751045607633; Fri, 27 Jun 2025 10:33:27 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4538233c749sm88394555e9.4.2025.06.27.10.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jun 2025 10:33:27 -0700 (PDT) Date: Fri, 27 Jun 2025 17:33:26 +0000 From: Bertrand Drouvot To: Tomas Vondra Cc: Christoph Berg , Andres Freund , Tomas Vondra , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Introduce pg_shmem_allocations_numa view Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Jun 27, 2025 at 04:52:08PM +0200, Tomas Vondra wrote: > Here's three small patches, that should handle the issue Thanks for the patches! > 0001 - Adds the batching into pg_numa_query_pages, so that the callers > don't need to do anything. > > The batching doesn't seem to cause any performance regression. 32-bit > systems can't use that much memory anyway, and on 64-bit systems the > batch is sufficiently large (1024). === 1 -#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \ +#define pg_numa_touch_mem_if_required(ptr) \ Looks unrelated, should be in 0002? === 2 I thought that it would be better to provide a batch size only in the 32-bit case (see [1]), but I now think it makes sense to also provide (a larger) one for non 32-bit (as you did) due to the CFI added in 0003 (as it's also good to have it for non 32-bit). > 0002 - Silences the valgrind about the memory touching. It replaces the > macro with a static inline function, and adds suppressions for both > 32-bit and 64-bits. The 32-bit may be a bit pointless, because on my > rpi5 valgrind produces about a bunch of other stuff anyway. But doesn't > hurt. > > The function now looks like this: > > static inline void > pg_numa_touch_mem_if_required(void *ptr) > { > volatile uint64 touch pg_attribute_unused(); > touch = *(volatile uint64 *) ptr; > } > > I did a lot of testing on multiple systems to check replacing the macro > with a static inline function still works - and it seems it does. But if > someone thinks the function won't work, I'd like to know. LGTM. > 0003 - While working on these patches, it occurred to me we could/should > add CHECK_FOR_INTERRUPTS() into the batch loop. This querying can take > quite a bit of time, so letting people to interrupt it seems reasonable. > It wasn't possible with just one call into the kernel, but with the > batching we can add a CFI. Yeah, LGTM. [1]: https://www.postgresql.org/message-id/aFuRoUieUVh%2BpMfZ%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com