Skip to contentSkip to conversation

mm: prototype: rid swapoff of quadratic complexity

RFC Hugh Dickins 1 participant 1 message Mar 23, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 10 lines · Kelley Nielsen

The function try_to_unuse() is of quadratic complexity, with a lot of wasted effort. It unuses swap entries one by one, potentially iterating over all the page tables for all the processes in the system for each one.

This new proposed implementation of try_to_unuse simplifies its complexity to linear. It iterates over the system's mms once, unusing all the affected entries as it walks each set of page tables. It also makes similar changes to shmem_unuse.

Quoted 8 lines

Improvement

Time took by swapoff on a swap partition containing about 240M of data, with about 1.1G free memory and about 520M swap available. Swap partition was on a laptop with a hard disk drive (not SSD).

Present implementation....about 13.8s
Prototype.................about 5.5s

I haven't studied the patch yet (and won't manage to do so in the week ahead), nor examined its performance; but I have taken it out for a spin, and I'm impressed by its robustness - swap being as racy as it is, I had expected plenty of trouble, but very little - well done.

Just three little self-explanatory fixes needed so far, all down at the out_put end: please fold in to your next version whenever.

Hugh

mm/swapfile.c +5 -3
@@ -1479,12 +1479,14 @@ out_put:
 		 * that we must not delete, since it may not have been written
 		 * out to swap yet.
 		 */
+		lock_page(page);
 		if (PageSwapCache(page) &&
-		    likely(page_private(page) == entry.val)){
-			lock_page(page);
+		    likely(page_private(page) == entry.val)) {
+			wait_on_page_writeback(page);
 			delete_from_swap_cache(page);
-			unlock_page(page);
 		}
+		unlock_page(page);
+		page_cache_release(page);
 	}
 out:
 	return retval;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>