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 1tAtwe-000khB-Ix for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 16:40:48 +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 1tAtwb-008GVC-PP for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 16:40:46 +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 1tAtwb-008GV1-A4 for pgsql-hackers@lists.postgresql.org; Tue, 12 Nov 2024 16:40:46 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAtwY-001ZPf-4B for pgsql-hackers@postgresql.org; Tue, 12 Nov 2024 16:40:45 +0000 Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-4609c96b2e5so38043811cf.0 for ; Tue, 12 Nov 2024 08:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wi3ck-info.20230601.gappssmtp.com; s=20230601; t=1731429641; x=1732034441; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9FKmqPUZiEGv35y54+PwepTrKG7cHIMr9ExsinUDwls=; b=AjJLP/GzodsH5gb/HmbE4hLH0TQc7njLzQsF+sR6XJliHZGmo2iRQ6sypMO3e9tO2R p1CaAzTQrkOHHu/3DrVtCB0vn/m2Te9kqnLwr6W+lBN7X4/8EB0boZLo1WO+/AcwD6x/ dnUVjlmIFvXu7jastkiDEab+EE5caCId6AVyAGY8vYbtMo90D+fUQyy9VwWOAFz2PKgq 91mIQ7+sJ2g/J2qffQ/kIk+0ooMJmVshRW4baFHghB4gNsxgRgmtbdO6lhQu4GswUixV Q1BjkR2rHCnBkq71Y30q5/uJYJSMUn23sRFUX9QnkAuIfYRxHbZSRCkFGhst/N7/Rj0k CXtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731429641; x=1732034441; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9FKmqPUZiEGv35y54+PwepTrKG7cHIMr9ExsinUDwls=; b=gzwkrY4LIvOCg2QNYMAv3gIdp0MV6+0sDCHZ8TKFS1HNHefrr96bIdmIKUVQ8BqEhG QtAD1m1nND4nbL/x1O7qJeE04JD8mwHHjqaJwUG1DM+DU+3m+B0etyOImOoa8ikNa1I6 bAFeDzuBerJHnGgcHqvhTINK/yATRcMHWwW0RmG4RmF3nqKEwtJvKd7x7Vr5kcfgq077 QGcPSLIeFblURgBWuUXwWTCTzUwDG3bbjaU0m+rw3BjQwx2HhHWnV+wYzQ8n+ylj2nPb YikeyGcnB1jfKbspQODo/gl/0c1/dxW8AU/wxG66y99mdIUZRzP2dBTZFs5n9hJepM4V BZPA== X-Forwarded-Encrypted: i=1; AJvYcCXUtAcPbmfrkXRT2ULpUq6hGsdYZ/lVqJXzuJPAdHWWgNxrNalJ3tGNW7jmS3agsp5w9kvDy15HgdY4GtH3@postgresql.org X-Gm-Message-State: AOJu0Yx/cMg9pTV2s9PCVtn/HvUPDOgs+RGypbxiHcJjVfy0lz/Ezmg7 2w6mZXs3mJw/jxeENuD8bupmrawPXtRal81GK49rUeQ9b0K6Z7UxMnuOaxEpbz0= X-Google-Smtp-Source: AGHT+IH4YrFKAoO20LVc6JwINRkedMYxjeuB4XoGdmL9g4hcyP5p7nQ6S/f8hcaqDuW7zKPhPNgXkg== X-Received: by 2002:a05:6214:428d:b0:6c1:6e3a:6d17 with SMTP id 6a1803df08f44-6d39e1673aemr230867256d6.6.1731429641436; Tue, 12 Nov 2024 08:40:41 -0800 (PST) Received: from [172.21.0.10] (pool-108-16-53-81.phlapa.fios.verizon.net. [108.16.53.81]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3961f4b51sm73031006d6.40.2024.11.12.08.40.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Nov 2024 08:40:41 -0800 (PST) Message-ID: <94fc0a8b-5d18-4a82-8082-b76a0e725788@wi3ck.info> Date: Tue, 12 Nov 2024 11:40:39 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Commit Timestamp and LSN Inversion issue To: Andres Freund Cc: Amit Kapila , Tomas Vondra , "Zhijie Hou (Fujitsu)" , Aleksander Alekseev , pgsql-hackers , shveta malik , Jan Wieck References: <11ee3489-40ba-45d6-ba6a-7c3def725e84@vondra.me> <00f7cfb2-e3a6-4bd7-b19c-fd75d3838049@wi3ck.info> <296b2c56-c688-41a0-a752-b242268691fd@wi3ck.info> Content-Language: en-US From: Jan Wieck In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, On 11/12/24 10:34, Andres Freund wrote: > I have working code - pretty ugly at this state, but mostly needs a fair bit > of elbow grease not divine inspiration... It's not a trivial change, but > entirely doable. > > The short summary of how it works is that it uses a single 64bit atomic that > is internally subdivided into a ringbuffer position in N high bits and an > offset from a base LSN in the remaining bits. The insertion sequence is > > ... > > This leaves you with a single xadd to contended cacheline as the contention > point (scales far better than cmpxchg and far far better than > cmpxchg16b). There's a bit of contention for the ringbuffer[].oldpos being set > and read, but it's only by two backends, not all of them. That sounds rather promising. Would it be reasonable to have both implementations available at least at compile time, if not at runtime? Is it possible that we need to do that anyway for some time or are those atomic operations available on all supported CPU architectures? > > The nice part is this scheme leaves you with a ringbuffer that's ordered by > the insertion-lsn. Which allows to make WaitXLogInsertionsToFinish() far more > efficient and to get rid of NUM_XLOGINSERT_LOCKS (by removing WAL insertion > locks). Right now NUM_XLOGINSERT_LOCKS is a major scalability limit - but at > the same time increasing it makes the contention on the spinlock *much* worse, > leading to slowdowns in other workloads. Yeah, that is a complex wart that I believe was the answer to the NUMA overload that Kevin Grittner and myself discovered many years ago, where on a 4-socket machine the cacheline stealing would get so bad that whoever was holding the lock could not release it. In any case, thanks for the input. Looks like in the long run we need to come up with a different way to solve the inversion problem. Best Regards, Jan