From patchwork Thu Sep 27 18:34:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 10618447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7D1315E8 for ; Thu, 27 Sep 2018 18:35:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10922BAE1 for ; Thu, 27 Sep 2018 18:35:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C51102BAE7; Thu, 27 Sep 2018 18:35:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61FB82BAE1 for ; Thu, 27 Sep 2018 18:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728501AbeI1Ayy (ORCPT ); Thu, 27 Sep 2018 20:54:54 -0400 Received: from smtp-34-i6.italiaonline.it ([213.209.14.34]:48601 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728251AbeI1Ayy (ORCPT ); Thu, 27 Sep 2018 20:54:54 -0400 Received: from venice.bhome ([84.223.214.84]) by smtp-34.iol.local with ESMTPA id 5b7zg9O8gq9Au5b88gnnnR; Thu, 27 Sep 2018 20:35:18 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1538073318; bh=Zd0XB2/3+InuPzTYI3AT+uOEuSwrcE2wtQ1rXUitQdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=m5PLyeb2wDv3dLSGs4f9dURQ5qZVYHKqKREgKEc3+z/WoydCmQjD21nYhHn2ZT36C oM+LphD+rUOeb+nSjXxOslgwOh/T0tT1TR9xCZftZ7smLNII8dnVUXvuFX9lno+m4z JCAndx6N/dfP8sBOIlxQw1rGRpJqSqnkqmwGrw+1eo/K7hyCENN9JKZqItd+toNmwT h5HDACp5MWawNcVDgNF95NssKQ5lLDNOPNmttNCFfoptDvS9clvXCbbpwXkdHgAtwz xWCrJqx6DM07s3xyU/8wJH17oEr2OkWJBadjlqtMlS480wNxbTeOE2FRwslTgEZ6Uo s/8Uz3CL3Bf6Q== X-CNFS-Analysis: v=2.3 cv=OoWeNB3t c=1 sm=1 tr=0 a=8ZjQKV1YVqnHfcWpVNE1cw==:117 a=8ZjQKV1YVqnHfcWpVNE1cw==:17 a=_nex0ghXHqrwvuxp8qYA:9 From: Goffredo Baroncelli To: grub-devel@gnu.org Cc: Daniel Kiper , linux-btrfs@vger.kernel.org, Goffredo Baroncelli Subject: [PATCH 4/9] btrfs: Avoid a rescan for a device which was already not found. Date: Thu, 27 Sep 2018 20:34:59 +0200 Message-Id: <20180927183504.18078-5-kreijack@libero.it> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927183504.18078-1-kreijack@libero.it> References: <20180927183504.18078-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfH+d8sZZBMVu/nghih0NId1a/SGM9cg3t69OOUnG6cv0rFtC3hWd0bqY5PeMnizamS0Fhi7cCC4ldzoKp5ed4KerxuiDWbPya++lQCFu67S7H5Q+Q1oD 8xH0YGcbFp+qoVAPu0w22owirLrgW0rKKT3SJadfzPb9ynVsXfRQ+9sO6d/rA+dcFjwaPM2dzkl9QAOrRmEge2+3/wWpd5C44qFdJ8k8VucW6/MtTFbr9Gff Bc/GhlNCWb5WrAQqe81eNqpAm4Jc4vj9y1Cawk4h9Fo= Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Goffredo Baroncelli Change the behavior of find_device(): before the patch, a read of a missed device may trigger a rescan. However, it is never recorded that a device is missed, so each single read of a missed device may triggers a rescan. It is the caller who decides if a rescan is performed in case of a missed device. And it does quite often, without considering if in the past a devices was already found as "missed" This behavior causes a lot of unneeded rescan, causing a huge slowdown in case of a missed device. After the patch, the "missed device" information is stored in the data->devices_attached[] array (as a NULL value in the field dev). A rescan is triggered only if no information at all is found. This means that only the first time a read of a missed device triggers a rescan. The change in the code is done removing "return NULL" when the disk is not found. So it is always executed the code which stores in the data->devices_attached[] array the value returned by grub_device_iterate(): NULL if the device is missed, or a valid data otherwise. Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 2b1dd7dd4..c07d91657 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -588,7 +588,7 @@ find_device_iter (const char *name, void *data) } static grub_device_t -find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) +find_device (struct grub_btrfs_data *data, grub_uint64_t id) { struct find_device_ctx ctx = { .data = data, @@ -600,10 +600,9 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) for (i = 0; i < data->n_devices_attached; i++) if (id == data->devices_attached[i].id) return data->devices_attached[i].dev; - if (do_rescan) - grub_device_iterate (find_device_iter, &ctx); - if (!ctx.dev_found) - return NULL; + + grub_device_iterate (find_device_iter, &ctx); + data->n_devices_attached++; if (data->n_devices_attached > data->n_devices_allocated) { @@ -615,7 +614,8 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) * sizeof (data->devices_attached[0])); if (!data->devices_attached) { - grub_device_close (ctx.dev_found); + if (ctx.dev_found) + grub_device_close (ctx.dev_found); data->devices_attached = tmp; return NULL; } @@ -898,7 +898,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr, addr); - dev = find_device (data, stripe->device_id, j); + dev = find_device (data, stripe->device_id); if (!dev) { grub_dprintf ("btrfs", @@ -975,7 +975,8 @@ grub_btrfs_unmount (struct grub_btrfs_data *data) unsigned i; /* The device 0 is closed one layer upper. */ for (i = 1; i < data->n_devices_attached; i++) - grub_device_close (data->devices_attached[i].dev); + if (data->devices_attached[i].dev) + grub_device_close (data->devices_attached[i].dev); grub_free (data->devices_attached); grub_free (data->extent); grub_free (data);