LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] free swap space when (re)activating page
@ 2007-02-16 22:46 Rik van Riel
2007-02-20 4:53 ` Christoph Lameter
2007-02-20 19:00 ` William Lee Irwin III
0 siblings, 2 replies; 15+ messages in thread
From: Rik van Riel @ 2007-02-16 22:46 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-mm, Christoph Lameter
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
The attached patch does what I described in the other thread, it
makes the pageout code free swap space when swap is getting full,
by taking away the swap space from pages that get moved onto or
back onto the active list.
In some tests on a system with 2GB RAM and 1GB swap, it kept the
free swap at 500MB for a 2.3GB qsbench, while without the patch
over 950MB of swap was in use all of the time.
This should give kswapd more flexibility in what to swap out.
What do you think?
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: 1988 bytes --]
--- linux-2.6.20.x86_64/mm/vmscan.c.swapfull 2007-02-16 06:47:02.000000000 -0500
+++ linux-2.6.20.x86_64/mm/vmscan.c 2007-02-16 07:03:30.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:
@@ -875,6 +878,11 @@ force_reclaim_mapped:
pagevec_strip(&pvec);
spin_lock_irq(&zone->lru_lock);
}
+ if (vm_swap_full()) {
+ spin_unlock_irq(&zone->lru_lock);
+ pagevec_swap_free(&pvec);
+ spin_lock_irq(&zone->lru_lock);
+ }
pgmoved = 0;
while (!list_empty(&l_active)) {
--- linux-2.6.20.x86_64/mm/swap.c.swapfull 2007-02-16 07:09:38.000000000 -0500
+++ linux-2.6.20.x86_64/mm/swap.c 2007-02-16 07:05:00.000000000 -0500
@@ -420,6 +420,24 @@ 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);
+ }
+ }
+}
+
/**
* pagevec_lookup - gang pagecache lookup
* @pvec: Where the resulting pages are placed
--- linux-2.6.20.x86_64/include/linux/pagevec.h.swapfull 2007-02-16 07:06:29.000000000 -0500
+++ linux-2.6.20.x86_64/include/linux/pagevec.h 2007-02-16 07:06:41.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] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-16 22:46 [PATCH] free swap space when (re)activating page Rik van Riel
@ 2007-02-20 4:53 ` Christoph Lameter
2007-02-20 13:28 ` Rik van Riel
2007-02-20 19:00 ` William Lee Irwin III
1 sibling, 1 reply; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 4:53 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm
On Fri, 16 Feb 2007, Rik van Riel wrote:
> What do you think?
Looks good apart from one passage (which just vanished when I tried to
reply, please post patches as inline text).
It was the portion that modifies shrink_active_list. Why operate
on the pagevec there? The pagevec only contains the leftovers to be
released from scanning over the temporary inactive list.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 4:53 ` Christoph Lameter
@ 2007-02-20 13:28 ` Rik van Riel
2007-02-20 16:37 ` Christoph Lameter
0 siblings, 1 reply; 15+ messages in thread
From: Rik van Riel @ 2007-02-20 13:28 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-kernel, linux-mm
Christoph Lameter wrote:
> On Fri, 16 Feb 2007, Rik van Riel wrote:
>
>> What do you think?
>
> Looks good apart from one passage (which just vanished when I tried to
> reply, please post patches as inline text).
>
> It was the portion that modifies shrink_active_list. Why operate
> on the pagevec there? The pagevec only contains the leftovers to be
> released from scanning over the temporary inactive list.
Why? Because the pages that were not referenced will be
going onto the inactive list and are now a candidate for
swapping out. I don't see why we would want to reclaim
the swap space for pages that area about to be swapped
out again.
--
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 13:28 ` Rik van Riel
@ 2007-02-20 16:37 ` Christoph Lameter
2007-02-20 16:46 ` Rik van Riel
0 siblings, 1 reply; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 16:37 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm
On Tue, 20 Feb 2007, Rik van Riel wrote:
> > It was the portion that modifies shrink_active_list. Why operate
> > on the pagevec there? The pagevec only contains the leftovers to be released
> > from scanning over the temporary inactive list.
>
> Why? Because the pages that were not referenced will be
> going onto the inactive list and are now a candidate for
> swapping out. I don't see why we would want to reclaim
> the swap space for pages that area about to be swapped
> out again.
Sounds sane. Then drop that piece. Again, you were only operating on the
pages left over in the pagevec after the move of the pages to the
inactive list. If you really wanted to do something there then the
processing should have covered all pages that go to the inactive list.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 16:37 ` Christoph Lameter
@ 2007-02-20 16:46 ` Rik van Riel
2007-02-20 18:20 ` Christoph Lameter
0 siblings, 1 reply; 15+ messages in thread
From: Rik van Riel @ 2007-02-20 16:46 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-kernel, linux-mm
Christoph Lameter wrote:
> On Tue, 20 Feb 2007, Rik van Riel wrote:
>
>>> It was the portion that modifies shrink_active_list. Why operate
>>> on the pagevec there? The pagevec only contains the leftovers to be released
>>> from scanning over the temporary inactive list.
>> Why? Because the pages that were not referenced will be
>> going onto the inactive list and are now a candidate for
>> swapping out. I don't see why we would want to reclaim
>> the swap space for pages that area about to be swapped
>> out again.
>
> Sounds sane. Then drop that piece. Again, you were only operating on the
> pages left over in the pagevec after the move of the pages to the
> inactive list. If you really wanted to do something there then the
> processing should have covered all pages that go to the inactive list.
Nono, I try to remove the swap space occupied by pages that
go back onto the active list. Regardless of whether they
were already there, or whether they started out on the
inactive list.
Stripping the swap space of the pages that are going to
the inactive list makes less sense IMHO, because those
pages are candidates for swapping out - meaning those
should keep the space.
--
All Rights Reversed
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 16:46 ` Rik van Riel
@ 2007-02-20 18:20 ` Christoph Lameter
2007-02-20 19:31 ` Rik van Riel
0 siblings, 1 reply; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 18:20 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm
On Tue, 20 Feb 2007, Rik van Riel wrote:
> Nono, I try to remove the swap space occupied by pages that
> go back onto the active list. Regardless of whether they
> were already there, or whether they started out on the
> inactive list.
Ok then do it for all pages that go back not just for those leftover from
the moving of pages to the inactive list (why would you move those???)
> Stripping the swap space of the pages that are going to
> the inactive list makes less sense IMHO, because those
> pages are candidates for swapping out - meaning those
> should keep the space.
Just trying to figure out what your patch does there and it does not make
much sense to me so far.
Maybe the hunk does apply in a different location than I thought. If you
do that in the loop over the pages on active list then it would make
sense. But in that case you need another piece of it doing the same to the
pages that are released at the end of shrink_active_list().
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 18:20 ` Christoph Lameter
@ 2007-02-20 19:31 ` Rik van Riel
2007-02-20 19:42 ` Christoph Lameter
2007-02-20 19:54 ` Rik van Riel
0 siblings, 2 replies; 15+ messages in thread
From: Rik van Riel @ 2007-02-20 19:31 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-kernel, linux-mm
Christoph Lameter wrote:
> On Tue, 20 Feb 2007, Rik van Riel wrote:
>
>> Nono, I try to remove the swap space occupied by pages that
>> go back onto the active list. Regardless of whether they
>> were already there, or whether they started out on the
>> inactive list.
>
> Ok then do it for all pages that go back not just for those leftover from
> the moving of pages to the inactive list (why would you move those???)
I do. The only pages that are exempt are the pages that move
from the active list to the inactive list, because those will
probably be evicted soon enough.
> Maybe the hunk does apply in a different location than I thought.
I suspect that's the case ...
> If you
> do that in the loop over the pages on active list then it would make
> sense. But in that case you need another piece of it doing the same to the
> pages that are released at the end of shrink_active_list().
... because I think this is what my patch does :)
--
All Rights Reversed
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 19:31 ` Rik van Riel
@ 2007-02-20 19:42 ` Christoph Lameter
2007-02-20 19:54 ` Rik van Riel
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 19:42 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm
On Tue, 20 Feb 2007, Rik van Riel wrote:
> > Maybe the hunk does apply in a different location than I thought.
>
> I suspect that's the case ...
No that is not the case:
@@ -875,6 +878,11 @@ force_reclaim_mapped:
pagevec_strip(&pvec);
spin_lock_irq(&zone->lru_lock);
}
+ if (vm_swap_full()) {
+ spin_unlock_irq(&zone->lru_lock);
+ pagevec_swap_free(&pvec);
+ spin_lock_irq(&zone->lru_lock);
+ }
pgmoved = 0;
while (!list_empty(&l_active)) {
So you do the swap free on the pages leftover from moving to the inactive
list and not to the pages that will be moved to the active list. It does
not do what you wanted to be done.
You need to
1. Do the pagevec_swap_free in the loop over the active pages
2. At end of the loop over the active pages do something like the above.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 19:31 ` Rik van Riel
2007-02-20 19:42 ` Christoph Lameter
@ 2007-02-20 19:54 ` Rik van Riel
2007-02-20 20:26 ` Christoph Lameter
2007-02-20 20:57 ` Christoph Lameter
1 sibling, 2 replies; 15+ messages in thread
From: Rik van Riel @ 2007-02-20 19:54 UTC (permalink / raw)
To: Rik van Riel; +Cc: Christoph Lameter, linux-kernel, linux-mm, Andrew Morton
[-- Attachment #1: Type: text/plain, Size: 284 bytes --]
Rik van Riel wrote:
> ... because I think this is what my patch does :)
Never mind, I see it now.
The attached patch should be correct.
Btw, why do we not call pagevec_strip on the pages on l_active?
I assume we want to reclaim their buffer heads, too...
--
All Rights Reversed
[-- 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] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 19:54 ` Rik van Riel
@ 2007-02-20 20:26 ` Christoph Lameter
2007-02-20 20:57 ` Christoph Lameter
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 20:26 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm, Andrew Morton
On Tue, 20 Feb 2007, Rik van Riel wrote:
> The attached patch should be correct.
Oh. It vanished again when I replied to your mail.
> Btw, why do we not call pagevec_strip on the pages on l_active?
> I assume we want to reclaim their buffer heads, too...
Yes we want to reduce buffer heads if we are over the limit.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-20 19:54 ` Rik van Riel
2007-02-20 20:26 ` Christoph Lameter
@ 2007-02-20 20:57 ` Christoph Lameter
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Lameter @ 2007-02-20 20:57 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm, Andrew Morton
On Tue, 20 Feb 2007, Rik van Riel wrote:
> Btw, why do we not call pagevec_strip on the pages on l_active?
> I assume we want to reclaim their buffer heads, too...
But those buffer heads may be used soon. So its better to leave them
alone.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
2007-02-16 22:46 [PATCH] free swap space when (re)activating page Rik van Riel
2007-02-20 4:53 ` Christoph Lameter
@ 2007-02-20 19:00 ` William Lee Irwin III
1 sibling, 0 replies; 15+ messages in thread
From: William Lee Irwin III @ 2007-02-20 19:00 UTC (permalink / raw)
To: Rik van Riel; +Cc: linux-kernel, linux-mm, Christoph Lameter
On Fri, Feb 16, 2007 at 05:46:29PM -0500, Rik van Riel wrote:
> The attached patch does what I described in the other thread, it
> makes the pageout code free swap space when swap is getting full,
> by taking away the swap space from pages that get moved onto or
> back onto the active list.
> In some tests on a system with 2GB RAM and 1GB swap, it kept the
> free swap at 500MB for a 2.3GB qsbench, while without the patch
> over 950MB of swap was in use all of the time.
> This should give kswapd more flexibility in what to swap out.
> What do you think?
> Signed-off-by: Rik van Riel <riel@redhat.com>
I would call this a bugfix, not an optimization.
-- wli
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] free swap space when (re)activating page
@ 2007-02-21 15:09 Al Boldi
0 siblings, 0 replies; 15+ messages in thread
From: Al Boldi @ 2007-02-21 15:09 UTC (permalink / raw)
To: linux-kernel
Rik van Riel wrote:
> Rik van Riel wrote:
> > ... because I think this is what my patch does :)
>
> Never mind, I see it now.
>
> The attached patch should be correct.
Your patch seems to improve the situation a little bit, but the numbers still
look weird, especially for swap-in, which gets progressively slower.
RAM 512mb , SWAP 1G
#mount -t tmpfs -o size=1G none /dev/shm
#time cat /dev/full > /dev/shm/x.dmp
15sec
#time cat /dev/shm/x.dmp > /dev/null
58sec
#time cat /dev/shm/x.dmp > /dev/null
72sec
#time cat /dev/shm/x.dmp > /dev/null
85sec
#time cat /dev/shm/x.dmp > /dev/null
93sec
#time cat /dev/shm/x.dmp > /dev/null
99sec
Thanks!
--
Al
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <7Pk3X-bD-17@gated-at.bofh.it>]
end of thread, other threads:[~2007-02-23 3:34 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-16 22:46 [PATCH] free swap space when (re)activating page Rik van Riel
2007-02-20 4:53 ` Christoph Lameter
2007-02-20 13:28 ` Rik van Riel
2007-02-20 16:37 ` Christoph Lameter
2007-02-20 16:46 ` Rik van Riel
2007-02-20 18:20 ` Christoph Lameter
2007-02-20 19:31 ` Rik van Riel
2007-02-20 19:42 ` Christoph Lameter
2007-02-20 19:54 ` Rik van Riel
2007-02-20 20:26 ` Christoph Lameter
2007-02-20 20:57 ` Christoph Lameter
2007-02-20 19:00 ` William Lee Irwin III
2007-02-21 15:09 Al Boldi
[not found] <7Pk3X-bD-17@gated-at.bofh.it>
[not found] ` <7QvgM-3aK-3@gated-at.bofh.it>
[not found] ` <7QDeB-7KY-11@gated-at.bofh.it>
[not found] ` <7QGc7-3ZB-13@gated-at.bofh.it>
[not found] ` <7QGlP-4e1-11@gated-at.bofh.it>
[not found] ` <7QHUO-6RS-5@gated-at.bofh.it>
[not found] ` <7QJ9Y-mo-1@gated-at.bofh.it>
[not found] ` <7QJk7-zW-51@gated-at.bofh.it>
2007-02-23 1:44 ` Bodo Eggert
2007-02-23 3:34 ` Rik van Riel
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).