-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
statistics(memory, _) unexpectedly reports very small numbers #290
Comments
On 02-03-18 09:22, Markus Triska wrote:
Please consider the following sample program:
:- use_module(library(clpfd)).
run(N0) :-
assertz(pred(mem)),
N #= N0 + 1,
( N mod 100 #= 0 ->
statistics(memory, [M|_]),
portray_clause(num_mem(N, M))
; true
),
run(N).
On Debian 9.3, I get with SWI-Prolog 7.7.9:
*?- run(0).*
num_mem(100, 6144).
num_mem(200, 7928).
num_mem(300, 9712).
num_mem(400, 11496).
num_mem(500, 13280).
*num_mem(600, 2352).*
num_mem(700, 4136).
num_mem(800, 5920).
num_mem(900, 7704).
num_mem(1000, 9488).
num_mem(1100, 11272).
num_mem(1200, 13056).
*num_mem(1300, 2544).*
...
num_mem(2482000, 64176).
...
*num_mem(2482400, 9552).*
...
num_mem(2492200, 60608).
...
*num_mem(2492700, 7768).*
etc.
It seems that no matter how long this runs, very small values of
unshared memory are periodically reported by |statistics/2| . However, I
see from |htop| that memory usage of this program *grows more or less
constantly* and without bounds.
I uses this code:
#if defined(HAVE_GETRUSAGE) && defined(HAVE_RU_IDRSS)
struct rusage usage;
if ( getrusage(RUSAGE_SELF, &usage) == 0 &&
usage.ru_idrss )
{ return usage.ru_idrss; /* total unshared data */
}
#endif
See UsedMemory() in pl-os.c
A (much) more accurate measure of the memory that is actually used is
obviously highly desirable in many situations, for example to assess how
much space particular terms take (example: SSL contexts).
Is |memory| intended to be a suitable measure for such cases? Is there a
parameter that lets us reliably obtain the used memory?
Not really. It is a Quintus compatibility key, but in modern OSes it
isn't that easy to get anything usable in a portable manner. If you
have glibc (Linux), there is library(mallocinfo) that provides much
more accurate and detailed statistics.
I recently found the heaptrack program. That is really neat.
For comparison, |statistics/2| behaves as I would expect in the
following case:
This suggests it didn't configure getrusage() right on your system.
I guess you can figure that out yourself :)
Cheers --- Jan
…
bigger([_|Ls], N0) :-
N #= N0 + 1,
( N mod 100 #= 0 ->
statistics(memory, [M|_]),
portray_clause(num_mem(N, M))
; true
),
bigger(Ls, N).
Sample query:
?- bigger(Ls, 0).
num_mem(100, 4964).
num_mem(200, 6272).
num_mem(300, 7580).
num_mem(400, 8888).
num_mem(500, 10196).
num_mem(600, 11504).
...
num_mem(110000, 1442456).
num_mem(110100, 1443764).
num_mem(110200, 1445072).
num_mem(110300, 1446380).
num_mem(110400, 1447688).
etc.
Further, I note the following unexpected result:
?- statistics(memory, X).
X = [10056,*-10057*].
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#290>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AC7cqnBBvBw4n4ajdOCtcPHKL5hiEfz2ks5taX-cgaJpZM4SaOYC>.
|
@JanWielemaker #if defined(HAVE_GETRUSAGE) && defined(HAVE_RU_IDRSS)
struct rusage usage;
if ( getrusage(RUSAGE_SELF, &usage) == 0 && usage.ru_idrss ) {
return usage.ru_idrss; /* total unshared data */
}
#endif If we run
Notice ru_idrss is |
What does htop use?I looked through What fields from statm to use?Mr. Jan mentions that it is difficult to decide what 'memory usage means'. This is so true. Now,
Maybe
|
The code for I don't think it is worth the trouble trying to maintain many platform specific implementations trying to provide an as good as possible approximation of used and free memory for which it is still hard to assess whether that figure provides what the user wants to know and that all means something slightly different. Note that the |
Hi Jan, Thanks! Why would the swi computation return that strangely low number? Perhaps there is some interaction
I have seen this before, but I can't reproduce it now. |
It has the strange habit to report the combined stack size, which are typically low in the toplevel. I'll change this to simply return |
Thanks! |
Pushed 696a260 to resolve this. |
Thanks! I just found term_size/2 gives you the precise size of a term in cells (8 bytes for 64bit; 4 bytes for 32bit). Perhaps @triska and others reading this thread will find this useful for use cases in which you want to know the precise size of a term. |
Please consider the following sample program:
On Debian 9.3, I get with SWI-Prolog 7.7.9:
It seems that no matter how long this runs, very small values of unshared memory are periodically reported by
statistics/2
. However, I see fromhtop
that memory usage of this program grows more or less constantly and without bounds.A (much) more accurate measure of the memory that is actually used is obviously highly desirable in many situations, for example to assess how much space particular terms take (example: SSL contexts).
Is
memory
intended to be a suitable measure for such cases? Is there a parameter that lets us reliably obtain the used memory?For comparison,
statistics/2
behaves as I would expect in the following case:Sample query:
Further, I note the following unexpected result:
The text was updated successfully, but these errors were encountered: