bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reclaiming memory before exit


From: Bruno Haible
Subject: Re: reclaiming memory before exit
Date: Fri, 15 May 2020 21:58:25 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; )

Kamil Dudka wrote:
> How old is the text in GNU standards that Bruno refers to?

How old it is, is irrelevant because the two main points are valid and will
continue to be valid (if the tools don't change):

  1) The sentence "if memory is used until just before a process exits,
     don’t free it simply to silence such a tool" [1] is valid as long
     as GNU targets not an embedded OS for a hardware without MMU, but
     an operation system that frees all resources of a process when the
     process exits.

     A call to 'free (ptr);' right before exit() is a big waste of
     computation resources, because
       - it fetches the memory page of 'ptr' from swap into main memory, or
       - it pulls the memory contents of 'ptr' in the L2 or L1 cache.

     This will not change. And by your argument in this thread, you want
     the program that we run with 'valgrind' (or gcc's or clang's
     LeakSanitizer) during "make check" to be identical to the program
     that you distribute as binaries.

  2) You are going for a goal that you can never fully achieve [2].

You can certainly bring up the issue on the bug-standards list. But you
will have no success, as long as these two points are eliminated.

What can be done to remove these points?

In [2] I suggested to standardize the suppressions file format.

Another possibility is to standardize on a GCC attribute for functions,
with the meaning "memory allocations done inside this functions are
on the same level as static initializations and don't need to be
reclaimed before program exit". valgrind and the leak sanitizers -
which do stack traces anyway - would need to test whether some function
that occur in such stack trace is marked with this GCC attribute.

This could eliminate the problem 2).

For problem 1), maybe trigger the explicit free before exit only if
some environment variable is set?

Bruno

[1] https://www.gnu.org/prep/standards/html_node/Memory-Usage.html
[2] https://lists.gnu.org/archive/html/bug-gnulib/2018-10/msg00037.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]