+extern boolean_t backing_store_stop_compaction;
+extern boolean_t compressor_store_stop_compaction;
+
+/*
+ * Routine: macx_backing_store_compaction
+ * Function:
+ * Turn compaction of swap space on or off. This is
+ * used during shutdown/restart so that the kernel
+ * doesn't waste time compacting swap files that are
+ * about to be deleted anyway. Compaction is always
+ * on by default when the system comes up and is turned
+ * off when a shutdown/restart is requested. It is
+ * re-enabled if the shutdown/restart is aborted for any reason.
+ *
+ * This routine assumes macx_lock has been locked by macx_triggers ->
+ * mach_macx_triggers -> macx_backing_store_compaction
+ */
+
+int
+macx_backing_store_compaction(int flags)
+{
+ int error;
+
+ lck_mtx_assert(macx_lock, LCK_MTX_ASSERT_OWNED);
+ if ((error = suser(kauth_cred_get(), 0)))
+ return error;
+
+ if (flags & SWAP_COMPACT_DISABLE) {
+ backing_store_stop_compaction = TRUE;
+ compressor_store_stop_compaction = TRUE;
+
+ kprintf("backing_store_stop_compaction = TRUE\n");
+
+ } else if (flags & SWAP_COMPACT_ENABLE) {
+ backing_store_stop_compaction = FALSE;
+ compressor_store_stop_compaction = FALSE;
+
+ kprintf("backing_store_stop_compaction = FALSE\n");
+ }
+
+ return 0;
+}
+
+/*
+ * Routine: macx_triggers
+ * Function:
+ * Syscall interface to set the call backs for low and
+ * high water marks.
+ */
+int
+macx_triggers(
+ struct macx_triggers_args *args)
+{
+ int error;
+
+ lck_mtx_lock(macx_lock);
+ error = suser(kauth_cred_get(), 0);
+ if (error)
+ return error;
+
+ error = mach_macx_triggers(args);
+
+ lck_mtx_unlock(macx_lock);
+ return error;
+}
+
+
+extern boolean_t dp_isssd;
+
+/*
+ * In the compressed pager world, the swapfiles are created by the kernel.
+ * Well, all except the first one. That swapfile is absorbed by the kernel at
+ * the end of the macx_swapon function (if swap is enabled). That's why
+ * we allow the first invocation of macx_swapon to succeed.
+ *
+ * If the compressor pool is running low, the kernel messages the dynamic pager
+ * on the port it has registered with the kernel. That port can transport 1 of 2
+ * pieces of information to dynamic pager: create a swapfile or delete a swapfile.
+ *
+ * We choose to transmit the former. So, that message tells dynamic pager
+ * to create a swapfile and activate it by calling macx_swapon.
+ *
+ * We deny this new macx_swapon request. That leads dynamic pager to interpret the
+ * failure as a serious error and notify all it's clients that swap is running low.
+ * That's how we get the loginwindow "Resume / Force Quit Applications" dialog to appear.
+ *
+ * NOTE:
+ * If the kernel has already created multiple swapfiles by the time the compressor
+ * pool is running low (and it has to play this trick), dynamic pager won't be able to
+ * create a file in user-space and, that too will lead to a similar notification blast
+ * to all of it's clients. So, that behaves as desired too.
+ */
+boolean_t macx_swapon_allowed = TRUE;
+