simple: swap policy
authorAlan Cox <alan@linux.intel.com>
Thu, 19 Feb 2015 23:05:07 +0000 (23:05 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 19 Feb 2015 23:05:07 +0000 (23:05 +0000)
Nice and easy, no common memory magic, no splitting buffers, it's either
mapped or its swapped

Kernel/simple.c

index 7a95718..915c301 100644 (file)
@@ -50,4 +50,69 @@ void pagemap_init(void)
 {
 }
 
+/*
+ *     Swap out the memory of a process to make room
+ *     for something else
+ */
+int swapout(ptptr p)
+{
+       uint16_t page = p->p_page;
+       uint16_t blk;
+       uint16_t map;
+
+       swapproc = p;
+
+       if (page) {
+#ifdef DEBUG
+               kprintf("Swapping out %x (%d)\n", p, p->p_page);
+#endif
+               /* Are we out of swap ? */
+               map = swapmap_alloc();
+               if (map == 0)
+                       return ENOMEM;
+                flush_cache(p);
+               blk = map * SWAP_SIZE;
+               /* Write the app (and possibly the uarea etc..) to disk */
+               swapwrite(SWAPDEV, blk, SWAPTOP - SWAPBASE,
+                         SWAPBASE);
+               p->p_page = 0;
+               p->p_page2 = map;
+#ifdef DEBUG
+               kprintf("%x: swapout done %d\n", p, p->p_page);
 #endif
+       }
+#ifdef DEBUG
+       else
+               kprintf("%x: process already swapped!\n", p);
+#endif
+       return 0;
+}
+
+/*
+ * Swap ourself in: must be on the swap stack when we do this
+ */
+void swapin(ptptr p)
+{
+       uint16_t blk = p->p_page2 * SWAP_SIZE;
+
+#ifdef DEBUG
+       kprintf("Swapin %x, %d\n", p, p->p_page);
+#endif
+       if (!p->p_page) {
+               kprintf("%x: nopage!\n", p);
+               return;
+       }
+
+       /* Return our swap */
+       swapmap_add(p->p_page2);
+
+       swapproc = p;           /* always ourself */
+       swapread(SWAPDEV, blk, SWAPTOP - SWAPBASE,
+                SWAPBASE);
+#ifdef DEBUG
+       kprintf("%x: swapin done %d\n", p, p->p_page);
+#endif
+}
+
+#endif
+