From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752109AbdBGCxB (ORCPT ); Mon, 6 Feb 2017 21:53:01 -0500 Received: from mga14.intel.com ([192.55.52.115]:32444 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456AbdBGCxA (ORCPT ); Mon, 6 Feb 2017 21:53:00 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,344,1477983600"; d="scan'208";a="222140824" From: "Huang\, Ying" To: Minchan Kim Cc: Andrew Morton , , , Tim Chen , Huang Ying , Hugh Dickins Subject: Re: [PATCH] swapfile: initialize spinlock for swap_cluster_info References: <1486434945-29753-1-git-send-email-minchan@kernel.org> Date: Tue, 07 Feb 2017 10:52:57 +0800 In-Reply-To: <1486434945-29753-1-git-send-email-minchan@kernel.org> (Minchan Kim's message of "Tue, 7 Feb 2017 11:35:45 +0900") Message-ID: <87vasmg19y.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Minchan, Minchan Kim writes: > 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 > Cc: Huang Ying > Cc: Hugh Dickins > Signed-off-by: Minchan Kim Good catch! Thanks a lot for your fixing! Reviewed-by: "Huang, Ying" Best Regards, Huang, Ying > --- > 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; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id BF3F86B0033 for ; Mon, 6 Feb 2017 21:53:00 -0500 (EST) Received: by mail-pg0-f70.google.com with SMTP id d185so129905970pgc.2 for ; Mon, 06 Feb 2017 18:53:00 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id u22si2583727plk.137.2017.02.06.18.52.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 18:52:59 -0800 (PST) From: "Huang\, Ying" Subject: Re: [PATCH] swapfile: initialize spinlock for swap_cluster_info References: <1486434945-29753-1-git-send-email-minchan@kernel.org> Date: Tue, 07 Feb 2017 10:52:57 +0800 In-Reply-To: <1486434945-29753-1-git-send-email-minchan@kernel.org> (Minchan Kim's message of "Tue, 7 Feb 2017 11:35:45 +0900") Message-ID: <87vasmg19y.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: owner-linux-mm@kvack.org List-ID: To: Minchan Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Tim Chen , Huang Ying , Hugh Dickins Hi, Minchan, Minchan Kim writes: > 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 > Cc: Huang Ying > Cc: Hugh Dickins > Signed-off-by: Minchan Kim Good catch! Thanks a lot for your fixing! Reviewed-by: "Huang, Ying" Best Regards, Huang, Ying > --- > 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; -- 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/ . Don't email: email@kvack.org