Re: 2.1.91pre2 death by swapping.

Rik van Riel (H.H.vanRiel@fys.ruu.nl)
Thu, 26 Mar 1998 14:29:30 +0100 (MET)


On Thu, 26 Mar 1998, Luca Lizzeri wrote:
> On Thu, Mar 26, 1998 at 03:45:44AM -0500, Myrdraal wrote:
>
> > Well, shortly after I wrote my previous message, 2.1.91pre2 died a nasty
> > death. This system has 64mb RAM and was lightly loaded, the main thing
> > it was doing was playing a MOD. It started to swap out of the blue, the
> > mod started skipping more and more, and eventually stopped playing
> > entiredly while the machine thrashed. It continued thrashing for 10-15
>
> It happened to me, while untar-ing a big file (egcs), repeatably.

I think I've found it... In page_alloc.c, a program calls
try_to_free_page() all by itself when there's no chunk of
memory available for it.
This:
- causes unneccessary head movement (because it's done unclustered)
- doesn't guarantee that the freed page is available for _itself_,
since another program might use it
- because of the above, it causes 128k free area's to be lost to
usermode allocations

It can be solved by:
- freeing more (lets say SWAP_CLUSTER_MAX) pages at once
- making sure the swap things are swapped to disk immediately
afterwards

The patch is attached...

Rik.
+-------------------------------------------+--------------------------+
| Linux: - LinuxHQ MM-patches page | Scouting webmaster |
| - kswapd ask-him & complain-to guy | Vries cubscout leader |
| http://www.fys.ruu.nl/~riel/ | <H.H.vanRiel@fys.ruu.nl> |
+-------------------------------------------+--------------------------+

--- ./mm/vmscan.c.pre91-2 Thu Mar 26 11:56:00 1998
+++ ./mm/vmscan.c Thu Mar 26 14:25:15 1998
@@ -568,7 +568,7 @@
* per second (1.6MB/s). This should be a /proc
* thing.
*/
- tries = 50;
+ tries = (50 << 2) >> free_memory_available(3);

while (tries--) {
int gfp_mask;
--- ./mm/page_alloc.c.pre91-2 Thu Mar 26 12:07:00 1998
+++ ./mm/page_alloc.c Thu Mar 26 14:26:59 1998
@@ -282,8 +282,11 @@
spin_lock_irqsave(&page_alloc_lock, flags);
RMQUEUE(order, maxorder, (gfp_mask & GFP_DMA));
spin_unlock_irqrestore(&page_alloc_lock, flags);
- if ((gfp_mask & __GFP_WAIT) && try_to_free_page(gfp_mask))
+ /* No free pages? Let's free some... */
+ if ((gfp_mask & __GFP_WAIT) && try_to_free_pages((gfp_mask & ~__GFP_WAIT),SWAP_CLUSTER_MAX)) {
+ run_task_queue(&tq_disk);
goto repeat;
+ }
nopage:
return 0;
}
--- ./include/linux/swap.h.pre91-2 Thu Mar 26 12:02:14 1998
+++ ./include/linux/swap.h Thu Mar 26 12:06:23 1998
@@ -122,6 +122,21 @@
}

/*
+ * When we're freeing pages from a user application, we want
+ * to cluster swapouts too. -- Rik.
+ * linux/mm/page_alloc.c
+ */
+static inline int try_to_free_pages(int gfp_mask, int count)
+{
+ int retval = 0;
+ while (count--) {
+ if (try_to_free_page(gfp_mask))
+ retval = 1;
+ }
+ return retval;
+}
+
+/*
* Make these inline later once they are working properly.
*/
extern long find_in_swap_cache(struct page *page);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu