git: 97ed4babb516 - main - zfs: avoid memory allocation in arc_prune_async

Jessica Clarke jrtc27 at freebsd.org
Sun Apr 11 12:25:14 UTC 2021


On 11 Apr 2021, at 07:43, Mateusz Guzik <mjg at FreeBSD.org> wrote:
> 
> The branch main has been updated by mjg:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=97ed4babb51636d8a4b11bc7b207c3219ffcd0e3
> 
> commit 97ed4babb51636d8a4b11bc7b207c3219ffcd0e3
> Author:     Mateusz Guzik <mjg at FreeBSD.org>
> AuthorDate: 2021-04-11 05:15:41 +0000
> Commit:     Mateusz Guzik <mjg at FreeBSD.org>
> CommitDate: 2021-04-11 05:19:56 +0000
> 
>    zfs: avoid memory allocation in arc_prune_async
> ---
> sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c
> index 201dbc423336..e73efd810e53 100644
> --- a/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c
> +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c
> @@ -158,10 +158,13 @@ arc_default_max(uint64_t min, uint64_t allmem)
> static void
> arc_prune_task(void *arg)
> {
> -	int64_t nr_scan = *(int64_t *)arg;
> +#ifdef __LP64__
> +	int64_t nr_scan = (int64_t)arg;
> +#else
> +	int64_t nr_scan = (int32_t)arg;
> +#endif

int64_t nr_scan = (intptr_t)arg;?

> 	arc_reduce_target_size(ptob(nr_scan));
> -	free(arg, M_TEMP);
> #if __FreeBSD_version >= 1300139
> 	sx_xlock(&arc_vnlru_lock);
> 	vnlru_free_vfsops(nr_scan, &zfs_vfsops, arc_vnlru_marker);
> @@ -185,13 +188,14 @@ arc_prune_task(void *arg)
> void
> arc_prune_async(int64_t adjust)
> {
> -
> 	int64_t *adjustptr;
> 
> -	if ((adjustptr = malloc(sizeof (int64_t), M_TEMP, M_NOWAIT)) == NULL)
> -		return;
> +#ifndef __LP64__
> +	if (adjust > __LONG_MAX)
> +		adjust = __LONG_MAX;
> +#endif

The code is correct without the ifdef, is this just to suppress a tautological
condition warning? If so, be precise in your condition and use __INT64_MAX__ >
__LONG_MAX__? LP64 conflates a lot of things into one variable, and so isn’t
defined for CHERI, but IMO it’s better to be precise *anyway* because then it’s
more self-documenting why the #if is there.

Jess



More information about the dev-commits-src-all mailing list