There’s this issue with kwin_wayland on Intel 256V (16 GB RAM) with Intel Arc 130V/140V (Xe2 driver), where if you saturate most of your available RAM (less than 1 GB) with swap enabled, then kwin will start hogging up a lot of your CPU and start having unusually long paint times. You can disable swap with swapoff -a and the issue disappears. After some profiling with perf, the reason for this seems to be inside kernel space. This kinda makes sense, considering how new Lunar Lake is.

Firstly, it has nothing to do with swap IO. I checked vmstat’s si and so columns, set swappiness to 0, and even disabled swap for Kwin entirely using Cgroups. This is ofc ignoring that Kwin is a pretty “hot” path for memory. A lot of people were telling me it wasn’t swap, and they were right.

I used Kwin’s debug console with the showfps graph to grab a picture of when a CPU spike occurs, to demonstrate that an issue is definitely occurring:

Oh, and I’m allocating memory using a short C program:

source
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#define GB 11

int main(void) {
        const int allocsize = 1024 * 1024;
        const long long target = 1024LL * 1024 * 1024 * GB;
        for (long long i = 0; i < target; i += allocsize) {
                int *p = malloc(allocsize);
                if (p == NULL) {
                        perror("malloc");
                        return 1;
                }
                for (int i = 0; i < allocsize / sizeof(int); ++i)
                        p[i] = rand();
        }
        printf("Done\n");
        char c;
        scanf("%c\n", &c);
}

After a few profiling runs with perf record --call-graph dwarf -p ... I got it to produce a (chunkier) call stack that seemed to signify some clues, different from my “baseline” profiling runs when I wasn’t triggering the conditions.

It seemed to at least point to this function called EGLNativeFence that seems to request a synchronization object (mutex?), which then led to calls to dri_create_fence_fd which are visible in the function. There is also a LOT of time spent in the libgallium.so and __GI__ioctl symbols.

This is where my investigation ended. I wanted to know more about profiling and how to get more information about what is occurring here. I intend to submit a bug report, but am not quite sure who to complain too, seeing as how it is probably an Intel issue.

Edit: I’ve tested it in Gnome and while less subtle, there is a stutter or two that I can detect with the profiler. This time I attached it to gnome-shell, and what do you know, it has the same stuff. I compared it to a normal profiling doing the same stuff like running Gnome animations, wiggling stuff, and the profile of that was normal. You can see there’s definitely a similarity with the KDE profiling for this one’s stress test.

  • Trucule
    link
    fedilink
    arrow-up
    2
    ·
    9 days ago

    Get kernel stacks for the time spent in the ioctl calls by recording the whole system while your allocation program runs.

    sudo perf record -a -g -- sleep 15
    sudo perf report --no-children --sort sym
    

    Check whether the kernel frames under the ioctl are in the xe driver or in memory reclaim functions such as shrink_node and try_to_free_pages.

    Run sudo perf trace -s -p $(pidof kwin_wayland) during a spike and compare the ioctl time in its summary against a run without memory pressure.

    Since it reproduces in GNOME too, I’d file it in the drm/xe tracker following Intel’s guide (https://drm.pages.freedesktop.org/intel-docs/how-to-file-i915-bugs.html) and attach both perf reports.

    Drafted with AI.