🐛 Hold three times WindowServer's measured blocks in its reserve

WindowServer's reserve kept the last 1024 of the block table's 16384 entries
for it, sized at three times the 366 blocks it held as five apps opened. With
some 70 processes open it held 1358 blocks, so once the other processes held
every entry outside the reserve, WindowServer was refused past its 1024th.

The reserve now keeps 4096 entries, three times the 1358, and the table's
sizes live in RgfxBlockTable.hpp, where the native test fills the kext's own
table with another process's blocks and checks WindowServer still gets them.
Its bytes stay at 160 MiB: most of the 169.7 MiB it held then were its no-copy
buffers' copies and its Managed textures' CPU copies, which lie in its own
pages now, as its Managed buffers' do.

For the guest: a process other than WindowServer is refused a block once the
table holds 12288 entries, where it was at 15360.
This commit is contained in:
Anees Iqbal committed 2026-11-05 21:59:33 -08:00
1 parent 3e33b3b66b
commit ccb9ea0e1f
4 files changed
+48 -12

No files matched your search

+10 -3
View File
@@ -1054,7 +1054,7 @@ Max at load averages of 28 to 52).
refuses an allocation only when memory runs out, never because another process
holds much, so neither does the kext. The one process whose refusal would stall
every other is the compositor. So the last 160 MiB of the blocks' room and the
last 1024 of the table's 16384 entries go only to WindowServer's blocks
last 4096 of the table's 16384 entries go only to WindowServer's blocks
(`RgfxBlockTable`'s reserve). WindowServer takes the first gap from the start
like any process, and reaches into the reserve only once the rest is full; any
other process is refused at the reserve's edge, as at the region's end. Of the
@@ -1064,8 +1064,15 @@ for one process's 2048 queues beside as many of the others'
WindowServer's blocks and queues came to, which is what the reserve is sized
from: on an RTX 5080 host at the display's 3840x2400 mode, WindowServer held
134 MiB at most, at login, and 118 to 126 MiB in 110 to 366 blocks as five apps
opened, with 2 queues (measured). A larger display, or a second one,
needs the reserve measured again.
opened, with 2 queues (measured). With some 70 processes open its blocks came to
1358 and 169.7 MiB, past the reserve's 160 (measured), most of the bytes its
no-copy buffers' copies and its Managed textures' CPU copies. Those lie in its own
pages now, as its Managed buffers' CPU copies do ("Managed storage"), so what
WindowServer keeps in the region is what no page of its own can hold: its rings,
its encoders' upload chunks and command buffers' bodies, its surfaces' blocks,
and the slabs the kernel had no superpage for. The entries hold three times the
1358 blocks. A larger display, or a second one, needs the reserve measured
again.
The kext knows WindowServer's client by two tests at its open: the opening
process is named `WindowServer`, and it holds the entitlement
+4 -9
View File
@@ -68,15 +68,10 @@
#include <sys/sysctl.h>
namespace {
// The most blocks handed out at once.
constexpr UInt32 kMaxBlocks = 16384;
// The blocks' reserve for WindowServer (RgfxBlockTable): the last bytes of the region and the last
// entries of the table, which no other process is given. Sized from what WindowServer held on an
// RTX 5080 host at the display's 3840x2400 mode, measured: 134 MiB at most (at login), 118 to
// 126 MiB as five apps opened, in 110 to 366 blocks; so the reserve holds a WindowServer started
// again with a fifth to spare, and three times its blocks.
constexpr UInt64 kWindowServerReserveBytes = 160ull << 20;
constexpr UInt32 kWindowServerReserveEntries = 1024;
// The most blocks handed out at once, and WindowServer's reserve of them (RgfxBlockTable.hpp).
constexpr UInt32 kMaxBlocks = kRgfxMaxBlocks;
constexpr UInt64 kWindowServerReserveBytes = kRgfxWindowServerReserveBytes;
constexpr UInt32 kWindowServerReserveEntries = kRgfxWindowServerReserveEntries;
// The most command queues watched at once, over every client (RgfxQueueLimits.hpp).
constexpr UInt32 kMaxWatched = kRgfxMaxWatchedQueues;
// A ring header's fields (RgfxRingHeader).
+13
View File
@@ -15,6 +15,19 @@
#include <stdint.h>
// The most blocks the kext's table hands out at once.
constexpr uint32_t kRgfxMaxBlocks = 16384;
// WindowServer's reserve (RgfxBlockTable's): the last bytes of the region and the last entries of
// the table, which no other process is given. Sized from what WindowServer held on an RTX 5080
// host at the display's 3840x2400 mode, measured: 134 MiB at most (at login), 118 to 126 MiB as
// five apps opened, so the bytes hold a WindowServer started again with a fifth to spare. Its
// blocks came to 110 to 366 there, and to 1358 with some 70 processes open; the entries hold
// three times that. Its blocks then held 169.7 MiB, most of it its no-copy buffers' copies and its
// Managed textures' CPU copies, which lie in its own pages now (the bundle's RgfxSlabs.hpp), as
// its Managed buffers' do.
constexpr uint64_t kRgfxWindowServerReserveBytes = 160ull << 20;
constexpr uint32_t kRgfxWindowServerReserveEntries = 4096;
// Where a block is in its life.
enum RgfxBlockState : uint8_t {
// Its owner's, to name in its messages.
+21
View File
@@ -459,6 +459,27 @@ int main()
"past which it is full for WindowServer too");
check(x.t.reservedPeakCount == 2, "the peak counts WindowServer's entries");
}
{
// The kext's own table: with every entry outside WindowServer's reserve held by other
// processes, WindowServer is still given three times the most blocks it was measured
// to hold (1358, with some 70 processes open), and the others none.
static RgfxBlock big[kRgfxMaxBlocks];
const uint64_t page = 0x1000;
RgfxBlockTable t = {big, 0, kRgfxMaxBlocks, page, page + 2ull * kRgfxMaxBlocks * page,
0, 0, 0, 0, 0, 0, 0};
t.reserveEntries = kRgfxWindowServerReserveEntries;
uint64_t at = 0;
uint32_t others = 0;
while (rgfxBlockAlloc(t, b, 2, page, page, &at) == kRgfxBlockOk)
others++;
check(others == kRgfxMaxBlocks - kRgfxWindowServerReserveEntries,
"the other processes fill every entry outside the reserve");
uint32_t ws = 0;
while (rgfxBlockAlloc(t, a, 1, page, page, &at, nullptr, true) == kRgfxBlockOk)
ws++;
check(ws >= 3 * 1358, "WindowServer gets three times its measured blocks");
check(t.reservedPeakCount == ws, "and its peak counts them");
}
{
// With no reserve, every allocation is as before.
Table x;