git: 4e00940e9f1f - stable/13 - uma: UMA_ALIGN_CACHE: Resolve the proper value at use point

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Thu, 21 Dec 2023 13:43:53 UTC
The branch stable/13 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e00940e9f1f7dc1210a094d916ef930ff447e4a

commit 4e00940e9f1f7dc1210a094d916ef930ff447e4a
Author:     Olivier Certner <olce.freebsd@certner.fr>
AuthorDate: 2023-10-13 12:13:30 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2023-12-21 13:39:34 +0000

    uma: UMA_ALIGN_CACHE: Resolve the proper value at use point
    
    Having a special value of -1 that is resolved internally to
    'uma_align_cache' provides no significant advantages and prevents
    changing that variable to an unsigned type, which is natural for an
    alignment mask.  So suppress it and replace its use with a call to
    uma_get_align_mask().  The small overhead of the added function call is
    irrelevant since UMA_ALIGN_CACHE is only used when creating new zones,
    which is not performance critical.
    
    Reviewed by:            markj, kib
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D42259
    
    (cherry picked from commit e557eafe7233f8231c1f5f5b098e4bab8e818645)
    
    Approved by:    markj (mentor)
---
 sys/vm/uma.h      | 2 +-
 sys/vm/uma_core.c | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/sys/vm/uma.h b/sys/vm/uma.h
index 4225bd83ba23..c748a7843374 100644
--- a/sys/vm/uma.h
+++ b/sys/vm/uma.h
@@ -301,7 +301,7 @@ uma_zone_t uma_zcache_create(const char *name, int size, uma_ctor ctor,
 #define UMA_ALIGN_INT	(sizeof(int) - 1)	/* "" int */
 #define UMA_ALIGN_SHORT	(sizeof(short) - 1)	/* "" short */
 #define UMA_ALIGN_CHAR	(sizeof(char) - 1)	/* "" char */
-#define UMA_ALIGN_CACHE	(0 - 1)			/* Cache line size align */
+#define UMA_ALIGN_CACHE	(uma_get_cache_align_mask()) /* Cache line size align */
 #define	UMA_ALIGNOF(type) (_Alignof(type) - 1)	/* Alignment fit for 'type' */
 
 #define	UMA_ANYDOMAIN	-1	/* Special value for domain search. */
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index 506bc63033ba..19ea5433559d 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -3182,7 +3182,7 @@ uma_kcreate(uma_zone_t zone, size_t size, uma_init uminit, uma_fini fini,
 	args.size = size;
 	args.uminit = uminit;
 	args.fini = fini;
-	args.align = (align == UMA_ALIGN_CACHE) ? uma_cache_align_mask : align;
+	args.align = align;
 	args.flags = flags;
 	args.zone = zone;
 	return (zone_alloc_item(kegs, &args, UMA_ANYDOMAIN, M_WAITOK));
@@ -3195,7 +3195,6 @@ uma_set_cache_align_mask(int mask)
 {
 
 	if (mask >= 0)
-		/* UMA_ALIGN_CACHE is also not permitted here. */
 		uma_cache_align_mask = mask;
 }