From patchwork Fri Aug 25 09:18:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9921499 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 ACE6E600C5 for ; Fri, 25 Aug 2017 09:19:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5B8E25EA6 for ; Fri, 25 Aug 2017 09:19:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A45527D4D; Fri, 25 Aug 2017 09:19:18 +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 43B9F25EA6 for ; Fri, 25 Aug 2017 09:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755234AbdHYJTR (ORCPT ); Fri, 25 Aug 2017 05:19:17 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38539 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754834AbdHYJTM (ORCPT ); Fri, 25 Aug 2017 05:19:12 -0400 Received: by mail-wm0-f68.google.com with SMTP id z132so1937374wmg.5 for ; Fri, 25 Aug 2017 02:19:12 -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=QKrYek8nLBVOgaErp/bJ3ZZ+h9/UDLCkfojufNEQ180=; b=EETCCgSCZwwFHqBuSTT3TeVFGNwhyAiUG89E2kFSu/FJEHNlQQsWNapGRb8FS1lqlv aWJPlSxP/EEQQpVeCByBlSj6uqxdRdNJ1flp03JX3eR11DRYAWJJl5czVmUWv//8NU1x JkIhiyAQC3o7tXfdL3mKmOVisQAhOcuH87/IFw68qEuEkYURKCn9bijC7MUwXhIgPkkH RjrkQgTupOSmO3h8MpCssUZM8YQp6rQN8T3Q/c51Ypir9PBtBQhW2WPIPWICwE1uaEBx RoWFRPAWNSiny1oyq1P0Hwq/INuYM9gx2rjLC40E7Y4yr9Wn11wUgbWAq0ZsefSUferq 28ZQ== 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=QKrYek8nLBVOgaErp/bJ3ZZ+h9/UDLCkfojufNEQ180=; b=qdnuoLcPKDAoAh/N5pk95umdJ4HChzsvhHcBNqoSjavvYszIthNctT+uLFF57j6Hex Pj3J764pGIgWYETrFvqUne8f8zilGa6J/ik7qmtOx66mQiPob2ITtax0vl4IkGcxNsfV w8/xDjuKfJkQKHb1iwunIzawmAkZplc6Sves25OiqZCF7ID5UI+02ok6mPVm2k101xtO cJFPdP0hHC2eH5XVx8FjfX2b+I7j1gT6A1SyCRLFla7D0mITRZmWphcS0qkwlB1uMUrV c2SQG8oov8BzNWBkCLJVrhr0UHjtD6ZKUd9ZUxREp0acGMbKuVvfWQmZEEnFehT96Pkq fXMQ== X-Gm-Message-State: AHYfb5hH8OlZ46V79j53MBVF/oJdK/GxnGsZoH4tL3tnRvotU9F0Ded4 IrndllK+Csh4vEyN X-Received: by 10.28.206.136 with SMTP id e130mr1150217wmg.91.1503652751599; Fri, 25 Aug 2017 02:19:11 -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.10 (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 3/6] Btrfs: implement heuristic sampling logic Date: Fri, 25 Aug 2017 12:18:42 +0300 Message-Id: <20170825091845.4120-4-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 Copy sample data from input data range to sample buffer then calculate byte type count for that sample into bucket. Signed-off-by: Timofey Titovets --- fs/btrfs/heuristic.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) -- 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 e3924c87af08..5192e51ab81e 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -69,8 +69,20 @@ static struct list_head *heuristic_alloc_workspace(void) static int heuristic(struct list_head *ws, struct inode *inode, u64 start, u64 end) { + struct workspace *workspace = list_entry(ws, struct workspace, list); struct page *page; u64 index, index_end; + u32 a, b; + u8 *in_data, *sample = workspace->sample; + u8 byte; + + /* + * Compression only handle first 128kb of input range + * And just shift over range in loop for compressing it. + * Let's do the same. + */ + if (end - start > BTRFS_MAX_UNCOMPRESSED) + end = start + BTRFS_MAX_UNCOMPRESSED; index = start >> PAGE_SHIFT; index_end = end >> PAGE_SHIFT; @@ -79,13 +91,37 @@ static int heuristic(struct list_head *ws, struct inode *inode, if (!IS_ALIGNED(end, PAGE_SIZE)) index_end++; + b = 0; for (; index < index_end; index++) { page = find_get_page(inode->i_mapping, index); - kmap(page); + in_data = kmap(page); + /* Handle case where start unaligned to PAGE_SIZE */ + a = start%PAGE_SIZE; + while (a < PAGE_SIZE - READ_SIZE) { + /* Prevent sample overflow */ + if (b >= MAX_SAMPLE_SIZE) + break; + /* Don't sample mem trash from last page */ + if (start > end - READ_SIZE) + break; + memcpy(&sample[b], &in_data[a], READ_SIZE); + a += ITER_SHIFT; + start += ITER_SHIFT; + b += READ_SIZE; + } kunmap(page); put_page(page); } + workspace->sample_size = b; + + memset(workspace->bucket, 0, sizeof(*workspace->bucket)*BUCKET_SIZE); + + for (a = 0; a < workspace->sample_size; a++) { + byte = sample[a]; + workspace->bucket[byte].count++; + } + return 1; }