From patchwork Tue Jan 12 06:49:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 8014221 X-Patchwork-Delegate: axboe@kernel.dk Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 01053BEEE5 for ; Tue, 12 Jan 2016 06:57:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0C82420379 for ; Tue, 12 Jan 2016 06:57:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22938201F4 for ; Tue, 12 Jan 2016 06:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761469AbcALGvP (ORCPT ); Tue, 12 Jan 2016 01:51:15 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36363 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760963AbcALGuI (ORCPT ); Tue, 12 Jan 2016 01:50:08 -0500 Received: by mail-wm0-f41.google.com with SMTP id l65so238870353wmf.1 for ; Mon, 11 Jan 2016 22:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=M5bUCUIwAEu+3jdYcfzqSN3rGeJ1Xv2FMOPVHJcMbc8=; b=fGwaEcEJaYZsMYEYIpPdXIkTI23wtpqf+8glO5iN+TV+q1qBiiHq7uX5YGpVTftGlS vLSfWUTBG/FB2/AXqb7ZKSrmlhFIFXvOc4XSIjCefwTqQSczKO1s+C87Xlqyfx7PSJsi XDuef23zEvu/4V+sLDvQEPEQi1zpK1ohz0560= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=M5bUCUIwAEu+3jdYcfzqSN3rGeJ1Xv2FMOPVHJcMbc8=; b=SAMZKLwsGwdtpatqnvQonI/UuRmuvfOUIUEUnLag6thlKbdx9oteY26k9uWlUVVT+g bYpQOVOGVecWXHq+GgHSaGrgM0KTYSTo33S/hxSnETWGX4AnpnXez5iy+odVsB5Te409 olqSFWdSqAfjc/L9QHut/GxwPf79WY2jRK8jHjHt6nJMVn8OXn9Hs6+Mjv9Ju3I0D6Zb AEbngRrM8S/esvAVJfIps+7vuQGIBzFqX4Wlows5joAFiwW6h+MS4TF8/paTNFSUdrlW zQV/obok8bZ7Oue3pQM+DQnlkbEqoTGgbRnpASJiwA9iMdvh/fILNMws9YcaP0ZmUU9N K7Sw== X-Gm-Message-State: ALoCoQkEj+MMuPDLKQWOiWX7Gd5lGD9lqC4KCQFt9HheSpAi0+liS4a1SpjAu0wSamZ1wBEdvmTrYd6x8zmMUEgwpQY2yDM2ig== X-Received: by 10.28.170.139 with SMTP id t133mr18523620wme.50.1452581407332; Mon, 11 Jan 2016 22:50:07 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id yz5sm70776886wjc.36.2016.01.11.22.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 22:50:06 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: Wenwei Tao , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 11/25] lightnvm: fix locking and mempool in rrpc_lun_gc Date: Tue, 12 Jan 2016 07:49:25 +0100 Message-Id: <1452581379-18162-12-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452581379-18162-1-git-send-email-m@bjorling.me> References: <1452581379-18162-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wenwei Tao This patch fix two issues in rrpc_lun_gc 1. prio_list is protected by rrpc_lun's lock not nvm_lun's, so acquire rlun's lock instead of lun's before operate on the list. 2. we delete block from prio_list before allocating gcb, but gcb allocation may fail, we end without putting it back to the list, this makes the block won't get reclaimed in the future. To solve this issue, delete block after gcb allocation. Signed-off-by: Wenwei Tao Signed-off-by: Matias Bjørling --- drivers/lightnvm/rrpc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index bee2352..745acd9 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -445,7 +445,7 @@ static void rrpc_lun_gc(struct work_struct *work) if (nr_blocks_need < rrpc->nr_luns) nr_blocks_need = rrpc->nr_luns; - spin_lock(&lun->lock); + spin_lock(&rlun->lock); while (nr_blocks_need > lun->nr_free_blocks && !list_empty(&rlun->prio_list)) { struct rrpc_block *rblock = block_prio_find_max(rlun); @@ -454,16 +454,16 @@ static void rrpc_lun_gc(struct work_struct *work) if (!rblock->nr_invalid_pages) break; + gcb = mempool_alloc(rrpc->gcb_pool, GFP_ATOMIC); + if (!gcb) + break; + list_del_init(&rblock->prio); BUG_ON(!block_is_full(rrpc, rblock)); pr_debug("rrpc: selected block '%lu' for GC\n", block->id); - gcb = mempool_alloc(rrpc->gcb_pool, GFP_ATOMIC); - if (!gcb) - break; - gcb->rrpc = rrpc; gcb->rblk = rblock; INIT_WORK(&gcb->ws_gc, rrpc_block_gc); @@ -472,7 +472,7 @@ static void rrpc_lun_gc(struct work_struct *work) nr_blocks_need--; } - spin_unlock(&lun->lock); + spin_unlock(&rlun->lock); /* TODO: Hint that request queue can be started again */ }