summaryrefslogtreecommitdiffstats
path: root/man3/malloc_info.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/malloc_info.3')
-rw-r--r--man3/malloc_info.355
1 files changed, 26 insertions, 29 deletions
diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
index ef57abaab..045430b0c 100644
--- a/man3/malloc_info.3
+++ b/man3/malloc_info.3
@@ -3,7 +3,7 @@
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
-.TH malloc_info 3 2023-02-05 "Linux man-pages 6.03"
+.TH malloc_info 3 2023-07-20 "Linux man-pages 6.05.01"
.SH NAME
malloc_info \- export malloc state to a stream
.SH LIBRARY
@@ -41,28 +41,25 @@ is set to indicate the error.
.B EINVAL
.I options
was nonzero.
-.SH VERSIONS
-.BR malloc_info ()
-was added in glibc 2.10.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
-.ad l
-.nh
.TS
allbox;
lbx lb lb
l l l.
Interface Attribute Value
T{
+.na
+.nh
.BR malloc_info ()
T} Thread safety MT-Safe
.TE
-.hy
-.ad
.sp 1
.SH STANDARDS
-This function is a GNU extension.
+GNU.
+.SH HISTORY
+glibc 2.10.
.SH NOTES
The memory-allocation information is provided as an XML string
(rather than a C structure)
@@ -133,7 +130,7 @@ glibc 2.13
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</malloc>
-
+\&
============ After allocating blocks ============
<malloc version="1">
<heap nr="0">
@@ -174,81 +171,81 @@ glibc 2.13
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
static size_t blockSize;
static size_t numThreads;
static unsigned int numBlocks;
-
+\&
static void *
thread_func(void *arg)
{
int tn = (int) arg;
-
+\&
/* The multiplier \[aq](2 + tn)\[aq] ensures that each thread (including
the main thread) allocates a different amount of memory. */
-
+\&
for (unsigned int j = 0; j < numBlocks; j++)
if (malloc(blockSize * (2 + tn)) == NULL)
err(EXIT_FAILURE, "malloc\-thread");
-
+\&
sleep(100); /* Sleep until main thread terminates. */
return NULL;
}
-
+\&
int
main(int argc, char *argv[])
{
int sleepTime;
pthread_t *thr;
-
+\&
if (argc < 4) {
fprintf(stderr,
"%s num\-threads num\-blocks block\-size [sleep\-time]\en",
argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
numThreads = atoi(argv[1]);
numBlocks = atoi(argv[2]);
blockSize = atoi(argv[3]);
sleepTime = (argc > 4) ? atoi(argv[4]) : 0;
-
+\&
thr = calloc(numThreads, sizeof(*thr));
if (thr == NULL)
err(EXIT_FAILURE, "calloc");
-
+\&
printf("============ Before allocating blocks ============\en");
malloc_info(0, stdout);
-
+\&
/* Create threads that allocate different amounts of memory. */
-
+\&
for (size_t tn = 0; tn < numThreads; tn++) {
errno = pthread_create(&thr[tn], NULL, thread_func,
(void *) tn);
if (errno != 0)
err(EXIT_FAILURE, "pthread_create");
-
+\&
/* If we add a sleep interval after the start\-up of each
thread, the threads likely won\[aq]t contend for malloc
mutexes, and therefore additional arenas won\[aq]t be
allocated (see malloc(3)). */
-
+\&
if (sleepTime > 0)
sleep(sleepTime);
}
-
+\&
/* The main thread also allocates some memory. */
-
+\&
for (unsigned int j = 0; j < numBlocks; j++)
if (malloc(blockSize) == NULL)
err(EXIT_FAILURE, "malloc");
-
+\&
sleep(2); /* Give all threads a chance to
complete allocations. */
-
+\&
printf("\en============ After allocating blocks ============\en");
malloc_info(0, stdout);
-
+\&
exit(EXIT_SUCCESS);
}
.EE