From: Cesar Eduardo Barros <cesarb@cesarb.net>
To: linux-mm@kvack.org
Cc: Cesar Eduardo Barros <cesarb@cesarb.net>
Subject: [PATCH 24/24] sys_swapon: separate final enabling of the swapfile
Date: Sat, 12 Feb 2011 16:49:25 -0200 [thread overview]
Message-ID: <1297536565-8059-24-git-send-email-cesarb@cesarb.net> (raw)
In-Reply-To: <4D56D5F9.8000609@cesarb.net>
The block in sys_swapon which does the final adjustments to the
swap_info_struct and to swap_list is the same as the block which
re-inserts it again at sys_swapoff on failure of try_to_unuse(). Move
this code to a separate function, and use it both in sys_swapon and
sys_swapoff.
Signed-off-by: Cesar Eduardo Barros <cesarb@cesarb.net>
---
mm/swapfile.c | 84 ++++++++++++++++++++++++++++----------------------------
1 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index deeb0b1..100236b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1550,6 +1550,36 @@ bad_bmap:
goto out;
}
+static void enable_swap_info(struct swap_info_struct *p, int prio,
+ unsigned char *swap_map)
+{
+ int i, prev;
+
+ spin_lock(&swap_lock);
+ if (prio >= 0)
+ p->prio = prio;
+ else
+ p->prio = --least_priority;
+ p->swap_map = swap_map;
+ p->flags |= SWP_WRITEOK;
+ nr_swap_pages += p->pages;
+ total_swap_pages += p->pages;
+
+ /* insert swap space into swap_list: */
+ prev = -1;
+ for (i = swap_list.head; i >= 0; i = swap_info[i]->next) {
+ if (p->prio >= swap_info[i]->prio)
+ break;
+ prev = i;
+ }
+ p->next = i;
+ if (prev < 0)
+ swap_list.head = swap_list.next = p->type;
+ else
+ swap_info[prev]->next = p->type;
+ spin_unlock(&swap_lock);
+}
+
SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
{
struct swap_info_struct *p = NULL;
@@ -1621,26 +1651,14 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
current->flags &= ~PF_OOM_ORIGIN;
if (err) {
+ /*
+ * reading p->prio and p->swap_map outside the lock is
+ * safe here because only sys_swapon and sys_swapoff
+ * change them, and there can be no other sys_swapon or
+ * sys_swapoff for this swap_info_struct at this point.
+ */
/* re-insert swap space back into swap_list */
- spin_lock(&swap_lock);
- if (p->prio < 0)
- p->prio = --least_priority;
- p->flags |= SWP_WRITEOK;
- nr_swap_pages += p->pages;
- total_swap_pages += p->pages;
-
- prev = -1;
- for (i = swap_list.head; i >= 0; i = swap_info[i]->next) {
- if (p->prio >= swap_info[i]->prio)
- break;
- prev = i;
- }
- p->next = i;
- if (prev < 0)
- swap_list.head = swap_list.next = type;
- else
- swap_info[prev]->next = type;
- spin_unlock(&swap_lock);
+ enable_swap_info(p, p->prio, p->swap_map);
goto out_dput;
}
@@ -2037,7 +2055,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
char *name;
struct file *swap_file = NULL;
struct address_space *mapping;
- int i, prev;
+ int i;
+ int prio;
int error;
union swap_header *swap_header;
int nr_extents;
@@ -2134,30 +2153,11 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
}
mutex_lock(&swapon_mutex);
- spin_lock(&swap_lock);
+ prio = -1;
if (swap_flags & SWAP_FLAG_PREFER)
- p->prio =
+ prio =
(swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT;
- else
- p->prio = --least_priority;
- p->swap_map = swap_map;
- p->flags |= SWP_WRITEOK;
- nr_swap_pages += p->pages;
- total_swap_pages += p->pages;
-
- /* insert swap space into swap_list: */
- prev = -1;
- for (i = swap_list.head; i >= 0; i = swap_info[i]->next) {
- if (p->prio >= swap_info[i]->prio)
- break;
- prev = i;
- }
- p->next = i;
- if (prev < 0)
- swap_list.head = swap_list.next = p->type;
- else
- swap_info[prev]->next = p->type;
- spin_unlock(&swap_lock);
+ enable_swap_info(p, prio, swap_map);
printk(KERN_INFO "Adding %uk swap on %s. "
"Priority:%d extents:%d across:%lluk %s%s\n",
--
1.7.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-02-12 18:49 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-12 18:48 [PATCH 00/24] Refactor sys_swapon Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 01/24] sys_swapon: use vzalloc instead of vmalloc/memset Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 02/24] sys_swapon: remove changelog from function comment Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 03/24] sys_swapon: do not depend on "type" after allocation Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 04/24] sys_swapon: separate swap_info allocation Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 05/24] sys_swapon: simplify error return from " Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 06/24] sys_swapon: simplify error flow in alloc_swap_info Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 07/24] sys_swapon: remove initial value of name variable Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 08/24] sys_swapon: move setting of error nearer use Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 09/24] sys_swapon: remove did_down variable Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 10/24] sys_swapon: remove bdev variable Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 11/24] sys_swapon: do only cleanup in the cleanup blocks Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 12/24] sys_swapon: use a single error label Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 13/24] sys_swapon: separate bdev claim and inode lock Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 14/24] sys_swapon: simplify error flow in claim_swapfile Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 15/24] sys_swapon: move setting of swapfilepages near use Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 16/24] sys_swapon: separate parsing of swapfile header Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 17/24] sys_swapon: simplify error flow in read_swap_header Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 18/24] sys_swapon: call swap_cgroup_swapon earlier Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 19/24] sys_swapon: separate parsing of bad blocks and extents Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 20/24] sys_swapon: simplify error flow in setup_swap_map_and_extents Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 21/24] sys_swapon: remove nr_good_pages variable Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 22/24] sys_swapon: move printk outside lock Cesar Eduardo Barros
2011-02-12 18:49 ` [PATCH 23/24] sys_swapoff: change order to match sys_swapon Cesar Eduardo Barros
2011-02-12 18:49 ` Cesar Eduardo Barros [this message]
2011-03-01 18:20 ` [PATCH 00/24] Refactor sys_swapon Eric B Munson
2011-03-01 23:23 ` Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 " Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 01/24] sys_swapon: use vzalloc instead of vmalloc/memset Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 02/24] sys_swapon: remove changelog from function comment Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 03/24] sys_swapon: do not depend on "type" after allocation Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 04/24] sys_swapon: separate swap_info allocation Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 05/24] sys_swapon: simplify error return from " Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 06/24] sys_swapon: simplify error flow in alloc_swap_info Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 07/24] sys_swapon: remove initial value of name variable Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 08/24] sys_swapon: move setting of error nearer use Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 09/24] sys_swapon: remove did_down variable Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 10/24] sys_swapon: remove bdev variable Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 11/24] sys_swapon: do only cleanup in the cleanup blocks Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 12/24] sys_swapon: use a single error label Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 13/24] sys_swapon: separate bdev claim and inode lock Cesar Eduardo Barros
2011-03-02 21:40 ` Eric B Munson
2011-03-02 23:02 ` Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 14/24] sys_swapon: simplify error flow in claim_swapfile Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 15/24] sys_swapon: move setting of swapfilepages near use Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 16/24] sys_swapon: separate parsing of swapfile header Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 17/24] sys_swapon: simplify error flow in read_swap_header Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 18/24] sys_swapon: call swap_cgroup_swapon earlier Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 19/24] sys_swapon: separate parsing of bad blocks and extents Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 20/24] sys_swapon: simplify error flow in setup_swap_map_and_extents Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 21/24] sys_swapon: remove nr_good_pages variable Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 22/24] sys_swapon: move printk outside lock Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 23/24] sys_swapoff: change order to match sys_swapon Cesar Eduardo Barros
2011-03-01 23:28 ` [PATCHv2 24/24] sys_swapon: separate final enabling of the swapfile Cesar Eduardo Barros
2011-03-02 21:06 ` [PATCHv2 00/24] Refactor sys_swapon Eric B Munson
2011-03-02 21:43 ` Eric B Munson
2011-03-03 16:15 ` Eric B Munson
2011-03-04 22:54 ` Cesar Eduardo Barros
2011-03-04 22:58 ` Eric B Munson
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=1297536565-8059-24-git-send-email-cesarb@cesarb.net \
--to=cesarb@cesarb.net \
--cc=linux-mm@kvack.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