git: 0883a572d27e - stable/13 - uma: Avoid polling for an invalid SMR sequence number

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 28 Jan 2022 14:13:36 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=0883a572d27ed147d9d9b1ce2e601bbdc8177aee

commit 0883a572d27ed147d9d9b1ce2e601bbdc8177aee
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-01-14 20:06:48 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-01-28 14:13:24 +0000

    uma: Avoid polling for an invalid SMR sequence number
    
    Buckets in an SMR-enabled zone can legitimately be tagged with
    SMR_SEQ_INVALID.  This effectively means that the zone destructor (if
    any) was invoked on all items in the bucket, and the contained memory is
    safe to reuse.  If the first bucket in the full bucket list was tagged
    this way, UMA would unnecessarily poll per-CPU state before attempting
    to fetch a full bucket from the list.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit a04ce833f9ba058ec3e04f686bd56fa0691bfcf0)
---
 sys/vm/uma_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index 3888ff26cca8..eb3773904db6 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -996,6 +996,7 @@ cache_fetch_bucket(uma_zone_t zone, uma_cache_t cache, int domain)
 {
 	uma_zone_domain_t zdom;
 	uma_bucket_t bucket;
+	smr_seq_t seq;
 
 	/*
 	 * Avoid the lock if possible.
@@ -1005,7 +1006,8 @@ cache_fetch_bucket(uma_zone_t zone, uma_cache_t cache, int domain)
 		return (NULL);
 
 	if ((cache_uz_flags(cache) & UMA_ZONE_SMR) != 0 &&
-	    !smr_poll(zone->uz_smr, zdom->uzd_seq, false))
+	    (seq = atomic_load_32(&zdom->uzd_seq)) != SMR_SEQ_INVALID &&
+	    !smr_poll(zone->uz_smr, seq, false))
 		return (NULL);
 
 	/*