[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 29f3d4d2c6: Add new function `malloc-trim'
From: |
Lars Ingebrigtsen |
Subject: |
master 29f3d4d2c6: Add new function `malloc-trim' |
Date: |
Sun, 1 May 2022 05:51:50 -0400 (EDT) |
branch: master
commit 29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add new function `malloc-trim'
* configure.ac (PGTK_LIBS): Check for malloc_trim.
* src/alloc.c (Fmalloc_trim): Add new function (bug#45200).
---
configure.ac | 2 ++
etc/NEWS | 5 +++++
src/alloc.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+)
diff --git a/configure.ac b/configure.ac
index 53e5779e2f..b7189593a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2939,6 +2939,8 @@ fi
AC_SUBST(PGTK_OBJ)
AC_SUBST(PGTK_LIBS)
+AC_CHECK_FUNCS(malloc_trim)
+
dnl D-Bus has been tested under GNU/Linux only. Must be adapted for
dnl other platforms.
HAVE_DBUS=no
diff --git a/etc/NEWS b/etc/NEWS
index 3f22e0b04e..371fbc2145 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1544,6 +1544,11 @@ functions.
* Lisp Changes in Emacs 29.1
+---
+** New function 'malloc-trim'.
+This function allows returning unused memory back to the operating
+system, and is mainly meant as a debugging tool.
+
---
** 'x-show-tip' no longer hard-codes a timeout default.
The new 'x-show-tooltip-timeout' variable allows the user to alter
diff --git a/src/alloc.c b/src/alloc.c
index b9712859c3..661f37dd5c 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -7479,6 +7479,37 @@ arenas. */)
}
#endif
+#ifdef HAVE_MALLOC_TRIM
+DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "",
+ doc: /* Release free memory from the heap.
+This function asks libc to return unused memory back to the operating
+system. This function isn't guaranteed to do anything, and is mainly
+meant as a debugging tool.
+
+If LEAVE_PADDING is given, ask the system to leave that much unused
+spaced in the heap. This should be an integer, and if not given,
+defaults to 0.
+
+This function returns nil if no memory could be returned to the
+system, and non-nil if some memory could be returned. */)
+ (Lisp_Object leave_padding)
+{
+ int pad = 0;
+
+ if (! NILP (leave_padding))
+ {
+ CHECK_FIXNAT (leave_padding);
+ pad = XFIXNUM (leave_padding);
+ }
+
+ /* 1 means that memory was released to the system. */
+ if (malloc_trim (pad) == 1)
+ return Qt;
+ else
+ return Qnil;
+}
+#endif
+
static bool
symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj)
{
@@ -7829,6 +7860,9 @@ N should be nonnegative. */);
(__GLIBC__ > 2 || __GLIBC_MINOR__ >= 10)
defsubr (&Smalloc_info);
+#endif
+#ifdef HAVE_MALLOC_TRIM
+ defsubr (&Smalloc_trim);
#endif
defsubr (&Ssuspicious_object);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 29f3d4d2c6: Add new function `malloc-trim',
Lars Ingebrigtsen <=