From patchwork Wed Oct 21 01:58:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ruffell X-Patchwork-Id: 1385285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CGDDg60CYz9sTR; Wed, 21 Oct 2020 12:58:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kV3Og-0005Y4-RJ; Wed, 21 Oct 2020 01:58:38 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kV3Oe-0005XZ-6n for kernel-team@lists.ubuntu.com; Wed, 21 Oct 2020 01:58:36 +0000 Received: from mail-pl1-f199.google.com ([209.85.214.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kV3Od-0002gv-Pt for kernel-team@lists.ubuntu.com; Wed, 21 Oct 2020 01:58:35 +0000 Received: by mail-pl1-f199.google.com with SMTP id y9so319797pll.18 for ; Tue, 20 Oct 2020 18:58:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ugR2M+xyFFHs11L3RtttyJRqpRfx6JfLhACJV8XoQUw=; b=ajG3G1Tt6TmRlMDair8Ki73zfzE3IQimCNGMUGhNVv2RTc/XUD3LoAdpq6ZGaoRiT7 ikJEzset8d0G99H4Gpoi1B/SARkJENv420ip9PoR1/DCNVXJOOzhAgTj2g7ncFztnXAj VfSRvBO/oJmT+qh4lYNFw/9+GWtXfQ0Z4jZnyAbzc4ERxnf4WYxjLsfy6zRX1BAEnb/d ugg8SH/lKno8+yBcmgUaP+lcU1Hzuk+g3xtW6EZHNk5M7V6fxnac8MIe5imwFDojl9PR brOUUod2+KVLNVViHmuTbZJ/fvdVzpwOZh1QZ1mGy97wx222BJtTObJKRbY5ZDKOFilH 2hnw== X-Gm-Message-State: AOAM530+V8JxXp36um3KLrxwwzZkRmGs/3T11l+YslXC+6UPC/i07An4 Kzz7Usq5grT+a8CUKPZlP3Idb9KgOuzm8rcAHV+cQGeBTPUn3qdW55/yW7Pi+wy0rpxBLujIdE0 OA3mlyWGKnETb/T3EMFvd5avdMavApjvafvzx1TU0Kw== X-Received: by 2002:a63:cd48:: with SMTP id a8mr961733pgj.83.1603245514305; Tue, 20 Oct 2020 18:58:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbxKg7BMZVS+21iGPJKRSKMp/bYObcFTiXDnxJVPVZzCZ4w43jsBjTmCYMUNhRkQot/Nmm4g== X-Received: by 2002:a63:cd48:: with SMTP id a8mr961722pgj.83.1603245514054; Tue, 20 Oct 2020 18:58:34 -0700 (PDT) Received: from localhost.localdomain (222-152-178-139-fibre.sparkbb.co.nz. [222.152.178.139]) by smtp.gmail.com with ESMTPSA id g15sm375982pgi.89.2020.10.20.18.58.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 18:58:33 -0700 (PDT) From: Matthew Ruffell To: kernel-team@lists.ubuntu.com Subject: [SRU][B][PATCH 3/3] bcache: reap from tail of c->btree_cache in bch_mca_scan() Date: Wed, 21 Oct 2020 14:58:11 +1300 Message-Id: <20201021015811.19159-4-matthew.ruffell@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201021015811.19159-1-matthew.ruffell@canonical.com> References: <20201021015811.19159-1-matthew.ruffell@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coly Li BugLink: https://bugs.launchpad.net/bugs/1898786 When shrink btree node cache from c->btree_cache in bch_mca_scan(), no matter the selected node is reaped or not, it will be rotated from the head to the tail of c->btree_cache list. But in bcache journal code, when flushing the btree nodes with oldest journal entry, btree nodes are iterated and slected from the tail of c->btree_cache list in btree_flush_write(). The list_rotate_left() in bch_mca_scan() will make btree_flush_write() iterate more nodes in c->btree_list in reverse order. This patch just reaps the selected btree node cache, and not move it from the head to the tail of c->btree_cache list. Then bch_mca_scan() will not mess up c->btree_cache list to btree_flush_write(). Signed-off-by: Coly Li Signed-off-by: Jens Axboe (cherry picked from commit e3de04469a49ee09c89e80bf821508df458ccee6) Signed-off-by: Matthew Ruffell --- drivers/md/bcache/btree.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index c38a8c9e0c8e..83c635b14e3a 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -710,19 +710,19 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, i++; } - for (; (nr--) && i < btree_cache_used; i++) { - if (list_empty(&c->btree_cache)) + list_for_each_entry_safe_reverse(b, t, &c->btree_cache, list) { + if (nr <= 0 || i >= btree_cache_used) goto out; - b = list_first_entry(&c->btree_cache, struct btree, list); - list_rotate_left(&c->btree_cache); - if (!mca_reap(b, 0, false)) { mca_bucket_free(b); mca_data_free(b); rw_unlock(true, b); freed++; } + + nr--; + i++; } out: mutex_unlock(&c->bucket_lock);