* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
* Mach Operating System
* Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
* All Rights Reserved.
* Mach Operating System
* Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
* All Rights Reserved.
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
-#include <vm/pmap.h> /* For pmap_clear_modify */
-#include <vm/vm_kern.h> /* For kernel_map, vm_move */
-#include <vm/vm_map.h> /* For vm_map_pageable */
-#include <vm/vm_purgeable_internal.h> /* Needed by some vm_page.h macros */
+#include <vm/pmap.h> /* For pmap_clear_modify */
+#include <vm/vm_kern.h> /* For kernel_map, vm_move */
+#include <vm/vm_map.h> /* For vm_map_pageable */
+#include <vm/vm_purgeable_internal.h> /* Needed by some vm_page.h macros */
#include <vm/vm_shared_region.h>
#include <vm/vm_external.h>
#include <vm/vm_protos.h>
#include <vm/vm_shared_region.h>
#include <vm/vm_external.h>
#include <vm/vm_protos.h>
-memory_object_default_t memory_manager_default = MEMORY_OBJECT_DEFAULT_NULL;
-decl_lck_mtx_data(, memory_manager_default_lock)
+memory_object_default_t memory_manager_default = MEMORY_OBJECT_DEFAULT_NULL;
+LCK_MTX_EARLY_DECLARE(memory_manager_default_lock, &vm_object_lck_grp);
(should_return != MEMORY_OBJECT_RETURN_NONE && \
(((m)->vmp_dirty || ((m)->vmp_dirty = pmap_is_modified(VM_PAGE_GET_PHYS_PAGE(m)))) || \
((m)->vmp_precious && (should_return) == MEMORY_OBJECT_RETURN_ALL) || \
(should_return) == MEMORY_OBJECT_RETURN_ANYTHING))
(should_return != MEMORY_OBJECT_RETURN_NONE && \
(((m)->vmp_dirty || ((m)->vmp_dirty = pmap_is_modified(VM_PAGE_GET_PHYS_PAGE(m)))) || \
((m)->vmp_precious && (should_return) == MEMORY_OBJECT_RETURN_ALL) || \
(should_return) == MEMORY_OBJECT_RETURN_ANYTHING))
-#define MEMORY_OBJECT_LOCK_RESULT_DONE 0
-#define MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK 1
-#define MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN 2
-#define MEMORY_OBJECT_LOCK_RESULT_MUST_FREE 3
+#define MEMORY_OBJECT_LOCK_RESULT_DONE 0
+#define MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK 1
+#define MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN 2
+#define MEMORY_OBJECT_LOCK_RESULT_MUST_FREE 3
- vm_page_t m,
- memory_object_return_t should_return,
- boolean_t should_flush,
- vm_prot_t prot);
+ vm_page_t m,
+ memory_object_return_t should_return,
+ boolean_t should_flush,
+ vm_prot_t prot);
- vm_page_t m,
- memory_object_return_t should_return,
- boolean_t should_flush,
- vm_prot_t prot)
+ vm_page_t m,
+ memory_object_return_t should_return,
+ boolean_t should_flush,
+ vm_prot_t prot)
- XPR(XPR_MEMORY_OBJECT,
- "m_o_lock_page, page 0x%X rtn %d flush %d prot %d\n",
- m, should_return, should_flush, prot, 0);
-
-
- if (m->vmp_busy || m->vmp_cleaning)
- return (MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK);
+ if (m->vmp_busy || m->vmp_cleaning) {
+ return MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK;
+ }
* The page is wired... just clean or return the page if needed.
* Wired pages don't get flushed or disconnected from the pmap.
*/
* The page is wired... just clean or return the page if needed.
* Wired pages don't get flushed or disconnected from the pmap.
*/
- if (memory_object_should_return_page(m, should_return))
- return (MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN);
+ if (memory_object_should_return_page(m, should_return)) {
+ return MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN;
+ }
* need to return the page... otherwise it's possible
* for the page to go from the clean to the dirty state
* after we've made our decision
* need to return the page... otherwise it's possible
* for the page to go from the clean to the dirty state
* after we've made our decision
* forms specified by "prot");
* 2) return data to the manager (if "should_return"
* is RETURN_DIRTY and the page is dirty, or
* forms specified by "prot");
* 2) return data to the manager (if "should_return"
* is RETURN_DIRTY and the page is dirty, or
* is either dirty or precious); and,
* 3) flush the cached copy (if "should_flush"
* is asserted).
* is either dirty or precious); and,
* 3) flush the cached copy (if "should_flush"
* is asserted).
- memory_object_control_t control,
- memory_object_offset_t offset,
- memory_object_size_t size,
- memory_object_offset_t * resid_offset,
- int * io_errno,
- memory_object_return_t should_return,
- int flags,
- vm_prot_t prot)
+ memory_object_control_t control,
+ memory_object_offset_t offset,
+ memory_object_size_t size,
+ memory_object_offset_t * resid_offset,
+ int * io_errno,
+ memory_object_return_t should_return,
+ int flags,
+ vm_prot_t prot)
(void)vm_object_update(object, offset, size, resid_offset,
(void)vm_object_update(object, offset, size, resid_offset,
- io_errno, should_return, flags, prot);
+ io_errno, should_return, flags, prot);
+ }
* being the name.
* If the decision is made to proceed the name field flag is set to
* false and the reference count is decremented. If the RESPECT_CACHE
* being the name.
* If the decision is made to proceed the name field flag is set to
* false and the reference count is decremented. If the RESPECT_CACHE
* memory_object is checked to see if it is cacheable otherwise when
* the reference count is zero, it is simply terminated.
*/
kern_return_t
memory_object_release_name(
* memory_object is checked to see if it is cacheable otherwise when
* the reference count is zero, it is simply terminated.
*/
kern_return_t
memory_object_release_name(
- vm_object_t object,
- vm_object_offset_t offset,
- vm_object_size_t size,
- boolean_t should_flush,
- boolean_t should_return,
- boolean_t should_iosync)
+ vm_object_t object,
+ vm_object_offset_t offset,
+ vm_object_size_t size,
+ boolean_t should_flush,
+ boolean_t should_return,
+ boolean_t should_iosync)
- XPR(XPR_VM_OBJECT,
- "vm_o_sync, object 0x%X, offset 0x%X size 0x%x flush %d rtn %d\n",
- object, offset, size, should_flush, should_return);
-
/*
* Lock the object, and acquire a paging reference to
* prevent the memory_object and control ports from
/*
* Lock the object, and acquire a paging reference to
* prevent the memory_object and control ports from
/*
* This flush is from an msync(), not a truncate(), so the
* contents of the file are not affected.
/*
* This flush is from an msync(), not a truncate(), so the
* contents of the file are not affected.
rv = vm_object_update(object, offset, (vm_object_size_t)size, NULL, NULL,
rv = vm_object_update(object, offset, (vm_object_size_t)size, NULL, NULL,
- (should_return) ?
- MEMORY_OBJECT_RETURN_ALL :
- MEMORY_OBJECT_RETURN_NONE,
- flags,
- VM_PROT_NO_CHANGE);
+ (should_return) ?
+ MEMORY_OBJECT_RETURN_ALL :
+ MEMORY_OBJECT_RETURN_NONE,
+ flags,
+ VM_PROT_NO_CHANGE);
#define LIST_REQ_PAGEOUT_PAGES(object, data_cnt, po, ro, ioerr, iosync) \
#define LIST_REQ_PAGEOUT_PAGES(object, data_cnt, po, ro, ioerr, iosync) \
-MACRO_BEGIN \
- \
- int upl_flags; \
- memory_object_t pager; \
- \
- if ((pager = (object)->pager) != MEMORY_OBJECT_NULL) { \
- vm_object_paging_begin(object); \
- vm_object_unlock(object); \
- \
- if (iosync) \
- upl_flags = UPL_MSYNC | UPL_IOSYNC; \
- else \
- upl_flags = UPL_MSYNC; \
- \
- (void) memory_object_data_return(pager, \
- po, \
- (memory_object_cluster_size_t)data_cnt, \
+MACRO_BEGIN \
+ \
+ int upl_flags; \
+ memory_object_t pager; \
+ \
+ if ((pager = (object)->pager) != MEMORY_OBJECT_NULL) { \
+ vm_object_paging_begin(object); \
+ vm_object_unlock(object); \
+ \
+ if (iosync) \
+ upl_flags = UPL_MSYNC | UPL_IOSYNC; \
+ else \
+ upl_flags = UPL_MSYNC; \
+ \
+ (void) memory_object_data_return(pager, \
+ po, \
+ (memory_object_cluster_size_t)data_cnt, \
- vm_object_t object,
- vm_object_offset_t offset,
- vm_object_offset_t offset_end,
- vm_object_offset_t *offset_resid,
- int *io_errno,
- boolean_t should_flush,
- memory_object_return_t should_return,
- boolean_t should_iosync,
- vm_prot_t prot)
+ vm_object_t object,
+ vm_object_offset_t offset,
+ vm_object_offset_t offset_end,
+ vm_object_offset_t *offset_resid,
+ int *io_errno,
+ boolean_t should_flush,
+ memory_object_return_t should_return,
+ boolean_t should_iosync,
+ vm_prot_t prot)
- vm_page_t m;
- int retval = 0;
- vm_object_offset_t paging_offset = 0;
- vm_object_offset_t next_offset = offset;
- memory_object_lock_result_t page_lock_result;
- memory_object_cluster_size_t data_cnt = 0;
- struct vm_page_delayed_work dw_array[DEFAULT_DELAYED_WORK_LIMIT];
- struct vm_page_delayed_work *dwp;
- int dw_count;
- int dw_limit;
- int dirty_count;
-
- dwp = &dw_array[0];
- dw_count = 0;
+ vm_page_t m;
+ int retval = 0;
+ vm_object_offset_t paging_offset = 0;
+ vm_object_offset_t next_offset = offset;
+ memory_object_lock_result_t page_lock_result;
+ memory_object_cluster_size_t data_cnt = 0;
+ struct vm_page_delayed_work dw_array;
+ struct vm_page_delayed_work *dwp, *dwp_start;
+ bool dwp_finish_ctx = TRUE;
+ int dw_count;
+ int dw_limit;
+ int dirty_count;
+
+ dwp_start = dwp = NULL;
+ dw_count = 0;
* Limit the number of pages to be cleaned at once to a contiguous
* run, or at most MAX_UPL_TRANSFER_BYTES
*/
if (data_cnt) {
if ((data_cnt >= MAX_UPL_TRANSFER_BYTES) || (next_offset != offset)) {
* Limit the number of pages to be cleaned at once to a contiguous
* run, or at most MAX_UPL_TRANSFER_BYTES
*/
if (data_cnt) {
if ((data_cnt >= MAX_UPL_TRANSFER_BYTES) || (next_offset != offset)) {
- vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, &dw_array[0], dw_count);
- dwp = &dw_array[0];
+ vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, dwp_start, dw_count);
+ dwp = dwp_start;
- paging_offset, offset_resid, io_errno, should_iosync);
+ paging_offset, offset_resid, io_errno, should_iosync);
page_lock_result = memory_object_lock_page(m, should_return, should_flush, prot);
if (data_cnt && page_lock_result != MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN) {
page_lock_result = memory_object_lock_page(m, should_return, should_flush, prot);
if (data_cnt && page_lock_result != MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN) {
- vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, &dw_array[0], dw_count);
- dwp = &dw_array[0];
+ vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, dwp_start, dw_count);
+ dwp = dwp_start;
- paging_offset, offset_resid, io_errno, should_iosync);
+ paging_offset, offset_resid, io_errno, should_iosync);
/*
* LIST_REQ_PAGEOUT_PAGES will drop the object lock which will
* allow the state of page 'm' to change... we need to re-lookup
/*
* LIST_REQ_PAGEOUT_PAGES will drop the object lock which will
* allow the state of page 'm' to change... we need to re-lookup
VM_PAGE_ADD_DELAYED_WORK(dwp, m, dw_count);
if (dw_count >= dw_limit) {
VM_PAGE_ADD_DELAYED_WORK(dwp, m, dw_count);
if (dw_count >= dw_limit) {
- vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, &dw_array[0], dw_count);
- dwp = &dw_array[0];
+ vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, dwp_start, dw_count);
+ dwp = dwp_start;
task_update_logical_writes(current_task(), (dirty_count * PAGE_SIZE), TASK_WRITE_INVALIDATED, vnode_pager_lookup_vnode(object->pager));
task_update_logical_writes(current_task(), (dirty_count * PAGE_SIZE), TASK_WRITE_INVALIDATED, vnode_pager_lookup_vnode(object->pager));
- if (dw_count)
- vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, &dw_array[0], dw_count);
+ if (dw_count) {
+ vm_page_do_delayed_work(object, VM_KERN_MEMORY_NONE, dwp_start, dw_count);
+ }
- LIST_REQ_PAGEOUT_PAGES(object, data_cnt,
- paging_offset, offset_resid, io_errno, should_iosync);
+ LIST_REQ_PAGEOUT_PAGES(object, data_cnt,
+ paging_offset, offset_resid, io_errno, should_iosync);
+ }
+
+ if (dwp_start && dwp_finish_ctx) {
+ vm_page_delayed_work_finish_ctx(dwp_start);
+ dwp_start = dwp = NULL;
- vm_object_t object,
- vm_object_offset_t offset,
- vm_object_size_t size,
- vm_object_offset_t *resid_offset,
- int *io_errno,
- memory_object_return_t should_return,
- int flags,
- vm_prot_t protection)
+ vm_object_t object,
+ vm_object_offset_t offset,
+ vm_object_size_t size,
+ vm_object_offset_t *resid_offset,
+ int *io_errno,
+ memory_object_return_t should_return,
+ int flags,
+ vm_prot_t protection)
- vm_object_t copy_object = VM_OBJECT_NULL;
- boolean_t data_returned = FALSE;
- boolean_t update_cow;
- boolean_t should_flush = (flags & MEMORY_OBJECT_DATA_FLUSH) ? TRUE : FALSE;
- boolean_t should_iosync = (flags & MEMORY_OBJECT_IO_SYNC) ? TRUE : FALSE;
- vm_fault_return_t result;
- int num_of_extents;
- int n;
-#define MAX_EXTENTS 8
-#define EXTENT_SIZE (1024 * 1024 * 256)
-#define RESIDENT_LIMIT (1024 * 32)
+ vm_object_t copy_object = VM_OBJECT_NULL;
+ boolean_t data_returned = FALSE;
+ boolean_t update_cow;
+ boolean_t should_flush = (flags & MEMORY_OBJECT_DATA_FLUSH) ? TRUE : FALSE;
+ boolean_t should_iosync = (flags & MEMORY_OBJECT_IO_SYNC) ? TRUE : FALSE;
+ vm_fault_return_t result;
+ int num_of_extents;
+ int n;
+#define MAX_EXTENTS 8
+#define EXTENT_SIZE (1024 * 1024 * 256)
+#define RESIDENT_LIMIT (1024 * 32)
- vm_object_offset_t e_base;
- vm_object_offset_t e_min;
- vm_object_offset_t e_max;
+ vm_object_offset_t e_base;
+ vm_object_offset_t e_min;
+ vm_object_offset_t e_max;
- update_cow = ((flags & MEMORY_OBJECT_DATA_FLUSH)
- && (!(flags & MEMORY_OBJECT_DATA_NO_CHANGE) &&
- !(flags & MEMORY_OBJECT_DATA_PURGE)))
- || (flags & MEMORY_OBJECT_COPY_SYNC);
-
+ update_cow = ((flags & MEMORY_OBJECT_DATA_FLUSH)
+ && (!(flags & MEMORY_OBJECT_DATA_NO_CHANGE) &&
+ !(flags & MEMORY_OBJECT_DATA_PURGE)))
+ || (flags & MEMORY_OBJECT_COPY_SYNC);
+
* need to do a try here since we're swimming upstream
* against the normal lock ordering... however, we need
* to hold the object stable until we gain control of the
* copy object so we have to be careful how we approach this
*/
* need to do a try here since we're swimming upstream
* against the normal lock ordering... however, we need
* to hold the object stable until we gain control of the
* copy object so we have to be careful how we approach this
*/
- if (vm_object_lock_try(copy_object)) {
- /*
- * we 'won' the lock on the copy object...
- * no need to hold the object lock any longer...
- * take a real reference on the copy object because
- * we're going to call vm_fault_page on it which may
- * under certain conditions drop the lock and the paging
- * reference we're about to take... the reference
- * will keep the copy object from going away if that happens
- */
- vm_object_unlock(object);
- vm_object_reference_locked(copy_object);
- break;
+ if (vm_object_lock_try(copy_object)) {
+ /*
+ * we 'won' the lock on the copy object...
+ * no need to hold the object lock any longer...
+ * take a real reference on the copy object because
+ * we're going to call vm_fault_page on it which may
+ * under certain conditions drop the lock and the paging
+ * reference we're about to take... the reference
+ * will keep the copy object from going away if that happens
+ */
+ vm_object_unlock(object);
+ vm_object_reference_locked(copy_object);
+ break;
- vm_map_size_t i;
- vm_map_size_t copy_size;
- vm_map_offset_t copy_offset;
- vm_prot_t prot;
- vm_page_t page;
- vm_page_t top_page;
- kern_return_t error = 0;
+ vm_object_offset_t i;
+ vm_object_size_t copy_size;
+ vm_object_offset_t copy_offset;
+ vm_prot_t prot;
+ vm_page_t page;
+ vm_page_t top_page;
+ kern_return_t error = 0;
- copy_offset = (offset >= copy_object->vo_shadow_offset) ?
- (vm_map_offset_t)(offset - copy_object->vo_shadow_offset) :
- (vm_map_offset_t) 0;
+ copy_offset = (offset >= copy_object->vo_shadow_offset) ?
+ (offset - copy_object->vo_shadow_offset) : 0;
fault_info.cluster_size = (vm_size_t) (copy_size - i);
assert(fault_info.cluster_size == copy_size - i);
fault_info.cluster_size = (vm_size_t) (copy_size - i);
assert(fault_info.cluster_size == copy_size - i);
- result = vm_fault_page(copy_object, i,
- VM_PROT_WRITE|VM_PROT_READ,
- FALSE,
- FALSE, /* page not looked up */
- &prot,
- &page,
- &top_page,
- (int *)0,
- &error,
- FALSE,
- FALSE, &fault_info);
+ result = vm_fault_page(copy_object, i,
+ VM_PROT_WRITE | VM_PROT_READ,
+ FALSE,
+ FALSE, /* page not looked up */
+ &prot,
+ &page,
+ &top_page,
+ (int *)0,
+ &error,
+ FALSE,
+ FALSE, &fault_info);
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
case VM_FAULT_INTERRUPTED:
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
case VM_FAULT_INTERRUPTED:
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
case VM_FAULT_MEMORY_SHORTAGE:
VM_PAGE_WAIT();
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
case VM_FAULT_MEMORY_SHORTAGE:
VM_PAGE_WAIT();
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
/* success but no VM page: fail */
vm_object_paging_end(copy_object);
vm_object_unlock(copy_object);
/* success but no VM page: fail */
vm_object_paging_end(copy_object);
vm_object_unlock(copy_object);
}
vm_object_paging_end(copy_object);
}
if ((flags & (MEMORY_OBJECT_DATA_SYNC | MEMORY_OBJECT_COPY_SYNC))) {
}
vm_object_paging_end(copy_object);
}
if ((flags & (MEMORY_OBJECT_DATA_SYNC | MEMORY_OBJECT_COPY_SYNC))) {
* the page which means the resident queue can change which
* means we can't walk the queue as we process the pages
* we also want to do the processing in offset order to allow
* the page which means the resident queue can change which
* means we can't walk the queue as we process the pages
* we also want to do the processing in offset order to allow
* a temporary solution (until we figure out how to deal with
* large address spaces more generically) is to pre-flight
* the resident page queue (if it's small enough) and develop
* a temporary solution (until we figure out how to deal with
* large address spaces more generically) is to pre-flight
* the resident page queue (if it's small enough) and develop
- if ((object->resident_page_count < RESIDENT_LIMIT) &&
- (atop_64(size) > (unsigned)(object->resident_page_count/(8 * MAX_EXTENTS)))) {
- vm_page_t next;
- vm_object_offset_t start;
- vm_object_offset_t end;
- vm_object_size_t e_mask;
+ if ((object->resident_page_count < RESIDENT_LIMIT) &&
+ (atop_64(size) > (unsigned)(object->resident_page_count / (8 * MAX_EXTENTS)))) {
+ vm_page_t next;
+ vm_object_offset_t start;
+ vm_object_offset_t end;
+ vm_object_size_t e_mask;
next = (vm_page_t) vm_page_queue_next(&m->vmp_listq);
if ((m->vmp_offset >= start) && (m->vmp_offset < end)) {
next = (vm_page_t) vm_page_queue_next(&m->vmp_listq);
if ((m->vmp_offset >= start) && (m->vmp_offset < end)) {
* use (PAGE_SIZE - 1) to determine the
* max offset so that we don't wrap if
* we're at the last page of the space
*/
* use (PAGE_SIZE - 1) to determine the
* max offset so that we don't wrap if
* we're at the last page of the space
*/
- if (m->vmp_offset < extents[n].e_min)
- extents[n].e_min = m->vmp_offset;
- else if ((m->vmp_offset + (PAGE_SIZE - 1)) > extents[n].e_max)
- extents[n].e_max = m->vmp_offset + (PAGE_SIZE - 1);
- break;
+ if (m->vmp_offset < extents[n].e_min) {
+ extents[n].e_min = m->vmp_offset;
+ } else if ((m->vmp_offset + (PAGE_SIZE - 1)) > extents[n].e_max) {
+ extents[n].e_max = m->vmp_offset + (PAGE_SIZE - 1);
+ }
+ break;
* we find in the range we're interested in...
* first, look through the extent list and
* develop the overall min and max for the
* pages we've looked at up to this point
* we find in the range we're interested in...
* first, look through the extent list and
* develop the overall min and max for the
* pages we've looked at up to this point
- */
- for (n = 1; n < num_of_extents; n++) {
- if (extents[n].e_min < extents[0].e_min)
- extents[0].e_min = extents[n].e_min;
- if (extents[n].e_max > extents[0].e_max)
- extents[0].e_max = extents[n].e_max;
+ */
+ for (n = 1; n < num_of_extents; n++) {
+ if (extents[n].e_min < extents[0].e_min) {
+ extents[0].e_min = extents[n].e_min;
+ }
+ if (extents[n].e_max > extents[0].e_max) {
+ extents[0].e_max = extents[n].e_max;
+ }
- if (vm_object_update_extent(object, extents[n].e_min, extents[n].e_max, resid_offset, io_errno,
- should_flush, should_return, should_iosync, protection))
- data_returned = TRUE;
+ if (vm_object_update_extent(object, extents[n].e_min, extents[n].e_max, resid_offset, io_errno,
+ should_flush, should_return, should_iosync, protection)) {
+ data_returned = TRUE;
+ }
- boolean_t object_became_ready;
-
- XPR(XPR_MEMORY_OBJECT,
- "m_o_set_attr_com, object 0x%X flg %x strat %d\n",
- object, (may_cache&1), copy_strategy, 0, 0);
+ boolean_t object_became_ready;
- switch(copy_strategy) {
- case MEMORY_OBJECT_COPY_NONE:
- case MEMORY_OBJECT_COPY_DELAY:
- break;
- default:
- return(KERN_INVALID_ARGUMENT);
+ switch (copy_strategy) {
+ case MEMORY_OBJECT_COPY_NONE:
+ case MEMORY_OBJECT_COPY_DELAY:
+ break;
+ default:
+ return KERN_INVALID_ARGUMENT;
- __unused memory_object_control_t control,
- __unused memory_object_offset_t offset,
- __unused memory_object_size_t length)
+ __unused memory_object_control_t control,
+ __unused memory_object_offset_t offset,
+ __unused memory_object_size_t length)
* in place, and cluster work is completed. See ifdef notyet
* below and note that vm_object_set_attributes_common()
* may have to be expanded.
*/
kern_return_t
memory_object_change_attributes(
* in place, and cluster work is completed. See ifdef notyet
* below and note that vm_object_set_attributes_common()
* may have to be expanded.
*/
kern_return_t
memory_object_change_attributes(
- memory_object_control_t control,
- memory_object_flavor_t flavor,
- memory_object_info_t attributes,
- mach_msg_type_number_t count)
+ memory_object_control_t control,
+ memory_object_flavor_t flavor,
+ memory_object_info_t attributes,
+ mach_msg_type_number_t count)
- memory_object_control_t control,
- memory_object_flavor_t flavor,
- memory_object_info_t attributes, /* pointer to OUT array */
- mach_msg_type_number_t *count) /* IN/OUT */
+ memory_object_control_t control,
+ memory_object_flavor_t flavor,
+ memory_object_info_t attributes, /* pointer to OUT array */
+ mach_msg_type_number_t *count) /* IN/OUT */
behave = (old_memory_object_behave_info_t) attributes;
behave->copy_strategy = object->copy_strategy;
behave->temporary = FALSE;
behave = (old_memory_object_behave_info_t) attributes;
behave->copy_strategy = object->copy_strategy;
behave->temporary = FALSE;
-#if notyet /* remove when vm_msync complies and clean in place fini */
- behave->invalidate = object->invalidate;
+#if notyet /* remove when vm_msync complies and clean in place fini */
+ behave->invalidate = object->invalidate;
- behave = (memory_object_behave_info_t) attributes;
- behave->copy_strategy = object->copy_strategy;
+ behave = (memory_object_behave_info_t) attributes;
+ behave->copy_strategy = object->copy_strategy;
-#if notyet /* remove when vm_msync complies and clean in place fini */
- behave->invalidate = object->invalidate;
+#if notyet /* remove when vm_msync complies and clean in place fini */
+ behave->invalidate = object->invalidate;
#else
behave->invalidate = FALSE;
#endif
behave->advisory_pageout = FALSE;
behave->silent_overwrite = FALSE;
#else
behave->invalidate = FALSE;
#endif
behave->advisory_pageout = FALSE;
behave->silent_overwrite = FALSE;
- attr = (old_memory_object_attr_info_t) attributes;
- attr->may_cache = object->can_persist;
- attr->copy_strategy = object->copy_strategy;
+ attr = (old_memory_object_attr_info_t) attributes;
+ attr->may_cache = object->can_persist;
+ attr->copy_strategy = object->copy_strategy;
- ipc_port_t port,
- memory_object_offset_t offset,
- upl_size_t *upl_size,
- upl_t *upl_ptr,
- upl_page_info_array_t user_page_list,
- unsigned int *page_list_count,
- upl_control_flags_t *flags,
- vm_tag_t tag)
+ ipc_port_t port,
+ memory_object_offset_t offset,
+ upl_size_t *upl_size,
+ upl_t *upl_ptr,
+ upl_page_info_array_t user_page_list,
+ unsigned int *page_list_count,
+ upl_control_flags_t *flags,
+ vm_tag_t tag)
- if(caller_flags & UPL_COPYOUT_FROM) {
- if((named_entry->protection & VM_PROT_READ)
- != VM_PROT_READ) {
- return(KERN_INVALID_RIGHT);
+ if (caller_flags & UPL_COPYOUT_FROM) {
+ if ((named_entry->protection & VM_PROT_READ)
+ != VM_PROT_READ) {
+ return KERN_INVALID_RIGHT;
- if((named_entry->protection &
- (VM_PROT_READ | VM_PROT_WRITE))
- != (VM_PROT_READ | VM_PROT_WRITE)) {
- return(KERN_INVALID_RIGHT);
+ if ((named_entry->protection &
+ (VM_PROT_READ | VM_PROT_WRITE))
+ != (VM_PROT_READ | VM_PROT_WRITE)) {
+ return KERN_INVALID_RIGHT;
/* the callers parameter offset is defined to be the */
/* offset from beginning of named entry offset in object */
offset = offset + named_entry->offset;
/* the callers parameter offset is defined to be the */
/* offset from beginning of named entry offset in object */
offset = offset + named_entry->offset;
vm_object_reference(object);
named_entry_unlock(named_entry);
} else if (ip_kotype(port) == IKOT_MEM_OBJ_CONTROL) {
vm_object_reference(object);
named_entry_unlock(named_entry);
} else if (ip_kotype(port) == IKOT_MEM_OBJ_CONTROL) {
- memory_object_control_t control,
- memory_object_offset_t offset,
- upl_size_t size,
- upl_t *upl_ptr,
- upl_page_info_array_t user_page_list,
- unsigned int *page_list_count,
- int cntrl_flags,
- int tag)
+ memory_object_control_t control,
+ memory_object_offset_t offset,
+ upl_size_t size,
+ upl_t *upl_ptr,
+ upl_page_info_array_t user_page_list,
+ unsigned int *page_list_count,
+ int cntrl_flags,
+ int tag)
* Routine: memory_object_super_upl_request [interface]
* Purpose:
* Cause the population of a portion of a vm_object
* Routine: memory_object_super_upl_request [interface]
* Purpose:
* Cause the population of a portion of a vm_object
kern_return_t
memory_object_super_upl_request(
memory_object_control_t control,
kern_return_t
memory_object_super_upl_request(
memory_object_control_t control,
- memory_object_offset_t offset,
- upl_size_t size,
- upl_size_t super_cluster,
- upl_t *upl,
- upl_page_info_t *user_page_list,
- unsigned int *page_list_count,
- int cntrl_flags,
- int tag)
+ memory_object_offset_t offset,
+ upl_size_t size,
+ upl_size_t super_cluster,
+ upl_t *upl,
+ upl_page_info_t *user_page_list,
+ unsigned int *page_list_count,
+ int cntrl_flags,
+ int tag)
- memory_object_control_t control,
- memory_object_offset_t *start,
- vm_size_t *length,
- uint32_t *io_streaming,
+ memory_object_control_t control,
+ memory_object_offset_t *start,
+ vm_size_t *length,
+ uint32_t *io_streaming,
*start -= object->paging_offset;
fault_info = (vm_object_fault_info_t)(uintptr_t) mo_fault_info;
vm_object_cluster_size(object,
*start -= object->paging_offset;
fault_info = (vm_object_fault_info_t)(uintptr_t) mo_fault_info;
vm_object_cluster_size(object,
lck_mtx_lock(&memory_manager_default_lock);
current = memory_manager_default;
if (current == MEMORY_OBJECT_DEFAULT_NULL) {
lck_mtx_lock(&memory_manager_default_lock);
current = memory_manager_default;
if (current == MEMORY_OBJECT_DEFAULT_NULL) {
/* Allow manipulation of individual page state. This is actually part of */
/* the UPL regimen but takes place on the object rather than on a UPL */
kern_return_t
memory_object_page_op(
/* Allow manipulation of individual page state. This is actually part of */
/* the UPL regimen but takes place on the object rather than on a UPL */
kern_return_t
memory_object_page_op(
- memory_object_control_t control,
- memory_object_offset_t offset,
- int ops,
- ppnum_t *phys_entry,
- int *flags)
+ memory_object_control_t control,
+ memory_object_offset_t offset,
+ int ops,
+ ppnum_t *phys_entry,
+ int *flags)
return vm_object_page_op(object, offset, ops, phys_entry, flags);
}
/*
return vm_object_page_op(object, offset, ops, phys_entry, flags);
}
/*
- * memory_object_range_op offers performance enhancement over
- * memory_object_page_op for page_op functions which do not require page
- * level state to be returned from the call. Page_op was created to provide
- * a low-cost alternative to page manipulation via UPLs when only a single
- * page was involved. The range_op call establishes the ability in the _op
+ * memory_object_range_op offers performance enhancement over
+ * memory_object_page_op for page_op functions which do not require page
+ * level state to be returned from the call. Page_op was created to provide
+ * a low-cost alternative to page manipulation via UPLs when only a single
+ * page was involved. The range_op call establishes the ability in the _op
* family of functions to work on multiple pages where the lack of page level
* state handling allows the caller to avoid the overhead of the upl structures.
*/
kern_return_t
memory_object_range_op(
* family of functions to work on multiple pages where the lack of page level
* state handling allows the caller to avoid the overhead of the upl structures.
*/
kern_return_t
memory_object_range_op(
- memory_object_control_t control,
- memory_object_offset_t offset_beg,
- memory_object_offset_t offset_end,
+ memory_object_control_t control,
+ memory_object_offset_t offset_beg,
+ memory_object_offset_t offset_end,
- memory_object_control_t control,
- __unused boolean_t rage)
+ memory_object_control_t control,
+ __unused boolean_t rage)
+void
+memory_object_mark_trusted(
+ memory_object_control_t control)
+{
+ vm_object_t object;
+
+ if (control == NULL) {
+ return;
+ }
+ object = memory_object_control_to_vm_object(control);
+
+ if (object != VM_OBJECT_NULL) {
+ vm_object_lock(object);
+ object->pager_trusted = TRUE;
+ vm_object_unlock(object);
+ }
+}
+
#if CONFIG_SECLUDED_MEMORY
void
memory_object_mark_eligible_for_secluded(
memory_object_control_t control,
#if CONFIG_SECLUDED_MEMORY
void
memory_object_mark_eligible_for_secluded(
memory_object_control_t control,
object->eligible_for_secluded = TRUE;
vm_page_secluded.eligible_for_secluded += object->resident_page_count;
} else if (!eligible_for_secluded &&
object->eligible_for_secluded = TRUE;
vm_page_secluded.eligible_for_secluded += object->resident_page_count;
} else if (!eligible_for_secluded &&
object->eligible_for_secluded = FALSE;
vm_page_secluded.eligible_for_secluded -= object->resident_page_count;
if (object->resident_page_count) {
object->eligible_for_secluded = FALSE;
vm_page_secluded.eligible_for_secluded -= object->resident_page_count;
if (object->resident_page_count) {
- memory_object_control_t control,
- boolean_t * has_pages_resident)
+ memory_object_control_t control,
+ boolean_t * has_pages_resident)
-static zone_t mem_obj_control_zone;
-
-__private_extern__ void
-memory_object_control_bootstrap(void)
-{
- int i;
-
- i = (vm_size_t) sizeof (struct memory_object_control);
- mem_obj_control_zone = zinit (i, 8192*i, 4096, "mem_obj_control");
- zone_change(mem_obj_control_zone, Z_CALLERACCT, FALSE);
- zone_change(mem_obj_control_zone, Z_NOENCRYPT, TRUE);
- return;
-}
+static ZONE_DECLARE(mem_obj_control_zone, "mem_obj_control",
+ sizeof(struct memory_object_control), ZC_NOENCRYPT);
control->moc_object = object;
}
__private_extern__ vm_object_t
memory_object_control_to_vm_object(
control->moc_object = object;
}
__private_extern__ vm_object_t
memory_object_control_to_vm_object(
{
zfree(mem_obj_control_zone, control);
}
void
memory_object_control_disable(
{
zfree(mem_obj_control_zone, control);
}
void
memory_object_control_disable(
(
memory_object_t memory_object,
memory_object_control_t memory_control,
(
memory_object_t memory_object,
memory_object_control_t memory_control,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
memory_object_cluster_size_t size,
memory_object_offset_t *resid_offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
memory_object_cluster_size_t size,
memory_object_offset_t *resid_offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
(
memory_object_t memory_object,
memory_object_offset_t offset,
* memory_object_map() is called by VM (in vm_map_enter() and its variants)
* each time a "named" VM object gets mapped directly or indirectly
* (copy-on-write mapping). A "named" VM object has an extra reference held
* memory_object_map() is called by VM (in vm_map_enter() and its variants)
* each time a "named" VM object gets mapped directly or indirectly
* (copy-on-write mapping). A "named" VM object has an extra reference held
* memory object (and its VM object) can be reclaimed.
* VM calls memory_object_last_unmap() (in vm_object_deallocate()) when all
* the mappings of that memory object have been removed.
* memory object (and its VM object) can be reclaimed.
* VM calls memory_object_last_unmap() (in vm_object_deallocate()) when all
* the mappings of that memory object have been removed.
- __unused ipc_port_t port,
- __unused mach_port_mscount_t mscount)
+ __unused ipc_port_t port,
+ __unused mach_port_mscount_t mscount)