From patchwork Fri Aug 25 09:18: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: 9921505 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 BA181600C5 for ; Fri, 25 Aug 2017 09:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B317E26D05 for ; Fri, 25 Aug 2017 09:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7EE227D4D; Fri, 25 Aug 2017 09:19:28 +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 3CD1A26D05 for ; Fri, 25 Aug 2017 09:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755240AbdHYJT0 (ORCPT ); Fri, 25 Aug 2017 05:19:26 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34388 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754673AbdHYJTO (ORCPT ); Fri, 25 Aug 2017 05:19:14 -0400 Received: by mail-wr0-f196.google.com with SMTP id y14so257209wrd.1 for ; Fri, 25 Aug 2017 02:19:13 -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=ZmNfA2U6C1XbLdl1R/SaBTXzcRuYGrubFZEz16sVUAc=; b=nhZrAQXLox2GC++2Bdhq+C5f7JqEwm7ZdKSQ7/qNyGfdT9RI4dA9zlgcAKv6CmUpQt MlSikEDZwOpCJq5+s7Vm0jRHTxYqMje/haLYoPJl4ypzPumMNZcKvLi7WLis5dNdF5id K1gwuzY2ksFf9Pib8MWCnv51NbGA9EwygKjt8klT4HjH1aDjwAPDBq3wV5/8pCyis0dW E31ghzkPPElFFkiByPUCAytzPDg6+8CSofh/QCVJCxcA8TkPZPPZxqnaAhd9r2VPmYof e40eC68FM0HpkerC93Q0/9dXiEe7daB1c3w8YZ21x/sFEjhgw53z0PPNABDvXf+Qxeje OlvA== 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=ZmNfA2U6C1XbLdl1R/SaBTXzcRuYGrubFZEz16sVUAc=; b=nRe46bMN2EnbDaXj2PON0z3VNHrIf6yKLrYzOWA+8MN1MnQ9B3vKchxNGbU09zrcYC cYtNafMOqMpkY9bPmIurZhjw7lB2QHIgSaHDAVPiONN1MMeVtXIlNRIlIHhy03N+COSt 1ys7g07fVIx8FyqurVuw8vf1CYGMyaA7c5hNbyHDgMEGJwVx/3SJzPHl0wZ44Smtxmez zFEF4Dkgny45v4f/k/2qXROkEa8d/rJOnn+l6cyem72Qn915m04nozAhN5hnxqIelCxo rEnCz8HZsmplbeLD945SQ8yTDPSO40CBiN+Ik/5efYqVk5TtNAKfvLFsmM9E3wxuens6 f2Og== X-Gm-Message-State: AHYfb5jCo67XM7GRKV1xTcoQgjPgoGX4slRksMroeEitrLvdzBwbqhxj 82s5v7Ov91T+1Kva X-Received: by 10.223.133.140 with SMTP id 12mr5113385wrt.102.1503652752599; Fri, 25 Aug 2017 02:19:12 -0700 (PDT) Received: from titovetst-l.itransition.corp ([93.170.143.179]) by smtp.gmail.com with ESMTPSA id o7sm6208243wra.39.2017.08.25.02.19.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 02:19:11 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v7 4/6] Btrfs: heuristic add detection of repeated data patterns Date: Fri, 25 Aug 2017 12:18:43 +0300 Message-Id: <20170825091845.4120-5-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170825091845.4120-1-nefelim4ag@gmail.com> References: <20170825091845.4120-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 5192e51ab81e..f1fa6e4f1c11 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) { @@ -115,6 +128,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++) {