public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nathan D. Fabian" <ndfabia@sandia.gov>
To: linux-kernel@vger.kernel.org
Subject: [Patch] swapfile.c
Date: Tue, 19 Jun 2001 18:24:25 -0600	[thread overview]
Message-ID: <01061918242500.00988@sphinx> (raw)

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

The following diff tries to improve on the efficiency of try_to_unuse().  It 
removes the potential O(|swap_map|^2) business and makes it linear time.  
I'm not sure what this means in terms of overall change, but Linus seemed 
interested in the innefficiency in that code.  Test with caution.

Nathan.

[-- Attachment #2: swapfile.diff --]
[-- Type: text/x-c, Size: 3018 bytes --]

diff -uwrN linux/mm/swapfile.c.old linux/mm/swapfile.c
--- linux/mm/swapfile.c.old	Tue Jun 19 17:15:07 2001
+++ linux/mm/swapfile.c	Tue Jun 19 17:44:24 2001
@@ -328,6 +328,41 @@
 	return;
 }
 
+static int unuse_entry (swp_entry_t entry) {
+	struct page *page;
+	struct task_struct *p;
+
+	/* Get a page for the entry, using the existing swap
+       	cache page if there is one.  Otherwise, get a clean
+       	page and read the swap into it. */
+	page = read_swap_cache_async(entry);
+	if (!page) {
+		swap_free(entry);
+		return -ENOMEM;
+	}
+
+	lock_page (page);
+	if (PageSwapCache(page))
+		delete_from_swap_cache_nolock(page);
+	UnlockPage (page);
+
+	read_lock(&tasklist_lock);
+	for_each_task(p)
+		unuse_process(p->mm, entry, page);
+	read_unlock(&tasklist_lock);
+
+	shmem_unuse(entry, page);
+	/* Now get rid of the extra reference to the temporary
+                 	page we've been using. */
+	page_cache_release(page);
+	/*
+ 	* Check for and clear any overflowed swap map counts.
+ 	*/
+	swap_free(entry);
+
+	return 0;
+}
+
 /*
  * We completely avoid races by reading each swap page in advance,
  * and then search for the process using it.  All the necessary
@@ -336,12 +371,10 @@
 static int try_to_unuse(unsigned int type)
 {
 	struct swap_info_struct * si = &swap_info[type];
-	struct task_struct *p;
-	struct page *page;
 	swp_entry_t entry;
 	int i;
+	int err;
 
-	while (1) {
 		/*
 		 * Find a swap page in use and read it in.
 		 */
@@ -356,42 +389,19 @@
 				 */
 				if (si->swap_map[i] != SWAP_MAP_MAX)
 					si->swap_map[i]++;
+
 				swap_device_unlock(si);
-				goto found_entry;
-			}
-		}
-		swap_device_unlock(si);
-		break;
 
-	found_entry:
 		entry = SWP_ENTRY(type, i);
-
-		/* Get a page for the entry, using the existing swap
-                   cache page if there is one.  Otherwise, get a clean
-                   page and read the swap into it. */
-		page = read_swap_cache_async(entry);
-		if (!page) {
-			swap_free(entry);
-  			return -ENOMEM;
+			err = unuse_entry (entry);
+			if (err < 0) {
+				return err;
 		}
-		lock_page(page);
-		if (PageSwapCache(page))
-			delete_from_swap_cache_nolock(page);
-		UnlockPage(page);
-		read_lock(&tasklist_lock);
-		for_each_task(p)
-			unuse_process(p->mm, entry, page);
-		read_unlock(&tasklist_lock);
-		shmem_unuse(entry, page);
-		/* Now get rid of the extra reference to the temporary
-                   page we've been using. */
-		page_cache_release(page);
-		/*
-		 * Check for and clear any overflowed swap map counts.
-		 */
-		swap_free(entry);
-		swap_list_lock();
+
 		swap_device_lock(si);
+
+			swap_list_lock();
+			/* check this value again after unusing the entry */
 		if (si->swap_map[i] > 0) {
 			if (si->swap_map[i] != SWAP_MAP_MAX)
 				printk("VM: Undead swap entry %08lx\n", 
@@ -399,9 +409,13 @@
 			nr_swap_pages++;
 			si->swap_map[i] = 0;
 		}
-		swap_device_unlock(si);
 		swap_list_unlock();
+
+			/* Leave the device locked for loop */
+		}
 	}
+	swap_device_unlock (si);
+
 	return 0;
 }
 

             reply	other threads:[~2001-06-20  0:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-20  0:24 Nathan D. Fabian [this message]
2001-06-20 15:16 ` [Patch] swapfile.c Nathan D. Fabian
  -- strict thread matches above, loose matches on Subject: below --
2002-03-02 21:25 [PATCH] swapfile.c Andries.Brouwer
2002-03-04 11:28 ` Andrey Panin
2002-03-04 18:48   ` Robert Love
2002-03-04 19:14     ` Dave Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01061918242500.00988@sphinx \
    --to=ndfabia@sandia.gov \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox