#endif
#ifdef INDIRECT_CORE
-void core_init(int table_size, int table_spare, int n_blocks)
+void core_init(int table_size, int n_blocks)
#else
-void core_init(int table_size, int table_spare)
+void core_init(int table_size)
#endif
{
pool_init(
&core_table,
0,
table_size,
- table_spare,
core_move,
#ifdef MOVEABLE_CORE
core_move_up
#include <stdint.h>
#include "pool.h"
-#define INDIRECT_CORE 1
-//#define MOVEABLE_CORE 1
+//#define INDIRECT_CORE 1
+#define MOVEABLE_CORE 1
#ifdef MOVEABLE_CORE
#define core_table_alloc(item, size) \
extern int *core_block_mem;
#ifdef INDIRECT_CORE
-void core_init(int n_table, int table_spare, int n_blocks);
+void core_init(int n_table, int n_blocks);
bool core_block_alloc(int *blocks, int size);
void core_block_free(int *blocks, int size);
#else
-void core_init(int n_table, int table_spare);
+void core_init(int n_table);
#endif
#endif
#!/bin/sh
echo "generate test script"
-./pool_test_gen 64 240 256 16 >pool_test.txt
+./pool_test_gen 64 256 1024 16 >pool_test.txt
echo "run test script, non-moveable"
-./pool_test_run 64 256 16 <pool_test.txt
+./pool_test_run 64 256 <pool_test.txt
echo "run test script, moveable"
-./pool_test_run 64 256 16 1 <pool_test.txt
+./pool_test_run 64 256 1 <pool_test.txt
echo "generate test script"
# preallocated core, possible preallocated swap (not indirect):
-#./process_test_gen 16 48 65536 32 >process_test.txt
+#./process_test_gen 16 48 1024 32 >process_test.txt
# non preallocated core, preallocated swap (not indirect):
-#./process_test_gen 16 176 65536 32 >process_test.txt
+#./process_test_gen 16 176 1024 32 >process_test.txt
# non preallocated core, non preallocated swap (or indirect swap):
-./process_test_gen 16 240 65536 32 >process_test.txt
+./process_test_gen 16 240 1024 32 >process_test.txt
echo "run test script"
# moveable swap (useable with any configuration):
-#./process_test_run 16 64 0 192 0 16 <process_test.txt
+./process_test_run 16 64 192 16 <process_test.txt
# non moveable swap (must be preallocated, may be indirect):
-#./process_test_run 16 64 0 384 0 16 192 <process_test.txt
+#./process_test_run 16 64 384 16 192 <process_test.txt
# non moveable core and swap (must be preallocated, may be indirect):
-./process_test_run 16 384 0 384 0 16 64 192 <process_test.txt
+#./process_test_run 16 384 384 16 64 192 <process_test.txt
int avail;
struct pool_item *p;
- avail = head->item.base - head->item.limit - head->spare;
+ avail = head->item.base - head->item.limit;
for (p = head->item.next; p != &head->item; p = p->next) {
assert(p->prev->next == p && p->next->prev == p);
assert(p->base >= p->prev->limit && p->limit <= p->next->base);
struct pool_head *head,
int base,
int limit,
- int spare,
void (*move)(struct pool_item *item, int new_base),
void (*move_up)(struct pool_item *item, int new_limit)
) {
head->item.next = &head->item;
head->item.base = limit; // note: swapped
head->item.limit = base; // note: swapped
- head->avail = limit - base - spare;
- head->spare = spare;
+ head->avail = limit - base;
head->move = move;
head->move_up = move_up;
check_invariants(head);
avail = head->avail - size;
if (avail < 0)
return false;
- avail += head->spare;
// first-fit algorithm
q = &head->item;
avail = head->avail - size_change;
if (avail < 0)
return false;
- avail += head->spare;
// first-fit algorithm, until our own list entry
q = &head->item;
avail = head->avail - size;
if (avail < 0)
return false;
- avail += head->spare;
// first-fit algorithm
q = &head->item;
avail = head->avail - size_change;
if (avail < 0)
return false;
- avail += head->spare;
// first-fit algorithm, until our own list entry
q = &head->item;
struct pool_head {
struct pool_item item;
int avail;
- int spare;
void (*move)(struct pool_item *item, int new_base);
void (*move_up)(struct pool_item *item, int new_limit);
};
struct pool_head *head,
int base,
int limit,
- int spare,
void (*move)(struct pool_item *item, int new_base),
void (*move_up)(struct pool_item *item, int new_limit)
);
}
int main(int argc, char **argv) {
- if (argc < 4) {
- printf("usage: %s n_items pool_size spare [moveable]\n", argv[0]);
+ if (argc < 3) {
+ printf("usage: %s n_items pool_size [moveable]\n", argv[0]);
exit(EXIT_FAILURE);
}
int n_items = atoi(argv[1]);
int pool_size = atoi(argv[2]);
- int spare = atoi(argv[3]);
- bool moveable = argc >= 5 ? (bool)atoi(argv[4]) : false;
+ bool moveable = argc >= 4 ? (bool)atoi(argv[3]) : false;
struct pool_head head;
- pool_init(&head, 0, pool_size, spare, move, move_up);
+ pool_init(&head, 0, pool_size, move, move_up);
struct pool_item *items = malloc(n_items * sizeof(struct pool_item));
rassert(items);
n_core_blocks +
#else
core_table.item.base -
- core_table.item.limit -
- core_table.spare +
+ core_table.item.limit +
#endif
#ifdef INDIRECT_SWAP
n_swap_blocks -
#else
swap_table.item.base -
swap_table.item.limit -
- swap_table.spare -
#endif
process_spare;
#if defined(PREALLOCATE_CORE)
- if (
- avail >
- core_table.item.base -
- core_table.item.limit -
- core_table.spare
- )
- avail =
- core_table.item.base -
- core_table.item.limit -
- core_table.spare;
+ if (avail > core_table.item.base - core_table.item.limit)
+ avail = core_table.item.base - core_table.item.limit;
#endif
#if defined(PREALLOCATE_SWAP)
- if (
- avail >
- swap_table.item.base -
- swap_table.item.limit -
- swap_table.spare
- )
- avail =
- swap_table.item.base -
- swap_table.item.limit -
- swap_table.spare;
+ if (avail > swap_table.item.base - swap_table.item.limit)
+ avail = swap_table.item.base - swap_table.item.limit;
#endif
if (victim == NULL) {
#ifdef PREALLOCATE_CORE
#include "pool.h"
-#define PREALLOCATE_CORE 1
-#define PREALLOCATE_SWAP 1
+//#define PREALLOCATE_CORE 1
+//#define PREALLOCATE_SWAP 1
struct lru_item {
struct lru_item *prev;
#include "swap.h"
int main(int argc, char **argv) {
- if (argc < 7) {
+ if (argc < 5) {
#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
- printf("usage: %s n_processes core_table_size core_table_spare swap_table_size swap_table_spare spare [n_core_blocks [n_swap_blocks]]\n", argv[0]);
+ printf("usage: %s n_processes core_table_size swap_table_size spare [n_core_blocks [n_swap_blocks]]\n", argv[0]);
#elif defined(INDIRECT_CORE)
- printf("usage: %s n_processes core_table_size core_table_spare swap_table_size swap_table_spare spare [n_core_blocks]\n", argv[0]);
+ printf("usage: %s n_processes core_table_size swap_table_size spare [n_core_blocks]\n", argv[0]);
#elif defined(INDIRECT_SWAP)
- printf("usage: %s n_processes core_table_size core_table_spare swap_table_size swap_table_spare spare [n_swap_blocks]\n", argv[0]);
+ printf("usage: %s n_processes core_table_size swap_table_size spare [n_swap_blocks]\n", argv[0]);
#else
- printf("usage: %s n_processes core_table_size core_table_spare swap_table_size swap_table_spare spare\n", argv[0]);
+ printf("usage: %s n_processes core_table_size swap_table_size spare\n", argv[0]);
#endif
exit(EXIT_FAILURE);
}
int n_processes = atoi(argv[1]);
int core_table_size = atoi(argv[2]);
- int core_table_spare = atoi(argv[3]);
- int swap_table_size = atoi(argv[4]);
- int swap_table_spare = atoi(argv[5]);
- int spare = atoi(argv[6]);
+ int swap_table_size = atoi(argv[3]);
+ int spare = atoi(argv[4]);
#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
- int n_core_blocks = argc >= 8 ? atoi(argv[7]) : core_table_size;
- int n_swap_blocks = argc >= 9 ? atoi(argv[8]) : swap_table_size;
+ int n_core_blocks = argc >= 6 ? atoi(argv[5]) : core_table_size;
+ int n_swap_blocks = argc >= 7 ? atoi(argv[6]) : swap_table_size;
#elif defined(INDIRECT_CORE)
- int n_core_blocks = argc >= 8 ? atoi(argv[7]) : core_table_size;
+ int n_core_blocks = argc >= 6 ? atoi(argv[5]) : core_table_size;
#elif defined(INDIRECT_SWAP)
- int n_swap_blocks = argc >= 8 ? atoi(argv[7]) : swap_table_size;
+ int n_swap_blocks = argc >= 6 ? atoi(argv[5]) : swap_table_size;
#endif
#ifdef INDIRECT_CORE
- core_init(core_table_size, core_table_spare, n_core_blocks);
+ core_init(core_table_size, n_core_blocks);
#else
- core_init(core_table_size, core_table_spare);
+ core_init(core_table_size);
#endif
#ifdef INDIRECT_SWAP
- swap_init(swap_table_size, swap_table_spare, n_swap_blocks);
+ swap_init(swap_table_size, n_swap_blocks);
#else
- swap_init(swap_table_size, swap_table_spare);
+ swap_init(swap_table_size);
#endif
process_init(n_processes, spare);
for (int i = 0; i < n_processes; ++i)
processes[i].size = -1;
while (true) {
- printf("avail %d %d(%d) %d(%d)\n", process_avail, core_avail(), core_table.avail, swap_avail(), swap_table.avail);
+ //printf("avail %d %d(%d) %d(%d)\n", process_avail, core_avail(), core_table.avail, swap_avail(), swap_table.avail);
char buf[256];
switch (scanf("%s", buf)) {
case -1:
#else
int core_block = core_base + i;
#endif
- printf("%d\n", core_block);
rassert(core_block_mem[core_block] == 0xaaaaaaaa);
core_block_mem[core_block] = (int)hash;
}
#endif
#ifdef INDIRECT_SWAP
-void swap_init(int table_size, int table_spare, int n_blocks)
+void swap_init(int table_size, int n_blocks)
#else
-void swap_init(int table_size, int table_spare)
+void swap_init(int table_size)
#endif
{
pool_init(
&swap_table,
~table_size,
-1,
- table_spare,
swap_move,
#ifdef MOVEABLE_SWAP
swap_move_up
#include <stdint.h>
#include "pool.h"
-#define INDIRECT_SWAP 1
-//#define MOVEABLE_SWAP 1
+//#define INDIRECT_SWAP 1
+#define MOVEABLE_SWAP 1
#ifdef MOVEABLE_SWAP
#define swap_table_alloc(item, size) \
extern int *swap_block_mem;
#ifdef INDIRECT_SWAP
-void swap_init(int n_table, int table_spare, int n_blocks);
+void swap_init(int n_table, int n_blocks);
bool swap_block_alloc(int *blocks, int size);
void swap_block_free(int *blocks, int size);
#else
-void swap_init(int n_table, int table_spare);
+void swap_init(int n_table);
#endif
void swap_read(int swap_base, int core_base, int size);
void swap_write(int swap_base, int core_base, int size);