public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/zack/y2038-preliminaries] misc: Use allocate_once in getmntent
@ 2019-08-28 13:04 Zack Weinberg
0 siblings, 0 replies; only message in thread
From: Zack Weinberg @ 2019-08-28 13:04 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=35ffd20dbd76d3cb6b478c7a69bb40d8c827ed81
commit 35ffd20dbd76d3cb6b478c7a69bb40d8c827ed81
Author: Florian Weimer <fweimer@redhat.com>
Date: Wed Aug 28 12:01:48 2019 +0200
misc: Use allocate_once in getmntent
Both the buffer and struct mntent are now allocated on the heap.
This results in a slight reduction of RSS usage.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
ChangeLog | 8 ++++++++
misc/mntent.c | 37 +++++++++++++++++++++----------------
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a0c6a0e..37c2ff3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2019-08-28 Florian Weimer <fweimer@redhat.com>
+ * misc/mntent.c (struct mntent_buffer): Define.
+ (mntent_buffer): Adjust type to void *.
+ (allocate): Adjust for allocate_once.
+ (deallocate): New function.
+ (getmntent): Call allocate_once.
+
+2019-08-28 Florian Weimer <fweimer@redhat.com>
+
nptl: Move pthread_attr_setdetachstate implementation into libc.
* nptl/Makefile (routines): Add pthread_attr_setdetachstate.
(libpthread-routines): Remove pthread_attr_setdetachstate.
diff --git a/misc/mntent.c b/misc/mntent.c
index 980ea40..8fae606 100644
--- a/misc/mntent.c
+++ b/misc/mntent.c
@@ -18,36 +18,41 @@
#include <mntent.h>
#include <stdlib.h>
-#include <libc-lock.h>
+#include <allocate_once.h>
-/* We don't want to allocate the static buffer all the time since it
- is not always used (in fact, rather infrequently). Accept the
- extra cost of a `malloc'. */
-libc_freeres_ptr (static char *getmntent_buffer);
+struct mntent_buffer
+{
+ struct mntent m;
+ char buffer[4096];
+};
-/* This is the size of the buffer. This is really big. */
-#define BUFFER_SIZE 4096
+/* We don't want to allocate the static buffer all the time since it
+ is not always used (in fact, rather infrequently). */
+libc_freeres_ptr (static void *mntent_buffer);
+static void *
+allocate (void *closure)
+{
+ return malloc (sizeof (struct mntent_buffer));
+}
static void
-allocate (void)
+deallocate (void *closure, void *ptr)
{
- getmntent_buffer = (char *) malloc (BUFFER_SIZE);
+ free (ptr);
}
-
struct mntent *
getmntent (FILE *stream)
{
- static struct mntent m;
- __libc_once_define (static, once);
- __libc_once (once, allocate);
-
- if (getmntent_buffer == NULL)
+ struct mntent_buffer *buffer = allocate_once (&mntent_buffer,
+ allocate, deallocate, NULL);
+ if (buffer == NULL)
/* If no core is available we don't have a chance to run the
program successfully and so returning NULL is an acceptable
result. */
return NULL;
- return __getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE);
+ return __getmntent_r (stream, &buffer->m,
+ buffer->buffer, sizeof (buffer->buffer));
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-08-28 13:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-28 13:04 [glibc/zack/y2038-preliminaries] misc: Use allocate_once in getmntent Zack Weinberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).