Skip to contentSkip to conversation

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

PATCH Larry Woodman 1 participant 1 message Dec 7, 1999

lore
Share & tools
lore
#0 lore raw

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

memory.c renamed from memory.c.sav +5 -2
@@ -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);
swap_state.c renamed from swap_state.c.sav +1 -1
@@ -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);
linux/swap.h renamed from linux/swap.h.sav +3 -2
@@ -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;
 }