2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: mach/vm_statistics.h
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young, David Golub
62 * Virtual memory statistics structure.
66 #ifndef _MACH_VM_STATISTICS_H_
67 #define _MACH_VM_STATISTICS_H_
69 #include <mach/machine/vm_types.h>
76 * rev0 - original structure.
77 * rev1 - added purgable info (purgable_count and purges).
78 * rev2 - added speculative_count.
80 * Note: you cannot add any new fields to this structure. Add them below in
84 struct vm_statistics
{
85 natural_t free_count
; /* # of pages free */
86 natural_t active_count
; /* # of pages active */
87 natural_t inactive_count
; /* # of pages inactive */
88 natural_t wire_count
; /* # of pages wired down */
89 natural_t zero_fill_count
; /* # of zero fill pages */
90 natural_t reactivations
; /* # of pages reactivated */
91 natural_t pageins
; /* # of pageins */
92 natural_t pageouts
; /* # of pageouts */
93 natural_t faults
; /* # of faults */
94 natural_t cow_faults
; /* # of copy-on-writes */
95 natural_t lookups
; /* object cache lookups */
96 natural_t hits
; /* object cache hits */
99 natural_t purgeable_count
; /* # of pages purgeable */
100 natural_t purges
; /* # of pages purged */
104 * NB: speculative pages are already accounted for in "free_count",
105 * so "speculative_count" is the number of "free" pages that are
106 * used to hold data that was read speculatively from disk but
107 * haven't actually been used by anyone so far.
109 natural_t speculative_count
; /* # of pages speculative */
112 /* Used by all architectures */
113 typedef struct vm_statistics
*vm_statistics_t
;
114 typedef struct vm_statistics vm_statistics_data_t
;
120 * rev0 - original structure.
121 * rev1 - added purgable info (purgable_count and purges).
122 * rev2 - added speculative_count.
124 * rev3 - changed name to vm_statistics64.
125 * changed some fields in structure to 64-bit on
126 * arm, i386 and x86_64 architectures.
127 * rev4 - require 64-bit alignment for efficient access
128 * in the kernel. No change to reported data.
132 struct vm_statistics64
{
133 natural_t free_count
; /* # of pages free */
134 natural_t active_count
; /* # of pages active */
135 natural_t inactive_count
; /* # of pages inactive */
136 natural_t wire_count
; /* # of pages wired down */
137 uint64_t zero_fill_count
; /* # of zero fill pages */
138 uint64_t reactivations
; /* # of pages reactivated */
139 uint64_t pageins
; /* # of pageins */
140 uint64_t pageouts
; /* # of pageouts */
141 uint64_t faults
; /* # of faults */
142 uint64_t cow_faults
; /* # of copy-on-writes */
143 uint64_t lookups
; /* object cache lookups */
144 uint64_t hits
; /* object cache hits */
145 uint64_t purges
; /* # of pages purged */
146 natural_t purgeable_count
; /* # of pages purgeable */
148 * NB: speculative pages are already accounted for in "free_count",
149 * so "speculative_count" is the number of "free" pages that are
150 * used to hold data that was read speculatively from disk but
151 * haven't actually been used by anyone so far.
153 natural_t speculative_count
; /* # of pages speculative */
156 uint64_t decompressions
; /* # of pages decompressed */
157 uint64_t compressions
; /* # of pages compressed */
158 uint64_t swapins
; /* # of pages swapped in (via compression segments) */
159 uint64_t swapouts
; /* # of pages swapped out (via compression segments) */
160 natural_t compressor_page_count
; /* # of pages used by the compressed pager to hold all the compressed data */
161 natural_t throttled_count
; /* # of pages throttled */
162 natural_t external_page_count
; /* # of pages that are file-backed (non-swap) */
163 natural_t internal_page_count
; /* # of pages that are anonymous */
164 uint64_t total_uncompressed_pages_in_compressor
; /* # of pages (uncompressed) held within the compressor. */
165 } __attribute__((aligned(8)));
167 typedef struct vm_statistics64
*vm_statistics64_t
;
168 typedef struct vm_statistics64 vm_statistics64_data_t
;
171 * VM_STATISTICS_TRUNCATE_TO_32_BIT
173 * This is used by host_statistics() to truncate and peg the 64-bit in-kernel values from
174 * vm_statistics64 to the 32-bit values of the older structure above (vm_statistics).
176 #define VM_STATISTICS_TRUNCATE_TO_32_BIT(value) ((uint32_t)(((value) > UINT32_MAX ) ? UINT32_MAX : (value)))
179 * vm_extmod_statistics
181 * Structure to record modifications to a task by an
185 * rev0 - original structure.
188 struct vm_extmod_statistics
{
189 int64_t task_for_pid_count
; /* # of times task port was looked up */
190 int64_t task_for_pid_caller_count
; /* # of times this task called task_for_pid */
191 int64_t thread_creation_count
; /* # of threads created in task */
192 int64_t thread_creation_caller_count
; /* # of threads created by task */
193 int64_t thread_set_state_count
; /* # of register state sets in task */
194 int64_t thread_set_state_caller_count
; /* # of register state sets by task */
195 } __attribute__((aligned(8)));
197 typedef struct vm_extmod_statistics
*vm_extmod_statistics_t
;
198 typedef struct vm_extmod_statistics vm_extmod_statistics_data_t
;
200 typedef struct vm_purgeable_stat
{
203 }vm_purgeable_stat_t
;
205 struct vm_purgeable_info
{
206 vm_purgeable_stat_t fifo_data
[8];
207 vm_purgeable_stat_t obsolete_data
;
208 vm_purgeable_stat_t lifo_data
[8];
211 typedef struct vm_purgeable_info
*vm_purgeable_info_t
;
213 /* included for the vm_map_page_query call */
215 #define VM_PAGE_QUERY_PAGE_PRESENT 0x1
216 #define VM_PAGE_QUERY_PAGE_FICTITIOUS 0x2
217 #define VM_PAGE_QUERY_PAGE_REF 0x4
218 #define VM_PAGE_QUERY_PAGE_DIRTY 0x8
219 #define VM_PAGE_QUERY_PAGE_PAGED_OUT 0x10
220 #define VM_PAGE_QUERY_PAGE_COPIED 0x20
221 #define VM_PAGE_QUERY_PAGE_SPECULATIVE 0x40
222 #define VM_PAGE_QUERY_PAGE_EXTERNAL 0x80
223 #define VM_PAGE_QUERY_PAGE_CS_VALIDATED 0x100
224 #define VM_PAGE_QUERY_PAGE_CS_TAINTED 0x200
226 #ifdef MACH_KERNEL_PRIVATE
229 * Each machine dependent implementation is expected to
230 * keep certain statistics. They may do this anyway they
231 * so choose, but are expected to return the statistics
232 * in the following structure.
235 struct pmap_statistics
{
236 integer_t resident_count
; /* # of pages mapped (total)*/
237 integer_t resident_max
; /* # of pages mapped (peak) */
238 integer_t wired_count
; /* # of pages wired */
241 integer_t device_peak
;
243 integer_t internal_peak
;
245 integer_t external_peak
;
247 integer_t reusable_peak
;
248 uint64_t compressed
__attribute__((aligned(8)));
249 uint64_t compressed_peak
__attribute__((aligned(8)));
250 uint64_t compressed_lifetime
__attribute__((aligned(8)));
253 typedef struct pmap_statistics
*pmap_statistics_t
;
255 #define PMAP_STATS_PEAK(field) \
257 if (field > field##_peak) { \
258 field##_peak = field; \
262 #endif /* MACH_KERNEL_PRIVATE */
265 * VM allocation flags:
268 * (really the absence of VM_FLAGS_ANYWHERE)
269 * Allocate new VM region at the specified virtual address, if possible.
272 * Allocate new VM region anywhere it would fit in the address space.
275 * Create a purgable VM object for that new VM region.
277 * VM_FLAGS_NO_PMAP_CHECK
278 * (for DEBUG kernel config only, ignored for other configs)
279 * Do not check that there is no stale pmap mapping for the new VM region.
280 * This is useful for kernel memory allocations at bootstrap when building
281 * the initial kernel address space while some memory is already in use.
284 * The new VM region can replace existing VM regions if necessary
285 * (to be used in combination with VM_FLAGS_FIXED).
288 * Pages brought in to this VM region are placed on the speculative
289 * queue instead of the active queue. In other words, they are not
290 * cached so that they will be stolen first if memory runs low.
292 #define VM_FLAGS_FIXED 0x0000
293 #define VM_FLAGS_ANYWHERE 0x0001
294 #define VM_FLAGS_PURGABLE 0x0002
295 #define VM_FLAGS_NO_CACHE 0x0010
296 #ifdef KERNEL_PRIVATE
297 #define VM_FLAGS_PERMANENT 0x0100 /* mapping can NEVER be unmapped */
298 #define VM_FLAGS_GUARD_AFTER 0x0200 /* guard page after the mapping */
299 #define VM_FLAGS_GUARD_BEFORE 0x0400 /* guard page before the mapping */
300 #define VM_FLAGS_SUBMAP 0x0800 /* mapping a VM submap */
301 #define VM_FLAGS_ALREADY 0x1000 /* OK if same mapping already exists */
302 #define VM_FLAGS_BEYOND_MAX 0x2000 /* map beyond the map's max offset */
303 #endif /* KERNEL_PRIVATE */
304 #define VM_FLAGS_OVERWRITE 0x4000 /* delete any existing mappings first */
305 #ifdef KERNEL_PRIVATE
306 #define VM_FLAGS_NO_PMAP_CHECK 0x8000 /* do not check that pmap is empty */
307 #endif /* KERNEL_PRIVATE */
309 * VM_FLAGS_SUPERPAGE_MASK
310 * 3 bits that specify whether large pages should be used instead of
311 * base pages (!=0), as well as the requested page size.
313 #define VM_FLAGS_SUPERPAGE_MASK 0x70000 /* bits 0x10000, 0x20000, 0x40000 */
314 #ifdef KERNEL_PRIVATE
315 #define VM_FLAGS_MAP_JIT 0x80000 /* Used to mark an entry as describing a JIT region */
316 #endif /* KERNEL_PRIVATE */
317 #define VM_FLAGS_RETURN_DATA_ADDR 0x100000 /* Return address of target data, rather than base of page */
318 #ifdef KERNEL_PRIVATE
319 #define VM_FLAGS_IOKIT_ACCT 0x200000 /* IOKit accounting */
320 #define VM_FLAGS_KEEP_MAP_LOCKED 0x400000 /* Keep the map locked when returning from vm_map_enter() */
321 #endif /* KERNEL_PRIVATE */
322 #define VM_FLAGS_ALIAS_MASK 0xFF000000
323 #define VM_GET_FLAGS_ALIAS(flags, alias) \
324 (alias) = ((flags) & VM_FLAGS_ALIAS_MASK) >> 24
325 #define VM_SET_FLAGS_ALIAS(flags, alias) \
326 (flags) = (((flags) & ~VM_FLAGS_ALIAS_MASK) | \
327 (((alias) & ~VM_FLAGS_ALIAS_MASK) << 24))
329 /* These are the flags that we accept from user-space */
330 #define VM_FLAGS_USER_ALLOCATE (VM_FLAGS_FIXED | \
331 VM_FLAGS_ANYWHERE | \
332 VM_FLAGS_PURGABLE | \
333 VM_FLAGS_NO_CACHE | \
334 VM_FLAGS_OVERWRITE | \
335 VM_FLAGS_SUPERPAGE_MASK | \
337 #define VM_FLAGS_USER_MAP (VM_FLAGS_USER_ALLOCATE | \
338 VM_FLAGS_RETURN_DATA_ADDR)
339 #define VM_FLAGS_USER_REMAP (VM_FLAGS_FIXED | \
340 VM_FLAGS_ANYWHERE | \
341 VM_FLAGS_OVERWRITE| \
342 VM_FLAGS_RETURN_DATA_ADDR)
344 #define VM_FLAGS_SUPERPAGE_SHIFT 16
345 #define SUPERPAGE_NONE 0 /* no superpages, if all bits are 0 */
346 #define SUPERPAGE_SIZE_ANY 1
347 #define VM_FLAGS_SUPERPAGE_NONE (SUPERPAGE_NONE << VM_FLAGS_SUPERPAGE_SHIFT)
348 #define VM_FLAGS_SUPERPAGE_SIZE_ANY (SUPERPAGE_SIZE_ANY << VM_FLAGS_SUPERPAGE_SHIFT)
349 #if defined(__x86_64__) || !defined(KERNEL)
350 #define SUPERPAGE_SIZE_2MB 2
351 #define VM_FLAGS_SUPERPAGE_SIZE_2MB (SUPERPAGE_SIZE_2MB<<VM_FLAGS_SUPERPAGE_SHIFT)
354 #define VM_MEMORY_MALLOC 1
355 #define VM_MEMORY_MALLOC_SMALL 2
356 #define VM_MEMORY_MALLOC_LARGE 3
357 #define VM_MEMORY_MALLOC_HUGE 4
358 #define VM_MEMORY_SBRK 5// uninteresting -- no one should call
359 #define VM_MEMORY_REALLOC 6
360 #define VM_MEMORY_MALLOC_TINY 7
361 #define VM_MEMORY_MALLOC_LARGE_REUSABLE 8
362 #define VM_MEMORY_MALLOC_LARGE_REUSED 9
364 #define VM_MEMORY_ANALYSIS_TOOL 10
366 #define VM_MEMORY_MALLOC_NANO 11
368 #define VM_MEMORY_MACH_MSG 20
369 #define VM_MEMORY_IOKIT 21
370 #define VM_MEMORY_STACK 30
371 #define VM_MEMORY_GUARD 31
372 #define VM_MEMORY_SHARED_PMAP 32
373 /* memory containing a dylib */
374 #define VM_MEMORY_DYLIB 33
375 #define VM_MEMORY_OBJC_DISPATCHERS 34
377 /* Was a nested pmap (VM_MEMORY_SHARED_PMAP) which has now been unnested */
378 #define VM_MEMORY_UNSHARED_PMAP 35
381 // Placeholders for now -- as we analyze the libraries and find how they
382 // use memory, we can make these labels more specific.
383 #define VM_MEMORY_APPKIT 40
384 #define VM_MEMORY_FOUNDATION 41
385 #define VM_MEMORY_COREGRAPHICS 42
386 #define VM_MEMORY_CORESERVICES 43
387 #define VM_MEMORY_CARBON VM_MEMORY_CORESERVICES
388 #define VM_MEMORY_JAVA 44
389 #define VM_MEMORY_COREDATA 45
390 #define VM_MEMORY_COREDATA_OBJECTIDS 46
391 #define VM_MEMORY_ATS 50
392 #define VM_MEMORY_LAYERKIT 51
393 #define VM_MEMORY_CGIMAGE 52
394 #define VM_MEMORY_TCMALLOC 53
396 /* private raster data (i.e. layers, some images, QGL allocator) */
397 #define VM_MEMORY_COREGRAPHICS_DATA 54
399 /* shared image and font caches */
400 #define VM_MEMORY_COREGRAPHICS_SHARED 55
402 /* Memory used for virtual framebuffers, shadowing buffers, etc... */
403 #define VM_MEMORY_COREGRAPHICS_FRAMEBUFFERS 56
405 /* Window backing stores, custom shadow data, and compressed backing stores */
406 #define VM_MEMORY_COREGRAPHICS_BACKINGSTORES 57
408 /* catch-all for other uses, such as the read-only shared data page */
409 #define VM_MEMORY_COREGRAPHICS_MISC VM_MEMORY_COREGRAPHICS
411 /* memory allocated by the dynamic loader for itself */
412 #define VM_MEMORY_DYLD 60
413 /* malloc'd memory created by dyld */
414 #define VM_MEMORY_DYLD_MALLOC 61
416 /* Used for sqlite page cache */
417 #define VM_MEMORY_SQLITE 62
419 /* JavaScriptCore heaps */
420 #define VM_MEMORY_JAVASCRIPT_CORE 63
421 /* memory allocated for the JIT */
422 #define VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR 64
423 #define VM_MEMORY_JAVASCRIPT_JIT_REGISTER_FILE 65
425 /* memory allocated for GLSL */
426 #define VM_MEMORY_GLSL 66
428 /* memory allocated for OpenCL.framework */
429 #define VM_MEMORY_OPENCL 67
431 /* memory allocated for QuartzCore.framework */
432 #define VM_MEMORY_COREIMAGE 68
434 /* memory allocated for WebCore Purgeable Buffers */
435 #define VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS 69
438 #define VM_MEMORY_IMAGEIO 70
440 /* CoreProfile memory */
441 #define VM_MEMORY_COREPROFILE 71
443 /* assetsd / MobileSlideShow memory */
444 #define VM_MEMORY_ASSETSD 72
446 /* libsystem_kernel os_once_alloc */
447 #define VM_MEMORY_OS_ALLOC_ONCE 73
449 /* libdispatch internal allocator */
450 #define VM_MEMORY_LIBDISPATCH 74
452 /* Accelerate.framework image backing stores */
453 #define VM_MEMORY_ACCELERATE 75
455 /* CoreUI image block data */
456 #define VM_MEMORY_COREUI 76
458 /* CoreUI image file */
459 #define VM_MEMORY_COREUIFILE 77
461 /* Genealogy buffers */
462 #define VM_MEMORY_GENEALOGY 78
464 /* Reserve 240-255 for application */
465 #define VM_MEMORY_APPLICATION_SPECIFIC_1 240
466 #define VM_MEMORY_APPLICATION_SPECIFIC_16 255
468 #define VM_MAKE_TAG(tag) ((tag) << 24)
470 #endif /* _MACH_VM_STATISTICS_H_ */