From patchwork Wed Aug 23 22:45:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9918597 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 DD44D600C5 for ; Wed, 23 Aug 2017 22:46:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D09C628A7E for ; Wed, 23 Aug 2017 22:46:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C586628A9F; Wed, 23 Aug 2017 22:46:15 +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 6AF0B28A7E for ; Wed, 23 Aug 2017 22:46:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdHWWqL (ORCPT ); Wed, 23 Aug 2017 18:46:11 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38226 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751003AbdHWWqB (ORCPT ); Wed, 23 Aug 2017 18:46:01 -0400 Received: by mail-wm0-f68.google.com with SMTP id a70so936118wmd.5 for ; Wed, 23 Aug 2017 15:46:00 -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=sSTAboPiAbR/MA+LwTYV54ykW2+4DAzQuEXuPM1NRfM=; b=WXlstTgIk7zKjlsp3UThcmxVPKaURvrDObBR0m75g9CISKbqoCmdB/z8JFQmdW+YYQ eBo+PIvzHoBuAapBRi3ckQuCQnLMmpUF9I0rn3r2PkcrFQ2OT8xlk6gBzxiIw67vutwp OgaVviHuW+1c4H+ScTgkRHA+JsMorzrG0J0tBj07z1nHByMJ/pkpPluCEbgGh+SDkqps r24lo9gNr4B3htQK6a7z1CtQGiiKuZ2QbK4DDYyU3QSWCabQnZWQSqFKFTtbhzP99vrR 8i8WocpEvUtsj1i0qUwyFO2QV1DNYqeaX1DFEmLaJ8Q5UHTNW0TAKCTbylcEnrYulvMO hOxw== 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=sSTAboPiAbR/MA+LwTYV54ykW2+4DAzQuEXuPM1NRfM=; b=kkTdeZ8LciwYLAHadKT1jZcPqUtAEUR9yyiSxKMbhy3ORyA7Tgu2R6+ZkY1jdH9Znx 7nEauJWOxaTDxdyDvmga/y9NC+I/M7Rc57u9U3q1YowyEiuKC8EXJHUYkFrHOJJjGmoK RJTWaVymU8R+f6dyeD/xZlsmoqE8VuyLQOSbCFfZlSHI66gkCo/sdj5S5vHK9ce7KpPf NFI3doBpTeQEugxL+dNtNbh+JXEOaxW/gkYUpvWiJ16QGp7bvHmasuJ8USLhd1rzQfZ1 2q5G+NoeVxcPRM3AcxF4QzX/FKrxOs3iZ4B2I6LZTAjdMW9fHIjDhAvjAwxBN3yhMb7l zJ+g== X-Gm-Message-State: AHYfb5iTJ3s3tHFiPot1wIgcRmU+EPcDXy1tqNckiAYsPLUx83VfwMoq xFLmfCgHV3khEOoC X-Received: by 10.28.87.209 with SMTP id l200mr173725wmb.143.1503528359805; Wed, 23 Aug 2017 15:45:59 -0700 (PDT) Received: from localhost.localdomain (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id m27sm5896166wrf.69.2017.08.23.15.45.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 15:45:59 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v6 4/6] Btrfs: heuristic add detection of repeated data patterns Date: Thu, 24 Aug 2017 01:45:43 +0300 Message-Id: <20170823224545.16375-5-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823224545.16375-1-nefelim4ag@gmail.com> References: <20170823224545.16375-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 Walk over data sample and use memcmp to detect repeated data (like zeroed) Signed-off-by: Timofey Titovets --- fs/btrfs/heuristic.c | 16 ++++++++++++++++ 1 file changed, 16 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 001118f98143..8df56ea93064 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -66,6 +66,19 @@ static struct list_head *heuristic_alloc_workspace(void) return ERR_PTR(-ENOMEM); } +static bool sample_repeated_patterns(struct workspace *ws) +{ + u32 i = 0; + u8 *p = ws->sample; + + for (; i < ws->sample_size - READ_SIZE; i += READ_SIZE) { + if(memcpy(&p[i], &p[i + READ_SIZE], READ_SIZE)) + return false; + } + + return true; +} + static int heuristic(struct list_head *ws, struct inode *inode, u64 start, u64 end) { @@ -118,6 +131,9 @@ static int heuristic(struct list_head *ws, struct inode *inode, workspace->sample_size = b; + if (sample_repeated_patterns(workspace)) + return 1; + memset(workspace->bucket, 0, sizeof(*workspace->bucket)*BUCKET_SIZE); for (a = 0; a < workspace->sample_size; a++) {