Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5Vsq-0006mK-BS for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 15:40:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l5Vsp-0004s8-AD for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 15:40:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5Vsp-0004s1-2y for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 15:40:27 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l5Vsk-0006Yl-Ag for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 15:40:26 +0000 Received: by mail-qk1-x731.google.com with SMTP id d85so9073094qkg.5 for ; Fri, 29 Jan 2021 07:40:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=R6bt9x/zsyJZuUe7qVyb3KZHoyu7mWv8FqatXA7Uuuk=; b=M3ckaw0/Ujq0okmoIb5Wt/rRSIYChI/pqDaAix2q8uQDyiA1VAYykN2uotoGFnt5CV DYWXUhmo3GaymhdCBpj3SPXCpvFfDTUHzPeqvDTxLJ7c5HsBrkLYMz2fTpRVxImZm9XU dx/5GVtKXN/VuGSa0pPsO12Rg0lBg75WdYydWWMXrRu02k1JhakJVIv8fooPseawLKQb 5sJLBwBaUM9rhHTvCvG1leMHTZhhcglR58k+B0N+f2YbKiJ/V7nBWjN7KQoUWlpJepjd jWlkSDupejqnAUhVez/cw0J0RuqAL0Q/lk2PhaZUQuFBIkds9OE0vHhZ4NB/+1OE7ihc KTew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=R6bt9x/zsyJZuUe7qVyb3KZHoyu7mWv8FqatXA7Uuuk=; b=ctCSEJcWO9fb58p+2csdXwgk5+dsPB3DruyxS2GVdC7sUONRcoXPhqtc6b6eFZtbMU BhV6ICko7VZD+3T5U7WsTMnu5woBkIiagtckM3ECZ4iy0gKTGj5kQmQFdsH3gkGe9yuF A/amfmmDzHb3hIZ2IeBHBoxnZgnRpIne7CWBQ2jdlpXf4tBZ71ACQBXrE2OXSmPksTBv WutwI6vXiTND84UIoudVWSNeFLdJSslM0zk2XAKPqdtpcsgs5erfBdljCv9OOTM3/IyX vK1LM191akwbhjt0R19LYOP0vDiWzOwAXh+kxgvsLlFKNqjxGRRw//JZMtQJ4hGhEtTB DvDQ== X-Gm-Message-State: AOAM533wX6CYa2zLjMhX01IttLKjP2pH9M9NKQY7WmxaCQgF9zDGW3sS LA7mg5sQvM+UDd6QZMpe8wmMDA== X-Google-Smtp-Source: ABdhPJxyU0HUD5EvKRz9xvSy9nvMlUrzpRjjLU0Uq8gIEFaQykBqYWO+G3tctnkW58n4aGoogi3f9g== X-Received: by 2002:a37:a80d:: with SMTP id r13mr4382010qke.117.1611934820666; Fri, 29 Jan 2021 07:40:20 -0800 (PST) Received: from perhan.alvh.no-ip.org ([190.95.19.177]) by smtp.gmail.com with ESMTPSA id o3sm5982801qkg.15.2021.01.29.07.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 07:40:19 -0800 (PST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 1465C2A0D43; Fri, 29 Jan 2021 12:40:18 -0300 (-03) Date: Fri, 29 Jan 2021 12:40:18 -0300 From: Alvaro Herrera To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org, Jaime Casanova Subject: Re: LogwrtResult contended spinlock Message-ID: <20210129154018.GA7723@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Aug-31, Andres Freund wrote: > Wouldn't the better fix here be to allow reading of individual members without a lock? E.g. by wrapping each in a 64bit atomic. So I've been playing with this and I'm annoyed about having two datatypes to represent Write/Flush positions: typedef struct XLogwrtRqst { XLogRecPtr Write; /* last byte + 1 to write out */ XLogRecPtr Flush; /* last byte + 1 to flush */ } XLogwrtRqst; typedef struct XLogwrtResult { XLogRecPtr Write; /* last byte + 1 written out */ XLogRecPtr Flush; /* last byte + 1 flushed */ } XLogwrtResult; Don't they look, um, quite similar? I am strongly tempted to remove that distinction, since it seems quite pointless, and introduce a different one: typedef struct XLogwrtAtomic { pg_atomic_uint64 Write; /* last byte + 1 of write position */ pg_atomic_uint64 Flush; /* last byte + 1 of flush position */ } XLogwrtAtomic; this one, with atomics, would be used for the XLogCtl struct members LogwrtRqst and LogwrtResult, and are always accessed using atomic ops. On the other hand we would have typedef struct XLogwrt { XLogRecPtr Write; /* last byte + 1 of write position */ XLogRecPtr Flush; /* last byte + 1 of flush position */ } XLogwrt; to be used for the local-memory-only LogwrtResult, using normal assignment. Now, I do wonder if there's a point in keeping LogwrtResult as a local variable at all; maybe since the ones in shared memory are going to use unlocked access, we don't need it anymore? I'd prefer to defer that decision to after this patch is done, since ISTM that it'd merit more careful benchmarking. Thoughts? -- Álvaro Herrera Valdivia, Chile