]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/kern_memorystatus_freeze.h
xnu-6153.81.5.tar.gz
[apple/xnu.git] / bsd / sys / kern_memorystatus_freeze.h
CommitLineData
cb323159
A
1/*
2 * Copyright (c) 2006-2018 Apple Computer, 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 SYS_MEMORYSTATUS_FREEZE_H
30#define SYS_MEMORYSTATUS_FREEZE_H
31
32#include <stdint.h>
33#include <sys/time.h>
34#include <sys/proc.h>
35#include <sys/param.h>
36#include <sys/kern_memorystatus.h>
37
38typedef struct memorystatus_freeze_entry {
39 int32_t pid;
40 uint32_t flags;
41 uint32_t pages;
42} memorystatus_freeze_entry_t;
43
44#ifdef XNU_KERNEL_PRIVATE
45
46extern unsigned long freeze_threshold_percentage;
47extern unsigned int memorystatus_frozen_count;
48extern unsigned int memorystatus_frozen_processes_max;
49extern unsigned int memorystatus_frozen_shared_mb;
50extern unsigned int memorystatus_frozen_shared_mb_max;
51extern unsigned int memorystatus_freeze_shared_mb_per_process_max; /* Max. MB allowed per process to be freezer-eligible. */
52extern unsigned int memorystatus_freeze_private_shared_pages_ratio; /* Ratio of private:shared pages for a process to be freezer-eligible. */
53extern unsigned int memorystatus_suspended_count;
54extern unsigned int memorystatus_thaw_count;
55extern unsigned int memorystatus_refreeze_eligible_count; /* # of processes currently thawed i.e. have state on disk & in-memory */
56
57void memorystatus_freeze_init(void);
58extern int memorystatus_freeze_process_sync(proc_t p);
59
60#ifdef CONFIG_FREEZE
61
62#define FREEZE_PAGES_MIN ( 8 * 1024 * 1024 / PAGE_SIZE)
63#define FREEZE_PAGES_MAX (max_task_footprint_mb == 0 ? INT_MAX : (max_task_footprint_mb << (20 - PAGE_SHIFT)))
64
65#define FREEZE_SUSPENDED_THRESHOLD_DEFAULT 4
66#define FREEZE_PROCESSES_MAX 20
67
68#define FREEZE_DAILY_MB_MAX_DEFAULT 1024
69#define FREEZE_DEGRADATION_BUDGET_THRESHOLD 25 //degraded perf. when the daily budget left falls below this threshold percentage
70
71#define MAX_FROZEN_SHARED_MB_PERCENT 10
72#define MAX_FROZEN_PROCESS_DEMOTIONS 2
73#define MIN_THAW_DEMOTION_THRESHOLD 5
74#define MIN_THAW_REFREEZE_THRESHOLD 3 /* min # of global thaws needed for us to consider refreezing these processes. */
75
76typedef struct throttle_interval_t {
77 uint32_t mins;
78 uint32_t burst_multiple;
79 uint32_t pageouts;
80 uint32_t max_pageouts;
81 mach_timespec_t ts;
82} throttle_interval_t;
83
84extern boolean_t memorystatus_freeze_enabled;
85extern int memorystatus_freeze_wakeup;
86
87/* Thresholds */
88extern unsigned int memorystatus_freeze_threshold;
89extern unsigned int memorystatus_freeze_pages_min;
90extern unsigned int memorystatus_freeze_pages_max;
91extern unsigned int memorystatus_freeze_suspended_threshold;
92extern unsigned int memorystatus_freeze_daily_mb_max;
93extern uint64_t memorystatus_freeze_budget_pages_remaining; //remaining # of pages that can be frozen to disk
94extern boolean_t memorystatus_freeze_degradation; //protected by the freezer mutex. Signals we are in a degraded freeze mode.
95
96extern unsigned int memorystatus_max_frozen_demotions_daily;
97extern unsigned int memorystatus_thaw_count_demotion_threshold;
98
99#if DEVELOPMENT || DEBUG
100#define FREEZER_CONTROL_GET_STATUS (1)
101#endif /* DEVELOPMENT || DEBUG */
102
103extern boolean_t memorystatus_freeze_enabled;
104extern int memorystatus_freeze_wakeup;
105extern int memorystatus_freeze_jetsam_band; /* the jetsam band which will contain P_MEMSTAT_FROZEN processes */
106
107boolean_t memorystatus_freeze_thread_should_run(void);
108int memorystatus_set_process_is_freezable(pid_t pid, boolean_t is_freezable);
109int memorystatus_get_process_is_freezable(pid_t pid, int *is_freezable);
110int memorystatus_freezer_control(int32_t flags, user_addr_t buffer, size_t buffer_size, int32_t *retval);
111
112#endif /* CONFIG_FREEZE */
113
114#endif /* XNU_KERNEL_PRIVATE */
115
116#endif /* SYS_MEMORYSTATUS_FREEZE_H */