You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Huge memory leak in the Linux kernel (400-500 MB, likely in the video driver) triggered on every opening KiCad with a moderately complex schematic. #6817
Every time I open a moderately complex schematic file in KiCad, and then immediately close KiCad without doing anything, the amount of free memory decreases by approximately 400 - 500 MB.
Each new launch of KiCad causes an additional 400 - 500 MB of memory loss. After 8 - 10 launches, the system runs out of memory and becomes unresponsive. After KiCad closes, the system shows reduced available memory, but no running processes account for the missing memory.
The leak appears to occur at the kernel level, most likely within the video driver.
I am attaching a test schematic file (test.kicad_sch) that reproduces the issue reliably.
The reasoning is that despite the KiCad process ending and it's PID disappears from process list, the system’s reported free memory does not recover. The lost memory remains occupied and cannot be used by other programs. In particular, no user-space process is holding that memory (it’s not visible in any running program or shared-memory segment).
I checked common shared-memory areas (e.g. /dev/shm) and found nothing unusual – no large temporary files or POSIX segments remain. This suggests the missing memory isn’t tied up in the normal shared-memory filesystem.
Since the KiCad process is gone, and by design its allocated pages should have been freed on exit, the only remaining explanation is that some kernel component is still holding the memory. In other words, the leak appears to be at the kernel level rather than in user space.
In additon Alt+SysRq+F is unable to free the leaked memory.
KiCad heavily utilizes the GPU for rendering, and since the amount of leaked memory after the process terminates appears to be proportional to the complexity of the schematic's geometry, this leads me to believe that the leak is most likely related to the GPU driver.
the only remaining explanation is that some kernel component is still holding the memory
I don't think that's true - it's also possible (and I tend to think more likely) that some part of the GUI is still holding resources on behalf of KiCad, even though the process has closed.
I don't think that's true - it's also possible (and I tend to think more likely) that some part of the GUI is still holding resources on behalf of KiCad, even though the process has closed.
Could you clarify which part of the GUI you believe might be holding these resources?
As I mentioned earlier, there are no processes listed that account for the missing memory, which strongly indicates that the leak is not occurring within user-space processes.
Additionally, I have tested restarting both wf-panel-pi and labwc, which fully resets the GUI, including returning to the login screen. However, immediately after logging back in, more than 3 GB of memory remains occupied, and there are still no processes in the process list that explain this usage.
This further supports the conclusion that the memory leak occurs at the kernel level rather than in user space.
I've not very familiar with the v3d driver, but there are some stats here:
$ cat /sys/kernel/debug/dri/fec00000.v3d/v3d_mm
0x0000000000000001-0x0000000000000003: 2: used
0x0000000000000003-0x0000000000001fa7: 8100: used
0x0000000000001fa7-0x0000000000001fa8: 1: used
0x0000000000001fa8-0x0000000000001fa9: 1: used
0x0000000000001fa9-0x000000000000204b: 162: used
0x000000000000204b-0x00000000000020cb: 128: used
0x00000000000020cb-0x00000000000020cc: 1: used
0x00000000000020cc-0x00000000000020cd: 1: used
0x00000000000020cd-0x0000000000004071: 8100: used
0x0000000000004071-0x0000000000100000: 1032079: free
total: 1048575, used 16496 free 1032079
(there may be others). Does this list appear to increase on each run?
It's also possible to investigate the BO count with /sys/kernel/debug/dri/fec00000.v3d/bo_stats, but from what @pelwell shared, there is indeed a memory leak.
I solved a similar issue yesterday and sent the fix upstream [1]. It's a long-standing issue that has existed since the driver was introduced, but most likely before 8dd6074 we couldn't see it (as we used to run OOM without using the whole memory space).
@pelwell, could you try [1]? It applies to rpi-6.12.y.
The having tried the X11 and wayfire options, neither of which seemed to leak, I've switched back to labwc and the results are confusingly variable/different. There are latencies and hysteresis in the system, but after the first run of KiCad I can no longer see consistent growth in memory usage.
I tried with your patch, Maira, and didn't see obvious change. Neither did reverting it.
I'll try a clean install, just in case raspi-config is not putting things back as they were.
The clean install did not leak to any obvious degree. However, I noticed that your instructions don't quite give the configuration you show - current images still ship with a 6.6 kernel, while you appear to be running 6.12, so you must at least have apt upgraded the kernel.
Oh, I forget to mention that this time around I got a warning about being unable to use OpenGL and falling back to a software renderer, that I don't remember from last time.
0: Just after system reboot, before open kicad, 1: after first start/close cycle, etc:
0: total: 1048575, used 8370 free 1040205
1: total: 1048575, used 88494 free 960081
2: total: 1048575, used 153254 free 895321
3: total: 1048575, used 217288 free 831287
10: total: 1048575, used 651607 free 396968
At open/close cycle 12 error happens on kicad startup:
OpenGL did not shut down properly.
Error: unmapping vertices buffer: invalid operation
Could not use OpenGL, falling back to software rendering
Error: creating buffer during defragmentation: out of memory
I also noticed that if audio is playing in the background (e.g., internet radio via mpg123 or just a sound file in VLC), starting or closing KiCad causes the audio to momentarily drop out, accompanied by very loud crackling from the speakers. This issue occurs even when opening very small schematics containing only a few lines.
It's also possible to investigate the BO count with /sys/kernel/debug/dri/fec00000.v3d/bo_stats, but from what @pelwell shared, there is indeed a memory leak.
it also grows (tested just after reboot with only lxterminal in background):
I was able to reproduce this error exclusively in the RPi 4 (which makes sense as it's a less powerful device, so it might trigger more sched timeouts). I wasn't able to reproduce it with RPi 5 even using the same SD card.
In order to check if there was a buffer object leak, I ran eeschema test.kicad_sch twice and then systemctl stop lightdm (which kills the graphical interface). With that, I was able to check that even without the graphical interface, there are BOs that weren't freed, which indicates a memory leak.
Therefore, from what I could see, [1] should fix this issue, but it would be great to hear some feedback, as Phil didn't get conclusive results. Maybe @zxmak can try the patch and see if it helps.
Activity
pelwell commentedon Apr 27, 2025
Please explain your reasoning.
zxmak commentedon Apr 27, 2025
The reasoning is that despite the KiCad process ending and it's PID disappears from process list, the system’s reported free memory does not recover. The lost memory remains occupied and cannot be used by other programs. In particular, no user-space process is holding that memory (it’s not visible in any running program or shared-memory segment).
I checked common shared-memory areas (e.g. /dev/shm) and found nothing unusual – no large temporary files or POSIX segments remain. This suggests the missing memory isn’t tied up in the normal shared-memory filesystem.
Since the KiCad process is gone, and by design its allocated pages should have been freed on exit, the only remaining explanation is that some kernel component is still holding the memory. In other words, the leak appears to be at the kernel level rather than in user space.
In additon Alt+SysRq+F is unable to free the leaked memory.
KiCad heavily utilizes the GPU for rendering, and since the amount of leaked memory after the process terminates appears to be proportional to the complexity of the schematic's geometry, this leads me to believe that the leak is most likely related to the GPU driver.
pelwell commentedon Apr 27, 2025
I don't think that's true - it's also possible (and I tend to think more likely) that some part of the GUI is still holding resources on behalf of KiCad, even though the process has closed.
zxmak commentedon Apr 27, 2025
Could you clarify which part of the GUI you believe might be holding these resources?
As I mentioned earlier, there are no processes listed that account for the missing memory, which strongly indicates that the leak is not occurring within user-space processes.
Additionally, I have tested restarting both wf-panel-pi and labwc, which fully resets the GUI, including returning to the login screen. However, immediately after logging back in, more than 3 GB of memory remains occupied, and there are still no processes in the process list that explain this usage.
This further supports the conclusion that the memory leak occurs at the kernel level rather than in user space.
popcornmix commentedon Apr 28, 2025
I've not very familiar with the v3d driver, but there are some stats here:
(there may be others). Does this list appear to increase on each run?
pelwell commentedon Apr 28, 2025
Yes, it does.
After reboot:
After 1 open/close cycle:
After 2:
Interestingly, the kernel kmemleak detection isn't showing anything.
mairacanal commentedon Apr 28, 2025
It's also possible to investigate the BO count with
/sys/kernel/debug/dri/fec00000.v3d/bo_stats, but from what @pelwell shared, there is indeed a memory leak.I solved a similar issue yesterday and sent the fix upstream [1]. It's a long-standing issue that has existed since the driver was introduced, but most likely before 8dd6074 we couldn't see it (as we used to run OOM without using the whole memory space).
@pelwell, could you try [1]? It applies to rpi-6.12.y.
[1] https://lore.kernel.org/dri-devel/ace509ac67221d5a3e7215ea132c8155179850e4.camel@igalia.com/T/
pelwell commentedon Apr 28, 2025
The having tried the X11 and wayfire options, neither of which seemed to leak, I've switched back to labwc and the results are confusingly variable/different. There are latencies and hysteresis in the system, but after the first run of KiCad I can no longer see consistent growth in memory usage.
I tried with your patch, Maira, and didn't see obvious change. Neither did reverting it.
I'll try a clean install, just in case raspi-config is not putting things back as they were.
pelwell commentedon Apr 28, 2025
The clean install did not leak to any obvious degree. However, I noticed that your instructions don't quite give the configuration you show - current images still ship with a 6.6 kernel, while you appear to be running 6.12, so you must at least have apt upgraded the kernel.
pelwell commentedon Apr 28, 2025
Oh, I forget to mention that this time around I got a warning about being unable to use OpenGL and falling back to a software renderer, that I don't remember from last time.
zxmak commentedon Apr 28, 2025
Yes, it grows very much.
0: Just after system reboot, before open kicad, 1: after first start/close cycle, etc:
At open/close cycle 12 error happens on kicad startup:
I also noticed that if audio is playing in the background (e.g., internet radio via mpg123 or just a sound file in VLC), starting or closing KiCad causes the audio to momentarily drop out, accompanied by very loud crackling from the speakers. This issue occurs even when opening very small schematics containing only a few lines.
zxmak commentedon Apr 28, 2025
it also grows (tested just after reboot with only lxterminal in background):
mairacanal commentedon Apr 28, 2025
I was able to reproduce this error exclusively in the RPi 4 (which makes sense as it's a less powerful device, so it might trigger more sched timeouts). I wasn't able to reproduce it with RPi 5 even using the same SD card.
In order to check if there was a buffer object leak, I ran
eeschema test.kicad_schtwice and thensystemctl stop lightdm(which kills the graphical interface). With that, I was able to check that even without the graphical interface, there are BOs that weren't freed, which indicates a memory leak.Now, after applying the patch mentioned previously [1], I get:
Therefore, from what I could see, [1] should fix this issue, but it would be great to hear some feedback, as Phil didn't get conclusive results. Maybe @zxmak can try the patch and see if it helps.
[1] https://lore.kernel.org/dri-devel/ace509ac67221d5a3e7215ea132c8155179850e4.camel@igalia.com/T/
pelwell commentedon Apr 29, 2025
Thanks for testing it Maira. I'll put your patch in a PR, then it will be easy for @zxmak to try it.
pelwell commentedon Apr 29, 2025
See #6822.
48 remaining items
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped
CVE-2026-74638: Add .vulnerable file
drm/v3d: Add job to pending list if the reset was skipped
drm/v3d: Add job to pending list if the reset was skipped