diff --git a/docs/graphics-kext/design.md b/docs/graphics-kext/design.md index f4a8da927..4f7d6b7d7 100644 --- a/docs/graphics-kext/design.md +++ b/docs/graphics-kext/design.md @@ -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 diff --git a/guest/kext/src/RgfxAcceleratorContexts.cpp b/guest/kext/src/RgfxAcceleratorContexts.cpp index 31d776911..b819cc0ff 100644 --- a/guest/kext/src/RgfxAcceleratorContexts.cpp +++ b/guest/kext/src/RgfxAcceleratorContexts.cpp @@ -68,15 +68,10 @@ #include 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). diff --git a/guest/kext/src/RgfxBlockTable.hpp b/guest/kext/src/RgfxBlockTable.hpp index a5494d02b..d85756cbe 100644 --- a/guest/kext/src/RgfxBlockTable.hpp +++ b/guest/kext/src/RgfxBlockTable.hpp @@ -15,6 +15,19 @@ #include +// 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. diff --git a/guest/kext/tests/blocks_test.cpp b/guest/kext/tests/blocks_test.cpp index 7b6ecd705..38ccff413 100644 --- a/guest/kext/tests/blocks_test.cpp +++ b/guest/kext/tests/blocks_test.cpp @@ -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;