2.3.29 patch for releasing swap cache pages on exit and fixing race in do_swap_page.Larry

Message ID 384D26E6.6E21C624@missioncriticallinux.com
State New, archived
Headers show
Series
  • 2.3.29 patch for releasing swap cache pages on exit and fixing race in do_swap_page.Larry
Related show

Commit Message

Larry Woodman Dec. 7, 1999, 3:25 p.m. UTC
We have run into two problems in 2.3 related to the swap cache: 1.) When
a process
exits, some of its private pages can remain in the swap cache and tie up
swap space
unless shrink_mmap runs.  2.) What looks like a race  between
do_swap_page
and shrink_mmap.

Here is my attempt at a patch that fixes both problems.

Larry Woodman
http://www/missioncriticallinux.com

Patch

--- mm/memory.c.sav	Tue Dec  7 10:04:33 1999
+++ mm/memory.c	Tue Dec  7 10:06:14 1999
@@ -1004,12 +1004,15 @@ 
 	pte = mk_pte(page, vma->vm_page_prot);
 
 	set_bit(PG_swap_entry, &page->flags);
+	lock_page(page);
 	if (write_access && !is_page_shared(page)) {
-		delete_from_swap_cache(page);
+		delete_from_swap_cache_nolock(page);
+		UnlockPage(page);
 		page = replace_with_highmem(page);
 		pte = mk_pte(page, vma->vm_page_prot);
 		pte = pte_mkwrite(pte_mkdirty(pte));
-	}
+	} else
+		UnlockPage(page);
 	set_pte(page_table, pte);
 	/* No need to invalidate - it was non-present before */
 	update_mmu_cache(vma, address, pte);
--- mm/swap_state.c.sav	Wed Dec  1 18:20:23 1999
+++ mm/swap_state.c	Tue Dec  7 10:07:17 1999
@@ -171,7 +171,7 @@ 
 	unlock_kernel();
 }
 
-static void delete_from_swap_cache_nolock(struct page *page)
+void delete_from_swap_cache_nolock(struct page *page)
 {
 	if (block_flushpage(NULL, page, 0))
 		lru_cache_del(page);
--- include/linux/swap.h.sav	Wed Dec  1 12:28:42 1999
+++ include/linux/swap.h	Tue Dec  7 10:01:16 1999
@@ -147,8 +147,9 @@ 
 	if (PageReserved(page))
 		return 1;
 	count = page_count(page);
-	if (PageSwapCache(page))
-		count += swap_count(page) - 2;
+	if (PageSwapCache(page)) 
+		/* page_count is 3 if shrink_mmap didnt free buffer yet */
+		count += swap_count(page) - 2 - !!page->buffers;
 	return  count > 1;
 }