* [PATCH] swapin readahead v4
@ 1998-12-03 10:21 Rik van Riel
1998-12-03 12:35 ` Stephen C. Tweedie
0 siblings, 1 reply; 3+ messages in thread
From: Rik van Riel @ 1998-12-03 10:21 UTC (permalink / raw)
To: Linux MM
Hi,
Stephen's messages gave away the clue to something I was just
about to track down myself. Anyway, here is the 4th version of
my swapin readahead patch.
cheers,
Rik -- the flu hits, the flu hits, the flu hits -- MORE
+-------------------------------------------------------------------+
| Linux memory management tour guide. H.H.vanRiel@phys.uu.nl |
| Scouting Vries cubscout leader. http://www.phys.uu.nl/~riel/ |
+-------------------------------------------------------------------+
--- ./mm/vmscan.c.orig Thu Nov 26 11:26:50 1998
+++ ./mm/vmscan.c Tue Dec 1 07:12:28 1998
@@ -431,6 +431,8 @@
kmem_cache_reap(gfp_mask);
if (buffer_over_borrow() || pgcache_over_borrow())
+ state = 0;
+ if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster / 2)
shrink_mmap(i, gfp_mask);
switch (state) {
--- ./mm/page_io.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/page_io.c Thu Nov 26 11:30:43 1998
@@ -60,7 +60,7 @@
}
/* Don't allow too many pending pages in flight.. */
- if (atomic_read(&nr_async_pages) > SWAP_CLUSTER_MAX)
+ if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
wait = 1;
p = &swap_info[type];
--- ./mm/page_alloc.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/page_alloc.c Tue Dec 1 18:11:22 1998
@@ -370,9 +370,32 @@
pte_t * page_table, unsigned long entry, int write_access)
{
unsigned long page;
- struct page *page_map;
-
+ int i;
+ struct page *page_map = lookup_swap_cache(entry);
+ unsigned long offset = SWP_OFFSET(entry);
+ struct swap_info_struct *swapdev = SWP_TYPE(entry) + swap_info;
+
+ if (!page_map) {
page_map = read_swap_cache(entry);
+
+ /*
+ * Primitive swap readahead code. We simply read the
+ * next 16 entries in the swap area. The break below
+ * is needed or else the request queue will explode :)
+ */
+ for (i = 1; i++ < 16;) {
+ offset++;
+ if (!swapdev->swap_map[offset] || offset >= swapdev->max
+ || nr_free_pages - atomic_read(&nr_async_pages) <
+ (freepages.high + freepages.low)/2)
+ break;
+ read_swap_cache_async(SWP_ENTRY(SWP_TYPE(entry), offset),
+0);
+ break;
+ }
+ } else {
+ page_map = read_swap_cache(entry);
+ }
if (pte_val(*page_table) != entry) {
if (page_map)
--- ./mm/swap_state.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/swap_state.c Thu Dec 3 11:11:31 1998
@@ -258,7 +258,7 @@
* incremented.
*/
-static struct page * lookup_swap_cache(unsigned long entry)
+struct page * lookup_swap_cache(unsigned long entry)
{
struct page *found;
@@ -329,6 +329,8 @@
set_bit(PG_locked, &new_page->flags);
rw_swap_page(READ, entry, (char *) new_page_addr, wait);
+ if (!wait)
+ __free_page(new_page);
#ifdef DEBUG_SWAP
printk("DebugVM: read_swap_cache_async created "
"entry %08lx at %p\n",
--- ./include/linux/swap.h.orig Tue Dec 1 07:29:56 1998
+++ ./include/linux/swap.h Tue Dec 1 07:31:03 1998
@@ -90,6 +90,7 @@
extern struct page * read_swap_cache_async(unsigned long, int);
#define read_swap_cache(entry) read_swap_cache_async(entry, 1);
extern int FASTCALL(swap_count(unsigned long));
+extern struct page * lookup_swap_cache(unsigned long);
/*
* Make these inline later once they are working properly.
*/
--
This is a majordomo managed list. To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] swapin readahead v4
1998-12-03 10:21 [PATCH] swapin readahead v4 Rik van Riel
@ 1998-12-03 12:35 ` Stephen C. Tweedie
1998-12-03 13:28 ` Rik van Riel
0 siblings, 1 reply; 3+ messages in thread
From: Stephen C. Tweedie @ 1998-12-03 12:35 UTC (permalink / raw)
To: Rik van Riel; +Cc: Linux MM, Stephen Tweedie
Hi,
In article
<Pine.LNX.3.96.981203111953.4894B-100000@mirkwood.dummy.home>, Rik van
Riel <H.H.vanRiel@phys.uu.nl> writes:
> Stephen's messages gave away the clue to something I was just
> about to track down myself. Anyway, here is the 4th version of
> my swapin readahead patch.
> @@ -329,6 +329,8 @@
> set_bit(PG_locked, &new_page->flags);
> rw_swap_page(READ, entry, (char *) new_page_addr, wait);
> + if (!wait)
> + __free_page(new_page);
> #ifdef DEBUG_SWAP
> printk("DebugVM: read_swap_cache_async created "
> "entry %08lx at %p\n",
Much better to do this after calling read_swap_cache_async(): it's bad
policy to make the reference count of the page after calling this
function dependent on the arguments: that is a maintenance nightmare.
Oh, and you _still_ need to check the swap_lockmap before calling
read_swap_cache_async(), and you still have the extra break() in the
readahead loop...
Finally, the code before the start of the readahead loop loops really
broken. You do both a lookup_swap_cache AND a read_swap_cache on the
entry, which is going to double-increment the page count: bad news.
It's probably best to leave the original swapin code intact, and just
add the readahead bits. You also seem to have a construct
if (!page_map) {
page_map = read_swap_cache(entry);
do something else
} else {
page_map = read_swap_cache(entry);
}
and I can't for the life of me work out why you are doing things this
way!
--Stephen
--
This is a majordomo managed list. To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] swapin readahead v4
1998-12-03 12:35 ` Stephen C. Tweedie
@ 1998-12-03 13:28 ` Rik van Riel
0 siblings, 0 replies; 3+ messages in thread
From: Rik van Riel @ 1998-12-03 13:28 UTC (permalink / raw)
To: Stephen C. Tweedie; +Cc: Linux MM
On Thu, 3 Dec 1998, Stephen C. Tweedie wrote:
> > Stephen's messages gave away the clue to something I was just
> > about to track down myself. Anyway, here is the 4th version of
> > my swapin readahead patch.
>
> Much better to do this after calling read_swap_cache_async(): it's bad
> policy to make the reference count of the page after calling this
> function dependent on the arguments: that is a maintenance nightmare.
>
> Oh, and you _still_ need to check the swap_lockmap before calling
> read_swap_cache_async(), and you still have the extra break() in the
> readahead loop...
Somebody forbid me to do coding while having a flu...
This patch (v5) should be much better (I haven't tried it
yet but it has all things Stephen told me to include -- as
far as I can see through the haze that surrounds me).
cheers,
Rik -- the flu hits, the flu hits, the flu hits -- MORE
+-------------------------------------------------------------------+
| Linux memory management tour guide. H.H.vanRiel@phys.uu.nl |
| Scouting Vries cubscout leader. http://www.phys.uu.nl/~riel/ |
+-------------------------------------------------------------------+
--- ./mm/vmscan.c.orig Thu Nov 26 11:26:50 1998
+++ ./mm/vmscan.c Tue Dec 1 07:12:28 1998
@@ -431,6 +431,8 @@
kmem_cache_reap(gfp_mask);
if (buffer_over_borrow() || pgcache_over_borrow())
+ state = 0;
+ if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster / 2)
shrink_mmap(i, gfp_mask);
switch (state) {
--- ./mm/page_io.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/page_io.c Thu Nov 26 11:30:43 1998
@@ -60,7 +60,7 @@
}
/* Don't allow too many pending pages in flight.. */
- if (atomic_read(&nr_async_pages) > SWAP_CLUSTER_MAX)
+ if (atomic_read(&nr_async_pages) > pager_daemon.swap_cluster)
wait = 1;
p = &swap_info[type];
--- ./mm/page_alloc.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/page_alloc.c Thu Dec 3 14:26:25 1998
@@ -370,9 +370,31 @@
pte_t * page_table, unsigned long entry, int write_access)
{
unsigned long page;
- struct page *page_map;
-
+ int i;
+ struct page *new_page, *page_map = lookup_swap_cache(entry);
+ unsigned long offset = SWP_OFFSET(entry);
+ struct swap_info_struct *swapdev = SWP_TYPE(entry) + swap_info;
+
+ if (!page_map) {
page_map = read_swap_cache(entry);
+
+ /*
+ * Primitive swap readahead code. We simply read the
+ * next 16 entries in the swap area. The break below
+ * is needed or else the request queue will explode :)
+ */
+ for (i = 1; i++ < 16;) {
+ offset++;
+ if (!swapdev->swap_map[offset] || offset >= swapdev->max
+ || nr_free_pages - atomic_read(&nr_async_pages) <
+ (freepages.high + freepages.low)/2 ||
+ test_bit(offset, swapdev->swap_lockmap))
+ continue;
+ new_page = read_swap_cache_async(SWP_ENTRY(SWP_TYPE(entry), offset), 0);
+ if (new_page)
+ __free_page(new_page);
+ }
+ }
if (pte_val(*page_table) != entry) {
if (page_map)
--- ./mm/swap_state.c.orig Thu Nov 26 11:26:49 1998
+++ ./mm/swap_state.c Thu Dec 3 14:19:19 1998
@@ -258,7 +258,7 @@
* incremented.
*/
-static struct page * lookup_swap_cache(unsigned long entry)
+struct page * lookup_swap_cache(unsigned long entry)
{
struct page *found;
--- ./include/linux/swap.h.orig Tue Dec 1 07:29:56 1998
+++ ./include/linux/swap.h Tue Dec 1 07:31:03 1998
@@ -90,6 +90,7 @@
extern struct page * read_swap_cache_async(unsigned long, int);
#define read_swap_cache(entry) read_swap_cache_async(entry, 1);
extern int FASTCALL(swap_count(unsigned long));
+extern struct page * lookup_swap_cache(unsigned long);
/*
* Make these inline later once they are working properly.
*/
--
This is a majordomo managed list. To unsubscribe, send a message with
the body 'unsubscribe linux-mm me@address' to: majordomo@kvack.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-12-03 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-03 10:21 [PATCH] swapin readahead v4 Rik van Riel
1998-12-03 12:35 ` Stephen C. Tweedie
1998-12-03 13:28 ` 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