OSDN Git Service

LDP: Address fuzzy changes (memory)
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / mallinfo.3
1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\"*******************************************************************
26 .\"
27 .\" This file was generated with po4a. Translate the source file.
28 .\"
29 .\"*******************************************************************
30 .TH MALLINFO 3 2020\-11\-01 Linux "Linux Programmer's Manual"
31 .SH 名前
32 mallinfo \- メモリー割り当て情報を取得する
33 .SH 書式
34 \fB#include <malloc.h>\fP
35 .PP
36 \fBstruct mallinfo mallinfo(void);\fP
37 .SH 説明
38 \fBmallinfo\fP() 関数は、 \fBmalloc\fP(3) や一連の関数により実行されたメモリー割り当てに関する情報を格納した構造体のコピーを返す。
39 .PP
40 Note that not all allocations are visible to \fBmallinfo\fP(); see BUGS and
41 consider using \fBmalloc_info\fP(3)  instead.
42 .PP
43 The returned structure is defined as follows:
44 .PP
45 .in +4n
46 .EX
47 struct mallinfo {
48     int arena;     /* Non\-mmapped space allocated (bytes) */
49     int ordblks;   /* Number of free chunks */
50     int smblks;    /* Number of free fastbin blocks */
51     int hblks;     /* Number of mmapped regions */
52     int hblkhd;    /* Space allocated in mmapped regions (bytes) */
53     int usmblks;   /* See below */
54     int fsmblks;   /* Space in freed fastbin blocks (bytes) */
55     int uordblks;  /* Total allocated space (bytes) */
56     int fordblks;  /* Total free space (bytes) */
57     int keepcost;  /* Top\-most, releasable space (bytes) */
58 };
59 .EE
60 .in
61 .PP
62 \fImallinfo\fP 構造体の各フィールドには以下の情報が格納される。
63 .TP  10
64 \fIarena\fP
65 \fBmmap\fP(2) 以外の手段で割り当てられた総メモリー量 (例えばヒープに割り当てられたメモリー) 。
66 この数字には使用中のブロックやフリーリスト上のブロックも含まれる。
67 .TP 
68 \fIordblks\fP
69 通常の (つまり fastbin ではない) 未使用ブロック数。
70 .TP 
71 \fIsmblks\fP
72 .\" the glibc info page wrongly says this field is unused
73 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=26746
74 fastbin 未使用ブロック数 (\fBmallopt\fP(3) 参照)。
75 .TP 
76 \fIhblks\fP
77 \fBmmap\fP(2) を使って現在割り当てられているブロック数 (\fBmallopt\fP(3) の \fBM_MMAP_THRESHOLD\fP
78 の議論を参照)。
79 .TP 
80 \fIhblkhd\fP
81 \fBmmap\fP(2) を使って現在割り当てられているブロックのバイト数。
82 .TP 
83 \fIusmblks\fP
84 .\" It seems to have been zero since at least as far back as glibc 2.15
85 This field is unused, and is always 0.  Historically, it was the "highwater
86 mark" for allocated space\(emthat is, the maximum amount of space that was
87 ever allocated (in bytes); this field was maintained only in nonthreading
88 environments.
89 .TP 
90 \fIfsmblks\fP
91 .\" the glibc info page wrongly says this field is unused
92 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=26746
93 fastbin フリーブロックの総バイト数。
94 .TP 
95 \fIuordblks\fP
96 使用中の割り当てメモリーで使われているバイト数。
97 .TP 
98 \fIfordblks\fP
99 フリーブロックの総バイト数。
100 .TP 
101 \fIkeepcost\fP
102 .\" .SH VERSIONS
103 .\" Available already in glibc 2.0, possibly earlier
104 ヒープの一番上にある解放可能な未使用の空間の大きさ。 この値は \fBmalloc_trim\fP(3) で理想的な場合に解放できる最大のバイト数である
105 (理想的というのは、 ページ境界の制限などを無視した場合である。
106 .SH 属性
107 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。
108 .TS
109 allbox;
110 lb lb lbw28
111 l l l.
112 インターフェース        属性  値
113 T{
114 \fBmallinfo\fP()
115 T}      Thread safety   MT\-Unsafe init const:mallopt
116 .TE
117 .sp 1
118 \fBmallinfo\fP()  would access some global internal objects.  If modify them
119 with non\-atomically, may get inconsistent results.  The identifier
120 \fImallopt\fP in \fIconst:mallopt\fP mean that \fBmallopt\fP()  would modify the
121 global internal objects with atomics, that make sure \fBmallinfo\fP()  is safe
122 enough, others modify with non\-atomically maybe not.
123 .SH 準拠
124 この関数は POSIX や C 標準では規定されていない。 多くの System V 由来のシステムに同様の関数が存在し、 SVID
125 では同様の関数が規定されていた。
126 .SH バグ
127 .\" FIXME . http://sourceware.org/bugzilla/show_bug.cgi?id=208
128 .\" See the 24 Aug 2011 mail by Paul Pluzhnikov:
129 .\"     "[patch] Fix mallinfo() to accumulate results for all arenas"
130 .\" on libc-alpha@sourceware.org
131 \fBこれらの情報はメインのメモリー割り当て領域に対するもののみである。\fP 他の領域の割り当ては対象にならない。
132 他の領域の情報も取得できる別の手段については \fBmalloc_stats\fP(3) や \fBmalloc_info\fP(3) を参照。
133 .PP
134 \fImallinfo\fP 構造体の各フィールドは \fIint\fP 型である。 しかし、 いくつかの内部管理用の値は \fIlong\fP 型の場合もあるので、
135 報告される値が一周してしまい、 不正確になる可能性がある。
136 .SH 例
137 以下のプログラムは \fBmallinfo\fP() を利用して、 メモリーブロックの割り当て、解放のそれぞれ前後でメモリー割り当ての統計情報を取得する。
138 統計情報は標準出力に表示される。
139 .PP
140 最初の 2 つのコマンドライン引き数は \fBmalloc\fP(3) で割り当てるブロック数とサイズを指定する。
141 .PP
142 残りの 3 つの引き数は、どの割り当てられたブロックを \fBfree\fP(3) で解放すべきかを指定する。 これらの 3 つの引き数の指定は任意で、
143 最初のものから順に以下の情報を指定する。 1 つ目の引き数は、 ブロックを解放するループで使用するステップサイズを指定する (デフォルト値は 1 で、
144 1 は指定した範囲のすべてのブロックを解放することを意味する)。 2 つ目の引き数は、 解放する先頭ブロックの場所番号を指定する (デフォルト値は 0
145 で、 0 は先頭の割り当て済みブロックを意味する)。 3 つ目の引き数は、 解放する最終ブロックの場所番号よりひとつ大きい値を指定する
146 (デフォルト値は最大ブロック番号よりもひとつ大きい値である)。 これらの 3 つの引き数が省略された場合、
147 デフォルトではすべての割り当てられたブロックが解放される。
148 .PP
149 以下のプログラムの実行例では、 100 バイトの割り当てを 1000 回実行し、 割り当てたブロックの 2 つに 1 つを解放する。
150 .PP
151 .in +4n
152 .EX
153 $ \fB./a.out 1000 100 2\fP
154 ============== Before allocating blocks ==============
155 Total non\-mmapped bytes (arena):       0
156 # of free chunks (ordblks):            1
157 # of free fastbin blocks (smblks):     0
158 # of mapped regions (hblks):           0
159 Bytes in mapped regions (hblkhd):      0
160 Max. total allocated space (usmblks):  0
161 Free bytes held in fastbins (fsmblks): 0
162 Total allocated space (uordblks):      0
163 Total free space (fordblks):           0
164 Topmost releasable block (keepcost):   0
165
166 ============== After allocating blocks ==============
167 Total non\-mmapped bytes (arena):       135168
168 # of free chunks (ordblks):            1
169 # of free fastbin blocks (smblks):     0
170 # of mapped regions (hblks):           0
171 Bytes in mapped regions (hblkhd):      0
172 Max. total allocated space (usmblks):  0
173 Free bytes held in fastbins (fsmblks): 0
174 Total allocated space (uordblks):      104000
175 Total free space (fordblks):           31168
176 Topmost releasable block (keepcost):   31168
177
178 ============== After freeing blocks ==============
179 Total non\-mmapped bytes (arena):       135168
180 # of free chunks (ordblks):            501
181 # of free fastbin blocks (smblks):     0
182 # of mapped regions (hblks):           0
183 Bytes in mapped regions (hblkhd):      0
184 Max. total allocated space (usmblks):  0
185 Free bytes held in fastbins (fsmblks): 0
186 Total allocated space (uordblks):      52000
187 Total free space (fordblks):           83168
188 Topmost releasable block (keepcost):   31168
189 .EE
190 .in
191 .SS プログラムのソース
192 \&
193 .EX
194 #include <malloc.h>
195 #include <stdlib.h>
196 #include <string.h>
197
198 static void
199 display_mallinfo(void)
200 {
201     struct mallinfo mi;
202
203     mi = mallinfo();
204
205     printf("Total non\-mmapped bytes (arena):       %d\en", mi.arena);
206     printf("# of free chunks (ordblks):            %d\en", mi.ordblks);
207     printf("# of free fastbin blocks (smblks):     %d\en", mi.smblks);
208     printf("# of mapped regions (hblks):           %d\en", mi.hblks);
209     printf("Bytes in mapped regions (hblkhd):      %d\en", mi.hblkhd);
210     printf("Max. total allocated space (usmblks):  %d\en", mi.usmblks);
211     printf("Free bytes held in fastbins (fsmblks): %d\en", mi.fsmblks);
212     printf("Total allocated space (uordblks):      %d\en", mi.uordblks);
213     printf("Total free space (fordblks):           %d\en", mi.fordblks);
214     printf("Topmost releasable block (keepcost):   %d\en", mi.keepcost);
215 }
216
217 int
218 main(int argc, char *argv[])
219 {
220 #define MAX_ALLOCS 2000000
221     char *alloc[MAX_ALLOCS];
222     int numBlocks, freeBegin, freeEnd, freeStep;
223     size_t blockSize;
224
225     if (argc < 3 || strcmp(argv[1], "\-\-help") == 0) {
226         fprintf(stderr, "%s num\-blocks block\-size [free\-step "
227                 "[start\-free [end\-free]]]\en", argv[0]);
228         exit(EXIT_FAILURE);
229     }
230
231     numBlocks = atoi(argv[1]);
232     blockSize = atoi(argv[2]);
233     freeStep = (argc > 3) ? atoi(argv[3]) : 1;
234     freeBegin = (argc > 4) ? atoi(argv[4]) : 0;
235     freeEnd = (argc > 5) ? atoi(argv[5]) : numBlocks;
236
237     printf("============== Before allocating blocks ==============\en");
238     display_mallinfo();
239
240     for (int j = 0; j < numBlocks; j++) {
241         if (numBlocks >= MAX_ALLOCS) {
242             fprintf(stderr, "Too many allocations\en");
243             exit(EXIT_FAILURE);
244         }
245
246         alloc[j] = malloc(blockSize);
247         if (alloc[j] == NULL) {
248             perror("malloc");
249             exit(EXIT_FAILURE);
250         }
251     }
252
253     printf("\en============== After allocating blocks ==============\en");
254     display_mallinfo();
255
256     for (int j = freeBegin; j < freeEnd; j += freeStep)
257         free(alloc[j]);
258
259     printf("\en============== After freeing blocks ==============\en");
260     display_mallinfo();
261
262     exit(EXIT_SUCCESS);
263 }
264 .EE
265 .SH 関連項目
266 .ad l
267 .nh
268 \fBmmap\fP(2), \fBmalloc\fP(3), \fBmalloc_info\fP(3), \fBmalloc_stats\fP(3),
269 \fBmalloc_trim\fP(3), \fBmallopt\fP(3)
270 .SH この文書について
271 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
272 \%https://www.kernel.org/doc/man\-pages/ に書かれている。