From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942CD2DC79B for ; Tue, 18 Nov 2025 23:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763508640; cv=none; b=q/8Fp4nroBB7jNx8cHCpH+Vuqh5FMTfukUT/vW8ZQIGOIV01PzD7yUardsZzL5liZiqLbXAlwb38AX2jqyLY6fWlKZG6q0wEhPlWXjn6vn3RJCASv37Pu1YcOfTq7A96PCUX1w5W1BeoMbrMY/gg54XFGxFdex2J4ZqDc34iuVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763508640; c=relaxed/simple; bh=Ll890/m+4oA95x8d4X0J/e5b2OUfoKs6Dh9eC3XMaNc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SwnxRrR/HYFQi3lXUgeUgzgejtRbyRMWufS3Wsa8LBj9X80ucwD+0nAvm7DJiKymYP6bjoSwzt6AA+DqNNTz+OEGqfdLivKf5nqaaIl5xqPNB/1m8behTafwWgIovUVgsthpjbG20PMcszGwDICaBKUdgYoEr/8kM1FHhrnp7TU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com; spf=pass smtp.mailfrom=fromorbit.com; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b=rKdfUEVi; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b="rKdfUEVi" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-29558061c68so70686385ad.0 for ; Tue, 18 Nov 2025 15:30:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1763508638; x=1764113438; darn=vger.kernel.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=MnIQ5czAIlDUTiRSsv9UfW61iWVDuRBQUnVcKZcJB1w=; b=rKdfUEViRk2eHns7ezpaBZ3rb6Xn7WELhxhLp9wibrXP37D45/opfQ8U/2wzneLYhX DQ+7yJTZg1ollHP+oUfyBZI59oSSk0ZNaittOqb35qxXB7TYcwqyWkl1mYc3GH5zdQQj DBpmc+wvoeVu45KKzzbWmimB+UiESiDxNl68cfSl0iCRpfZbmCZ8i37HM/G/rrPHkoNc GMinkDCJSMinucjmFt4pUg2qsRFxSAU+W1DBOcCF0bnw6eLIV3AFU5OOtcI2d0+EaLtZ UtHj0jNUF+ADLSBs01d3xl6rmfbMzWVob0j+RJIPAkZcpFOe85R2CIvTuWMo5/rNgalN KFXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763508638; x=1764113438; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MnIQ5czAIlDUTiRSsv9UfW61iWVDuRBQUnVcKZcJB1w=; b=SyXsN5XeiTkKUhdXfZ5omBljoqKRwZcQTqrgVaB3T7TSg/vG5SSzKFeoGQn30jYZcQ owX66q8Cu3hrpMJ/OFeSEWpGFkDfSxsmJNHyF/6cvmHLzuRsIo0oOCP1viYwEVw0xc9e pw+5YmweM+bFc4ONUyeAaTTNSb0Q7/NDptyYtzF96FAIdZ9SQr9NDIWYfNrSmOBerZvd MAG8rDhc1Q5yJOHKyT/Cu9QEGv6JTCXlyMg/65XoyFz3PhNKQMDo6+XqcMWBvqkoXYMq o8xgao1WqUVgLv7s5VNdGnyIvzgwuYM7LSyiCitw5Vsg8bx1mHyKvkAc4lHRinckkVs1 89bw== X-Forwarded-Encrypted: i=1; AJvYcCU7G/FkfYDsjAWlvaKnZcd/CeBO+fYKnpPZXY5BD0qjWeID2e3u3VetYx639aYZxX2yFscniA69Y3+RwUo=@vger.kernel.org X-Gm-Message-State: AOJu0YyDWH1QdwwOIzd7EVNo2T8YLWwteiEYlsdcidJqn/WW9s7EuJnO y+777Aqpg2aoReRBPCVreXxVCPNAZbzf23n/fe87PjyMfDXdxj/lo6L3bMKKMyzn2so= X-Gm-Gg: ASbGncvvLRurX0nisYWltTWE12hQ0YjVTRVG0LE7rQY8QP/54oK1ao67Oeq06bS4lXD Px82J+msEcP+PaMoIevTJAbuDJ26uI6lKiJVT5epStkyS7VmY8M2kMslZwu6aW090V58uS2sW0y RnIGPXS1eAh5/AMUSAiRxcdJPT16xfUkbuwZxm7bbd7qg3iSKB9tMOFn5kXGW0rJXsr/bR3RmBU i1GmK4QiwyF6AzoptB10Y1QKSqpuAItNEjtGeN/T4pVCIMjfunfry3K6EckXvJC9l83Gt0fRyFz IWSsW5BLBLBr9SB6YARyutvAfdofYs69nvGcwxzEHVrSPbbqkA9Q3ccmeyWVF2fO6Zh6L2AyCdW 2IXOokeNEdUAFyUJGyByyFbhfyu2R7LizWUBvV1emON0D+3RBFbE5/553cu2cgeWCjqMZvVa9JT rvq9WyEBliwiW63oi7VlqqlMVu0AY8RG8RiQtSNWhlhWnFyZMtieirTVrFZ5b8K8PirkBD0l9/z 2Cz4UfCXso= X-Google-Smtp-Source: AGHT+IG0xrV617/K2Q2zctZIX2rlkSw5B1Jp1MywYakVFhxJ0IxXfb/aHGJIAHe675+ap1LI/Djfwg== X-Received: by 2002:a17:90b:570c:b0:340:cb39:74cd with SMTP id 98e67ed59e1d1-345bd413f51mr358384a91.32.1763508637774; Tue, 18 Nov 2025 15:30:37 -0800 (PST) Received: from dread.disaster.area (pa49-181-58-136.pa.nsw.optusnet.com.au. [49.181.58.136]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-345bc110a6dsm560282a91.14.2025.11.18.15.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 15:30:37 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.98.2) (envelope-from ) id 1vLV9e-0000000Ceqh-0jNc; Wed, 19 Nov 2025 10:30:34 +1100 Date: Wed, 19 Nov 2025 10:30:34 +1100 From: Dave Chinner To: Ritesh Harjani Cc: Matthew Wilcox , Ojaswin Mujoo , Christian Brauner , djwong@kernel.org, john.g.garry@oracle.com, tytso@mit.edu, dchinner@redhat.com, hch@lst.de, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, jack@suse.cz, nilay@linux.ibm.com, martin.petersen@oracle.com, rostedt@goodmis.org, axboe@kernel.dk, linux-block@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/8] mm: Add PG_atomic Message-ID: References: <5f0a7c62a3c787f2011ada10abe3826a94f99e17.1762945505.git.ojaswin@linux.ibm.com> <87ecq18azq.ritesh.list@gmail.com> <878qg32u3d.ritesh.list@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878qg32u3d.ritesh.list@gmail.com> On Tue, Nov 18, 2025 at 09:47:42PM +0530, Ritesh Harjani wrote: > Matthew Wilcox writes: > > > On Fri, Nov 14, 2025 at 10:30:09AM +0530, Ritesh Harjani wrote: > >> Matthew Wilcox writes: > >> > >> > On Wed, Nov 12, 2025 at 04:36:05PM +0530, Ojaswin Mujoo wrote: > >> >> From: John Garry > >> >> > >> >> Add page flag PG_atomic, meaning that a folio needs to be written back > >> >> atomically. This will be used by for handling RWF_ATOMIC buffered IO > >> >> in upcoming patches. > >> > > >> > Page flags are a precious resource. I'm not thrilled about allocating one > >> > to this rather niche usecase. Wouldn't this be more aptly a flag on the > >> > address_space rather than the folio? ie if we're doing this kind of write > >> > to a file, aren't most/all of the writes to the file going to be atomic? > >> > >> As of today the atomic writes functionality works on the per-write > >> basis (given it's a per-write characteristic). > >> > >> So, we can have two types of dirty folios sitting in the page cache of > >> an inode. Ones which were done using atomic buffered I/O flag > >> (RWF_ATOMIC) and the other ones which were non-atomic writes. Hence a > >> need of a folio flag to distinguish between the two writes. > > > > I know, but is this useful? AFAIK, the files where Postgres wants to > > use this functionality are the log files, and all writes to the log > > files will want to use the atomic functionality. What's the usecase > > for "I want to mix atomic and non-atomic buffered writes to this file"? > > Actually this goes back to the design of how we added support of atomic > writes during DIO. So during the initial design phase we decided that > this need not be a per-inode attribute or an open flag, but this is a > per write I/O characteristic. > > So as per the current design, we don't have any open flag or a > persistent inode attribute which says kernel should permit _only_ atomic > writes I/O to this file. Instead what we support today is DIO atomic > writes using RWF_ATOMIC flag in pwritev2 syscall. Which, if we can't do with REQ_ATOMIC IO, we fall back to the filesystem COW IO path to provide RWF_ATOMIC semantics without needing to involve the page cache. IOWs, DIO REQ_ATOMIC writes are simply a fast path for the atomic COW IO path inherent in COW-capable filesystems. This is no different for buffered RWF_ATOMIC writes. We need to ingest the data into the page cache as a COW operation, then at writeback time we optimise away the COW operations if REQ_ATOMIC IO can be performed instead. Using COW for buffered RWF_ATOMIC writes means don't need to involve the page caceh at all - this can all be implemented at the filesystem extent mapping and iomap layers.... > Having said that there can be several policy decision that could still be > discussed e.g. make sure any previous dirty data is flushed to disk when a > buffered atomic write request is made to an inode. We don't need to care about mixed dirty non-atomic/atomic data on the same file if REQ_ATOMIC is used as an optimisation for COW-based atomic IO. Filesystems like XFS naturally separate COW and non-COW extents. If we combine non-atomic and atomic data into a single atomic update at writeback(be it COW or REQ_ATOMIC IO), then we have still honoured the requested atomic semantics required to persist the data. It just doesn't matter. IMO, trying to hack atomic physical IO semantics through the page cache creates all sorts of issues that simply don't exist when we use the atomic overwrite paths present in modern COW capable filesystems.... -Dave. -- Dave Chinner david@fromorbit.com