From patchwork Wed Aug 23 22:45: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: 9918595 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 14414600C5 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 07EF728A7E for ; Wed, 23 Aug 2017 22:46:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0FCE28A9F; Wed, 23 Aug 2017 22:46:14 +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 8FFC628A7E for ; Wed, 23 Aug 2017 22:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751201AbdHWWqM (ORCPT ); Wed, 23 Aug 2017 18:46:12 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34239 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751102AbdHWWqA (ORCPT ); Wed, 23 Aug 2017 18:46:00 -0400 Received: by mail-wr0-f195.google.com with SMTP id f6so529798wra.1 for ; Wed, 23 Aug 2017 15:45:59 -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=D3DariVH8UubcXQNCWSuL1RGpnuNhgGaeD3x/1J8qjQ=; b=WGjXWU8H1nK1Hjox881V1eGutI6JRD4TnXITWeJVD4bJKElSAEliGFv/XtBzeQA5oU v/dmKYCAfotj1bWfMdfjo1qYgM0FR/v2eQMUx2fZas1Gl6tDm0V0KdjXx4xS0hwDHsAo QnjysDZ6zyu0XuTrzeW0AiEJCVMhWiARUP5gVIjymRdo1LtVGI0GosT40oSlZEV+epIe 98Knnp/49REl46t95nmAd2kf/LKheKmMyd0BA4w8kamYpJ0K2HNbfPZ+nQ6TY+Dx0cnH W5jaMqPPMjuJqVljrh/v2HE39MizzkAKU9D/b+ijfZRd4hljDKfvRwKdDmMxmadINsbC wJLA== 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=D3DariVH8UubcXQNCWSuL1RGpnuNhgGaeD3x/1J8qjQ=; b=q4ZFU5w91Zi/JdJ6mDrjjylsgfZh+hTv6DdWs0G30i69UHq5JTrgsjQ1ZFk0F3L+OH erq01pbyOAeEhHHsDNNxyQ/V7G+zPnHswx3aBcmcDAxUQeljPFxCoeRj6VSO/kWQ97SF LXHlIjEjLJ1cKxwAxJfOnaGlCZ+zMBYIkhobhLvHhT2s4Wx9gA4soQeE8f9Qu7nxNYeR kUdtp2UNw1BhFXu2ePElDrSxowH5gKO8JWRvS2pCvdxadNzu11fUgzUc8/VIiNBj0k7v gqPQn00bnMLAHssLsJafdEeyCI5w8u72kD40qpcqlV77yqITzZ4TRjifE4vU8UB2A/jF bjBA== X-Gm-Message-State: AHYfb5jz8fc0/9vxU/8tbsw93aX3q4itAIZl+QBO3xPCRgmnOOaUQJ0u oMGF7otId80q83va X-Received: by 10.223.132.164 with SMTP id 33mr2271311wrg.132.1503528358893; Wed, 23 Aug 2017 15:45:58 -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:58 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v6 3/6] Btrfs: implement heuristic sampling logic Date: Thu, 24 Aug 2017 01:45:42 +0300 Message-Id: <20170823224545.16375-4-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 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 9a212674f527..001118f98143 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; @@ -82,13 +94,37 @@ static int heuristic(struct list_head *ws, struct inode *inode, if(end%PAGE_SIZE == 0) 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; }