Subject: Re: bug#49656: more data on #43389

From: Madhu <[email-masked]>
Date: Wed, 21 Jul 2021 07:16:23 +0530 (IST)

*  Eli Zaretskii <[email-masked]> <[email-masked]>
Wrote on Tue, 20 Jul 2021 20:11:29 +0300
>> Date: Tue, 20 Jul 2021 21:38:37 +0530 (IST)
>> From: Madhu <[email-masked]>
>>
>> In all other cases I hit the memory leak gc thinks it only has 200M
>> while the process has 1.5 to 3.5 GB resident.
>>
>> I don't see how this can  be a user error.
>
> It could be if, for example, you are using packages or your own code
> which plays with GC thresholds.  E.g., I'm told that lsp-mode does
> that; are you per chance using it?

No I haven't gotten around to trying that i'm sure none of my packages
mess with gc-threshold.  I will double check that.

> How much memory and swap do you have there?  Can you enlarge the total
> VM size (by enlarging swap) so that you could run Emacs longer when it
> gets to such large sizes?

The problem is not that emacs won't run.  I am unable to use the
memory in the machine for other purposes and am obliged to kill emacs.

> Btw, 1.5GB is not too large for several days worth of work.

I also have emacs running for several weeks when the problem doesn't
happen with RES never above say 500M for the same workloads and usage
patterns.

> Are you sure no package you use does something like that?  What were
> the values of GC thresholds when the memory was large?

Yes I do not run a lot of packages and certainly nothing that I don't
audit first - I am aware of all the packages that are loaded at least
in the exceptional cases.  There is no reason for me to suspect those
packages because I use them all the time in emacs sessions where the
problem does not manifest.

>  Was the value of gcs-done increasing with time, or did it stay put
> (which would be an evidence that Emacs doesn't run GC at all)?  If
> GC was running, how frequently did it run?  (You could answer the
> last question either by looking at the rate of growth in gcs-done,
> or by setting garbage-collection-messages non-nil, which will cause
> Emacs announce ever GC in the echo area.)

There is nothing exceptional with GC. GC usually completes quickly
because it doesnt access much memory.

>> But doesn't the malloc info allocation and the gc reports indicate a
>> clear discrepancy?
>
> Not to me, it doesn't.  It means the malloc arena holds to a lot of
> memory that it cannot release to the OS, but it is known that this can
> happen for certain patterns of memory allocation and deallocation.
> You can find explanations of why this happens on the net.

But that is the point - I've been asking from the first time I posted
on this - WHAT is emacs allocating in these exceptional cases.  I
understand my usage patterns over the years of constant emacs use and
the "random" memory bloat in some sessions makes no sense and it only
suggests a memory leak in emacs code.

>> Does it not indicate a leak which the GC is not aware of?
>
> No.  Emacs allocates a lot of memory for purposes other than Lisp
> objects, and that memory is not visible to GC nor to memory-report.

This is too vague.  This 2GB active memory is not legitimate and the
point is to figure out where and why emacs is holding on to this
memory.

This is where I need assistance.  my usage patterns are pretty
deterministic The memory usage of the qlisp packages I use would show
up in GC.

SO what could that be, which it is NOT allocating under identical
usage patterns?  It isn't fonts or external images or anything else I
can see.

I'm sure others should be hitting the problem too