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 1uUJGD-001BuH-Pa for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jun 2025 06:05:29 +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 1uUJGB-0007ua-SS for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jun 2025 06:05:28 +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 1uUJGB-0007uO-Ej for pgsql-hackers@lists.postgresql.org; Wed, 25 Jun 2025 06:05:28 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uUJG9-003rKU-0n for pgsql-hackers@lists.postgresql.org; Wed, 25 Jun 2025 06:05:27 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3a548a73ff2so1131021f8f.0 for ; Tue, 24 Jun 2025 23:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750831524; x=1751436324; 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=StgEYDtSHEkFjM9TfLxZQK/DskmWZXnocYE+o69CasQ=; b=Pwgzu0uS8Cf0Q/Sgn2qfNzyfHjGZCYxyQSgIff2JV3WuEFpnnohNnXAjasL95QTob8 91xo4OvawtZ6zceXnZ512VBfNvjInytvlHmz9TuLB1iTVG6qmVAohftBkw4ZHzdSm8dL d0C6zfvrRumCvlA25U08wBdo1Lqr+ka1F53RLANHG3Rk/LgUFtvi2mSWpfKbKHkhzA42 8AMLJdLq5+0neTQYZF26eslKh6tu50aDYO79B3+8r9hJNMrAD/3UtFshVjoSpfD3jQFi 4dDOjo6X4/L1mDTt28zNZD1M7yWjNfQr6MJEbBYbCqLwS8q9O97VT0KSthVt6bsVIeXi Gfgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750831524; x=1751436324; 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=StgEYDtSHEkFjM9TfLxZQK/DskmWZXnocYE+o69CasQ=; b=jH28rsSrY/vi/CDn/7/yOEsbmzuTZKb1YwNtkFg+8Noow/wTMrpdf0vQraAvTo7OUM qmMvK2f2t9PbBmnxEOOADj86a2ZjSaBsYPaWejA3pwsqFXx5Yb/FcqB24u17AaSVsSPz PtxbUnuJRJVFc6d4IGpknif50zbRMXc9NdFodgEU3G5dpRqeIi30w8NwLDochkZ+lWqF I5QON8bVjbkSRTAiMwUGgkkx79qGh1oPdJNx41HrjT6C9yKVwy8oPzBVXjbAft7qCXJY Dxg6cfIhSLM2fwItPYqA+cQU57XJ3458k1xKmrybztbQbEDfpvdvwQXzfDMBYKtZpwSx Q/4A== X-Forwarded-Encrypted: i=1; AJvYcCWQsQoQpLsb9bOJyw4Z5xdsV1LUwv1jV/eGnBKYTTFZWay9y+pUf9jOL/qasuIZJvKga0gTgqGqBSmXvkrk@lists.postgresql.org X-Gm-Message-State: AOJu0YxjTC/+21+RRevlVxWCg09RLkamwSbe2MNb2Wm2m4yYHSgQpFX5 fQ4IpmGEIJjpY8dhAdtJtYdzOAVdvyBqj0ekLTUyCdQ25xTNvYnjXxxt X-Gm-Gg: ASbGncvjVdlpMr5OEpAXiapdY4DqzZSKxqcnLkKdkIV8NveG+gLEFvySKa4Eo4E/5Ps TdMduvmB5bAUiRZzbE/t2voBNLJKPEJoBo+hxctriXsatFqe0e6/J9BZkoP+x9r30o1hLHMQiri 7m28197dGqhiS5U3b9wI/GcMjDKoz4fOjqvLAc6KgiawXKLGRFm8ESJglf0JJxK4b2euY5qWe5N Q1FJDb7lrSpT0VuKs2Hdl9iCRyy122L2euolPdVz35CsAcMqr/R+hjZ525pyyyslGE2W2MYgUB/ mEFBcwYm3aMShlGfREozvUhSb8Jx1uRreE/lm6oi+ONBjhC2a8kBNfhOvKocm/NHEGVP2Qywe+A lV1N+Ur/DLIljiGV+fWtJcPgHa2WSxvjHj356p4Ybcr/NkfXbkXwXpZZnQ+/0WJ9sCK1u2S0rbE NsxH/oV43U6vYDnT1ubw== X-Google-Smtp-Source: AGHT+IFMoRN5mKez/O6s5YhItGRPyJ/FNhjBDO6/g3vnZg1UN5sVTaTMy+qSuNqRCwmrlhIRR5Fkpg== X-Received: by 2002:a05:6000:4a19:b0:3a5:243c:6042 with SMTP id ffacd0b85a97d-3a6ed5b8e60mr1023153f8f.2.1750831523352; Tue, 24 Jun 2025 23:05:23 -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 ffacd0b85a97d-3a6e80f2792sm3682731f8f.54.2025.06.24.23.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 23:05:22 -0700 (PDT) Date: Wed, 25 Jun 2025 06:05:21 +0000 From: Bertrand Drouvot To: Christoph Berg Cc: Tomas Vondra , Andres Freund , Tomas Vondra , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Introduce pg_shmem_allocations_numa view Message-ID: References: <0643ae61-cf9d-482c-9b2c-fb861b24fd22@vondra.me> <6342f601-77de-4ee0-8c2a-3deb50ceac5b@vondra.me> <8649a4e3-c60d-4f37-aa6f-e7e7c14c581e@vondra.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="iGQ7zMJ2Rzk0wyeD" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --iGQ7zMJ2Rzk0wyeD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Tue, Jun 24, 2025 at 04:41:33PM +0200, Christoph Berg wrote: > Re: Bertrand Drouvot > > Yes, I think compat_uptr_t usage is missing in do_pages_stat() (while it's used > > in do_pages_move()). > > I was also reading the kernel source around that place but you spotted > the problem before me. This patch resolves the issue here: > > diff --git a/mm/migrate.c b/mm/migrate.c > index 8cf0f9c9599..542c81ec3ed 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -2444,7 +2444,13 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages, > if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status))) > break; > > - pages += chunk_nr; > + if (in_compat_syscall()) { > + compat_uptr_t __user *pages32 = (compat_uptr_t __user *)pages; > + > + pages32 += chunk_nr; > + pages = (const void __user * __user *) pages32; > + } else > + pages += chunk_nr; > status += chunk_nr; > nr_pages -= chunk_nr; > } > Thanks! Yeah, I had the same kind of patch idea in mind. > > + #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) { > > Perhaps optimize it to this: > > #if sizeof(void *) == 4 > #define NUMA_QUERY_CHUNK_SIZE 16 /* has to be <= DO_PAGES_STAT_CHUNK_NR (do_pages_stat())*/ > #else > #define NUMA_QUERY_CHUNK_SIZE 1024 > #endif > > ... or some other bigger number. I had in mind to split the batch size on the PG side only for 32-bits, what about the attached? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --iGQ7zMJ2Rzk0wyeD Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Work-around-Linux-kernel-bug-in-do_pages_stat.patch"