Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10233537ybi; Wed, 24 Jul 2019 18:57:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMpl9oNwY5vnnAl33ZI5hsW+hs7GDG+zjNPFAH8Ds7D01UFUyFF4Tc9eVQdsBFBoDS9bwi X-Received: by 2002:a17:902:a612:: with SMTP id u18mr86034467plq.181.1564019875386; Wed, 24 Jul 2019 18:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564019875; cv=none; d=google.com; s=arc-20160816; b=al/e3m2bSfin2bnqf9nOhVHAPFajy40hYz2UbKlCfFMAwxj5EZhkAYbUOS3IhMus6f iIBRU4obkXRXkiVrSAil5d4kmgJ+MC1bodH5Mqa5JJo1POTiXdW9IjRDa5l16mTp7f6a b80D4zjavTdw/OE0vbfkeNCqWpNA0/rEVDv7xNpUmbO6meUYbSWNmBsxvk6jD8FEvLGJ 2w/B5oqPief84wAVt+ljkRzN+gzbTSlsWbv8ZFRJwj8vxY4YU8M/DwvXlvxtDcRR+fnd xJ11XYpiCPI8U5Q6ht4s2fqWbheDzyccuuEfi6fFHWvhe7iDS857hCX0f70Mjn7qQziJ DIwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7MgAAyaEkukMlQ7dUr6LT/9EK2UlhPoKzJk0P2gPYm4=; b=CyzAA8CqKOSQ6IBcj0aUwsl7aPPdosMYtHyqOtguMuvV6FwQPK6C5HGPYy9ciq1axK 6xHyATftWXRs6/ho1nn2SbO67ITFF3XV0vKxIaGfOr0UstWvxwYWgT8H8wHQM8iIKa3I CeoPSSd88mjCr4gS7MKCPOVe+BDhOp/YPy5H69YNALgnwpJAmG722xgjSTCkoPfxPawP 0eIRTa5B2VcRamMztLo2eE1prmKvfSkjYltlO15ilzj+8AUBNrhVudRuAV6KV/MHAMfF cBEsED+pXkt0HNIqBmCFJCbgqLLbS0ZYLE2kOKF0ibXWKpEVLNd3STT7OITXp+T7WzaY 3UsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZZFhC2tT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si16582972pln.70.2019.07.24.18.57.28; Wed, 24 Jul 2019 18:57:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZZFhC2tT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389102AbfGXTgT (ORCPT + 99 others); Wed, 24 Jul 2019 15:36:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:35932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389303AbfGXTgR (ORCPT ); Wed, 24 Jul 2019 15:36:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 705A422ADA; Wed, 24 Jul 2019 19:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996976; bh=Kak5/0BK9iP1Hj+5V6tKBmEacMdzyjKBRg2fhLgY8EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZFhC2tTWsFNQFijEk/rzKCe1uR6tIFgL/PdHUmiSj2zN7hyS7E6JxRaxs4zYk3vm gWzHyhFGf9hhPuOzEKrjbMJ7fgW3ZlU6w9ClNg+LTRPltb0Ku2Ze8eYW6sBYRUhVda BN7PPGdLmoB7acSfQFf91uoGnXb6pHGGK45y135g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Tang Junhui , Jens Axboe Subject: [PATCH 5.2 281/413] bcache: Revert "bcache: fix high CPU occupancy during journal" Date: Wed, 24 Jul 2019 21:19:32 +0200 Message-Id: <20190724191756.393800729@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li commit 249a5f6da57c28a903c75d81505d58ec8c10030d upstream. This reverts commit c4dc2497d50d9c6fb16aa0d07b6a14f3b2adb1e0. This patch enlarges a race between normal btree flush code path and flush_btree_write(), which causes deadlock when journal space is exhausted. Reverts this patch makes the race window from 128 btree nodes to only 1 btree nodes. Fixes: c4dc2497d50d ("bcache: fix high CPU occupancy during journal") Signed-off-by: Coly Li Cc: stable@vger.kernel.org Cc: Tang Junhui Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/bcache.h | 2 - drivers/md/bcache/journal.c | 47 ++++++++++++++------------------------------ drivers/md/bcache/util.h | 2 - 3 files changed, 15 insertions(+), 36 deletions(-) --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -726,8 +726,6 @@ struct cache_set { #define BUCKET_HASH_BITS 12 struct hlist_head bucket_hash[1 << BUCKET_HASH_BITS]; - - DECLARE_HEAP(struct btree *, flush_btree); }; struct bbio { --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c @@ -391,12 +391,6 @@ err: } /* Journalling */ -#define journal_max_cmp(l, r) \ - (fifo_idx(&c->journal.pin, btree_current_write(l)->journal) < \ - fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal)) -#define journal_min_cmp(l, r) \ - (fifo_idx(&c->journal.pin, btree_current_write(l)->journal) > \ - fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal)) static void btree_flush_write(struct cache_set *c) { @@ -404,35 +398,25 @@ static void btree_flush_write(struct cac * Try to find the btree node with that references the oldest journal * entry, best is our current candidate and is locked if non NULL: */ - struct btree *b; - int i; + struct btree *b, *best; + unsigned int i; atomic_long_inc(&c->flush_write); - retry: - spin_lock(&c->journal.lock); - if (heap_empty(&c->flush_btree)) { - for_each_cached_btree(b, c, i) - if (btree_current_write(b)->journal) { - if (!heap_full(&c->flush_btree)) - heap_add(&c->flush_btree, b, - journal_max_cmp); - else if (journal_max_cmp(b, - heap_peek(&c->flush_btree))) { - c->flush_btree.data[0] = b; - heap_sift(&c->flush_btree, 0, - journal_max_cmp); - } - } - - for (i = c->flush_btree.used / 2 - 1; i >= 0; --i) - heap_sift(&c->flush_btree, i, journal_min_cmp); - } + best = NULL; - b = NULL; - heap_pop(&c->flush_btree, b, journal_min_cmp); - spin_unlock(&c->journal.lock); + for_each_cached_btree(b, c, i) + if (btree_current_write(b)->journal) { + if (!best) + best = b; + else if (journal_pin_cmp(c, + btree_current_write(best)->journal, + btree_current_write(b)->journal)) { + best = b; + } + } + b = best; if (b) { mutex_lock(&b->write_lock); if (!btree_current_write(b)->journal) { @@ -874,8 +858,7 @@ int bch_journal_alloc(struct cache_set * j->w[0].c = c; j->w[1].c = c; - if (!(init_heap(&c->flush_btree, 128, GFP_KERNEL)) || - !(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) || + if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) || !(j->w[0].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS)) || !(j->w[1].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS))) return -ENOMEM; --- a/drivers/md/bcache/util.h +++ b/drivers/md/bcache/util.h @@ -113,8 +113,6 @@ do { \ #define heap_full(h) ((h)->used == (h)->size) -#define heap_empty(h) ((h)->used == 0) - #define DECLARE_FIFO(type, name) \ struct { \ size_t front, back, size, mask; \