2021-04-12 15:31:44

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members

> Below are the results of running xfstests for "all" with the following
> configuration in local.config:

...

> Other tests might need to be run in order to verify everything is working
> as expected. For such tests, the intervention of the maintainers might be
> needed.

This is a little weird for a commit log. If you want to show results
this would be something that goes into a cover letter.

> +/*
> + * Calculates the size of structure xfs_efi_log_format followed by an
> + * array of n number of efi_extents elements.
> + */
> +static inline size_t
> +sizeof_efi_log_format(size_t n)
> +{
> + return struct_size((struct xfs_efi_log_format *)0, efi_extents, n);

These helpers are completely silly. Just keep the existing open code
version using sizeof with the one-off removed.

> - (sizeof(struct xfs_efd_log_item) +
> - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
> - sizeof(struct xfs_extent)),
> - 0, 0, NULL);
> + struct_size((struct xfs_efd_log_item *)0,
> + efd_format.efd_extents,
> + XFS_EFD_MAX_FAST_EXTENTS),
> + 0, 0, NULL);
> if (!xfs_efd_zone)
> goto out_destroy_buf_item_zone;
>
> xfs_efi_zone = kmem_cache_create("xfs_efi_item",
> - (sizeof(struct xfs_efi_log_item) +
> - (XFS_EFI_MAX_FAST_EXTENTS - 1) *
> - sizeof(struct xfs_extent)),
> + struct_size((struct xfs_efi_log_item *)0,
> + efi_format.efi_extents,
> + XFS_EFI_MAX_FAST_EXTENTS),

Same here. And this obsfucated version also adds completely pointless
overly long lines while making the code unreadable.


2021-04-12 15:40:09

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members



On 4/12/21 10:29, Christoph Hellwig wrote:
>> Below are the results of running xfstests for "all" with the following
>> configuration in local.config:
>
> ...
>
>> Other tests might need to be run in order to verify everything is working
>> as expected. For such tests, the intervention of the maintainers might be
>> needed.
>
> This is a little weird for a commit log. If you want to show results
> this would be something that goes into a cover letter.
>
>> +/*
>> + * Calculates the size of structure xfs_efi_log_format followed by an
>> + * array of n number of efi_extents elements.
>> + */
>> +static inline size_t
>> +sizeof_efi_log_format(size_t n)
>> +{
>> + return struct_size((struct xfs_efi_log_format *)0, efi_extents, n);
>
> These helpers are completely silly. Just keep the existing open code
> version using sizeof with the one-off removed.

This was proposed by Darrick[1]. However, I'm curious, why do you think
they are "completely silly"?

>
>> - (sizeof(struct xfs_efd_log_item) +
>> - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
>> - sizeof(struct xfs_extent)),
>> - 0, 0, NULL);
>> + struct_size((struct xfs_efd_log_item *)0,
>> + efd_format.efd_extents,
>> + XFS_EFD_MAX_FAST_EXTENTS),
>> + 0, 0, NULL);
>> if (!xfs_efd_zone)
>> goto out_destroy_buf_item_zone;
>>
>> xfs_efi_zone = kmem_cache_create("xfs_efi_item",
>> - (sizeof(struct xfs_efi_log_item) +
>> - (XFS_EFI_MAX_FAST_EXTENTS - 1) *
>> - sizeof(struct xfs_extent)),
>> + struct_size((struct xfs_efi_log_item *)0,
>> + efi_format.efi_extents,
>> + XFS_EFI_MAX_FAST_EXTENTS),
>
> Same here. And this obsfucated version also adds completely pointless
> overly long lines while making the code unreadable.

This could actually use one of the inline helpers you think are silly. :)

Thanks
--
Gustavo

[1] https://lore.kernel.org/lkml/20210311031745.GT3419940@magnolia/

2021-04-12 15:50:20

by Darrick J. Wong

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members

On Mon, Apr 12, 2021 at 04:29:06PM +0100, Christoph Hellwig wrote:
> > Below are the results of running xfstests for "all" with the following
> > configuration in local.config:
>
> ...
>
> > Other tests might need to be run in order to verify everything is working
> > as expected. For such tests, the intervention of the maintainers might be
> > needed.
>
> This is a little weird for a commit log. If you want to show results
> this would be something that goes into a cover letter.

Agreed, please don't post fstests output in the commit message.

> > +/*
> > + * Calculates the size of structure xfs_efi_log_format followed by an
> > + * array of n number of efi_extents elements.
> > + */
> > +static inline size_t
> > +sizeof_efi_log_format(size_t n)
> > +{
> > + return struct_size((struct xfs_efi_log_format *)0, efi_extents, n);
>
> These helpers are completely silly. Just keep the existing open code
> version using sizeof with the one-off removed.

A couple of revisions ago I specifically asked Gustavo to create these
'silly' sizeof helpers to clean up...

> > - (sizeof(struct xfs_efd_log_item) +
> > - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
> > - sizeof(struct xfs_extent)),
> > - 0, 0, NULL);
> > + struct_size((struct xfs_efd_log_item *)0,
> > + efd_format.efd_extents,
> > + XFS_EFD_MAX_FAST_EXTENTS),

...these even uglier multiline statements. I was also going to ask for
these kmem cache users to get cleaned up. I'd much rather look at:

xfs_efi_zone = kmem_cache_create("xfs_efi_item",
sizeof_xfs_efi(XFS_EFI_MAX_FAST_EXTENTS), 0);
if (!xfs_efi_zone)
goto the_drop_zone;

even if it means another static inline.

--D

> > + 0, 0, NULL);
> > if (!xfs_efd_zone)
> > goto out_destroy_buf_item_zone;
> >
> > xfs_efi_zone = kmem_cache_create("xfs_efi_item",
> > - (sizeof(struct xfs_efi_log_item) +
> > - (XFS_EFI_MAX_FAST_EXTENTS - 1) *
> > - sizeof(struct xfs_extent)),
> > + struct_size((struct xfs_efi_log_item *)0,
> > + efi_format.efi_extents,
> > + XFS_EFI_MAX_FAST_EXTENTS),
>
> Same here. And this obsfucated version also adds completely pointless
> overly long lines while making the code unreadable.

2021-04-12 15:58:38

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members



On 4/12/21 10:48, Darrick J. Wong wrote:
> On Mon, Apr 12, 2021 at 04:29:06PM +0100, Christoph Hellwig wrote:
>>> Below are the results of running xfstests for "all" with the following
>>> configuration in local.config:
>>
>> ...
>>
>>> Other tests might need to be run in order to verify everything is working
>>> as expected. For such tests, the intervention of the maintainers might be
>>> needed.
>>
>> This is a little weird for a commit log. If you want to show results
>> this would be something that goes into a cover letter.
>
> Agreed, please don't post fstests output in the commit message.

OK. I've got it.

>
>>> +/*
>>> + * Calculates the size of structure xfs_efi_log_format followed by an
>>> + * array of n number of efi_extents elements.
>>> + */
>>> +static inline size_t
>>> +sizeof_efi_log_format(size_t n)
>>> +{
>>> + return struct_size((struct xfs_efi_log_format *)0, efi_extents, n);
>>
>> These helpers are completely silly. Just keep the existing open code
>> version using sizeof with the one-off removed.
>
> A couple of revisions ago I specifically asked Gustavo to create these
> 'silly' sizeof helpers to clean up...
>
>>> - (sizeof(struct xfs_efd_log_item) +
>>> - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
>>> - sizeof(struct xfs_extent)),
>>> - 0, 0, NULL);
>>> + struct_size((struct xfs_efd_log_item *)0,
>>> + efd_format.efd_extents,
>>> + XFS_EFD_MAX_FAST_EXTENTS),
>
> ...these even uglier multiline statements. I was also going to ask for
> these kmem cache users to get cleaned up. I'd much rather look at:
>
> xfs_efi_zone = kmem_cache_create("xfs_efi_item",
> sizeof_xfs_efi(XFS_EFI_MAX_FAST_EXTENTS), 0);
> if (!xfs_efi_zone)
> goto the_drop_zone;
>
> even if it means another static inline.

Yep; I agree[1].

Thanks
--
Gustavo

[1] https://lore.kernel.org/lkml/[email protected]/

2021-04-13 21:53:40

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members

On Mon, Apr 12, 2021 at 08:48:08AM -0700, Darrick J. Wong wrote:
> A couple of revisions ago I specifically asked Gustavo to create these
> 'silly' sizeof helpers to clean up...
>
> > > - (sizeof(struct xfs_efd_log_item) +
> > > - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
> > > - sizeof(struct xfs_extent)),
> > > - 0, 0, NULL);
> > > + struct_size((struct xfs_efd_log_item *)0,
> > > + efd_format.efd_extents,
> > > + XFS_EFD_MAX_FAST_EXTENTS),
>
> ...these even uglier multiline statements. I was also going to ask for
> these kmem cache users to get cleaned up. I'd much rather look at:
>
> xfs_efi_zone = kmem_cache_create("xfs_efi_item",
> sizeof_xfs_efi(XFS_EFI_MAX_FAST_EXTENTS), 0);
> if (!xfs_efi_zone)
> goto the_drop_zone;
>
> even if it means another static inline.

Which doesn't really work with struct_size or rather leads to a mess
like the above as struct_size really wants a variable and not just a
type. Making it really nasty for both allocations and creating slab
caches. I tried to find a workaround for that, but that makes the
compiler unhappy based its inlining heuristics.

Anyway, a lot of the helpers are pretty silly as they duplicate stuff
without cleaning up the underlying mess. I tried to sort much of this
out here, still WIP:

http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-array-size

2021-07-14 09:28:48

by Chen, Rong A

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members



On 4/14/2021 12:53 AM, Christoph Hellwig wrote:
> On Mon, Apr 12, 2021 at 08:48:08AM -0700, Darrick J. Wong wrote:
>> A couple of revisions ago I specifically asked Gustavo to create these
>> 'silly' sizeof helpers to clean up...
>>
>>>> - (sizeof(struct xfs_efd_log_item) +
>>>> - (XFS_EFD_MAX_FAST_EXTENTS - 1) *
>>>> - sizeof(struct xfs_extent)),
>>>> - 0, 0, NULL);
>>>> + struct_size((struct xfs_efd_log_item *)0,
>>>> + efd_format.efd_extents,
>>>> + XFS_EFD_MAX_FAST_EXTENTS),
>>
>> ...these even uglier multiline statements. I was also going to ask for
>> these kmem cache users to get cleaned up. I'd much rather look at:
>>
>> xfs_efi_zone = kmem_cache_create("xfs_efi_item",
>> sizeof_xfs_efi(XFS_EFI_MAX_FAST_EXTENTS), 0);
>> if (!xfs_efi_zone)
>> goto the_drop_zone;
>>
>> even if it means another static inline.
>
> Which doesn't really work with struct_size or rather leads to a mess
> like the above as struct_size really wants a variable and not just a
> type. Making it really nasty for both allocations and creating slab
> caches. I tried to find a workaround for that, but that makes the
> compiler unhappy based its inlining heuristics.
>
> Anyway, a lot of the helpers are pretty silly as they duplicate stuff
> without cleaning up the underlying mess. I tried to sort much of this
> out here, still WIP:
>
> http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-array-size
>

Hi xfs maintainers,

Kindly ping, is there any new progress on this patch series?

Best Regards,
Rong Chen

2021-07-15 05:53:06

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4][next] xfs: Replace one-element arrays with flexible-array members

I'll repost the series eventually as it requires some deeper changes.