Skip to contentSkip to conversation

kanoj-mm9-2.2.10 simplify swapcache/shm code interaction

RFC PATCH In review Kanoj Sarcar 3 participants 6 messages Jun 19, 1999 – Jun 21, 1999

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 kanoj-mm9-2.2.10 simplify swapcache/shm code interaction

There is no reason for shared memory pages to have to be marked PG_swap_cache to fool the underlying swap io routines. Not doing this will also make sure shrink_mmap does not steal such pages, and an extra page reference bumping is not neccesary to ensure this. Also, this makes things more consistent, in the sense that pages marked PG_swap_cache are always in the swap cache, and vice versa.

Kanoj
[email protected]

page_io.c renamed from usr/tmp/p_rdiff_a005Qw/page_io.c +8 -12
@@ -35,7 +35,7 @@
  * that shared pages stay shared while being swapped.
  */
 
-static void rw_swap_page_base(int rw, unsigned long entry, struct page *page, int wait)
+static void rw_swap_page_base(int rw, unsigned long entry, struct page *page, int wait, int shmfs)
 {
 	unsigned long type, offset;
 	struct swap_info_struct * p;
@@ -84,7 +84,7 @@
 		return;
 	}
 
-	if (PageSwapCache(page)) {
+	if (!shmfs) {
 		/* Make sure we are the only process doing I/O with this swap page. */
 		while (test_and_set_bit(offset,p->swap_lockmap)) {
 			run_task_queue(&tq_disk);
@@ -162,7 +162,7 @@
 		/* Do some cleaning up so if this ever happens we can hopefully
 		 * trigger controlled shutdown.
 		 */
-		if (PageSwapCache(page)) {
+		if (!shmfs) {
 			if (!test_and_clear_bit(offset,p->swap_lockmap))
 				printk("swap_after_unlock_page: lock already cleared\n");
 			wake_up(&lock_queue);
@@ -174,7 +174,7 @@
  		set_bit(PG_decr_after, &page->flags);
  		atomic_inc(&nr_async_pages);
  	}
- 	if (PageSwapCache(page)) {
+ 	if (!shmfs) {
  		/* only lock/unlock swap cache pages! */
  		set_bit(PG_swap_unlock_after, &page->flags);
  	}
@@ -256,7 +256,7 @@
 		printk ("swap entry mismatch");
 		return;
 	}
-	rw_swap_page_base(rw, entry, page, wait);
+	rw_swap_page_base(rw, entry, page, wait, 0);
 }
 
 /*
@@ -270,7 +270,7 @@
 	page = mem_map + MAP_NR((unsigned long) buffer);
 	wait_on_page(page);
 	set_bit(PG_locked, &page->flags);
-	if (test_and_set_bit(PG_swap_cache, &page->flags)) {
+	if (test_bit(PG_swap_cache, &page->flags)) {
 		printk ("VM: read_swap_page: page already in swap cache!\n");
 		return;
 	}
@@ -278,13 +278,9 @@
 		printk ("VM: read_swap_page: page already in page cache!\n");
 		return;
 	}
-	page->inode = &swapper_inode;
 	page->offset = entry;
-	atomic_inc(&page->count);	/* Protect from shrink_mmap() */
-	rw_swap_page(rw, entry, buffer, 1);
+	rw_swap_page_base(rw, entry, page, 1, 0);
 	atomic_dec(&page->count);
-	page->inode = 0;
-	clear_bit(PG_swap_cache, &page->flags);
 }
 
 /*
@@ -305,5 +301,5 @@
 		printk ("VM: rw_swap_page_nolock: page in swap cache!\n");
 		return;
 	}
-	rw_swap_page_base(rw, entry, page, wait);
+	rw_swap_page_base(rw, entry, page, wait, 1);
 }
linux/swap.h renamed from usr/tmp/p_rdiff_a005UY/swap.h +0 -7
@@ -144,13 +144,6 @@
 extern unsigned long swap_cache_find_success;
 #endif
 
-extern inline unsigned long in_swap_cache(struct page *page)
-{
-	if (PageSwapCache(page))
-		return page->offset;
-	return 0;
-}
-
 /*
  * Work out if there are any other processes sharing this page, ignoring
  * any page reference coming from the swap cache, or from outstanding

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#1 lore raw

Hi,

Quoted 2 lines · On Sat, 19 Jun 1999 16:14:26 -0700 (PDT), [email protected] (Kanoj…

There is no reason for shared memory pages to have to be marked PG_swap_cache to fool the underlying swap io routines.

That code was never intended to "fool" anyone: the swap IO code is able to do read/write swap even in the absense of swap cache entries for the page. Only recently have we forced all swap to go through the swap cache, but the IO routines are still capable of doing it both ways.

page_io.c line 90

Quoted 5 lines
page_io.c renamed from usr/tmp/p_rdiff_a005Qw/page_io.c +1 -1
-	if (PageSwapCache(page)) {
+	if (!shmfs) {
 		/* Make sure we are the only process doing I/O with this swap page. */
 		while (test_and_set_bit(offset,p->swap_lockmap)) {
 			run_task_queue(&tq_disk);

This looks wrong, conceptually. I'd prefer to see us do the locking any time the page happens to have an appropriate swap lock map bit. PageSwapCache() is the right test in this case: the rw_swap_page stuff shouldn't care about whether it is shmfs calling it or not. It should just care about doing the swap cache locking correctly if that happens to be required.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#2 lore raw
Quoted 27 lines

Hi,

Quoted 2 lines · On Sat, 19 Jun 1999 16:14:26 -0700 (PDT), [email protected] (Kanoj…

There is no reason for shared memory pages to have to be marked PG_swap_cache to fool the underlying swap io routines.

That code was never intended to "fool" anyone: the swap IO code is able to do read/write swap even in the absense of swap cache entries for the page. Only recently have we forced all swap to go through the swap cache, but the IO routines are still capable of doing it both ways.

Review

Quoted 5 lines
(quoted diff) +1 -1
-	if (PageSwapCache(page)) {
+	if (!shmfs) {
 		/* Make sure we are the only process doing I/O with this swap page. */
 		while (test_and_set_bit(offset,p->swap_lockmap)) {
 			run_task_queue(&tq_disk);

This looks wrong, conceptually. I'd prefer to see us do the locking any time the page happens to have an appropriate swap lock map bit. PageSwapCache() is the right test in this case: the rw_swap_page stuff shouldn't care about whether it is shmfs calling it or not. It should just care about doing the swap cache locking correctly if that happens to be required.

Quoted 2 lines

--Stephen

Okay, wrong choice of name on the parameter "shmfs". Would it help to think of the new last parameter to rw_swap_page_base as "dolock", which the caller has to pass in to indicate whether there is a swap lock map bit?

I am reposting the patch with this change, specially since there is a page reference count problem on the original patch.

Thanks.

Kanoj
[email protected]

page_io.c renamed from page_io.old +8 -13
@@ -35,7 +35,7 @@
  * that shared pages stay shared while being swapped.
  */
 
-static void rw_swap_page_base(int rw, unsigned long entry, struct page *page, int wait)
+static void rw_swap_page_base(int rw, unsigned long entry, struct page *page, int wait, int dolock)
 {
 	unsigned long type, offset;
 	struct swap_info_struct * p;
@@ -84,7 +84,7 @@
 		return;
 	}
 
-	if (PageSwapCache(page)) {
+	if (dolock) {
 		/* Make sure we are the only process doing I/O with this swap page. */
 		while (test_and_set_bit(offset,p->swap_lockmap)) {
 			run_task_queue(&tq_disk);
@@ -162,7 +162,7 @@
 		/* Do some cleaning up so if this ever happens we can hopefully
 		 * trigger controlled shutdown.
 		 */
-		if (PageSwapCache(page)) {
+		if (dolock) {
 			if (!test_and_clear_bit(offset,p->swap_lockmap))
 				printk("swap_after_unlock_page: lock already cleared\n");
 			wake_up(&lock_queue);
@@ -174,7 +174,7 @@
  		set_bit(PG_decr_after, &page->flags);
  		atomic_inc(&nr_async_pages);
  	}
- 	if (PageSwapCache(page)) {
+ 	if (dolock) {
  		/* only lock/unlock swap cache pages! */
  		set_bit(PG_swap_unlock_after, &page->flags);
  	}
@@ -256,7 +256,7 @@
 		printk ("swap entry mismatch");
 		return;
 	}
-	rw_swap_page_base(rw, entry, page, wait);
+	rw_swap_page_base(rw, entry, page, wait, 1);
 }
 
 /*
@@ -270,7 +270,7 @@
 	page = mem_map + MAP_NR((unsigned long) buffer);
 	wait_on_page(page);
 	set_bit(PG_locked, &page->flags);
-	if (test_and_set_bit(PG_swap_cache, &page->flags)) {
+	if (test_bit(PG_swap_cache, &page->flags)) {
 		printk ("VM: read_swap_page: page already in swap cache!\n");
 		return;
 	}
@@ -278,13 +278,8 @@
 		printk ("VM: read_swap_page: page already in page cache!\n");
 		return;
 	}
-	page->inode = &swapper_inode;
 	page->offset = entry;
-	atomic_inc(&page->count);	/* Protect from shrink_mmap() */
-	rw_swap_page(rw, entry, buffer, 1);
-	atomic_dec(&page->count);
-	page->inode = 0;
-	clear_bit(PG_swap_cache, &page->flags);
+	rw_swap_page_base(rw, entry, page, 1, 1);
 }
 
 /*
@@ -305,5 +300,5 @@
 		printk ("VM: rw_swap_page_nolock: page in swap cache!\n");
 		return;
 	}
-	rw_swap_page_base(rw, entry, page, wait);
+	rw_swap_page_base(rw, entry, page, wait, 0);
 }
linux/swap.h renamed from usr/tmp/p_rdiff_a005UY/swap.h +0 -7
@@ -144,13 +144,6 @@
 extern unsigned long swap_cache_find_success;
 #endif
 
-extern inline unsigned long in_swap_cache(struct page *page)
-{
-	if (PageSwapCache(page))
-		return page->offset;
-	return 0;
-}
-
 /*
  * Work out if there are any other processes sharing this page, ignoring
  * any page reference coming from the swap cache, or from outstanding

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#3 lore raw

Hi,

Quoted 4 lines · On Mon, 21 Jun 1999 10:17:10 -0700 (PDT), [email protected] (Kanoj…

Okay, wrong choice of name on the parameter "shmfs". Would it help to think of the new last parameter to rw_swap_page_base as "dolock", which the caller has to pass in to indicate whether there is a swap lock map bit?

Maybe, but I still don't see what it buys.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#4 lore raw
Quoted 7 lines · Stephen C. Tweedie
Quoted 4 lines · On Mon, 21 Jun 1999 10:17:10 -0700 (PDT), [email protected] (Kanoj…

Okay, wrong choice of name on the parameter "shmfs". Would it help to think of the new last parameter to rw_swap_page_base as "dolock", which the caller has to pass in to indicate whether there is a swap lock map bit?

Kanoj did you took a look at my VM (I pointed out to you the url some time ago). Here I just safely removed the swaplockmap completly. All the page-contentions get automagically resolved from the swap cache also for shm.c. I sent the relevant patches to Linus just before the page cache code gone and the new page/buffer cache broken them in part. But now I am running again rock solid with 2.3.7_andrea1 with SMP so if Linus will agree I'll return to send him patches about such shm/swap-lockmap issue. Just to show you:

andrea@laser:/usr/src$ cvs diff -u -r linux-2_3_7 linux/mm/page_io.c|diffstat
 page_io.c |  129 ++------------------------------------------------------------
 1 files changed, 6 insertions, 123 deletions

(should be enough to explain the thing :)

Andrea Arcangeli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#5 lore raw

Re: [RFC] [RFT] [PATCH] kanoj-mm9-2.2.10 simplify swapcache/shm code

Quoted 11 lines · Stephen C. Tweedie
Quoted 8 lines
Quoted 4 lines · On Mon, 21 Jun 1999 10:17:10 -0700 (PDT), [email protected] (Kanoj…

Okay, wrong choice of name on the parameter "shmfs". Would it help to think of the new last parameter to rw_swap_page_base as "dolock", which the caller has to pass in to indicate whether there is a swap lock map bit?

Quoted 9 lines

Kanoj did you took a look at my VM (I pointed out to you the url some time ago). Here I just safely removed the swaplockmap completly. All the page-contentions get automagically resolved from the swap cache also for shm.c. I sent the relevant patches to Linus just before the page cache code gone and the new page/buffer cache broken them in part. But now I am running again rock solid with 2.3.7_andrea1 with SMP so if Linus will agree I'll return to send him patches about such shm/swap-lockmap issue. Just to show you:

I skimmed thru your patch earlier, but was too lazy to concentrate on the details ...

I took the time now to look into your changes to page_io.c and shm.c, and I like it better than the current code, for the reason that pages marked PageSwapCache will actually end up being in the swap cache. Which is what I was trying to do in my patch ...

If Linus is willing to take your patch, we can stop talking about mine ...

Thanks.

Kanoj
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/