Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #642

Closed
smalltalking opened this issue Jun 19, 2022 · 15 comments
Closed

Memory leak #642

smalltalking opened this issue Jun 19, 2022 · 15 comments
Labels

Comments

@smalltalking
Copy link
Contributor

I noticed that recent VMs leak a few hundred kilobytes of memory every 3-6 seconds. It happens even if you just start VM and do nothing with the image.
I tested it with various 64-bit Linux VMs. There seems to be no upper limit on the leaked memory. The leak happens even with the -memory option set. The size of the object memory is not affected by the leak, saved images remain small and the image does not see the increase in memory usage.
Affected VMs include: 5.0-202206021410, 5.0-202205110711, 5.0-202204190959
Unaffected VMs include: 5.0-202112022203 and 5.0-202112201228
The 5.0-202206021410 assert and debug VMs leak the memory as well.

@OpenSmalltalk-Bot
Copy link

OpenSmalltalk-Bot commented Jun 21, 2022 via email

@OpenSmalltalk-Bot
Copy link

OpenSmalltalk-Bot commented Jun 21, 2022 via email

@eliotmiranda
Copy link
Contributor

eliotmiranda commented Jun 21, 2022 via email

@marceltaeumel
Copy link
Contributor

marceltaeumel commented Jun 22, 2022

I cannot reproduce this issue on

OS: Win32 10.0 X64
VM: 202206021410 (c9fd365)
SQ: Squeak6.0beta #22056 (64 bit)

Yet, I can reproduce it on Ubuntu 18.04 👍

@edoneel
Copy link
Collaborator

edoneel commented Jun 22, 2022

So I can trigger it so I'll try to bisect it.

Squeak6.0beta
latest update: #22053

platform sources revision VM: 202206181934 XXX@YYY/opensmalltalk-vm Date: Sat Jun 18 12:34:41 2022 CommitHash: 27657fe Plugins: 202206181934 XXX@YYY:tmp/opensmalltalk-vm
CoInterpreter VMMaker.oscog-eem.3188 uuid: 010bab73-d814-4c05-b0f1-f2da78c1568f Jun 20 2022
StackToRegisterMappingCogit VMMaker.oscog-eem.3188 uuid: 010bab73-d814-4c05-b0f1-f2da78c1568f Jun 20 2022

Ubuntu 22.04 - x86-64, does it, see below

Raspberry PI ARMv8 64 bit based on Debian 11.3, ie, April 4 2022, does not.

Raspberry PI ARMv7 32 bit based on Debian 11.3, ie, April 4 2022 does not. Of course this one is the 32 bit VM and the 32 bit image but the identical image/vm combo as above.

Ubuntu 18.04 ARMv8 64 bit does it, also see below.

==========================
Ubuntu 22.04 - x86-64.

$ while true; do ps -C squeak -o rss; sleep 5; done
RSS
71668
RSS
71928
RSS
72984
RSS
73248
RSS
73248
RSS
73512
RSS
73776
RSS
73776
RSS
74040
RSS
74040
RSS
74304
RSS
74304
RSS
74568
RSS
74568
RSS
74832
RSS
75096
RSS
75096
RSS
75360
RSS
75360
RSS
75624
RSS
75624
RSS
75888
RSS
76152
RSS
76152

=====================================
Ubuntu 18.04, ARMv8 64 bit

76764
RSS
76764
RSS
77028
RSS
77292
RSS
77292
RSS
77556
RSS
77556
RSS
77820
RSS
77820
RSS
78084
RSS
78348
RSS
78348
RSS
78612
RSS
78612
RSS
78876
RSS
78876
RSS
79140
RSS
79404
RSS
79404
RSS
79668
RSS
79668
RSS
79932
RSS
79932
RSS
80196
RSS
80460

@edoneel
Copy link
Collaborator

edoneel commented Jun 23, 2022

So I spent some time looking into this and I think I have tracked down when it happens. In all cases my test case was Ubuntu 22.04 on x86-64 but I also see it on Ubuntu 18.04 on ARMv8.

Some recent change to the combo of the VM and the image will do this, but, only on a local X11 display when you are displaying. Using -vm-display-X11 -headless prevents this from happening, so, good news, servers will be ok. It also does not happen when you use a remote X11 display. It only happens when you use a local graphics card.

It does not show up in the squeak memory usage, just the RSS size. I guess that something is not getting freed somewhere in C, and it looks to be somewhere in the C code for the X11 driver.

Wayland vs X11 does not change anything.

This was not in Squeak 5.3 and the Squeak 53 VM running almost the newest 6.0 image is ok too.

e908c9c 20220621T1716 ** Squeak6.0rc1 22076 ** Bad
202206021410 ** Squeak6.0rc1 22076 ** Bad
e908c9c 20220621T1716 ** Squeak5.3-19481 ** Good
6a0bc96 202003021730 ** Squeak6.0beta-21757 ** Good

@edoneel
Copy link
Collaborator

edoneel commented Jun 24, 2022

This can be closed here because it is not a VM issue. It is an image side issue between image update 20981, which is good, and image update 21617 which has this problem. Updating a working 20981 image with all updates causes it to start increasing RSS.

@edoneel
Copy link
Collaborator

edoneel commented Jun 24, 2022

Closed relative to squeak-smalltalk/squeak-object-memory#51

@edoneel edoneel closed this as completed Jun 24, 2022
@edoneel edoneel reopened this Jun 24, 2022
@edoneel
Copy link
Collaborator

edoneel commented Jun 24, 2022

I think this might be better solved on the VM side.

@edoneel
Copy link
Collaborator

edoneel commented Jun 24, 2022

So - Sometime this spring between change 20981 and change 21617 there were changes made to the screen resolution code that changed how often, it seems, we call display_ioScreenScaleFactor. Before it must have been rarely called like on startup and resize or whatever and now it is called often, sometimes many times per second.

The X11 code, being X11 code for Linux, has multiple ways of getting the screen scale factor. Which path was followed depended on some things but on assorted Ubuntu systems the path followed called scale_Xftdpi_usable. This called XrmGetStringDatabase every time it entered but if Xft.dpi was there then it returned without calling XrmDestroyDatabase. Ergo the memory leaked.

The patch is trivial and attached

PatchX11Scale.patch.txt
.

@edoneel edoneel closed this as completed Jun 24, 2022
@krono
Copy link
Member

krono commented Jun 24, 2022

Oh, how embarrasing. I'm really sorry.

@marceltaeumel
Copy link
Contributor

This can be closed here because it is not a VM issue. It is an image side issue between image update 20981, which is good, and image update 21617 which has this problem. Updating a working 20981 image with all updates causes it to start increasing RSS.

Just a minor remark on this intermediate conclusion. At that point, we already knew that the .image file was not affected. It did not get bigger because of the memory leak. While an image-side workaround might have been possible, it clearly pointed to VM-side code not being correct. From the top of my hat, I cannot think of a scenario where non-FFI, image-only code leaks memory without affecting the .image size. (Maybe thousands of open file handles? But those have image-side counterparts as well, thus affecting the .image size.)

Thanks for the thorough investigation, Bruce!!! ❤️

@marceltaeumel
Copy link
Contributor

@edoneel
Copy link
Collaborator

edoneel commented Oct 11, 2022 via email

@OpenSmalltalk-Bot
Copy link

OpenSmalltalk-Bot commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants