Profiling and finding more information on a Mesa bug

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:

https://lemmy.today/pictrs/image/4f4eac00-db6f-4a10-8a08-dd0f0a54d5e4.png

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.

https://lemmy.today/pictrs/image/049fda3a-7a79-4551-824b-799518157c3c.avif

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.

https://lemmy.today/pictrs/image/1a20d0df-cad1-4793-85c2-2a858605eb58.png