Files
nvdriver/kernel-open
Mike Biggerstaff b295cd58e3 uvm: sorted range and external-map tables with binary search; UVM file capacity 4096 -> 16384 (#596)
* uvm: sorted range and external-map tables with binary search; capacity 4096 -> 16384

The UVM ranges and external-map tables were unordered fixed arrays of
MAX_RANGES = 4096 entries with linear scans. A full table returned
NV_ERR_NO_MEMORY at about 4,000 pinned allocations (#412), and a larger
constant alone made every map slower.

Both tables are now dense and sorted (ranges by start, maps by
(gpu, start)). Lookups use partition_point; insert and remove move the
tail with element loops (black_box on the index, so no memmove). Loops
over all ranges stop at range_count. FILE_RANGES is 16384.

Tests: logarithmic probe bound per create/map/free, sorted order through
a managed split and VMA close, full-table NO_MEMORY, last-byte lookup.

Fixes #412

* uvm: charge the per-open file state to the opener's memcg

nv_rs_uvm_open allocates the handle and the UVM file state (about 1.87 MB
at the 16384 capacity) with GFP_KERNEL. The device is mode 0666, so a
local user could open it many times and grow kernel memory that no cgroup
limit sees. Allocate both with GFP_KERNEL_ACCOUNT, as dmabuf_p2p.c does,
so the opener's memory cgroup pays for each open and its limit applies.

The idle cost per open does not change. Lazy table capacity is a
possible follow-up.

---------

Co-authored-by: GrowDev1 <growdev1@users.noreply.github.com>
2026-12-05 06:30:48 -08:00
..