From patchwork Thu Sep 28 14:33:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9976247 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 A51946037E for ; Thu, 28 Sep 2017 14:33:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9764F2951A for ; Thu, 28 Sep 2017 14:33:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AB6D2951D; Thu, 28 Sep 2017 14:33:59 +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 251D62951A for ; Thu, 28 Sep 2017 14:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753350AbdI1Od5 (ORCPT ); Thu, 28 Sep 2017 10:33:57 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:37373 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753339AbdI1Ody (ORCPT ); Thu, 28 Sep 2017 10:33:54 -0400 Received: by mail-wr0-f194.google.com with SMTP id u48so2236406wrf.4 for ; Thu, 28 Sep 2017 07:33:53 -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=LySyN6PzNZcjAiayXSz9K1+LzuaRB8LPTzjH916nRCo=; b=ifCSBlub1s+DSGTQRjE7t2G+dfE0iVb++XqN37eelRonDN/+1FTA2ad20TlDJZppZg NCyUSCSeX4hhN0vrV0T8nWkD+peghh0sOAEVegspljtbqqDeSCCqAypl5Kn9cZAmzegf 6dFOjaBR0FhTm816Yz2e2c58cDb5vLisirIMR2HLOV1yHhjFbk3WvvVukS1Fr04W9SZ8 OvEyL1mUjTIMPV3Mlc/vtvE2PE6c0nsH30IEntvzeOMcvpJGu1kExEPDeUB21sT9VJ3E cWT7AJ9O0SBDJQPdnln9wErqbopqvVCNwHghGXkBx1iAYuuPO11AAaJP9JyGhY5m9cFS +H0A== 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=LySyN6PzNZcjAiayXSz9K1+LzuaRB8LPTzjH916nRCo=; b=Dwvs/gBUKbkwaQjaK4Af14qJb+sS0y/7cZ13YQFecwpskvFOgV/eNQ9lMNd1ZGzUiS yjnto18n8aH8PKTTpdv5QHyGz3UPtebh1oDSWPAl3JO6Pnh7oyJIDoh2AwoyIv9KCmMo xWtTc4DXYklYt5LmN2yAttE1lpC281crM5iJPZlN3l2Fm/DUeoWuS9Uk4HDaT2VtzTc9 chK0Aeds5xCGx/GSAZRuqGwckSgXV07c+j6XW4NcWDWOB49HpAwEAAnLynTNDY32bEdk CgaqpYZJeyznjxijQgvGYEPfI275qUpu5p+QsqFzmSrfctpJCM1YJxpuNtgykdt2uV0N IRvg== X-Gm-Message-State: AHPjjUgCiYgLzih9TTYAGpeR6TzfMgj7WQY5/Efi9wWfDnRrwoWlF0s0 GqYLWQ2WvZ2eB5EnWUshzaLUEQ== X-Google-Smtp-Source: AOwi7QAnx3zzrc6O0dpVVsOSVHUMCDAxwincxl7iZTCPHz2TauQ5GOvMFAlEKSlRoVvNuQr67e6jUA== X-Received: by 10.223.175.230 with SMTP id y38mr4429740wrd.213.1506609232805; Thu, 28 Sep 2017 07:33:52 -0700 (PDT) Received: from titovetst-l.itransition.corp ([93.171.6.182]) by smtp.gmail.com with ESMTPSA id k82sm460633wmf.19.2017.09.28.07.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Sep 2017 07:33:52 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v8 4/6] Btrfs: heuristic add detection of repeated data patterns Date: Thu, 28 Sep 2017 17:33:39 +0300 Message-Id: <20170928143341.24491-5-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20170928143341.24491-1-nefelim4ag@gmail.com> References: <20170928143341.24491-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/compression.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 2.14.2 -- 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/compression.c b/fs/btrfs/compression.c index e2419639ae7f..1cb4df023d5e 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1200,6 +1200,16 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start, return 1; } + +static bool sample_repeated_patterns(struct heuristic_ws *ws) +{ + u32 half_of_sample = ws->sample_size / 2; + u8 *p = ws->sample; + + return !memcmp(&p[0], &p[half_of_sample], half_of_sample); +} + + static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end, struct heuristic_ws *ws) { @@ -1278,6 +1288,11 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end) heuristic_collect_sample(inode, start, end, ws); + if (sample_repeated_patterns(ws)) { + ret = 1; + goto out; + } + memset(ws->bucket, 0, sizeof(*ws->bucket)*BUCKET_SIZE); for (i = 0; i < ws->sample_size; i++) { @@ -1285,7 +1300,7 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end) ws->bucket[byte].count++; } +out: __free_workspace(0, ws_list, true); - return ret; }