From 635d7d45ff063ac2201db6c3086cba8346921ce7 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 28 Sep 2017 21:43:37 +0100 Subject: [PATCH] swap: add reporting of swap space free/available --- Kernel/platform-coco2/discard.c | 2 +- Kernel/platform-coco2cart/discard.c | 2 +- Kernel/platform-coco3/main.c | 2 +- Kernel/platform-dragon-nx32/discard.c | 2 +- Kernel/platform-micropack/devices.c | 2 +- Kernel/platform-msp430fr5969/main_discard.c | 2 +- Kernel/platform-mtx/devices.c | 2 +- Kernel/platform-pdp11/devices.c | 2 +- Kernel/platform-px4plus/init.c | 2 +- Kernel/platform-trs80/devhd_discard.c | 2 +- Kernel/platform-ubee/devices.c | 2 +- Kernel/platform-v68-banked/devices.c | 2 +- Kernel/platform-v68/devices.c | 2 +- Kernel/platform-z80pack/devices.c | 2 +- Kernel/platform-z80pack32/devices.c | 2 +- Kernel/platform-zx128/main.c | 6 ++--- Kernel/swap.c | 25 +++++++++++++++++---- 17 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Kernel/platform-coco2/discard.c b/Kernel/platform-coco2/discard.c index 17917697..3dba3ac9 100644 --- a/Kernel/platform-coco2/discard.c +++ b/Kernel/platform-coco2/discard.c @@ -69,5 +69,5 @@ void map_init(void) /* We put swap on the start of slice 0, but with the first 64K free so we can keep the OS image linearly there */ for (i = 0; i < MAX_SWAPS; i++) - swapmap_add(i + 128); + swapmap_init(i + 128); } diff --git a/Kernel/platform-coco2cart/discard.c b/Kernel/platform-coco2cart/discard.c index de6fbfcd..1a2b3528 100644 --- a/Kernel/platform-coco2cart/discard.c +++ b/Kernel/platform-coco2cart/discard.c @@ -77,5 +77,5 @@ void map_init(void) /* We put swap on the start of slice 0, but with the first 64K free so we can keep the OS image linearly there */ for (i = 0; i < MAX_SWAPS; i++) - swapmap_add(i + 128); + swapmap_init(i + 128); } diff --git a/Kernel/platform-coco3/main.c b/Kernel/platform-coco3/main.c index 3ad64d63..9ea67ac9 100644 --- a/Kernel/platform-coco3/main.c +++ b/Kernel/platform-coco3/main.c @@ -79,7 +79,7 @@ void pagemap_init(void) pagemap_add(6); /* initialize swap pages */ for (i = 0; i= MAX_SWAPS) cyls = MAX_SWAPS - 1; for (i = 0; i < cyls; i++) { - swapmap_add(i); + swapmap_init(i); } kputs("swap-"); } diff --git a/Kernel/platform-ubee/devices.c b/Kernel/platform-ubee/devices.c index 50f30698..7eb72f73 100644 --- a/Kernel/platform-ubee/devices.c +++ b/Kernel/platform-ubee/devices.c @@ -40,5 +40,5 @@ void device_init(void) inittod(); /* Add 64 swaps (2MB) */ for (i = MAX_SWAPS - 1 ; i >= 0; i--) - swapmap_add(i); + swapmap_init(i); } diff --git a/Kernel/platform-v68-banked/devices.c b/Kernel/platform-v68-banked/devices.c index 623668c7..46ccf83d 100644 --- a/Kernel/platform-v68-banked/devices.c +++ b/Kernel/platform-v68-banked/devices.c @@ -41,5 +41,5 @@ void device_init(void) devide_init(); for (i = 1; i <= MAX_SWAPS; i++) - swapmap_add(i); + swapmap_init(i); } diff --git a/Kernel/platform-v68/devices.c b/Kernel/platform-v68/devices.c index 623668c7..46ccf83d 100644 --- a/Kernel/platform-v68/devices.c +++ b/Kernel/platform-v68/devices.c @@ -41,5 +41,5 @@ void device_init(void) devide_init(); for (i = 1; i <= MAX_SWAPS; i++) - swapmap_add(i); + swapmap_init(i); } diff --git a/Kernel/platform-z80pack/devices.c b/Kernel/platform-z80pack/devices.c index 9d3c0ed6..8301c232 100644 --- a/Kernel/platform-z80pack/devices.c +++ b/Kernel/platform-z80pack/devices.c @@ -42,6 +42,6 @@ void device_init(void) zrtc_init(); /* Add 64 swaps (4MB) to use the entire J drive */ for (i = 0; i < MAX_SWAPS; i++) - swapmap_add(i); + swapmap_init(i); sock_init(); } diff --git a/Kernel/platform-z80pack32/devices.c b/Kernel/platform-z80pack32/devices.c index 31151c65..87d36c8f 100644 --- a/Kernel/platform-z80pack32/devices.c +++ b/Kernel/platform-z80pack32/devices.c @@ -39,5 +39,5 @@ void device_init(void) int i; /* Add 64 swaps (4MB) to use the entire J drive */ for (i = 0; i < MAX_SWAPS; i++) - swapmap_add(i); + swapmap_init(i); } diff --git a/Kernel/platform-zx128/main.c b/Kernel/platform-zx128/main.c index 41d6f390..9903ee4d 100644 --- a/Kernel/platform-zx128/main.c +++ b/Kernel/platform-zx128/main.c @@ -11,9 +11,9 @@ void pagemap_init(void) { #ifdef SWAPDEV /* Swap */ - swapmap_add(0); - swapmap_add(1); - swapmap_add(2); + swapmap_init(0); + swapmap_init(1); + swapmap_init(2); #endif } diff --git a/Kernel/swap.c b/Kernel/swap.c index ef619358..10040f45 100644 --- a/Kernel/swap.c +++ b/Kernel/swap.c @@ -1,6 +1,10 @@ /* - * Very simplistic for now disk swap logic. As we have a fixed - * process size at this point we use a fixed swap size too + * For small machines it's cheaper to simply allocate banks in the size + * needed for the largest swapout of the application as that'll be under + * 64K. For split I/D we can allocate pairs of swap banks. + * + * It's possible to be a lot smarter about this and for 32bit systems + * it becomes a necessity not to use this simple swap logic. */ #include @@ -18,21 +22,34 @@ uint16_t swappage; /* Target page */ static uint8_t swapmap[MAX_SWAPS]; static uint8_t swapptr = 0; +static const char maxswap[] = PANIC_MAXSWAP; + void swapmap_add(uint8_t swap) { if (swapptr == MAX_SWAPS) - panic(PANIC_MAXSWAP); + panic(maxswap); swapmap[swapptr++] = swap; + sysinfo.swapusedk += SWAP_SIZE / 2; } int swapmap_alloc(void) { - if (swapptr) + if (swapptr) { + sysinfo.swapusedk -= SWAP_SIZE / 2; return swapmap[--swapptr]; + } else return 0; } +void swapmap_init(uint8_t swap) +{ + if (swapptr == MAX_SWAPS) + panic(maxswap); + swapmap[swapptr++] = swap; + sysinfo.swapk += SWAP_SIZE / 2; +} + /* We can re-use udata.u_block and friends as we can never be swapped while we are in the middle of an I/O (at least for now). If we rework the kernel for sleepable I/O this will change */ -- 2.34.1