I just did then. You'll need to call
freed = shrink_all_memory(99);
to free up 99 pages. It returns the number which it actually
freed. If that's not 99 then it's time to give up. There is
no oom-killer in this code path.
I haven't tested it yet. And it's quite a long way back in the
queue I'm afraid - it has a dependency chain, and I prefer to
send stuff to Linus which has been tested for a couple of weeks, and
hasn't changed for one week.
Can you use the allocate-lots-then-free-it trick in the meanwhile?
include/linux/swap.h | 1 +
mm/vmscan.c | 46 ++++++++++++++++++++++++++++++++++++++++------
2 files changed, 41 insertions, 6 deletions
--- 2.5.36/mm/vmscan.c~swsusp-feature Wed Sep 18 13:55:20 2002
+++ 2.5.36-akpm/mm/vmscan.c Wed Sep 18 14:29:13 2002
@@ -694,12 +694,19 @@ try_to_free_pages(struct zone *classzone
}
/*
- * kswapd will work across all this node's zones until they are all at
- * pages_high.
+ * For kswapd, balance_pgdat() will work across all this node's zones until
+ * they are all at pages_high.
+ *
+ * If `nr_pages' is non-zero then it is the number of pages which are to be
+ * reclaimed, regardless of the zone occupancies. This is a software suspend
+ * special.
+ *
+ * Returns the number of pages which were actually freed.
*/
-static void kswapd_balance_pgdat(pg_data_t *pgdat)
+static int balance_pgdat(pg_data_t *pgdat, int nr_pages)
{
- int priority = DEF_PRIORITY;
+ int to_free = nr_pages;
+ int priority;
int i;
for (priority = DEF_PRIORITY; priority; priority--) {
@@ -712,13 +719,15 @@ static void kswapd_balance_pgdat(pg_data
int to_reclaim;
to_reclaim = zone->pages_high - zone->free_pages;
+ if (nr_pages && to_free > 0)
+ to_reclaim = min(to_free, SWAP_CLUSTER_MAX*8);
if (to_reclaim <= 0)
continue;
success = 0;
max_scan = zone->nr_inactive >> priority;
if (max_scan < to_reclaim * 2)
max_scan = to_reclaim * 2;
- shrink_zone(zone, max_scan, GFP_KSWAPD,
+ to_free -= shrink_zone(zone, max_scan, GFP_KSWAPD,
to_reclaim, &nr_mapped);
shrink_slab(max_scan + nr_mapped, GFP_KSWAPD);
}
@@ -726,6 +735,7 @@ static void kswapd_balance_pgdat(pg_data
break; /* All zones are at pages_high */
blk_congestion_wait(WRITE, HZ/4);
}
+ return nr_pages - to_free;
}
/*
@@ -772,10 +782,34 @@ int kswapd(void *p)
prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
schedule();
finish_wait(&pgdat->kswapd_wait, &wait);
- kswapd_balance_pgdat(pgdat);
+ balance_pgdat(pgdat, 0);
blk_run_queues();
}
}
+
+#ifdef CONFIG_SOFTWARE_SUSPEND
+/*
+ * Try to free `nr_pages' of memory, system-wide. Returns the number of freed
+ * pages.
+ */
+int shrink_all_memory(int nr_pages)
+{
+ pg_data_t *pgdat;
+ int nr_to_free = nr_pages;
+ int ret = 0;
+
+ for_each_pgdat(pgdat) {
+ int freed;
+
+ freed = balance_pgdat(pgdat, nr_to_free);
+ ret += freed;
+ nr_to_free -= freed;
+ if (nr_to_free <= 0)
+ break;
+ }
+ return ret;
+}
+#endif
static int __init kswapd_init(void)
{
--- 2.5.36/include/linux/swap.h~swsusp-feature Wed Sep 18 14:03:01 2002
+++ 2.5.36-akpm/include/linux/swap.h Wed Sep 18 14:16:29 2002
@@ -163,6 +163,7 @@ extern void swap_setup(void);
/* linux/mm/vmscan.c */
extern int try_to_free_pages(struct zone *, unsigned int, unsigned int);
+int shrink_all_memory(int nr_pages);
/* linux/mm/page_io.c */
int swap_readpage(struct file *file, struct page *page);
.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/