From: Alan Cox Date: Thu, 19 Feb 2015 23:05:07 +0000 (+0000) Subject: simple: swap policy X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=14eee5046ca6d3f53a54a5573d6707f80eaa62dc;p=FUZIX.git simple: swap policy Nice and easy, no common memory magic, no splitting buffers, it's either mapped or its swapped --- diff --git a/Kernel/simple.c b/Kernel/simple.c index 7a957186..915c301b 100644 --- a/Kernel/simple.c +++ b/Kernel/simple.c @@ -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 +