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 1qVvsP-001caV-Ry for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 15:22:34 +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 1qVvsO-00FLda-Cr for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 15:22:32 +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 1qVvsO-00FLcq-2s for pgsql-hackers@lists.postgresql.org; Tue, 15 Aug 2023 15:22:32 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qVvsK-000Hbm-PU for pgsql-hackers@postgresql.org; Tue, 15 Aug 2023 15:22:31 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3a78604f47fso5134279b6e.1 for ; Tue, 15 Aug 2023 08:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692112948; x=1692717748; 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=JwuEfDW+DmRIcaIDixSZPyG+IZJ4GXcZRPizdOWcxbc=; b=WIFizoH5jJg7KLhyQT3+kE5Ct93V6La4gpyqZpKjlIuqIgIAJJWjqeQqNCpxvgHVxv JdNWOpN2lmB0cqTNhC3+qRu9lIBjdQcMT67SIqIgfQCDBvKNDDwQr8lKdIGr00T385mP EHQMwcvQ+e9kwQY/aOX/6rDhJXK4VtmPJSztjV231tiLDXJudGgS1IIcMogGPnYRXlLF 5OKdOrrcP5OZWg3WLwqQen6gwfHeaQALHZ+laVbRuX2TKa4C+myWHcfyNcNAi7co8iXu Ge4TgG2geRqVPnWq6eXIeRJIVs1FdPsKAQD56DJtH1WQE6s7CScZk/Q2+NVw5Kt4z8bX nfDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692112948; x=1692717748; 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=JwuEfDW+DmRIcaIDixSZPyG+IZJ4GXcZRPizdOWcxbc=; b=MO1qHgFJ4LbmJzd8hGc2UsnXkkC5IuqIuiWzUyPbpY8rKZv8aAUAcfznlQHv2DjklE xrS/pslDLPn9kTkJb/xA4y4JyDuwyvNgPcBK9nu+EeB/V7ZXh1+BQ0wFS37PZroeHkCA cNY9lzyYHHSWiwY9Ox2gCoIGEGiZogd5KAP5S+Tp8yAjJGzgp1RJN5faeL/kIZr1x61y Y1RTSM9ERel7EiDLKsNrK+4BUcV65p8FMJNCG9lo2W1g6bd17w8t9vQpP4LmqKHeHgnr H/qtcpLI03siX6ieT8UKaWYEqCQjbNTds0bixG0CUg/9SoEnyg0J10WjyXXIf3os/Uc+ zvNg== X-Gm-Message-State: AOJu0YwhL4ekXNIkVK8u5TAyKhFah5LeWuLN7IlGCttFKtHSPucHQnMv cF8AOrSr3NCkVBG65t6jKHH06OSSl14= X-Google-Smtp-Source: AGHT+IGiSfKjeJI+0t1TEcDT/lJS0ijbGKu3Z8tgQNCG4dbPJISYUy7cAauk4o2Kb/yibTP/7WWn7Q== X-Received: by 2002:aca:6506:0:b0:3a7:6532:75f3 with SMTP id m6-20020aca6506000000b003a7653275f3mr13348380oim.46.1692112947954; Tue, 15 Aug 2023 08:22:27 -0700 (PDT) Received: from nathanxps13 ([2600:1700:48f8:340f:1461:f5a:50a7:967f]) by smtp.gmail.com with ESMTPSA id c6-20020a056808138600b003a463ded3a3sm5527370oiw.53.2023.08.15.08.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 08:22:27 -0700 (PDT) Date: Tue, 15 Aug 2023 08:22:24 -0700 From: Nathan Bossart To: Michail Nikolaev Cc: PostgreSQL Hackers , Tom Lane Subject: Re: Replace known_assigned_xids_lck by memory barrier Message-ID: <20230815152224.GA2296544@nathanxps13> References: <20230814153634.GB1395427@nathanxps13> 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 On Tue, Aug 15, 2023 at 12:29:24PM +0200, Michail Nikolaev wrote: >> What sort of benefits do you see from this patch? It might be worthwhile >> in itself to remove spinlocks when possible, but IME it's much easier to >> justify such changes when there is a tangible benefit we can point to. > > Oh, it is not an easy question :) > > The answer, probably, looks like this: > 1) performance benefits of spin lock acquire removing in > KnownAssignedXidsGetOldestXmin and KnownAssignedXidsSearch > 2) it is closing 13-year-old tech depth > > But in reality, it is not easy to measure performance improvement > consistently for this change. Okay. Elsewhere, it seems like folks are fine with patches that reduce shared memory space via atomics or barriers even if there's no immediate benefit [0], so I think it's fine to proceed. >> Are the assignments in question guaranteed to be atomic? IIUC we assume >> that aligned 4-byte loads/stores are atomic, so we should be okay as long >> as we aren't handling anything larger. > > Yes, 4-bytes assignment are atomic, locking is used to ensure memory > write ordering in this place. Yeah, it looks like both the values that are protected by known_assigned_xids_lck are integers, so this should be okay. One remaining question I have is whether it is okay if we see an updated value for one of the head/tail variables but not the other. It looks like the tail variable is only updated with ProcArrayLock held exclusively, which IIUC wouldn't prevent such mismatches even today, since we use a separate spinlock for reading them in some cases. [0] https://postgr.es/m/20230524214958.mt6f5xokpumvnrio%40awork3.anarazel.de -- Nathan Bossart Amazon Web Services: https://aws.amazon.com