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 1nKEG1-0001Vk-Fu for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Feb 2022 06:57:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKEFz-0005A0-V7 for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Feb 2022 06:57:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nKEFz-00059r-Js for pgsql-hackers@lists.postgresql.org; Wed, 16 Feb 2022 06:57:43 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKEFs-0004ck-I4 for pgsql-hackers@postgresql.org; Wed, 16 Feb 2022 06:57:43 +0000 Received: by mail-pj1-x1030.google.com with SMTP id v8-20020a17090a634800b001bb78857ccdso3291876pjs.1 for ; Tue, 15 Feb 2022 22:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=i1n9LF0zz8DmUAuzX3IRpx2d40UetJeRacumSlmhRvY=; b=LEsYZY8zwpcKybuIJckweg/95fCw9N7fy1mX/xFWj1IJ3dmtY1bN5yWDorFA7ZVdkn 1/d8sOLNKCm8o+JkbE5BdDW4hguCKx1J0mwmZHRijFBMLGgXgy1AnmdDwhokbPyxx2zl ghgmgvJOrmOth1VkWqtwwNqINkbm84suiBDPG+XbgXRqWEbG8NRK+CNB/p8ir9P0Y0Kg UWWEnubwR0s7EL0XWhAKE2qkJh9EPPO+MXw4bnKAuBdlDPuprlKT+X2m0J2sAdzQaKIM V1GU08EFD62X5+h/gXvxhbgvufVuF03lKuHqjywrSzDm1wHIhg4INzJHu5bKfUw3at6u NnwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=i1n9LF0zz8DmUAuzX3IRpx2d40UetJeRacumSlmhRvY=; b=1E9X7HVuc1cxvAYrD90+niPoWQUY7WPfiWHi4tDtspKNswLvFLf9zeggNiN01KFOfu bqkxYWy+Nw5rt/kEsRpx5vSbtGMSqGK7hFi77BLE/W9zp5NUscc3/0AkXeyMIErDV4Yr 8l75etghbMjhuU81xXTtmCjd6Jc3g0JqfFyCmCC4qVeJ4/PrG3l0sQBlmyqJu79/HJws f1iDfFXAcZz//0S4C5wxUEqdBo97f/63LusYg48p1J7ntvf15QbcKwV2s/hepLJ7x5f8 G7ns5g7qtqZQf1GLlLQIxPkwq92xY07RvzRGq5mw7ggrRWnncgsM6r1tlYwMb0H1QVbV /amw== X-Gm-Message-State: AOAM533HA03vpKYFwt3vivQAs0LilbSS5DbSIaKlw51m/tJpyBwkCCWZ v/YjBr7C7v5CZoG3cD+240w= X-Google-Smtp-Source: ABdhPJx4QU1Ren/lijf9MnCSLH7nBD2/w49uKrQldCYbhh6QQRyY0ToOHP+vfeb2bvSSPca8ci2+mg== X-Received: by 2002:a17:902:cec8:b0:14f:f55:6fb7 with SMTP id d8-20020a170902cec800b0014f0f556fb7mr1059126plg.35.1644994654263; Tue, 15 Feb 2022 22:57:34 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id e4sm3221854pgr.35.2022.02.15.22.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 22:57:33 -0800 (PST) Date: Tue, 15 Feb 2022 22:57:32 -0800 From: Nathan Bossart To: Andres Freund Cc: Thomas Munro , pgsql-hackers Subject: Re: USE_BARRIER_SMGRRELEASE on Linux? Message-ID: <20220216065732.GA2932808@nathanxps13> References: <20220215235845.GA2665318@nathanxps13> <20220216045911.GA2791824@nathanxps13> <20220216050645.7u3nguccykpqaw7p@alap3.anarazel.de> <20220216061404.GA2813338@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="u3/rZRmxL6MmkK24" Content-Disposition: inline In-Reply-To: <20220216061404.GA2813338@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --u3/rZRmxL6MmkK24 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Feb 15, 2022 at 10:14:04PM -0800, Nathan Bossart wrote: > It looks like register_unlink_segment() is called prior to the checkpoint, > but the checkpointer is not calling RememberSyncRequest() until after > SyncPreCheckpoint(). This means that the requests are registered with the > next checkpoint cycle count, so they aren't processed until the next > checkpoint. Calling AbsorbSyncRequests() before advancing the checkpoint cycle counter seems to fix the issue. However, this requires moving SyncPreCheckpoint() out of the critical section in CreateCheckPoint(). Patch attached. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --u3/rZRmxL6MmkK24 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-call-AbsorbSyncRequests-before-advancing-checkpoi.patch" From 188fbe8ab12387c423081edfb85b26e43b342f4e Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 15 Feb 2022 22:53:04 -0800 Subject: [PATCH v1 1/1] call AbsorbSyncRequests() before advancing checkpoint cycle counter --- src/backend/access/transam/xlog.c | 14 +++++++------- src/backend/storage/sync/sync.c | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 60d0f3d99e..c72d6faa88 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9042,6 +9042,13 @@ CreateCheckPoint(int flags) MemSet(&CheckpointStats, 0, sizeof(CheckpointStats)); CheckpointStats.ckpt_start_t = GetCurrentTimestamp(); + /* + * Let smgr prepare for checkpoint; this has to happen before we determine + * the REDO pointer. Note that smgr must not do anything that'd have to + * be undone if we decide no checkpoint is needed. + */ + SyncPreCheckpoint(); + /* * Use a critical section to force system panic if we have trouble. */ @@ -9055,13 +9062,6 @@ CreateCheckPoint(int flags) LWLockRelease(ControlFileLock); } - /* - * Let smgr prepare for checkpoint; this has to happen before we determine - * the REDO pointer. Note that smgr must not do anything that'd have to - * be undone if we decide no checkpoint is needed. - */ - SyncPreCheckpoint(); - /* Begin filling in the checkpoint WAL record */ MemSet(&checkPoint, 0, sizeof(checkPoint)); checkPoint.time = (pg_time_t) time(NULL); diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c index 543f691f2d..8ffb3b8279 100644 --- a/src/backend/storage/sync/sync.c +++ b/src/backend/storage/sync/sync.c @@ -180,6 +180,12 @@ InitSync(void) void SyncPreCheckpoint(void) { + /* + * Some operations assume that the next checkpoint will process recently + * forwarded requests, so absorb them before we advance the cycle counter. + */ + AbsorbSyncRequests(); + /* * Any unlink requests arriving after this point will be assigned the next * cycle counter, and won't be unlinked until next checkpoint. -- 2.25.1 --u3/rZRmxL6MmkK24--