diff options
| author | Lars Ingebrigtsen | 2022-05-01 11:51:35 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-01 11:51:43 +0200 |
| commit | 29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035 (patch) | |
| tree | 65df665be56947d52a993896705a6c7c03503019 | |
| parent | 6984f325bdbaf15b1190d0d03b01eebe9cfbbb71 (diff) | |
| download | emacs-29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035.tar.gz emacs-29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035.zip | |
Add new function `malloc-trim'
* configure.ac (PGTK_LIBS): Check for malloc_trim.
* src/alloc.c (Fmalloc_trim): Add new function (bug#45200).
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | src/alloc.c | 34 |
3 files changed, 41 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 53e5779e2f7..b7189593a63 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -2939,6 +2939,8 @@ fi | |||
| 2939 | AC_SUBST(PGTK_OBJ) | 2939 | AC_SUBST(PGTK_OBJ) |
| 2940 | AC_SUBST(PGTK_LIBS) | 2940 | AC_SUBST(PGTK_LIBS) |
| 2941 | 2941 | ||
| 2942 | AC_CHECK_FUNCS(malloc_trim) | ||
| 2943 | |||
| 2942 | dnl D-Bus has been tested under GNU/Linux only. Must be adapted for | 2944 | dnl D-Bus has been tested under GNU/Linux only. Must be adapted for |
| 2943 | dnl other platforms. | 2945 | dnl other platforms. |
| 2944 | HAVE_DBUS=no | 2946 | HAVE_DBUS=no |
| @@ -1545,6 +1545,11 @@ functions. | |||
| 1545 | * Lisp Changes in Emacs 29.1 | 1545 | * Lisp Changes in Emacs 29.1 |
| 1546 | 1546 | ||
| 1547 | --- | 1547 | --- |
| 1548 | ** New function 'malloc-trim'. | ||
| 1549 | This function allows returning unused memory back to the operating | ||
| 1550 | system, and is mainly meant as a debugging tool. | ||
| 1551 | |||
| 1552 | --- | ||
| 1548 | ** 'x-show-tip' no longer hard-codes a timeout default. | 1553 | ** 'x-show-tip' no longer hard-codes a timeout default. |
| 1549 | The new 'x-show-tooltip-timeout' variable allows the user to alter | 1554 | The new 'x-show-tooltip-timeout' variable allows the user to alter |
| 1550 | this for packages that don't use 'tooltip-show', but instead calls the | 1555 | this for packages that don't use 'tooltip-show', but instead calls the |
diff --git a/src/alloc.c b/src/alloc.c index b9712859c38..661f37dd5cc 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -7479,6 +7479,37 @@ arenas. */) | |||
| 7479 | } | 7479 | } |
| 7480 | #endif | 7480 | #endif |
| 7481 | 7481 | ||
| 7482 | #ifdef HAVE_MALLOC_TRIM | ||
| 7483 | DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "", | ||
| 7484 | doc: /* Release free memory from the heap. | ||
| 7485 | This function asks libc to return unused memory back to the operating | ||
| 7486 | system. This function isn't guaranteed to do anything, and is mainly | ||
| 7487 | meant as a debugging tool. | ||
| 7488 | |||
| 7489 | If LEAVE_PADDING is given, ask the system to leave that much unused | ||
| 7490 | spaced in the heap. This should be an integer, and if not given, | ||
| 7491 | defaults to 0. | ||
| 7492 | |||
| 7493 | This function returns nil if no memory could be returned to the | ||
| 7494 | system, and non-nil if some memory could be returned. */) | ||
| 7495 | (Lisp_Object leave_padding) | ||
| 7496 | { | ||
| 7497 | int pad = 0; | ||
| 7498 | |||
| 7499 | if (! NILP (leave_padding)) | ||
| 7500 | { | ||
| 7501 | CHECK_FIXNAT (leave_padding); | ||
| 7502 | pad = XFIXNUM (leave_padding); | ||
| 7503 | } | ||
| 7504 | |||
| 7505 | /* 1 means that memory was released to the system. */ | ||
| 7506 | if (malloc_trim (pad) == 1) | ||
| 7507 | return Qt; | ||
| 7508 | else | ||
| 7509 | return Qnil; | ||
| 7510 | } | ||
| 7511 | #endif | ||
| 7512 | |||
| 7482 | static bool | 7513 | static bool |
| 7483 | symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj) | 7514 | symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj) |
| 7484 | { | 7515 | { |
| @@ -7830,6 +7861,9 @@ N should be nonnegative. */); | |||
| 7830 | 7861 | ||
| 7831 | defsubr (&Smalloc_info); | 7862 | defsubr (&Smalloc_info); |
| 7832 | #endif | 7863 | #endif |
| 7864 | #ifdef HAVE_MALLOC_TRIM | ||
| 7865 | defsubr (&Smalloc_trim); | ||
| 7866 | #endif | ||
| 7833 | defsubr (&Ssuspicious_object); | 7867 | defsubr (&Ssuspicious_object); |
| 7834 | 7868 | ||
| 7835 | Lisp_Object watcher; | 7869 | Lisp_Object watcher; |