]>
Commit | Line | Data |
---|---|---|
3a60a9f5 | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved. |
3a60a9f5 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
3a60a9f5 | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
3a60a9f5 A |
27 | */ |
28 | ||
29 | #include <kern/kalloc.h> | |
30 | #include <kern/machine.h> | |
31 | #include <kern/misc_protos.h> | |
32 | #include <kern/thread.h> | |
33 | #include <kern/processor.h> | |
34 | #include <mach/machine.h> | |
35 | #include <mach/processor_info.h> | |
36 | #include <mach/mach_types.h> | |
37 | #include <default_pager/default_pager_internal.h> | |
38 | #include <IOKit/IOPlatformExpert.h> | |
3a60a9f5 A |
39 | |
40 | #include <IOKit/IOHibernatePrivate.h> | |
41 | #include <vm/vm_page.h> | |
42 | #include <vm/vm_pageout.h> | |
2d21ac55 | 43 | #include <vm/vm_purgeable_internal.h> |
39236c6e | 44 | #include <vm/vm_compressor.h> |
3a60a9f5 | 45 | |
3a60a9f5 A |
46 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
47 | ||
39236c6e A |
48 | boolean_t need_to_unlock_decompressor = FALSE; |
49 | ||
3a60a9f5 | 50 | kern_return_t |
39236c6e A |
51 | hibernate_alloc_page_lists( |
52 | hibernate_page_list_t ** page_list_ret, | |
53 | hibernate_page_list_t ** page_list_wired_ret, | |
54 | hibernate_page_list_t ** page_list_pal_ret) | |
3a60a9f5 | 55 | { |
39236c6e A |
56 | kern_return_t retval = KERN_SUCCESS; |
57 | ||
3a60a9f5 A |
58 | hibernate_page_list_t * page_list = NULL; |
59 | hibernate_page_list_t * page_list_wired = NULL; | |
6d2010ae | 60 | hibernate_page_list_t * page_list_pal = NULL; |
3a60a9f5 | 61 | |
db609669 | 62 | page_list = hibernate_page_list_allocate(TRUE); |
39236c6e A |
63 | if (!page_list) { |
64 | ||
65 | retval = KERN_RESOURCE_SHORTAGE; | |
66 | goto done; | |
67 | } | |
db609669 | 68 | page_list_wired = hibernate_page_list_allocate(FALSE); |
3a60a9f5 A |
69 | if (!page_list_wired) |
70 | { | |
39236c6e A |
71 | kfree(page_list, page_list->list_size); |
72 | ||
73 | retval = KERN_RESOURCE_SHORTAGE; | |
74 | goto done; | |
3a60a9f5 | 75 | } |
db609669 | 76 | page_list_pal = hibernate_page_list_allocate(FALSE); |
6d2010ae A |
77 | if (!page_list_pal) |
78 | { | |
39236c6e A |
79 | kfree(page_list, page_list->list_size); |
80 | kfree(page_list_wired, page_list_wired->list_size); | |
81 | ||
82 | retval = KERN_RESOURCE_SHORTAGE; | |
83 | goto done; | |
84 | } | |
85 | *page_list_ret = page_list; | |
86 | *page_list_wired_ret = page_list_wired; | |
87 | *page_list_pal_ret = page_list_pal; | |
88 | ||
89 | done: | |
90 | return (retval); | |
91 | ||
92 | } | |
93 | ||
94 | extern int sync_internal(void); | |
95 | ||
96 | kern_return_t | |
97 | hibernate_setup(IOHibernateImageHeader * header, | |
98 | uint32_t free_page_ratio, | |
99 | uint32_t free_page_time, | |
100 | boolean_t vmflush, | |
101 | hibernate_page_list_t * page_list, | |
102 | hibernate_page_list_t * page_list_wired __unused, | |
103 | hibernate_page_list_t * page_list_pal __unused) | |
104 | { | |
105 | uint32_t gobble_count; | |
106 | kern_return_t retval = KERN_SUCCESS; | |
107 | ||
108 | hibernate_create_paddr_map(); | |
109 | ||
110 | if (vmflush && (COMPRESSED_PAGER_IS_ACTIVE || dp_isssd)) { | |
111 | ||
112 | sync_internal(); | |
113 | ||
114 | if (COMPRESSED_PAGER_IS_ACTIVE) { | |
115 | vm_decompressor_lock(); | |
116 | need_to_unlock_decompressor = TRUE; | |
117 | } | |
118 | hibernate_flush_memory(); | |
6d2010ae | 119 | } |
3a60a9f5 | 120 | |
39236c6e | 121 | |
3a60a9f5 | 122 | // pages we could force out to reduce hibernate image size |
b0d623f7 | 123 | gobble_count = (uint32_t)((((uint64_t) page_list->page_count) * ((uint64_t) free_page_ratio)) / 100); |
3a60a9f5 A |
124 | |
125 | // no failures hereafter | |
126 | ||
127 | hibernate_processor_setup(header); | |
128 | ||
3a60a9f5 | 129 | if (gobble_count) |
39236c6e | 130 | hibernate_gobble_pages(gobble_count, free_page_time); |
3a60a9f5 | 131 | |
db609669 A |
132 | HIBLOG("hibernate_alloc_pages act %d, inact %d, anon %d, throt %d, spec %d, wire %d, wireinit %d\n", |
133 | vm_page_active_count, vm_page_inactive_count, | |
134 | vm_page_anonymous_count, vm_page_throttled_count, vm_page_speculative_count, | |
135 | vm_page_wire_count, vm_page_wire_count_initial); | |
136 | ||
39236c6e A |
137 | if (retval != KERN_SUCCESS && need_to_unlock_decompressor == TRUE) { |
138 | need_to_unlock_decompressor = FALSE; | |
139 | vm_decompressor_unlock(); | |
140 | } | |
141 | return (retval); | |
3a60a9f5 A |
142 | } |
143 | ||
144 | kern_return_t | |
145 | hibernate_teardown(hibernate_page_list_t * page_list, | |
99c3a104 A |
146 | hibernate_page_list_t * page_list_wired, |
147 | hibernate_page_list_t * page_list_pal) | |
3a60a9f5 | 148 | { |
b0d623f7 | 149 | hibernate_free_gobble_pages(); |
3a60a9f5 A |
150 | |
151 | if (page_list) | |
152 | kfree(page_list, page_list->list_size); | |
153 | if (page_list_wired) | |
154 | kfree(page_list_wired, page_list_wired->list_size); | |
99c3a104 A |
155 | if (page_list_pal) |
156 | kfree(page_list_pal, page_list_pal->list_size); | |
3a60a9f5 | 157 | |
39236c6e A |
158 | if (COMPRESSED_PAGER_IS_ACTIVE) { |
159 | if (need_to_unlock_decompressor == TRUE) { | |
160 | need_to_unlock_decompressor = FALSE; | |
161 | vm_decompressor_unlock(); | |
162 | } | |
8a3053a0 | 163 | vm_compressor_delay_trim(); |
39236c6e | 164 | } |
3a60a9f5 A |
165 | return (KERN_SUCCESS); |
166 | } | |
167 |