[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5d26fa3b-ec34-bc39-ecfe-4616a04977ca@oracle.com>
Date: Mon, 2 Oct 2023 11:10:43 +0100
From: John Garry <john.g.garry@...cle.com>
To: Bart Van Assche <bvanassche@....org>, axboe@...nel.dk,
kbusch@...nel.org, hch@....de, sagi@...mberg.me,
jejb@...ux.ibm.com, martin.petersen@...cle.com, djwong@...nel.org,
viro@...iv.linux.org.uk, brauner@...nel.org,
chandan.babu@...cle.com, dchinner@...hat.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-nvme@...ts.infradead.org, linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org, tytso@....edu, jbongio@...gle.com,
linux-api@...r.kernel.org
Subject: Re: [PATCH 10/21] block: Add fops atomic write support
On 29/09/2023 18:51, Bart Van Assche wrote:
> On 9/29/23 03:27, John Garry wrote:
>> + if (pos % atomic_write_unit_min_bytes)
>> + return false;
>> + if (iov_iter_count(iter) % atomic_write_unit_min_bytes)
>> + return false;
>> + if (!is_power_of_2(iov_iter_count(iter)))
>> + return false;
> [ ... ]
>> + if (pos % iov_iter_count(iter))
>> + return false;
>
> Where do these rules come from? Is there any standard that requires
> any of the above?
SCSI and NVMe have slightly different atomic writes semantics, and the
rules are created to work for both.
In addition, the rules are related to FS extent alignment.
Note that for simplicity and consistency we use the same rules for
regular files as for bdev's.
This is the coding for the rules and where they come from:
> + if (!atomic_write_unit_min_bytes)
> + return false;
If atomic_write_unit_min_bytes == 0, then we just don't support atomic
writes.
> + if (pos % atomic_write_unit_min_bytes)
> + return false;
See later rules.
> + if (iov_iter_count(iter) % atomic_write_unit_min_bytes)
> + return false;
For SCSI, there is an atomic write granularity, which dictates
atomic_write_unit_min_bytes. So here we need to ensure that the length
is a multiple of this value.
> + if (!is_power_of_2(iov_iter_count(iter)))
> + return false;
This rule comes from FS block alignment and NVMe atomic boundary.
FSes (XFS) have discontiguous extents. We need to ensure that an atomic
write does not cross discontiguous extents. To do this we ensure extent
length and alignment and limit atomic_write_unit_max_bytes to that.
For NVMe, an atomic write boundary is a boundary in LBA space which an
atomic write should not cross. We limit atomic_write_unit_max_bytes such
that it is evenly divisible into this atomic write boundary.
To ensure that the write does not cross these alignment boundaries we
say that it must be naturally aligned and a power-of-2 in length.
We may be able to relax this rule but I am not sure it buys us anything
- typically we want to be writing a 64KB block aligned to 64KB, for example.
> + if (iov_iter_count(iter) > atomic_write_unit_max_bytes)
> + return false;
We just can't exceed this length.
> + if (pos % iov_iter_count(iter))
> + return false;
As above, ensure naturally aligned.
Thanks,
John
Powered by blists - more mailing lists