Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp708795pxv; Thu, 15 Jul 2021 14:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZJftzvdSS0zPiF32o/Ux17CpMe/U5U3kht4uX+wvwO9CNWy5K4Hez0W3h4EHLox01TRZA X-Received: by 2002:a05:6402:4246:: with SMTP id g6mr9668346edb.134.1626383125704; Thu, 15 Jul 2021 14:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383125; cv=none; d=google.com; s=arc-20160816; b=1CCPNUDIDQPsJ4kAyR3sFOb/gIJKAfxFONvFn21m9cYchsuIize0PJYNiJwAdeeajS MubpXJNFJ030+Ar7SRq0HsR4sW6AgyZhFT3itD2glTlOANJJJrbuK19NR3tcO0R7GwoG Us6HmbN44y/ADXTeWjmBQ2ypcDmTz7mar5pjNgv7lUvU7Hj6XHp12Jj8KSO7hNX+O2V5 synWnpHl+cXKeBy9LLZ3P6ZbkIDwDfFKErs5q2/Kn/tl4bFJO3Q3ykssrL1C/kJ1k1Z6 xKGTvSwqfMZvWy6DxsfZ0UO4j9t1uJmAdjMjXoL9H+v0urvqVhndkMtzoDD5pm5Ixf84 o5Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0FbUq0I21DEOjshkU+SDgVpKSwyDRIRCnBKREhXFWNA=; b=hN7tgJC3Ynyp/+GEoGOt4t9W7HdlFT1falbYCKG1f0hpIrdGHW0Qv6Lf3npt1v7NPm 66MQ7g4aoMM+mmlmaqeqPUvVgDj2hVf+Al/UF08UhSY8ExujGb6ap82rdIoDBiJ86JsA sQT0pVEJwYoHiggB5ngE8wyClZhOufyFHDfjsTUCmPdvyVULWBpbOSifdDh8t/AzrpYl ElVsXB9kCx53boikr+kuobRgu1S2I+y+feb6aXVc+hE1ge9IAF/axQAAV06e+iuJgX3x Bt7OPJSc33w6+7sPe+0JOMCXf2w4BKSvDCpo2d6RbTs6vVhfapXIVpZ+j7hgZBRbcXn1 7Nlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="a/o6xqwf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si9859031edj.103.2021.07.15.14.05.03; Thu, 15 Jul 2021 14:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="a/o6xqwf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244229AbhGOTOh (ORCPT + 99 others); Thu, 15 Jul 2021 15:14:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:35680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241982AbhGOS71 (ORCPT ); Thu, 15 Jul 2021 14:59:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 15C7D60D07; Thu, 15 Jul 2021 18:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375368; bh=OM0QNoOAzXMgTPxuxyfZQkJXBzjgf6bYaRl08h2/2Kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/o6xqwf+q56ywooy3fmCqA/KGV1a1XszSDxUFQ4+MH4zKZm6Tv8iUE8ehx4eJJpO vYy6C3+0Kxk1J8bhqvsPN9AFWmH0r9G8RnFktB/+aK8szl2QJn1ZtFbCPtj3RLs3C5 F0CB+NyMfemqAc5P7jSU9rnMpQ3tQZrOk0t1ZfWw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joe Thornber , Mike Snitzer , Sasha Levin Subject: [PATCH 5.12 056/242] dm space maps: dont reset space map allocation cursor when committing Date: Thu, 15 Jul 2021 20:36:58 +0200 Message-Id: <20210715182602.216897048@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joe Thornber [ Upstream commit 5faafc77f7de69147d1e818026b9a0cbf036a7b2 ] Current commit code resets the place where the search for free blocks will begin back to the start of the metadata device. There are a couple of repercussions to this: - The first allocation after the commit is likely to take longer than normal as it searches for a free block in an area that is likely to have very few free blocks (if any). - Any free blocks it finds will have been recently freed. Reusing them means we have fewer old copies of the metadata to aid recovery from hardware error. Fix these issues by leaving the cursor alone, only resetting when the search hits the end of the metadata device. Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/persistent-data/dm-space-map-disk.c | 9 ++++++++- drivers/md/persistent-data/dm-space-map-metadata.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c index bf4c5e2ccb6f..e0acae7a3815 100644 --- a/drivers/md/persistent-data/dm-space-map-disk.c +++ b/drivers/md/persistent-data/dm-space-map-disk.c @@ -171,6 +171,14 @@ static int sm_disk_new_block(struct dm_space_map *sm, dm_block_t *b) * Any block we allocate has to be free in both the old and current ll. */ r = sm_ll_find_common_free_block(&smd->old_ll, &smd->ll, smd->begin, smd->ll.nr_blocks, b); + if (r == -ENOSPC) { + /* + * There's no free block between smd->begin and the end of the metadata device. + * We search before smd->begin in case something has been freed. + */ + r = sm_ll_find_common_free_block(&smd->old_ll, &smd->ll, 0, smd->begin, b); + } + if (r) return r; @@ -199,7 +207,6 @@ static int sm_disk_commit(struct dm_space_map *sm) return r; memcpy(&smd->old_ll, &smd->ll, sizeof(smd->old_ll)); - smd->begin = 0; smd->nr_allocated_this_transaction = 0; r = sm_disk_get_nr_free(sm, &nr_free); diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c index 9e3c64ec2026..da439ac85796 100644 --- a/drivers/md/persistent-data/dm-space-map-metadata.c +++ b/drivers/md/persistent-data/dm-space-map-metadata.c @@ -452,6 +452,14 @@ static int sm_metadata_new_block_(struct dm_space_map *sm, dm_block_t *b) * Any block we allocate has to be free in both the old and current ll. */ r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, smm->begin, smm->ll.nr_blocks, b); + if (r == -ENOSPC) { + /* + * There's no free block between smm->begin and the end of the metadata device. + * We search before smm->begin in case something has been freed. + */ + r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, 0, smm->begin, b); + } + if (r) return r; @@ -503,7 +511,6 @@ static int sm_metadata_commit(struct dm_space_map *sm) return r; memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll)); - smm->begin = 0; smm->allocated_this_transaction = 0; return 0; -- 2.30.2