vm_object.c (e6e746bfb086d563bf0ad454a33ecbcab8836dbf) vm_object.c (e735691b613c2ac4aed254ffefeef429c91c2e0d)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 152 unchanged lines hidden (view full) ---

161static void vm_object_zdtor(void *mem, int size, void *arg);
162
163static void
164vm_object_zdtor(void *mem, int size, void *arg)
165{
166 vm_object_t object;
167
168 object = (vm_object_t)mem;
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 152 unchanged lines hidden (view full) ---

161static void vm_object_zdtor(void *mem, int size, void *arg);
162
163static void
164vm_object_zdtor(void *mem, int size, void *arg)
165{
166 vm_object_t object;
167
168 object = (vm_object_t)mem;
169 KASSERT(object->ref_count == 0,
170 ("object %p ref_count = %d", object, object->ref_count));
169 KASSERT(TAILQ_EMPTY(&object->memq),
170 ("object %p has resident pages in its memq", object));
171 KASSERT(vm_radix_is_empty(&object->rtree),
172 ("object %p has resident pages in its trie", object));
173#if VM_NRESERVLEVEL > 0
174 KASSERT(LIST_EMPTY(&object->rvq),
175 ("object %p has reservations",
176 object));

--- 5 unchanged lines hidden (view full) ---

182 ("object %p paging_in_progress = %d",
183 object, object->paging_in_progress));
184 KASSERT(object->resident_page_count == 0,
185 ("object %p resident_page_count = %d",
186 object, object->resident_page_count));
187 KASSERT(object->shadow_count == 0,
188 ("object %p shadow_count = %d",
189 object, object->shadow_count));
171 KASSERT(TAILQ_EMPTY(&object->memq),
172 ("object %p has resident pages in its memq", object));
173 KASSERT(vm_radix_is_empty(&object->rtree),
174 ("object %p has resident pages in its trie", object));
175#if VM_NRESERVLEVEL > 0
176 KASSERT(LIST_EMPTY(&object->rvq),
177 ("object %p has reservations",
178 object));

--- 5 unchanged lines hidden (view full) ---

184 ("object %p paging_in_progress = %d",
185 object, object->paging_in_progress));
186 KASSERT(object->resident_page_count == 0,
187 ("object %p resident_page_count = %d",
188 object, object->resident_page_count));
189 KASSERT(object->shadow_count == 0,
190 ("object %p shadow_count = %d",
191 object, object->shadow_count));
192 KASSERT(object->type == OBJT_DEAD,
193 ("object %p has non-dead type %d",
194 object, object->type));
190}
191#endif
192
193static int
194vm_object_zinit(void *mem, int size, int flags)
195{
196 vm_object_t object;
197
198 object = (vm_object_t)mem;
199 rw_init_flags(&object->lock, "vm object", RW_DUPOK | RW_NEW);
200
201 /* These are true for any object that has been freed */
195}
196#endif
197
198static int
199vm_object_zinit(void *mem, int size, int flags)
200{
201 vm_object_t object;
202
203 object = (vm_object_t)mem;
204 rw_init_flags(&object->lock, "vm object", RW_DUPOK | RW_NEW);
205
206 /* These are true for any object that has been freed */
207 object->type = OBJT_DEAD;
208 object->ref_count = 0;
202 object->rtree.rt_root = 0;
203 object->rtree.rt_flags = 0;
204 object->paging_in_progress = 0;
205 object->resident_page_count = 0;
206 object->shadow_count = 0;
207 object->cache.rt_root = 0;
208 object->cache.rt_flags = 0;
209 object->rtree.rt_root = 0;
210 object->rtree.rt_flags = 0;
211 object->paging_in_progress = 0;
212 object->resident_page_count = 0;
213 object->shadow_count = 0;
214 object->cache.rt_root = 0;
215 object->cache.rt_flags = 0;
216
217 mtx_lock(&vm_object_list_mtx);
218 TAILQ_INSERT_TAIL(&vm_object_list, object, object_list);
219 mtx_unlock(&vm_object_list_mtx);
209 return (0);
210}
211
212static void
213_vm_object_allocate(objtype_t type, vm_pindex_t size, vm_object_t object)
214{
215
216 TAILQ_INIT(&object->memq);

--- 30 unchanged lines hidden (view full) ---

247 object->cred = NULL;
248 object->charge = 0;
249 object->handle = NULL;
250 object->backing_object = NULL;
251 object->backing_object_offset = (vm_ooffset_t) 0;
252#if VM_NRESERVLEVEL > 0
253 LIST_INIT(&object->rvq);
254#endif
220 return (0);
221}
222
223static void
224_vm_object_allocate(objtype_t type, vm_pindex_t size, vm_object_t object)
225{
226
227 TAILQ_INIT(&object->memq);

--- 30 unchanged lines hidden (view full) ---

258 object->cred = NULL;
259 object->charge = 0;
260 object->handle = NULL;
261 object->backing_object = NULL;
262 object->backing_object_offset = (vm_ooffset_t) 0;
263#if VM_NRESERVLEVEL > 0
264 LIST_INIT(&object->rvq);
265#endif
255
256 mtx_lock(&vm_object_list_mtx);
257 TAILQ_INSERT_TAIL(&vm_object_list, object, object_list);
258 mtx_unlock(&vm_object_list_mtx);
259}
260
261/*
262 * vm_object_init:
263 *
264 * Initialize the VM objects module.
265 */
266void

--- 399 unchanged lines hidden (view full) ---

666 * vm_object_destroy removes the object from the global object list
667 * and frees the space for the object.
668 */
669void
670vm_object_destroy(vm_object_t object)
671{
672
673 /*
266}
267
268/*
269 * vm_object_init:
270 *
271 * Initialize the VM objects module.
272 */
273void

--- 399 unchanged lines hidden (view full) ---

673 * vm_object_destroy removes the object from the global object list
674 * and frees the space for the object.
675 */
676void
677vm_object_destroy(vm_object_t object)
678{
679
680 /*
674 * Remove the object from the global object list.
675 */
676 mtx_lock(&vm_object_list_mtx);
677 TAILQ_REMOVE(&vm_object_list, object, object_list);
678 mtx_unlock(&vm_object_list_mtx);
679
680 /*
681 * Release the allocation charge.
682 */
683 if (object->cred != NULL) {
681 * Release the allocation charge.
682 */
683 if (object->cred != NULL) {
684 KASSERT(object->type == OBJT_DEFAULT ||
685 object->type == OBJT_SWAP,
686 ("%s: non-swap obj %p has cred", __func__, object));
687 swap_release_by_cred(object->charge, object->cred);
688 object->charge = 0;
689 crfree(object->cred);
690 object->cred = NULL;
691 }
692
693 /*
694 * Free the space for the object.

--- 88 unchanged lines hidden (view full) ---

783
784#if VM_NRESERVLEVEL > 0
785 if (__predict_false(!LIST_EMPTY(&object->rvq)))
786 vm_reserv_break_all(object);
787#endif
788 if (__predict_false(!vm_object_cache_is_empty(object)))
789 vm_page_cache_free(object, 0, 0);
790
684 swap_release_by_cred(object->charge, object->cred);
685 object->charge = 0;
686 crfree(object->cred);
687 object->cred = NULL;
688 }
689
690 /*
691 * Free the space for the object.

--- 88 unchanged lines hidden (view full) ---

780
781#if VM_NRESERVLEVEL > 0
782 if (__predict_false(!LIST_EMPTY(&object->rvq)))
783 vm_reserv_break_all(object);
784#endif
785 if (__predict_false(!vm_object_cache_is_empty(object)))
786 vm_page_cache_free(object, 0, 0);
787
788 KASSERT(object->cred == NULL || object->type == OBJT_DEFAULT ||
789 object->type == OBJT_SWAP,
790 ("%s: non-swap obj %p has cred", __func__, object));
791
791 /*
792 * Let the pager know object is dead.
793 */
794 vm_pager_deallocate(object);
795 VM_OBJECT_WUNLOCK(object);
796
797 vm_object_destroy(object);
798}

--- 999 unchanged lines hidden (view full) ---

1798 *
1799 * Since the backing object has no pages, no pager left,
1800 * and no object references within it, all that is
1801 * necessary is to dispose of it.
1802 */
1803 KASSERT(backing_object->ref_count == 1, (
1804"backing_object %p was somehow re-referenced during collapse!",
1805 backing_object));
792 /*
793 * Let the pager know object is dead.
794 */
795 vm_pager_deallocate(object);
796 VM_OBJECT_WUNLOCK(object);
797
798 vm_object_destroy(object);
799}

--- 999 unchanged lines hidden (view full) ---

1799 *
1800 * Since the backing object has no pages, no pager left,
1801 * and no object references within it, all that is
1802 * necessary is to dispose of it.
1803 */
1804 KASSERT(backing_object->ref_count == 1, (
1805"backing_object %p was somehow re-referenced during collapse!",
1806 backing_object));
1807 backing_object->type = OBJT_DEAD;
1808 backing_object->ref_count = 0;
1806 VM_OBJECT_WUNLOCK(backing_object);
1807 vm_object_destroy(backing_object);
1808
1809 object_collapses++;
1810 } else {
1811 vm_object_t new_backing_object;
1812
1813 /*

--- 706 unchanged lines hidden ---
1809 VM_OBJECT_WUNLOCK(backing_object);
1810 vm_object_destroy(backing_object);
1811
1812 object_collapses++;
1813 } else {
1814 vm_object_t new_backing_object;
1815
1816 /*

--- 706 unchanged lines hidden ---