mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 08/13] get_swap_page drop swap_list_lock
Date: Sat, 9 Jul 2005 01:07:37 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0507090106320.13391@goblin.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0507090057340.13391@goblin.wat.veritas.com>

Rewrite get_swap_page to allocate in just the same sequence as before,
but without holding swap_list_lock across its scan_swap_map.  Decrement
nr_swap_pages and update swap_list.next in advance, while still holding
swap_list_lock.  Skip full devices by testing highest_bit.  Swapoff hold
swap_device_lock as well as swap_list_lock to clear SWP_WRITEOK.  Reduces
lock contention when there are parallel swap devices of the same priority.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---

 mm/swapfile.c |   73 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 35 insertions(+), 38 deletions(-)

--- swap7/mm/swapfile.c	2005-07-08 19:14:39.000000000 +0100
+++ swap8/mm/swapfile.c	2005-07-08 19:14:54.000000000 +0100
@@ -137,7 +137,6 @@ static inline unsigned long scan_swap_ma
 		}
 		si->swap_map[offset] = 1;
 		si->inuse_pages++;
-		nr_swap_pages--;
 		si->cluster_next = offset+1;
 		return offset;
 	}
@@ -148,50 +147,45 @@ static inline unsigned long scan_swap_ma
 
 swp_entry_t get_swap_page(void)
 {
-	struct swap_info_struct * p;
-	unsigned long offset;
-	swp_entry_t entry;
-	int type, wrapped = 0;
+	struct swap_info_struct *si;
+	pgoff_t offset;
+	int type, next;
+	int wrapped = 0;
 
-	entry.val = 0;	/* Out of memory */
 	swap_list_lock();
-	type = swap_list.next;
-	if (type < 0)
-		goto out;
 	if (nr_swap_pages <= 0)
-		goto out;
+		goto noswap;
+	nr_swap_pages--;
 
-	while (1) {
-		p = &swap_info[type];
-		if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {
-			swap_device_lock(p);
-			offset = scan_swap_map(p);
-			swap_device_unlock(p);
-			if (offset) {
-				entry = swp_entry(type,offset);
-				type = swap_info[type].next;
-				if (type < 0 ||
-					p->prio != swap_info[type].prio) {
-						swap_list.next = swap_list.head;
-				} else {
-					swap_list.next = type;
-				}
-				goto out;
-			}
+	for (type = swap_list.next; type >= 0 && wrapped < 2; type = next) {
+		si = swap_info + type;
+		next = si->next;
+		if (next < 0 ||
+		    (!wrapped && si->prio != swap_info[next].prio)) {
+			next = swap_list.head;
+			wrapped++;
 		}
-		type = p->next;
-		if (!wrapped) {
-			if (type < 0 || p->prio != swap_info[type].prio) {
-				type = swap_list.head;
-				wrapped = 1;
-			}
-		} else
-			if (type < 0)
-				goto out;	/* out of swap space */
+
+		if (!si->highest_bit)
+			continue;
+		if (!(si->flags & SWP_WRITEOK))
+			continue;
+
+		swap_list.next = next;
+		swap_device_lock(si);
+		swap_list_unlock();
+		offset = scan_swap_map(si);
+		swap_device_unlock(si);
+		if (offset)
+			return swp_entry(type, offset);
+		swap_list_lock();
+		next = swap_list.next;
 	}
-out:
+
+	nr_swap_pages++;
+noswap:
 	swap_list_unlock();
-	return entry;
+	return (swp_entry_t) {0};
 }
 
 static struct swap_info_struct * swap_info_get(swp_entry_t entry)
@@ -1103,8 +1097,11 @@ asmlinkage long sys_swapoff(const char _
 	}
 	nr_swap_pages -= p->pages;
 	total_swap_pages -= p->pages;
+	swap_device_lock(p);
 	p->flags &= ~SWP_WRITEOK;
+	swap_device_unlock(p);
 	swap_list_unlock();
+
 	current->flags |= PF_SWAPOFF;
 	err = try_to_unuse(type);
 	current->flags &= ~PF_SWAPOFF;

  parent reply	other threads:[~2005-07-09  0:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09  0:00 [PATCH 00/13] some swapfile patches Hugh Dickins
2005-07-09  0:01 ` [PATCH 01/13] update swapfile i_sem comment Hugh Dickins
2005-07-09  0:01 ` [PATCH 02/13] correct swapfile nr_good_pages Hugh Dickins
2005-07-09  0:02 ` [PATCH 03/13] move destroy_swap_extents calls Hugh Dickins
2005-07-09  0:03 ` [PATCH 04/13] swap extent list is ordered Hugh Dickins
2005-07-09  0:04 ` [PATCH 05/13] show span of swap extents Hugh Dickins
2005-07-09  0:05 ` [PATCH 06/13] swap unsigned int consistency Hugh Dickins
2005-07-09  0:06 ` [PATCH 07/13] freeing update swap_list.next Hugh Dickins
2005-07-09  0:07 ` Hugh Dickins [this message]
2005-07-09  0:08 ` [PATCH 09/13] scan_swap_map restyled Hugh Dickins
2005-07-09  0:09 ` [PATCH 10/13] scan_swap_map drop swap_device_lock Hugh Dickins
2005-07-09  0:10 ` [PATCH 11/13] scan_swap_map latency breaks Hugh Dickins
2005-07-09  0:11 ` [PATCH 12/13] swap_lock replace list+device Hugh Dickins
2005-07-09  0:15 ` [PATCH 13/13] update swsusp use of swap_info Hugh Dickins
2005-07-09 11:13   ` [PATCH 14/13] swsusp mod needed parentheses Hugh Dickins

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=Pine.LNX.4.61.0507090106320.13391@goblin.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@osdl.org \
    --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

all inboxes | Powered by JetHome®