From patchwork Fri Jun 19 07:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11613329 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3405E913 for ; Fri, 19 Jun 2020 07:51:23 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A66982078D for ; Fri, 19 Jun 2020 07:51:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZeHvv0Ev" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A66982078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592553081; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lWmS9J2mt+5cpMp0YVTBQIxCvldoDpeoIRsintgnM8Y=; b=ZeHvv0EvqW1DiCaqwtCbTJTSYUklebgMCZcCL04svxrE0et8n1E7EoJQeL3L4OW9uzbebr C0aMDffZE/Ku1y4azPuAn2mXV8e8DGAW41CilS+isXwM3iTOFFRkYjjwkvhaDbwyZRKM6F +OdYXLNugkeiRXG1jZiTjWvzY37qiKg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-qTFnqSvtO9OnvYDGfXdz0A-1; Fri, 19 Jun 2020 03:51:19 -0400 X-MC-Unique: qTFnqSvtO9OnvYDGfXdz0A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8C33EC1A0; Fri, 19 Jun 2020 07:51:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACC0A5C1D0; Fri, 19 Jun 2020 07:51:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7A28A180954D; Fri, 19 Jun 2020 07:51:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05J7p9Am022295 for ; Fri, 19 Jun 2020 03:51:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 700ED10EE828; Fri, 19 Jun 2020 07:51:09 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AF3F1000D90 for ; Fri, 19 Jun 2020 07:51:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A80E8007CB for ; Fri, 19 Jun 2020 07:51:06 +0000 (UTC) Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-R3KQ2Xe9Nfu8CdojmzFBlg-2; Fri, 19 Jun 2020 03:51:04 -0400 X-MC-Unique: R3KQ2Xe9Nfu8CdojmzFBlg-2 IronPort-SDR: B+TDjyFiyT/3lIBlAoMlNVneHyqsxMgt1L3VQOMhQnIFWL/9sxUKsBic+jUxfMliTE+Ut6AK+U CB4jrfoaQbNuUxWHLN0xE0yGv8SYSbSbGDz4jGgTKF7I4xLJ9kjM4UzsmQZYtgpowCkf+KHvlQ pC086r63Ku9Lc8e+W/8oGWdQrTRKq70EszhJ4hjhgC9Jf+omp7kzJMiPAkc2RGcoea7pl/wAJy UF+JcbxGAoKnArRjUEcEj/9n/N7xI4Ap1g2ZWySu+VpvfGGaU7rV8XiqmwpQuIGth81YK8GTm5 WMw= X-IronPort-AV: E=Sophos;i="5.75,254,1589212800"; d="scan'208";a="249594581" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 19 Jun 2020 15:49:58 +0800 IronPort-SDR: LUx//uy1SUB/1hpAcAlqZ6cv7VAcXmJRyojB4cokmgIMHUFtOr0ech8lumcqUxQt45m4HtN5Xq mTS1NIDK75CZOVZhlGiEawQlfg4y0X/bM= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2020 00:38:37 -0700 IronPort-SDR: dnSNJ47MK6VOo9E2UZguMXpSa7tzqmz+ikLmOrpfVbAKBCZU7OUrVK50jPV+IDT5ZdK13b0Ayj kaR2KHcU/ImQ== WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Jun 2020 00:49:58 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer Date: Fri, 19 Jun 2020 16:49:55 +0900 Message-Id: <20200619074956.352647-2-damien.lemoal@wdc.com> In-Reply-To: <20200619074956.352647-1-damien.lemoal@wdc.com> References: <20200619074956.352647-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: dm-devel@redhat.com Cc: Shin'ichiro Kawasaki Subject: [dm-devel] [PATCH 1/2] dm zoned: Fix random zone reclaim selection X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Commit 2094045fe5b5 ("dm zoned: prefer full zones for reclaim") modified dmz_get_rnd_zone_for_reclaim() to add a search for the buffer zone with the heaviest weight as an optimal candidate for reclaim. This modification uses the zone pointer variabl "last" which is set only once and never modified as zones are scanned, resulting in the search being inefective. Furthermore, if the selected buffer zone at the end of the search loop is active or already locked for reclaim, dmz_get_rnd_zone_for_reclaim() returns NULL even if other random zones with a lesser weight can be reclaimed. To fix the search and to guarantee that reclaim can make forward progress, fix dmz_get_rnd_zone_for_reclaim() loop to correctly find the buffer zone with the heaviest weight using the variable maxw_z. Also make sure to fallback to finding the first random zone that can be reclaimed if this best candidate zone cannot be reclaimed. While at it, also fix the device index check to consider only random zones, ignoring cache zones belonging to the cache device if one is used as that device does not have a reclaim process. Fixes: 2094045fe5b5 ("dm zoned: prefer full zones for reclaim") Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/md/dm-zoned-metadata.c | 35 ++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 130b5a6d9f12..8bdf71dce7fb 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -1949,7 +1949,7 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd, unsigned int idx, bool idle) { struct dm_zone *dzone = NULL; - struct dm_zone *zone, *last = NULL; + struct dm_zone *zone, *maxw_z = NULL; struct list_head *zone_list; /* If we have cache zones select from the cache zone list */ @@ -1961,18 +1961,37 @@ static struct dm_zone *dmz_get_rnd_zone_for_reclaim(struct dmz_metadata *zmd, } else zone_list = &zmd->dev[idx].map_rnd_list; + /* + * Find the buffer zone with the heaviest weight or the first (oldest) + * data zone that can be reclaimed. + */ list_for_each_entry(zone, zone_list, link) { if (dmz_is_buf(zone)) { dzone = zone->bzone; - if (dzone->dev->dev_idx != idx) + if (dmz_is_rnd(dzone) && dzone->dev->dev_idx != idx) continue; - if (!last) { - last = dzone; - continue; - } - if (last->weight < dzone->weight) + if (!maxw_z || maxw_z->weight < dzone->weight) + maxw_z = dzone; + } else { + dzone = zone; + if (dmz_lock_zone_reclaim(dzone)) + return dzone; + } + } + + if (maxw_z && dmz_lock_zone_reclaim(maxw_z)) + return maxw_z; + + /* + * If we come here, none of the zones inspected could be locked for + * reclaim. Try again, being more aggressive, that is, find the + * first zone that can be reclaimed regardless of its weitght. + */ + list_for_each_entry(zone, zone_list, link) { + if (dmz_is_buf(zone)) { + dzone = zone->bzone; + if (dmz_is_rnd(dzone) && dzone->dev->dev_idx != idx) continue; - dzone = last; } else dzone = zone; if (dmz_lock_zone_reclaim(dzone)) From patchwork Fri Jun 19 07:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11613331 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 469BB138C for ; Fri, 19 Jun 2020 07:51:27 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 029DD2078D for ; Fri, 19 Jun 2020 07:51:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J2fOG8wW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 029DD2078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592553086; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iwVrb3tBwfAHnDyIZtqswMgucJsw2SR+Xw5LbUXzKwQ=; b=J2fOG8wW2oRlCL1yfAVvQV2CJjhPdMSgilyIPSybEQNMAAyOHUUWA1nJthEPkIe1iAKOeR /zv4Bbsus0YV215RrtkE4mx0oQedybEL2L2r+SUNNUt8gl4Pv5vOC0z5Su4K7AtMOMXZgm XTOpphU6utYNmzzHrgwAvXaHoggyQPE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-U5gnIq_2McqABxqn-6V3tg-1; Fri, 19 Jun 2020 03:51:20 -0400 X-MC-Unique: U5gnIq_2McqABxqn-6V3tg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00D71107ACCA; Fri, 19 Jun 2020 07:51:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3C5D5D9E5; Fri, 19 Jun 2020 07:51:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 156E81809557; Fri, 19 Jun 2020 07:51:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05J7pAIl022305 for ; Fri, 19 Jun 2020 03:51:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id E27E7103281; Fri, 19 Jun 2020 07:51:10 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE42E103284 for ; Fri, 19 Jun 2020 07:51:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AD32101A526 for ; Fri, 19 Jun 2020 07:51:08 +0000 (UTC) Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-x2n3pNHHOrKhrDbZI7SOfg-1; Fri, 19 Jun 2020 03:51:04 -0400 X-MC-Unique: x2n3pNHHOrKhrDbZI7SOfg-1 IronPort-SDR: /gYIIN/W0S+3aW17NW4z7nfiC+CK73UcLpiLLovXFAUa1nVs+lnXH9tZM2edU2LnaDQ2Q4izMX LKROsawLdB+yEnFHNHw4VS5AefmCI7jO3qhRQuX1MbnLBn8jtPPJ5sij+8rW1FDSB5kWMJeZhJ 9mN3Om1oxKCuAWf1orxWcUHsdjBTWv9WQJdtiXN6mRuDszctoOOa9ZyKxeVWQCS6VjkGjDppK6 szkS3nIP28dFDoYCD2saSvJXLuPkhJW/D4ucbvbd+hYJVidptFTNFv9E271iFungRrCEdD06g5 i1Q= X-IronPort-AV: E=Sophos;i="5.75,254,1589212800"; d="scan'208";a="249594582" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 19 Jun 2020 15:49:59 +0800 IronPort-SDR: tsnlKhZb56nZEbcm2ImNJIbnT0zqbB69vbjpPK0QhgImwIEbY74+dh9nRRcLf2LReD0quWAQFv xpFkPKAFBFTc53UUquBga0CDvoGZq7F/U= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2020 00:38:38 -0700 IronPort-SDR: z8gYTk+GooNe33um/XvPO3v+N+lRx4X/QIdnRX9RcZpHleMNtFwAhQ1qhMWjhWYCABUPgtCZzi Ng9TLZ/4lpXg== WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Jun 2020 00:49:59 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer Date: Fri, 19 Jun 2020 16:49:56 +0900 Message-Id: <20200619074956.352647-3-damien.lemoal@wdc.com> In-Reply-To: <20200619074956.352647-1-damien.lemoal@wdc.com> References: <20200619074956.352647-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: dm-devel@redhat.com Cc: Shin'ichiro Kawasaki Subject: [dm-devel] [PATCH 2/2] dm zoned: Fix reclaim zone selection X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Shin'ichiro Kawasaki When dm zoned has multiple devices, random zones are never selected for reclaim if all reserved sequential write zones are in use and no sequential write required zones can be selected for reclaim. This can lead to deadlocks as selecting a cache zone allows reclaiming a sequential zone, ensuring forward progress. Fix this by always defaulting to selecting a random zone when no sequential write required zone can be selected. [Damien: fix commit message] Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/md/dm-zoned-metadata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 8bdf71dce7fb..c332e2c121b8 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -2025,7 +2025,7 @@ static struct dm_zone *dmz_get_seq_zone_for_reclaim(struct dmz_metadata *zmd, struct dm_zone *dmz_get_zone_for_reclaim(struct dmz_metadata *zmd, unsigned int dev_idx, bool idle) { - struct dm_zone *zone; + struct dm_zone *zone = NULL; /* * Search for a zone candidate to reclaim: 2 cases are possible. @@ -2038,7 +2038,7 @@ struct dm_zone *dmz_get_zone_for_reclaim(struct dmz_metadata *zmd, dmz_lock_map(zmd); if (list_empty(&zmd->reserved_seq_zones_list)) zone = dmz_get_seq_zone_for_reclaim(zmd, dev_idx); - else + if (!zone) zone = dmz_get_rnd_zone_for_reclaim(zmd, dev_idx, idle); dmz_unlock_map(zmd);