From patchwork Wed Aug 23 00:26:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9916413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8160E603FF for ; Wed, 23 Aug 2017 00:27:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74987287E3 for ; Wed, 23 Aug 2017 00:27:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69AE42892C; Wed, 23 Aug 2017 00:27:17 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 189AE2891E for ; Wed, 23 Aug 2017 00:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752902AbdHWA1P (ORCPT ); Tue, 22 Aug 2017 20:27:15 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33687 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752770AbdHWA1M (ORCPT ); Tue, 22 Aug 2017 20:27:12 -0400 Received: by mail-wm0-f68.google.com with SMTP id q189so723320wmd.0 for ; Tue, 22 Aug 2017 17:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Zi2dNuUoVemTRpe1C5qvDSfss6ybPYJrTRey4fRRE3c=; b=BayKPTue9ZO+JijrAKiTzmaeocqBA/deMq+9GlOLH/rKdIVXg3inSfHe27YWi92ALz FuNws89MfZNSAv7NZCU1uOsha8JU5EFWCvcSKUoVJXHWvQoMxeof8xO5yK2uZE374rZi LSg56dV+JveO/WzjnhG3/Z6w1dKhBVMAoHx3nxkGWhyPI9Po2oEzwr3szXHkB8CN9yUo Rs/nXZ3r34FY/dseyxXy+oQSNZwmEaCUkbvHjzzX4E+dfDxu9246toB/jvUZY5f1ngp4 X1sZTKDfelao1zuz4wIPRaput0pesUaZ9BLz56dj9rYUjwYd2fuw6BUimHJ02d2NEsjp jPAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Zi2dNuUoVemTRpe1C5qvDSfss6ybPYJrTRey4fRRE3c=; b=GViT4wX7eGqgwVsdI46/ztEDsLVNe+KJVhRz8CLVW+JX4z5aMvS1mFt5vI+3eMsyWs hwneimjVMcHEXvn6F6Qlvky97FcjRvVjfxRNWT6NT6EBoKO7C1nRuh8B/Jj/ZGGtcftN Hqs2ti77XeSkVRHNDvhncmbClxWCTWgTVgGXCVSSbybtrIS7RfJ4EtLr6uI1YjXKZ8+W wn1No7dZCqf2dcnzEFA2myIPKP06C1p4T76Vkk+IHl1rm8Tra0TdNxpSaiK6UOBUzcvM FbPrBqM4sBYFfntiDf58WwugkAx4hOdMKVjquAywVisgWyCogdRhjLLJSwNUdKzKkumK 4aHA== X-Gm-Message-State: AHYfb5i3F1S6kV5LfFncqdvsYNSes+0NdFlx/SHhsmpSh9cm5DniFRw5 w8GD+j+PCJrx5PS5 X-Received: by 10.28.238.143 with SMTP id j15mr324850wmi.180.1503448030719; Tue, 22 Aug 2017 17:27:10 -0700 (PDT) Received: from titovetst-l.itransition.corp (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id k45sm136926wre.1.2017.08.22.17.27.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 17:27:10 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v5 4/6] Btrfs: heuristic add detection of zeroed sample Date: Wed, 23 Aug 2017 03:26:48 +0300 Message-Id: <20170823002650.3133-5-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823002650.3133-1-nefelim4ag@gmail.com> References: <20170823002650.3133-1-nefelim4ag@gmail.com> 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 Use memcmp for check sample data to zeroes. Signed-off-by: Timofey Titovets --- fs/btrfs/heuristic.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/heuristic.c b/fs/btrfs/heuristic.c index 5336638a3b7c..4557ea1db373 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -73,6 +73,21 @@ static struct list_head *heuristic_alloc_workspace(void) return ERR_PTR(-ENOMEM); } +static bool sample_zeroed(struct workspace *workspace) +{ + u32 i; + u8 zero[READ_SIZE]; + + memset(&zero, 0, sizeof(zero)); + + for (i = 0; i < workspace->sample_size; i += sizeof(zero)) { + if (memcmp(&workspace->sample[i], &zero, sizeof(zero))) + return false; + } + + return true; +} + static int heuristic(struct list_head *ws, struct inode *inode, u64 start, u64 end) { @@ -110,6 +125,9 @@ static int heuristic(struct list_head *ws, struct inode *inode, workspace->sample_size = b; + if (sample_zeroed(workspace)) + return 1; + memset(workspace->bucket, 0, sizeof(*workspace->bucket)*BUCKET_SIZE); for (a = 0; a < workspace->sample_size; a++) {