diff mbox series

[3/3] btrfs: document extent mapping assumptions in checksum

Message ID 20181127160010.18123-4-jthumshirn@suse.de (mailing list archive)
State New, archived
Headers show
Series Misc cosmetic changes for map_private_extent_buffer | expand

Commit Message

Johannes Thumshirn Nov. 27, 2018, 4 p.m. UTC
Document why map_private_extent_buffer() cannot return '1' (i.e. the map
spans two pages) for the csum_tree_block() case.

The current algorithm for detecting a page boundary crossing in
map_private_extent_buffer() will return a '1' *IFF* the product of the
extent buffer's offset in the page + the offset passed in by
csum_tree_block() and the minimal length passed in by csum_tree_block() - 1
are bigger than PAGE_SIZE.

We always pass BTRFS_CSUM_SIZE (32) as offset and a minimal length of 32
and the current extent buffer allocator always guarantees page aligned
extends, so the above condition can't be true.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 fs/btrfs/disk-io.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Nikolay Borisov Nov. 27, 2018, 4:36 p.m. UTC | #1
On 27.11.18 г. 18:00 ч., Johannes Thumshirn wrote:
> Document why map_private_extent_buffer() cannot return '1' (i.e. the map
> spans two pages) for the csum_tree_block() case.
> 
> The current algorithm for detecting a page boundary crossing in
> map_private_extent_buffer() will return a '1' *IFF* the product of the

I think the word product must be replaced with 'sum', since product
implies multiplication :)

> extent buffer's offset in the page + the offset passed in by
> csum_tree_block() and the minimal length passed in by csum_tree_block() - 1
> are bigger than PAGE_SIZE.
> 
> We always pass BTRFS_CSUM_SIZE (32) as offset and a minimal length of 32
> and the current extent buffer allocator always guarantees page aligned
> extends, so the above condition can't be true.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>

With that wording changed:

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/disk-io.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 4bc270ef29b4..14d355d0cb7a 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -279,6 +279,12 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
>  
>  	len = buf->len - offset;
>  	while (len > 0) {
> +		/*
> +		 * Note: we don't need to check for the err == 1 case here, as
> +		 * with the given combination of 'start = BTRFS_CSUM_SIZE (32)'
> +		 * and 'min_len = 32' and the currently implemented mapping
> +		 * algorithm we cannot cross a page boundary.
> +		 */
>  		err = map_private_extent_buffer(buf, offset, 32,
>  					&kaddr, &map_start, &map_len);
>  		if (err)
>
Noah Massey Nov. 27, 2018, 7:08 p.m. UTC | #2
On Tue, Nov 27, 2018 at 11:43 AM Nikolay Borisov <nborisov@suse.com> wrote:
>
> On 27.11.18 г. 18:00 ч., Johannes Thumshirn wrote:
> > Document why map_private_extent_buffer() cannot return '1' (i.e. the map
> > spans two pages) for the csum_tree_block() case.
> >
> > The current algorithm for detecting a page boundary crossing in
> > map_private_extent_buffer() will return a '1' *IFF* the product of the
>
> I think the word product must be replaced with 'sum', since product
> implies multiplication :)
>

doesn't 'sum' imply addition? How about 'output'?

> > extent buffer's offset in the page + the offset passed in by
> > csum_tree_block() and the minimal length passed in by csum_tree_block() - 1
> > are bigger than PAGE_SIZE.
> >
> > We always pass BTRFS_CSUM_SIZE (32) as offset and a minimal length of 32
> > and the current extent buffer allocator always guarantees page aligned
> > extends, so the above condition can't be true.
> >
> > Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
>
> With that wording changed:
>
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
>
> > ---
> >  fs/btrfs/disk-io.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> > index 4bc270ef29b4..14d355d0cb7a 100644
> > --- a/fs/btrfs/disk-io.c
> > +++ b/fs/btrfs/disk-io.c
> > @@ -279,6 +279,12 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
> >
> >       len = buf->len - offset;
> >       while (len > 0) {
> > +             /*
> > +              * Note: we don't need to check for the err == 1 case here, as
> > +              * with the given combination of 'start = BTRFS_CSUM_SIZE (32)'
> > +              * and 'min_len = 32' and the currently implemented mapping
> > +              * algorithm we cannot cross a page boundary.
> > +              */
> >               err = map_private_extent_buffer(buf, offset, 32,
> >                                       &kaddr, &map_start, &map_len);
> >               if (err)
> >
Nikolay Borisov Nov. 27, 2018, 7:32 p.m. UTC | #3
On 27.11.18 г. 21:08 ч., Noah Massey wrote:
> On Tue, Nov 27, 2018 at 11:43 AM Nikolay Borisov <nborisov@suse.com> wrote:
>>
>> On 27.11.18 г. 18:00 ч., Johannes Thumshirn wrote:
>>> Document why map_private_extent_buffer() cannot return '1' (i.e. the map
>>> spans two pages) for the csum_tree_block() case.
>>>
>>> The current algorithm for detecting a page boundary crossing in
>>> map_private_extent_buffer() will return a '1' *IFF* the product of the
>>
>> I think the word product must be replaced with 'sum', since product
>> implies multiplication :)
>>
> 
> doesn't 'sum' imply addition? How about 'output'?

It does and the code indeed sums the value and not multiply them hence
my suggestion.

> 
>>> extent buffer's offset in the page + the offset passed in by
>>> csum_tree_block() and the minimal length passed in by csum_tree_block() - 1
>>> are bigger than PAGE_SIZE.
>>>
>>> We always pass BTRFS_CSUM_SIZE (32) as offset and a minimal length of 32
>>> and the current extent buffer allocator always guarantees page aligned
>>> extends, so the above condition can't be true.
>>>
>>> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
>>
>> With that wording changed:
>>
>> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
>>
>>> ---
>>>  fs/btrfs/disk-io.c | 6 ++++++
>>>  1 file changed, 6 insertions(+)
>>>
>>> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
>>> index 4bc270ef29b4..14d355d0cb7a 100644
>>> --- a/fs/btrfs/disk-io.c
>>> +++ b/fs/btrfs/disk-io.c
>>> @@ -279,6 +279,12 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
>>>
>>>       len = buf->len - offset;
>>>       while (len > 0) {
>>> +             /*
>>> +              * Note: we don't need to check for the err == 1 case here, as
>>> +              * with the given combination of 'start = BTRFS_CSUM_SIZE (32)'
>>> +              * and 'min_len = 32' and the currently implemented mapping
>>> +              * algorithm we cannot cross a page boundary.
>>> +              */
>>>               err = map_private_extent_buffer(buf, offset, 32,
>>>                                       &kaddr, &map_start, &map_len);
>>>               if (err)
>>>
>
Noah Massey Nov. 27, 2018, 8:20 p.m. UTC | #4
On Tue, Nov 27, 2018 at 2:32 PM Nikolay Borisov <nborisov@suse.com> wrote:
>
> On 27.11.18 г. 21:08 ч., Noah Massey wrote:
> > On Tue, Nov 27, 2018 at 11:43 AM Nikolay Borisov <nborisov@suse.com> wrote:
> >>
> >> On 27.11.18 г. 18:00 ч., Johannes Thumshirn wrote:
> >>> Document why map_private_extent_buffer() cannot return '1' (i.e. the map
> >>> spans two pages) for the csum_tree_block() case.
> >>>
> >>> The current algorithm for detecting a page boundary crossing in
> >>> map_private_extent_buffer() will return a '1' *IFF* the product of the
> >>
> >> I think the word product must be replaced with 'sum', since product
> >> implies multiplication :)
> >>
> >
> > doesn't 'sum' imply addition? How about 'output'?
>
> It does and the code indeed sums the value and not multiply them hence
> my suggestion.
>

I'm sorry, I didn't phrase that well.

Since 'sum' already implies addition, it gets confusing with the
mathematical operators used later in the description. So, if a
objective noun is required, a generic term such as 'output' or
'result' reads more cleanly for me. OTOH, dropping that and creating
an actual expression

*IFF* the extent buffer's offset in the page + the offset passed in by
csum_tree_block() + the minimal length passed in by csum_tree_block()
- 1 > PAGE_SIZE.

is also straightforward.
Johannes Thumshirn Nov. 28, 2018, 8:39 a.m. UTC | #5
On 27/11/2018 17:36, Nikolay Borisov wrote:
> 
> 
> On 27.11.18 г. 18:00 ч., Johannes Thumshirn wrote:
>> Document why map_private_extent_buffer() cannot return '1' (i.e. the map
>> spans two pages) for the csum_tree_block() case.
>>
>> The current algorithm for detecting a page boundary crossing in
>> map_private_extent_buffer() will return a '1' *IFF* the product of the
> 
> I think the word product must be replaced with 'sum', since product
> implies multiplication :)

*doh* m)

Yes thanks for spotting this.
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4bc270ef29b4..14d355d0cb7a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -279,6 +279,12 @@  static int csum_tree_block(struct btrfs_fs_info *fs_info,
 
 	len = buf->len - offset;
 	while (len > 0) {
+		/*
+		 * Note: we don't need to check for the err == 1 case here, as
+		 * with the given combination of 'start = BTRFS_CSUM_SIZE (32)'
+		 * and 'min_len = 32' and the currently implemented mapping
+		 * algorithm we cannot cross a page boundary.
+		 */
 		err = map_private_extent_buffer(buf, offset, 32,
 					&kaddr, &map_start, &map_len);
 		if (err)