/*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * 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
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * 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.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE 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.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* @OSF_COPYRIGHT@
#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 */
#if MACH_PAGEMAP
#include <vm/vm_external.h>
memory_object_default_t memory_manager_default = MEMORY_OBJECT_DEFAULT_NULL;
-vm_size_t memory_manager_default_cluster = 0;
-decl_mutex_data(, memory_manager_default_lock)
+decl_lck_mtx_data(, memory_manager_default_lock)
/*
{
XPR(XPR_MEMORY_OBJECT,
"m_o_lock_page, page 0x%X rtn %d flush %d prot %d\n",
- (integer_t)m, should_return, should_flush, prot, 0);
+ m, should_return, should_flush, prot, 0);
/*
* If we cannot change access to the page,
* wired, then give up.
*/
- if (m->busy || m->cleaning)
- return(MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK);
+ if (m->busy || m->cleaning) {
+ if (m->list_req_pending && (m->pageout || m->cleaning) &&
+ should_return == MEMORY_OBJECT_RETURN_NONE &&
+ should_flush == TRUE) {
+ /*
+ * if pageout is set, page was earmarked by vm_pageout_scan
+ * to be cleaned and stolen... if cleaning is set, we're
+ * pre-cleaning pages for a hibernate...
+ * in either case, we're going
+ * to take it back since we are being asked to
+ * flush the page w/o cleaning it (i.e. we don't
+ * care that it's dirty, we want it gone from
+ * the cache) and we don't want to stall
+ * waiting for it to be cleaned for 2 reasons...
+ * 1 - no use paging it out since we're probably
+ * shrinking the file at this point or we no
+ * longer care about the data in the page
+ * 2 - if we stall, we may casue a deadlock in
+ * the FS trying to acquire its locks
+ * on the VNOP_PAGEOUT path presuming that
+ * those locks are already held on the truncate
+ * path before calling through to this function
+ *
+ * so undo all of the state that vm_pageout_scan
+ * hung on this page
+ */
+ m->busy = FALSE;
+
+ vm_pageout_queue_steal(m, FALSE);
+ } else
+ return(MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK);
+ }
/*
* Don't worry about pages for which the kernel
/* dump the page, pager wants us to */
/* clean it up and there is no */
/* relevant data to return */
- if(m->wire_count == 0) {
+ if ( !VM_PAGE_WIRED(m)) {
VM_PAGE_FREE(m);
return(MEMORY_OBJECT_LOCK_RESULT_DONE);
}
assert(!m->fictitious);
- if (m->wire_count != 0) {
- /*
- * If no change would take place
- * anyway, return successfully.
- *
- * No change means:
- * Not flushing AND
- * No change to page lock [2 checks] AND
- * Should not return page
- *
- * XXX This doesn't handle sending a copy of a wired
- * XXX page to the pager, but that will require some
- * XXX significant surgery.
- */
- if (!should_flush &&
- (m->page_lock == prot || prot == VM_PROT_NO_CHANGE) &&
- ! memory_object_should_return_page(m, should_return)) {
-
- /*
- * Restart page unlock requests,
- * even though no change took place.
- * [Memory managers may be expecting
- * to see new requests.]
- */
- m->unlock_request = VM_PROT_NONE;
- PAGE_WAKEUP(m);
+ /*
+ * If the page is wired, just clean or return the page if needed.
+ * Wired pages don't get flushed or disconnected from the pmap.
+ */
- return(MEMORY_OBJECT_LOCK_RESULT_DONE);
+ if (VM_PAGE_WIRED(m)) {
+ if (memory_object_should_return_page(m, should_return)) {
+ if (m->dirty)
+ return(MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN);
+ else
+ return(MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN);
}
- return(MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK);
+ return(MEMORY_OBJECT_LOCK_RESULT_DONE);
}
/*
*/
if (prot != VM_PROT_NO_CHANGE) {
- if ((m->page_lock ^ prot) & prot) {
- pmap_page_protect(m->phys_page, VM_PROT_ALL & ~prot);
- }
-#if 0
- /* code associated with the vestigial
- * memory_object_data_unlock
- */
- m->page_lock = prot;
- m->lock_supplied = TRUE;
- if (prot != VM_PROT_NONE)
- m->unusual = TRUE;
- else
- m->unusual = FALSE;
+ pmap_page_protect(m->phys_page, VM_PROT_ALL & ~prot);
- /*
- * Restart any past unlock requests, even if no
- * change resulted. If the manager explicitly
- * requested no protection change, then it is assumed
- * to be remembering past requests.
- */
-
- m->unlock_request = VM_PROT_NONE;
-#endif /* 0 */
PAGE_WAKEUP(m);
}
/*
* Handle page returning.
*/
-
if (memory_object_should_return_page(m, should_return)) {
/*
* maps now.
*/
- vm_page_lock_queues();
+ vm_page_lockspin_queues();
VM_PAGE_QUEUES_REMOVE(m);
vm_page_unlock_queues();
/*
* Handle flushing
*/
-
if (should_flush) {
VM_PAGE_FREE(m);
} else {
if (vm_page_deactivate_hint &&
(should_return != MEMORY_OBJECT_RETURN_NONE)) {
- vm_page_lock_queues();
+ vm_page_lockspin_queues();
vm_page_deactivate(m);
vm_page_unlock_queues();
}
MACRO_BEGIN \
\
register int upl_flags; \
+ memory_object_t pager; \
\
- vm_object_unlock(object); \
+ 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; \
+ if (iosync) \
+ upl_flags = UPL_MSYNC | UPL_IOSYNC; \
+ else \
+ upl_flags = UPL_MSYNC; \
\
- (void) memory_object_data_return(object->pager, \
- po, \
- data_cnt, \
- ro, \
- ioerr, \
- (action == MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN), \
- !should_flush, \
- upl_flags); \
+ (void) memory_object_data_return(pager, \
+ po, \
+ (memory_object_cluster_size_t)data_cnt, \
+ ro, \
+ ioerr, \
+ (action) == MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN,\
+ !should_flush, \
+ upl_flags); \
\
- vm_object_lock(object); \
+ vm_object_lock(object); \
+ vm_object_paging_end(object); \
+ } \
MACRO_END
/*
vm_prot_t prot)
{
vm_object_t object;
- __unused boolean_t should_flush;
-
- should_flush = flags & MEMORY_OBJECT_DATA_FLUSH;
-
- XPR(XPR_MEMORY_OBJECT,
- "m_o_lock_request, control 0x%X off 0x%X size 0x%X flags %X prot %X\n",
- (integer_t)control, offset, size,
- (((should_return&1)<<1)|should_flush), prot);
- /*
+ /*
* Check for bogus arguments.
*/
object = memory_object_control_to_vm_object(control);
*/
vm_object_lock(object);
vm_object_paging_begin(object);
+
+ if (flags & MEMORY_OBJECT_DATA_FLUSH_ALL) {
+ if ((should_return != MEMORY_OBJECT_RETURN_NONE) || offset || object->copy) {
+ flags &= ~MEMORY_OBJECT_DATA_FLUSH_ALL;
+ flags |= MEMORY_OBJECT_DATA_FLUSH;
+ }
+ }
offset -= object->paging_offset;
- (void)vm_object_update(object,
- offset, size, resid_offset, io_errno, should_return, flags, prot);
+ if (flags & MEMORY_OBJECT_DATA_FLUSH_ALL)
+ vm_object_reap_pages(object, REAP_DATA_FLUSH);
+ else
+ (void)vm_object_update(object, offset, size, resid_offset,
+ io_errno, should_return, flags, prot);
vm_object_paging_end(object);
vm_object_unlock(object);
XPR(XPR_VM_OBJECT,
"vm_o_sync, object 0x%X, offset 0x%X size 0x%x flush %d rtn %d\n",
- (integer_t)object, offset, size, should_flush, should_return);
+ object, offset, size, should_flush, should_return);
/*
* Lock the object, and acquire a paging reference to
{
vm_page_t m;
int retval = 0;
- vm_size_t data_cnt = 0;
+ memory_object_cluster_size_t data_cnt = 0;
vm_object_offset_t paging_offset = 0;
- vm_object_offset_t last_offset = offset;
+ vm_object_offset_t next_offset = offset;
memory_object_lock_result_t page_lock_result;
memory_object_lock_result_t pageout_action;
offset += PAGE_SIZE_64) {
/*
- * Limit the number of pages to be cleaned at once.
+ * Limit the number of pages to be cleaned at once to a contiguous
+ * run, or at most MAX_UPL_TRANSFER size
*/
- if (data_cnt >= PAGE_SIZE * MAX_UPL_TRANSFER) {
- LIST_REQ_PAGEOUT_PAGES(object, data_cnt,
- pageout_action, paging_offset, offset_resid, io_errno, should_iosync);
- data_cnt = 0;
+ if (data_cnt) {
+ if ((data_cnt >= PAGE_SIZE * MAX_UPL_TRANSFER) || (next_offset != offset)) {
+ LIST_REQ_PAGEOUT_PAGES(object, data_cnt,
+ pageout_action, paging_offset, offset_resid, io_errno, should_iosync);
+ data_cnt = 0;
+ }
}
while ((m = vm_page_lookup(object, offset)) != VM_PAGE_NULL) {
XPR(XPR_MEMORY_OBJECT,
"m_o_update: lock_page, obj 0x%X offset 0x%X result %d\n",
- (integer_t)object, offset, page_lock_result, 0, 0);
+ object, offset, page_lock_result, 0, 0);
switch (page_lock_result)
{
*
* if this would form a discontiguous block,
* clean the old pages and start anew.
- *
- * Mark the page busy since we will unlock the
- * object if we issue the LIST_REQ_PAGEOUT
*/
- m->busy = TRUE;
- if (data_cnt &&
- ((last_offset != offset) || (pageout_action != page_lock_result))) {
+ if (data_cnt && pageout_action != page_lock_result) {
LIST_REQ_PAGEOUT_PAGES(object,
data_cnt, pageout_action,
paging_offset, offset_resid, io_errno, should_iosync);
data_cnt = 0;
+ continue;
}
- m->busy = FALSE;
-
if (m->cleaning) {
PAGE_SLEEP(object, m, THREAD_UNINT);
continue;
paging_offset = offset;
}
data_cnt += PAGE_SIZE;
- last_offset = offset + PAGE_SIZE_64;
+ next_offset = offset + PAGE_SIZE_64;
- vm_page_lock_queues();
/*
* Clean
*/
m->list_req_pending = TRUE;
m->cleaning = TRUE;
- if (should_flush) {
+ if (should_flush &&
+ /* let's not flush a wired page... */
+ !VM_PAGE_WIRED(m)) {
/*
* and add additional state
* for the flush
*/
m->busy = TRUE;
m->pageout = TRUE;
+
+ vm_page_lockspin_queues();
vm_page_wire(m);
+ vm_page_unlock_queues();
}
- vm_page_unlock_queues();
retval = 1;
break;
int flags,
vm_prot_t protection)
{
- vm_object_t copy_object;
+ 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
!(flags & MEMORY_OBJECT_DATA_PURGE)))
|| (flags & MEMORY_OBJECT_COPY_SYNC);
+ if (update_cow || (flags & (MEMORY_OBJECT_DATA_PURGE | MEMORY_OBJECT_DATA_SYNC))) {
+ int collisions = 0;
+
+ while ((copy_object = object->copy) != VM_OBJECT_NULL) {
+ /*
+ * 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;
+ }
+ vm_object_unlock(object);
+
+ collisions++;
+ mutex_pause(collisions);
- if((((copy_object = object->copy) != NULL) && update_cow) ||
- (flags & MEMORY_OBJECT_DATA_SYNC)) {
+ vm_object_lock(object);
+ }
+ }
+ if ((copy_object != VM_OBJECT_NULL && update_cow) || (flags & MEMORY_OBJECT_DATA_SYNC)) {
vm_map_size_t i;
vm_map_size_t copy_size;
vm_map_offset_t copy_offset;
vm_page_t page;
vm_page_t top_page;
kern_return_t error = 0;
+ struct vm_object_fault_info fault_info;
+
+ if (copy_object != VM_OBJECT_NULL) {
+ /*
+ * translate offset with respect to shadow's offset
+ */
+ copy_offset = (offset >= copy_object->shadow_offset) ?
+ (vm_map_offset_t)(offset - copy_object->shadow_offset) :
+ (vm_map_offset_t) 0;
+
+ if (copy_offset > copy_object->size)
+ copy_offset = copy_object->size;
+
+ /*
+ * clip size with respect to shadow offset
+ */
+ if (offset >= copy_object->shadow_offset) {
+ copy_size = size;
+ } else if (size >= copy_object->shadow_offset - offset) {
+ copy_size = size - (copy_object->shadow_offset - offset);
+ } else {
+ copy_size = 0;
+ }
+
+ if (copy_offset + copy_size > copy_object->size) {
+ if (copy_object->size >= copy_offset) {
+ copy_size = copy_object->size - copy_offset;
+ } else {
+ copy_size = 0;
+ }
+ }
+ copy_size+=copy_offset;
- if(copy_object != NULL) {
- /* translate offset with respect to shadow's offset */
- copy_offset = (offset >= copy_object->shadow_offset)?
- (vm_map_offset_t)(offset - copy_object->shadow_offset) :
- (vm_map_offset_t) 0;
- if(copy_offset > copy_object->size)
- copy_offset = copy_object->size;
-
- /* clip size with respect to shadow offset */
- if (offset >= copy_object->shadow_offset) {
- copy_size = size;
- } else if (size >= copy_object->shadow_offset - offset) {
- copy_size = size -
- (copy_object->shadow_offset - offset);
- } else {
- copy_size = 0;
- }
-
- if (copy_offset + copy_size > copy_object->size) {
- if (copy_object->size >= copy_offset) {
- copy_size = copy_object->size - copy_offset;
- } else {
- copy_size = 0;
- }
- }
-
- copy_size+=copy_offset;
-
- vm_object_unlock(object);
- vm_object_lock(copy_object);
} else {
copy_object = object;
copy_size = offset + size;
copy_offset = offset;
}
+ fault_info.interruptible = THREAD_UNINT;
+ fault_info.behavior = VM_BEHAVIOR_SEQUENTIAL;
+ fault_info.user_tag = 0;
+ fault_info.lo_offset = copy_offset;
+ fault_info.hi_offset = copy_size;
+ fault_info.no_cache = FALSE;
+ fault_info.stealth = TRUE;
+ fault_info.mark_zf_absent = FALSE;
vm_object_paging_begin(copy_object);
- for (i=copy_offset; i<copy_size; i+=PAGE_SIZE) {
+
+ for (i = copy_offset; i < copy_size; i += PAGE_SIZE) {
RETRY_COW_OF_LOCK_REQUEST:
- prot = VM_PROT_WRITE|VM_PROT_READ;
- switch (vm_fault_page(copy_object, i,
- VM_PROT_WRITE|VM_PROT_READ,
- FALSE,
- THREAD_UNINT,
- copy_offset,
- copy_offset+copy_size,
- VM_BEHAVIOR_SEQUENTIAL,
- &prot,
- &page,
- &top_page,
- (int *)0,
- &error,
- FALSE,
- FALSE, NULL, 0)) {
+ fault_info.cluster_size = (vm_size_t) (copy_size - i);
+ assert(fault_info.cluster_size == copy_size - i);
+ prot = VM_PROT_WRITE|VM_PROT_READ;
+ result = vm_fault_page(copy_object, i,
+ VM_PROT_WRITE|VM_PROT_READ,
+ FALSE,
+ &prot,
+ &page,
+ &top_page,
+ (int *)0,
+ &error,
+ FALSE,
+ FALSE, &fault_info);
+
+ switch (result) {
case VM_FAULT_SUCCESS:
- if(top_page) {
+ if (top_page) {
vm_fault_cleanup(
page->object, top_page);
- PAGE_WAKEUP_DONE(page);
- vm_page_lock_queues();
- if (!page->active && !page->inactive)
- vm_page_activate(page);
- vm_page_unlock_queues();
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
- } else {
- PAGE_WAKEUP_DONE(page);
- vm_page_lock_queues();
- if (!page->active && !page->inactive)
- vm_page_activate(page);
+ }
+ if (!page->active &&
+ !page->inactive &&
+ !page->throttled) {
+ vm_page_lockspin_queues();
+ if (!page->active &&
+ !page->inactive &&
+ !page->throttled)
+ vm_page_deactivate(page);
vm_page_unlock_queues();
}
+ PAGE_WAKEUP_DONE(page);
break;
case VM_FAULT_RETRY:
prot = VM_PROT_WRITE|VM_PROT_READ;
vm_object_lock(copy_object);
vm_object_paging_begin(copy_object);
goto RETRY_COW_OF_LOCK_REQUEST;
+ case VM_FAULT_SUCCESS_NO_VM_PAGE:
+ /* success but no VM page: fail */
+ vm_object_paging_end(copy_object);
+ vm_object_unlock(copy_object);
+ /*FALLTHROUGH*/
case VM_FAULT_MEMORY_ERROR:
+ if (object != copy_object)
+ vm_object_deallocate(copy_object);
vm_object_lock(object);
goto BYPASS_COW_COPYIN;
+ default:
+ panic("vm_object_update: unexpected error 0x%x"
+ " from vm_fault_page()\n", result);
}
}
vm_object_paging_end(copy_object);
- if(copy_object != object) {
+ }
+ if ((flags & (MEMORY_OBJECT_DATA_SYNC | MEMORY_OBJECT_COPY_SYNC))) {
+ if (copy_object != VM_OBJECT_NULL && copy_object != object) {
vm_object_unlock(copy_object);
+ vm_object_deallocate(copy_object);
vm_object_lock(object);
}
+ return KERN_SUCCESS;
}
- if((flags & (MEMORY_OBJECT_DATA_SYNC | MEMORY_OBJECT_COPY_SYNC))) {
- return KERN_SUCCESS;
- }
- if(((copy_object = object->copy) != NULL) &&
- (flags & MEMORY_OBJECT_DATA_PURGE)) {
- copy_object->shadow_severed = TRUE;
- copy_object->shadowed = FALSE;
- copy_object->shadow = NULL;
- /* delete the ref the COW was holding on the target object */
- vm_object_deallocate(object);
+ if (copy_object != VM_OBJECT_NULL && copy_object != object) {
+ if ((flags & MEMORY_OBJECT_DATA_PURGE)) {
+ copy_object->shadow_severed = TRUE;
+ copy_object->shadowed = FALSE;
+ copy_object->shadow = NULL;
+ /*
+ * delete the ref the COW was holding on the target object
+ */
+ vm_object_deallocate(object);
+ }
+ vm_object_unlock(copy_object);
+ vm_object_deallocate(copy_object);
+ vm_object_lock(object);
}
BYPASS_COW_COPYIN:
memory_object_synchronize_completed(
memory_object_control_t control,
memory_object_offset_t offset,
- vm_offset_t length)
+ memory_object_size_t length)
{
vm_object_t object;
msync_req_t msr;
XPR(XPR_MEMORY_OBJECT,
"m_o_sync_completed, object 0x%X, offset 0x%X length 0x%X\n",
- (integer_t)object, offset, length, 0, 0);
+ object, offset, length, 0, 0);
/*
* Look for bogus arguments
boolean_t may_cache,
memory_object_copy_strategy_t copy_strategy,
boolean_t temporary,
- memory_object_cluster_size_t cluster_size,
boolean_t silent_overwrite,
boolean_t advisory_pageout)
{
XPR(XPR_MEMORY_OBJECT,
"m_o_set_attr_com, object 0x%X flg %x strat %d\n",
- (integer_t)object, (may_cache&1)|((temporary&1)<1), copy_strategy, 0, 0);
+ object, (may_cache&1)|((temporary&1)<1), copy_strategy, 0, 0);
if (object == VM_OBJECT_NULL)
return(KERN_INVALID_ARGUMENT);
may_cache = TRUE;
if (temporary)
temporary = TRUE;
- if (cluster_size != 0) {
- int pages_per_cluster;
- pages_per_cluster = atop_32(cluster_size);
- /*
- * Cluster size must be integral multiple of page size,
- * and be a power of 2 number of pages.
- */
- if ((cluster_size & (PAGE_SIZE-1)) ||
- ((pages_per_cluster-1) & pages_per_cluster))
- return KERN_INVALID_ARGUMENT;
- }
vm_object_lock(object);
object->temporary = temporary;
object->silent_overwrite = silent_overwrite;
object->advisory_pageout = advisory_pageout;
- if (cluster_size == 0)
- cluster_size = PAGE_SIZE;
- object->cluster_size = cluster_size;
-
- assert(cluster_size >= PAGE_SIZE &&
- cluster_size % PAGE_SIZE == 0);
/*
* Wake up anyone waiting for the ready attribute
boolean_t temporary;
boolean_t may_cache;
boolean_t invalidate;
- memory_object_cluster_size_t cluster_size;
memory_object_copy_strategy_t copy_strategy;
boolean_t silent_overwrite;
boolean_t advisory_pageout;
#if notyet
invalidate = object->invalidate;
#endif
- cluster_size = object->cluster_size;
vm_object_unlock(object);
switch (flavor) {
perf = (memory_object_perf_info_t) attributes;
may_cache = perf->may_cache;
- cluster_size = round_page_32(perf->cluster_size);
break;
}
may_cache = attr->may_cache;
copy_strategy = attr->copy_strategy;
- cluster_size = page_size;
break;
}
copy_strategy = attr->copy_strategy;
may_cache = attr->may_cache_object;
- cluster_size = attr->cluster_size;
temporary = attr->temporary;
break;
may_cache,
copy_strategy,
temporary,
- cluster_size,
silent_overwrite,
advisory_pageout));
}
}
perf = (memory_object_perf_info_t) attributes;
- perf->cluster_size = object->cluster_size;
+ perf->cluster_size = PAGE_SIZE;
perf->may_cache = object->can_persist;
*count = MEMORY_OBJECT_PERF_INFO_COUNT;
attr = (memory_object_attr_info_t) attributes;
attr->copy_strategy = object->copy_strategy;
- attr->cluster_size = object->cluster_size;
+ attr->cluster_size = PAGE_SIZE;
attr->may_cache_object = object->can_persist;
attr->temporary = object->temporary;
if(*upl_size == 0) {
if(offset >= named_entry->size)
return(KERN_INVALID_RIGHT);
- *upl_size = named_entry->size - offset;
+ *upl_size = (upl_size_t)(named_entry->size - offset);
+ if (*upl_size != named_entry->size - offset)
+ return KERN_INVALID_ARGUMENT;
}
if(caller_flags & UPL_COPYOUT_FROM) {
if((named_entry->protection & VM_PROT_READ)
object = memory_object_control_to_vm_object(control);
if (object == VM_OBJECT_NULL)
- return (KERN_INVALID_ARGUMENT);
+ return (KERN_TERMINATED);
return vm_object_upl_request(object,
offset,
cntrl_flags);
}
+kern_return_t
+memory_object_cluster_size(memory_object_control_t control, memory_object_offset_t *start,
+ vm_size_t *length, uint32_t *io_streaming, memory_object_fault_info_t fault_info)
+{
+ vm_object_t object;
+
+ object = memory_object_control_to_vm_object(control);
+
+ if (object == VM_OBJECT_NULL || object->paging_offset > *start)
+ return (KERN_INVALID_ARGUMENT);
+
+ *start -= object->paging_offset;
+
+ vm_object_cluster_size(object, (vm_object_offset_t *)start, length, (vm_object_fault_info_t)fault_info, io_streaming);
+
+ *start += object->paging_offset;
+
+ return (KERN_SUCCESS);
+}
+
+
int vm_stat_discard_cleared_reply = 0;
int vm_stat_discard_cleared_unset = 0;
int vm_stat_discard_cleared_too_late = 0;
host_default_memory_manager(
host_priv_t host_priv,
memory_object_default_t *default_manager,
- memory_object_cluster_size_t cluster_size)
+ __unused memory_object_cluster_size_t cluster_size)
{
memory_object_default_t current_manager;
memory_object_default_t new_manager;
memory_object_default_t returned_manager;
+ kern_return_t result = KERN_SUCCESS;
if (host_priv == HOST_PRIV_NULL)
return(KERN_INVALID_HOST);
assert(host_priv == &realhost);
new_manager = *default_manager;
- mutex_lock(&memory_manager_default_lock);
+ lck_mtx_lock(&memory_manager_default_lock);
current_manager = memory_manager_default;
+ returned_manager = MEMORY_OBJECT_DEFAULT_NULL;
if (new_manager == MEMORY_OBJECT_DEFAULT_NULL) {
/*
* Retrieve the current value.
*/
- memory_object_default_reference(current_manager);
returned_manager = current_manager;
+ memory_object_default_reference(returned_manager);
} else {
+
+ /*
+ * If this is the first non-null manager, start
+ * up the internal pager support.
+ */
+ if (current_manager == MEMORY_OBJECT_DEFAULT_NULL) {
+ result = vm_pageout_internal_start();
+ if (result != KERN_SUCCESS)
+ goto out;
+ }
+
/*
* Retrieve the current value,
* and replace it with the supplied value.
* but we have to take a reference on the new
* one.
*/
-
returned_manager = current_manager;
memory_manager_default = new_manager;
memory_object_default_reference(new_manager);
- if (cluster_size % PAGE_SIZE != 0) {
-#if 0
- mutex_unlock(&memory_manager_default_lock);
- return KERN_INVALID_ARGUMENT;
-#else
- cluster_size = round_page_32(cluster_size);
-#endif
- }
- memory_manager_default_cluster = cluster_size;
-
/*
* In case anyone's been waiting for a memory
* manager to be established, wake them up.
*/
thread_wakeup((event_t) &memory_manager_default);
- }
- mutex_unlock(&memory_manager_default_lock);
+ /*
+ * Now that we have a default pager for anonymous memory,
+ * reactivate all the throttled pages (i.e. dirty pages with
+ * no pager).
+ */
+ if (current_manager == MEMORY_OBJECT_DEFAULT_NULL) {
+ vm_page_reactivate_all_throttled();
+ }
+ }
+ out:
+ lck_mtx_unlock(&memory_manager_default_lock);
*default_manager = returned_manager;
- return(KERN_SUCCESS);
+ return(result);
}
/*
*/
__private_extern__ memory_object_default_t
-memory_manager_default_reference(
- memory_object_cluster_size_t *cluster_size)
+memory_manager_default_reference(void)
{
memory_object_default_t current_manager;
- mutex_lock(&memory_manager_default_lock);
+ lck_mtx_lock(&memory_manager_default_lock);
current_manager = memory_manager_default;
while (current_manager == MEMORY_OBJECT_DEFAULT_NULL) {
wait_result_t res;
- res = thread_sleep_mutex((event_t) &memory_manager_default,
- &memory_manager_default_lock,
- THREAD_UNINT);
+ res = lck_mtx_sleep(&memory_manager_default_lock,
+ LCK_SLEEP_DEFAULT,
+ (event_t) &memory_manager_default,
+ THREAD_UNINT);
assert(res == THREAD_AWAKENED);
current_manager = memory_manager_default;
}
memory_object_default_reference(current_manager);
- *cluster_size = memory_manager_default_cluster;
- mutex_unlock(&memory_manager_default_lock);
+ lck_mtx_unlock(&memory_manager_default_lock);
return current_manager;
}
{
memory_object_default_t current;
- mutex_lock(&memory_manager_default_lock);
+ lck_mtx_lock(&memory_manager_default_lock);
current = memory_manager_default;
if (current == MEMORY_OBJECT_DEFAULT_NULL) {
static boolean_t logged; /* initialized to 0 */
boolean_t complain = !logged;
logged = TRUE;
- mutex_unlock(&memory_manager_default_lock);
+ lck_mtx_unlock(&memory_manager_default_lock);
if (complain)
printf("Warning: No default memory manager\n");
return(KERN_FAILURE);
} else {
- mutex_unlock(&memory_manager_default_lock);
+ lck_mtx_unlock(&memory_manager_default_lock);
return(KERN_SUCCESS);
}
}
memory_manager_default_init(void)
{
memory_manager_default = MEMORY_OBJECT_DEFAULT_NULL;
- mutex_init(&memory_manager_default_lock, 0);
+ lck_mtx_init(&memory_manager_default_lock, &vm_object_lck_grp, &vm_object_lck_attr);
}
offset_beg,
offset_end,
ops,
- range);
+ (uint32_t *) range);
}
return (KERN_SUCCESS);
}
+kern_return_t
+memory_object_signed(
+ memory_object_control_t control,
+ boolean_t is_signed)
+{
+ vm_object_t object;
+
+ object = memory_object_control_to_vm_object(control);
+ if (object == VM_OBJECT_NULL)
+ return KERN_INVALID_ARGUMENT;
+
+ vm_object_lock(object);
+ object->code_signed = is_signed;
+ vm_object_unlock(object);
+
+ return KERN_SUCCESS;
+}
static zone_t mem_obj_control_zone;
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_NOENCRYPT, TRUE);
return;
}
memory_object_t memory_object,
memory_object_offset_t offset,
memory_object_cluster_size_t length,
- vm_prot_t desired_access
+ vm_prot_t desired_access,
+ memory_object_fault_info_t fault_info
)
{
return (memory_object->mo_pager_ops->memory_object_data_request)(
memory_object,
offset,
length,
- desired_access);
+ desired_access,
+ fault_info);
}
/* Routine memory_object_data_return */
(
memory_object_t memory_object,
memory_object_offset_t offset,
- vm_size_t size,
+ memory_object_cluster_size_t size,
memory_object_offset_t *resid_offset,
int *io_error,
boolean_t dirty,
(
memory_object_t memory_object,
memory_object_offset_t offset,
- vm_size_t size
+ memory_object_cluster_size_t size
)
{
return (memory_object->mo_pager_ops->memory_object_data_initialize)(
(
memory_object_t memory_object,
memory_object_offset_t offset,
- vm_size_t size,
+ memory_object_size_t size,
vm_prot_t desired_access
)
{
(
memory_object_t memory_object,
memory_object_offset_t offset,
- vm_size_t size,
+ memory_object_size_t size,
vm_sync_t sync_flags
)
{
sync_flags);
}
-/* Routine memory_object_unmap */
-kern_return_t memory_object_unmap
+
+/*
+ * 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
+ * by the pager to keep it alive until the pager decides that the
+ * 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.
+ *
+ * For a given VM object, calls to memory_object_map() and memory_object_unmap()
+ * are serialized (through object->mapping_in_progress), to ensure that the
+ * pager gets a consistent view of the mapping status of the memory object.
+ *
+ * This allows the pager to keep track of how many times a memory object
+ * has been mapped and with which protections, to decide when it can be
+ * reclaimed.
+ */
+
+/* Routine memory_object_map */
+kern_return_t memory_object_map
+(
+ memory_object_t memory_object,
+ vm_prot_t prot
+)
+{
+ return (memory_object->mo_pager_ops->memory_object_map)(
+ memory_object,
+ prot);
+}
+
+/* Routine memory_object_last_unmap */
+kern_return_t memory_object_last_unmap
(
memory_object_t memory_object
)
{
- return (memory_object->mo_pager_ops->memory_object_unmap)(
+ return (memory_object->mo_pager_ops->memory_object_last_unmap)(
memory_object);
}