linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] free swap space of (re)activated pages
@ 2007-03-02 20:31 Rik van Riel
  2007-03-03  1:18 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2007-03-02 20:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm

[-- Attachment #1: Type: text/plain, Size: 617 bytes --]

Hi Andrew,

the attached patch frees the swap space of already resident pages
when swap space starts getting tight, instead of only freeing up
the swap space taken up by newly swapped in pages.

This should result in the swap space of pages that remain resident
in memory being freed, allowing kswapd more chances to actually swap
a page out (instead of rotating it back onto the active list).

Signed-off-by: Rik van Riel <riel@redhat.com>

-- 
Politics is the struggle between those who want to make their country
the best in the world, and those who believe it already is.  Each group
calls the other unpatriotic.

[-- Attachment #2: linux-2.6-swapfree.patch --]
[-- Type: text/x-patch, Size: 2259 bytes --]

--- linux-2.6.20.noarch/mm/vmscan.c.swapfree	2007-02-20 06:44:13.000000000 -0500
+++ linux-2.6.20.noarch/mm/vmscan.c	2007-02-20 06:54:10.000000000 -0500
@@ -587,6 +587,9 @@ free_it:
 		continue;
 
 activate_locked:
+		/* Not a candidate for swapping, so reclaim swap space. */
+		if (PageSwapCache(page) && vm_swap_full())
+			remove_exclusive_swap_page(page);
 		SetPageActive(page);
 		pgactivate++;
 keep_locked:
@@ -889,6 +892,8 @@ force_reclaim_mapped:
 			__mod_zone_page_state(zone, NR_ACTIVE, pgmoved);
 			pgmoved = 0;
 			spin_unlock_irq(&zone->lru_lock);
+			if (vm_swap_full())
+				pagevec_swap_free(&pvec);
 			__pagevec_release(&pvec);
 			spin_lock_irq(&zone->lru_lock);
 		}
@@ -899,6 +904,8 @@ force_reclaim_mapped:
 	__count_vm_events(PGDEACTIVATE, pgdeactivate);
 	spin_unlock_irq(&zone->lru_lock);
 
+	if (vm_swap_full())
+		pagevec_swap_free(&pvec);
 	pagevec_release(&pvec);
 }
 
--- linux-2.6.20.noarch/mm/swap.c.swapfree	2007-02-04 13:44:54.000000000 -0500
+++ linux-2.6.20.noarch/mm/swap.c	2007-02-20 06:44:17.000000000 -0500
@@ -420,6 +420,26 @@ void pagevec_strip(struct pagevec *pvec)
 	}
 }
 
+/*
+ * Try to free swap space from the pages in a pagevec
+ */
+void pagevec_swap_free(struct pagevec *pvec)
+{
+	int i;
+
+	for (i = 0; i < pagevec_count(pvec); i++) {
+		struct page *page = pvec->pages[i];
+
+		if (PageSwapCache(page) && !TestSetPageLocked(page)) {
+			if (PageSwapCache(page))
+				remove_exclusive_swap_page(page);
+			unlock_page(page);
+			if (printk_ratelimit())
+				printk("kswapd freed a swap space\n");
+		}
+	}
+}
+
 /**
  * pagevec_lookup - gang pagecache lookup
  * @pvec:	Where the resulting pages are placed
--- linux-2.6.20.noarch/include/linux/pagevec.h.swapfree	2007-02-04 13:44:54.000000000 -0500
+++ linux-2.6.20.noarch/include/linux/pagevec.h	2007-02-20 06:44:17.000000000 -0500
@@ -26,6 +26,7 @@ void __pagevec_free(struct pagevec *pvec
 void __pagevec_lru_add(struct pagevec *pvec);
 void __pagevec_lru_add_active(struct pagevec *pvec);
 void pagevec_strip(struct pagevec *pvec);
+void pagevec_swap_free(struct pagevec *pvec);
 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
 		pgoff_t start, unsigned nr_pages);
 unsigned pagevec_lookup_tag(struct pagevec *pvec,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] free swap space of (re)activated pages
  2007-03-02 20:31 [PATCH] free swap space of (re)activated pages Rik van Riel
@ 2007-03-03  1:18 ` Andrew Morton
  2007-03-03  1:31   ` Rik van Riel
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2007-03-03  1:18 UTC (permalink / raw)
  To: Rik van Riel; +Cc: linux-kernel, linux-mm

On Fri, 02 Mar 2007 15:31:19 -0500
Rik van Riel <riel@redhat.com> wrote:

> the attached patch frees the swap space of already resident pages
> when swap space starts getting tight, instead of only freeing up
> the swap space taken up by newly swapped in pages.
> 
> This should result in the swap space of pages that remain resident
> in memory being freed, allowing kswapd more chances to actually swap
> a page out (instead of rotating it back onto the active list).

Fair enough.   How do we work out if this helps things?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] free swap space of (re)activated pages
  2007-03-03  1:18 ` Andrew Morton
@ 2007-03-03  1:31   ` Rik van Riel
  2007-03-03  3:04     ` Con Kolivas
  0 siblings, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2007-03-03  1:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm

Andrew Morton wrote:
> On Fri, 02 Mar 2007 15:31:19 -0500
> Rik van Riel <riel@redhat.com> wrote:
> 
>> the attached patch frees the swap space of already resident pages
>> when swap space starts getting tight, instead of only freeing up
>> the swap space taken up by newly swapped in pages.
>>
>> This should result in the swap space of pages that remain resident
>> in memory being freed, allowing kswapd more chances to actually swap
>> a page out (instead of rotating it back onto the active list).
> 
> Fair enough.   How do we work out if this helps things?

I suspect it should mostly help on desktop systems that slowly
fill up (and run out of) swap.  I'm not sure how to create that
synthetically.

I have seen that swap is kept free much easier in a qsbench
test, but that's probably not a very good test since it swaps
things in and out all the time...

-- 
Politics is the struggle between those who want to make their country
the best in the world, and those who believe it already is.  Each group
calls the other unpatriotic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] free swap space of (re)activated pages
  2007-03-03  1:31   ` Rik van Riel
@ 2007-03-03  3:04     ` Con Kolivas
  0 siblings, 0 replies; 4+ messages in thread
From: Con Kolivas @ 2007-03-03  3:04 UTC (permalink / raw)
  To: Rik van Riel, ck list; +Cc: Andrew Morton, linux-kernel, linux-mm

On Saturday 03 March 2007 12:31, Rik van Riel wrote:
> Andrew Morton wrote:
> > On Fri, 02 Mar 2007 15:31:19 -0500
> >
> > Rik van Riel <riel@redhat.com> wrote:
> >> the attached patch frees the swap space of already resident pages
> >> when swap space starts getting tight, instead of only freeing up
> >> the swap space taken up by newly swapped in pages.
> >>
> >> This should result in the swap space of pages that remain resident
> >> in memory being freed, allowing kswapd more chances to actually swap
> >> a page out (instead of rotating it back onto the active list).
> >
> > Fair enough.   How do we work out if this helps things?
>
> I suspect it should mostly help on desktop systems that slowly
> fill up (and run out of) swap.  I'm not sure how to create that
> synthetically.

Ooh you have a vm patch that helps swap on the desktop! I can help you here 
with my experience from swap prefetch.

1. Get it reviewed and have noone show any evidence it harms
2. Find hundreds of users who can testify it helps
3. Find a way of quantifying it.
4. ...
5. Merge into mainline.


There, that should get you as far as 4. 

I haven't figured out what 4 is yet. I believe it may be goto 1;

-- 
-ck

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-03  3:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-02 20:31 [PATCH] free swap space of (re)activated pages Rik van Riel
2007-03-03  1:18 ` Andrew Morton
2007-03-03  1:31   ` Rik van Riel
2007-03-03  3:04     ` Con Kolivas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).