]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/os/proc.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / libsyscall / os / proc.h
1 /*
2 * Copyright (c) 2019 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef __OS_PROC__
30 #define __OS_PROC__
31
32 #include <stddef.h>
33 #include <sys/cdefs.h>
34 #include <os/availability.h>
35
36 /*!
37 * @header
38 *
39 * @preprocinfo
40 * This is for functions that operate on the calling process alone.
41 */
42
43 __BEGIN_DECLS
44
45 /*!
46 * @function os_proc_available_memory
47 *
48 * @abstract
49 * Return the number of bytes remaining, at the time of the call, before the
50 * current process will hit its current dirty memory limit.
51 *
52 * @discussion
53 * Developers can query this value efficiently whenever it is needed. The return
54 * value is only a snapshot at the time of the call. Caching the result is not
55 * advised. The result may be instantaneously invalidated by actions taken in
56 * another thread or another framework.
57 *
58 * Memory limits can change during the app life cycle. Make sure to check accordingly.
59 *
60 * The size returned is not representative of the total memory of the device, it
61 * is the current dirty memory limit minus the dirty memory footprint used at the
62 * time of the query.
63 *
64 * This interface allows an app to efficiently consume all available memory resources.
65 * Significant memory use, even under the current memory limit, may still cause
66 * system-wide performance including the termination of other apps and system
67 * processes. Take care to use the minimum amount of memory needed to satisfy the
68 * user’s need.
69 *
70 * If you need more information than just the available memory, you can use task_info().
71 * The information returned is equivalent to the task_vm_info.limit_bytes_remaining
72 * field. task_info() is a more expensive call, and will return information such
73 * as your phys_footprint, which is used to calculate the return of this function.
74 *
75 * Dirty memory contains data that must be kept in RAM (or the equivalent) even
76 * when unused. It is memory that has been modified.
77 *
78 * @param none
79 *
80 * @result
81 * The remaining bytes. 0 is returned if the calling process is not an app, or
82 * the calling process exceeds its memory limit.
83 */
84
85 API_UNAVAILABLE(macos) API_AVAILABLE(ios(13.0), tvos(13.0), watchos(6.0), bridgeos(4.0))
86 extern
87 size_t os_proc_available_memory(void);
88
89 __END_DECLS
90
91 #endif