Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1575329

[PATCH] swapfile: initialize spinlock for swap_cluster_info

From Minchan Kim <minchan@kernel.org>
Newsgroups linux.kernel
Subject [PATCH] swapfile: initialize spinlock for swap_cluster_info
Date 2017-02-07 03:40 +0100
Message-ID <t83Rg-50z-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


We changed swap_cluster_info lock from bit_spin_lock to spinlock
so we need to initialize the spinlock before the using. Otherwise,
lockdep is broken.

Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
Andrew,
I think it's no worth to add this patch to separate commit.
If you don't mind, it's okay to fold this patch to mm-swap-add-cluster-lock-v5.
Thanks.

 mm/swapfile.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 1fc1824140e1..5ac2cb40dbd3 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2762,6 +2762,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 
 	if (p->bdev && blk_queue_nonrot(bdev_get_queue(p->bdev))) {
 		int cpu;
+		unsigned long ci, nr_cluster;
 
 		p->flags |= SWP_SOLIDSTATE;
 		/*
@@ -2769,13 +2770,17 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 		 * SSD
 		 */
 		p->cluster_next = 1 + (prandom_u32() % p->highest_bit);
+		nr_cluster = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER);
 
-		cluster_info = vzalloc(DIV_ROUND_UP(maxpages,
-			SWAPFILE_CLUSTER) * sizeof(*cluster_info));
+		cluster_info = vzalloc(nr_cluster * sizeof(*cluster_info));
 		if (!cluster_info) {
 			error = -ENOMEM;
 			goto bad_swap;
 		}
+
+		for (ci = 0; ci < nr_cluster; ci++)
+			spin_lock_init(&((cluster_info + ci)->lock));
+
 		p->percpu_cluster = alloc_percpu(struct percpu_cluster);
 		if (!p->percpu_cluster) {
 			error = -ENOMEM;
-- 
2.7.4

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH] swapfile: initialize spinlock for swap_cluster_info Minchan Kim <minchan@kernel.org> - 2017-02-07 03:40 +0100
  Re: [PATCH] swapfile: initialize spinlock for swap_cluster_info "Huang\, Ying" <ying.huang@intel.com> - 2017-02-07 04:00 +0100

csiph-web