]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/vm/dp_backing_file.c
xnu-2050.48.11.tar.gz
[apple/xnu.git] / bsd / vm / dp_backing_file.c
index 0f72ed2f114763282d46cf068efc150ea32153d5..9df1b810effdd830ec465bda7c6dcfb67a778a8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <sys/namei.h>
 #include <sys/ubc_internal.h>
 #include <sys/malloc.h>
+#include <sys/user.h>
+#if CONFIG_PROTECT
+#include <sys/cprotect.h>
+#endif
 
 #include <default_pager/default_pager_types.h>
 #include <default_pager/default_pager_object.h>
@@ -205,6 +209,9 @@ macx_triggers(
        return mach_macx_triggers(args);
 }
 
+
+extern boolean_t dp_isssd;
+
 /*
  *     Routine:        macx_swapon
  *     Function:
@@ -226,6 +233,8 @@ macx_swapon(
        off_t                   file_size;
        vfs_context_t           ctx = vfs_context_current();
        struct proc             *p =  current_proc();
+       int                     dp_cluster_size;
+
 
        AUDIT_MACH_SYSCALL_ENTER(AUE_SWAPON);
        AUDIT_ARG(value32, args->priority);
@@ -236,15 +245,10 @@ macx_swapon(
        if ((error = suser(kauth_cred_get(), 0)))
                goto swapon_bailout;
 
-       if(default_pager_init_flag == 0) {
-               start_def_pager(NULL);
-               default_pager_init_flag = 1;
-       }
-
        /*
         * Get a vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
+       NDINIT(ndp, LOOKUP, OP_LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
               ((IS_64BIT_PROCESS(p)) ? UIO_USERSPACE64 : UIO_USERSPACE32),
               (user_addr_t) args->filename, ctx);
 
@@ -273,6 +277,21 @@ macx_swapon(
        if ((file_size < (off_t)size) && ((error = vnode_setsize(vp, (off_t)size, 0, ctx)) != 0))
                goto swapon_bailout;
 
+#if CONFIG_PROTECT
+       {
+               /* initialize content protection keys manually */
+               if ((error = cp_handle_vnop(vp, CP_WRITE_ACCESS, 0)) != 0) {
+                       goto swapon_bailout;
+               }
+       }
+#endif
+
+
+       if (default_pager_init_flag == 0) {
+               start_def_pager(NULL);
+               default_pager_init_flag = 1;
+       }
+
        /* add new backing store to list */
        i = 0;
        while(bs_port_table[i].vp != 0) {
@@ -300,9 +319,26 @@ macx_swapon(
           goto swapon_bailout;
        }
 
+#if CONFIG_EMBEDDED
+       dp_cluster_size = 1 * PAGE_SIZE;
+#else
+       if ((dp_isssd = vnode_pager_isSSD(vp)) == TRUE) {
+               /*
+                * keep the cluster size small since the
+                * seek cost is effectively 0 which means
+                * we don't care much about fragmentation
+                */
+               dp_cluster_size = 2 * PAGE_SIZE;
+       } else {
+               /*
+                * use the default cluster size
+                */
+               dp_cluster_size = 0;
+       }
+#endif
        kr = default_pager_backing_store_create(default_pager, 
                                        -1, /* default priority */
-                                       0, /* default cluster size */
+                                       dp_cluster_size,
                                        &backing_store);
        memory_object_default_deallocate(default_pager);
 
@@ -358,6 +394,12 @@ swapon_bailout:
        }
        (void) thread_funnel_set(kernel_flock, FALSE);
        AUDIT_MACH_SYSCALL_EXIT(error);
+
+       if (error)
+               printf("macx_swapon FAILED - %d\n", error);
+       else
+               printf("macx_swapon SUCCESS\n");
+
        return(error);
 }
 
@@ -381,6 +423,8 @@ macx_swapoff(
        int                     error;
        boolean_t               funnel_state;
        vfs_context_t ctx = vfs_context_current();
+       struct uthread  *ut;
+       int                     orig_iopol_disk;
 
        AUDIT_MACH_SYSCALL_ENTER(AUE_SWAPOFF);
 
@@ -394,7 +438,7 @@ macx_swapoff(
        /*
         * Get the vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
+       NDINIT(ndp, LOOKUP, OP_LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
               ((IS_64BIT_PROCESS(p)) ? UIO_USERSPACE64 : UIO_USERSPACE32),
               (user_addr_t) args->filename, ctx);
 
@@ -426,7 +470,15 @@ macx_swapoff(
        }
        backing_store = (mach_port_t)bs_port_table[i].bs;
 
+       ut = get_bsdthread_info(current_thread());
+
+       orig_iopol_disk = proc_get_thread_selfdiskacc();
+       proc_apply_thread_selfdiskacc(IOPOL_THROTTLE);
+
        kr = default_pager_backing_store_delete(backing_store);
+
+       proc_apply_thread_selfdiskacc(orig_iopol_disk);
+
        switch (kr) {
                case KERN_SUCCESS:
                        error = 0;
@@ -455,6 +507,12 @@ swapoff_bailout:
 
        (void) thread_funnel_set(kernel_flock, FALSE);
        AUDIT_MACH_SYSCALL_EXIT(error);
+
+       if (error)
+               printf("macx_swapoff FAILED - %d\n", error);
+       else
+               printf("macx_swapoff SUCCESS\n");
+
        return(error);
 }