🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages Started by bugzilla-noreply Fri, 27 Nov 2026 23:29
[Bug 301207] uma(9): item_domain() evaluates vtophys() before vm_phys_domain() checks vm_ndomains, so every FIRSTTOUCH free call...
#816
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 23:29
93 lines
5669 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301207

            Bug ID: 301207
           Summary: uma(9): item_domain() evaluates vtophys() before
                    vm_phys_domain() checks vm_ndomains, so every
                    FIRSTTOUCH free calls pmap_kextract() on single-domain
                    systems
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

With options NUMA enabled in GENERIC, keg_ctor() sets
UMA_ZONE_FIRSTTOUCH on standard zones, so cache_free_reuse() and
cache_free_defer() in sys/vm/uma_core.c (main 2534dcb233ad) call
item_domain(item) on every per-CPU cache free:

        static int
        item_domain(void *item)
        {
                int domain;

                domain = vm_phys_domain(vtophys(item));

Since commit 431fb8abd794 made vm_phys_domain() in sys/vm/vm_phys.h an
inline function beginning with:

        if (vm_ndomains == 1)
                return (0);

C still evaluates the argument vtophys(item) (out-of-line
pmap_kextract()) before entering vm_phys_domain(). On single-domain
systems (vm.ndomains=1), every uma_zfree_arg() and uma_zfree_smr() on a
FIRSTTOUCH zone calls pmap_kextract() (walking kernel page tables for
multipage KVA slabs) and discards the returned physical address.

On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C, vm.ndomains=1), counting non-DMAP pmap_kextract() calls during
6000 zero-length 256-iovec writev() calls to /dev/null (5000 warmup +
1000 timed, freeing 4144-byte uio buffers from malloc-8192) shows half
of all pmap_kextract() calls (the 6000 calls from uma_zfree_arg(), plus
1 from fdescfree(), leaving only the 6000 from free() -> vtozoneslab())
disappearing:

cc -O2 -Wall -Wextra -Werror -o uma_free_churn uma_free_churn.c
dtrace -x nolibs -qn 'fbt::pmap_kextract:entry /pid == $target/ { @ = count();
}' -c './uma_free_churn writev 1000'

Unmodified GENERIC-NODEBUG: 12001
Patched GENERIC-NODEBUG:     6002

Across 10 runs of 500000 writev() calls (ns/call):

x base_writev.txt
+ patched_writev.txt
+--------------------------------------------------------------------------+
|+  + +  +  +     +            x+   * x   * x       x+   xx     x         x|
|  |___________M_____A______________|__|________M_A____________|           |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  10        445.46        451.15        447.72       447.946     1.8136348
+  10        441.56        448.35       443.395       444.236     2.3725945
Difference at 95.0% confidence
        -3.71 +/- 1.98414
        -0.828225% +/- 0.441591%
        (Student's t, pooled s = 2.11169)

On 1-page DMAP frees (2000000 __getcwd() calls on NAMEI, N=10), mean
latency moves from 91.78 ns to 91.38 ns (-0.44% +/- 0.10% at 95%
confidence), and debug GENERIC (INVARIANTS and WITNESS, including the
uma_zalloc_domain() KASSERT) boots and runs cleanly.

Checking vm_ndomains == 1 at the top of item_domain() returns 0 before
evaluating vtophys(item).

Tested on 16.0-CURRENT amd64 with vm.ndomains=1; I have not tested a
multi-domain (vm.ndomains > 1) NUMA machine or arm64.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301207] uma(9): item_domain() evaluates vtophys() before vm_phys_domain() checks vm_ndomains, so every FIRSTTOUCH free call...
#817
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 23:30
17 lines
2603 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301207

--- Comment #2 from laamalif@proton.me ---
Created attachment 277839
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277839&action=edit
benchmark: multipage KVA writev() and 1-page DMAP __getcwd() UMA free
microbenchmark

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads