From patchwork Wed Aug 23 00:26:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9916419 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 2FB7E603FF for ; Wed, 23 Aug 2017 00:27:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22859287E3 for ; Wed, 23 Aug 2017 00:27:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177FE2892C; Wed, 23 Aug 2017 00:27:26 +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 BF930287E3 for ; Wed, 23 Aug 2017 00:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752937AbdHWA1Y (ORCPT ); Tue, 22 Aug 2017 20:27:24 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:35205 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752766AbdHWA1K (ORCPT ); Tue, 22 Aug 2017 20:27:10 -0400 Received: by mail-wr0-f193.google.com with SMTP id p8so148818wrf.2 for ; Tue, 22 Aug 2017 17:27:10 -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=/X0pVJWD1t4994SU5mPbKBqDQW2uhe/q0KQZy9bRsEE=; b=PUbuX8SWU315dNNPxUc/3rzuM3AVAgB5KeOe6GY4BBCzy/KJdsX4DhtQ7NRE2y8W8N bMmTXrZ2B3P6o/tQRXFMLQCwyaJ+P8pXEHd/WhK3cbrSMp27Da3ehA/jf9Z917jbVO+B /MdyQH6HCMVEL7cL74mLxcBv7xEAFrm1P5O4hYvFIxc8QJiZQwdyYcOfvWeHO7UvQNrA mzEUdCaPVqhv4yT8S+DCeqrnpsyHwT0veuLdhBWU80bRDqSd5Ga1EhH9AdZMD40sImKV Yks5EQXbwHWIeNmYinbrr6FzhAJcLmdBovWEyvNJd+Z0xghCFuTHUoMwrlNrdIhU8t+m 8O1A== 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=/X0pVJWD1t4994SU5mPbKBqDQW2uhe/q0KQZy9bRsEE=; b=oI6pstc6C6EZc2B1eMdTPjuUiG/ElX/70hHGUWO4n0NSAOd/ri2JeU6CdatZAh0CAH s9Ov5XqXX2GV1SO4prtsHanHPdnGoDhCbX2ER/lFbCnNem6DDtwvzJxycw/S5sezgryo LLLEzwgumtoYjSBF9kjrc8U/HO0zi39zwHyn8nv5VVHcx+y1G631tdeq0SzrrL2mbp5n qKsWqnADAQZVTbZZcTzFuUrIEbJRxDcPV+NYjDQfMa6DldjKwTi9EEd5pQHk51mYowLd wRjZGcqDBc1HOfOiMDzufKj5IHXTMHLkB/lHeCI0hgeRaYAuYb2gk6C8DD50MKz0/883 vGxg== X-Gm-Message-State: AHYfb5g/8RfF9WR6zDtkoDCBXIdfA1CgHRJjc4DkChXuD56O4UHKi1nZ atdfEb51Rdsj6qG/ X-Received: by 10.223.165.3 with SMTP id i3mr546431wrb.298.1503448029600; Tue, 22 Aug 2017 17:27:09 -0700 (PDT) Received: from titovetst-l.itransition.corp (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id k45sm136926wre.1.2017.08.22.17.27.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 17:27:09 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v5 3/6] Btrfs: implement heuristic sampling logic Date: Wed, 23 Aug 2017 03:26:47 +0300 Message-Id: <20170823002650.3133-4-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823002650.3133-1-nefelim4ag@gmail.com> References: <20170823002650.3133-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 | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) -- 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 2c2cadc9dfad..5336638a3b7c 100644 --- a/fs/btrfs/heuristic.c +++ b/fs/btrfs/heuristic.c @@ -76,20 +76,47 @@ 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; - u8 *input_data; + u8 *in_data; + u32 a, b; + 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; + b = 0; for (; index <= index_end; index++) { page = find_get_page(inode->i_mapping, index); - input_data = kmap(page); + in_data = kmap(page); + a = 0; + while (a < PAGE_SIZE-READ_SIZE && b < MAX_SAMPLE_SIZE) { + memcpy(&workspace->sample[b], &in_data[a], READ_SIZE); + a += 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 = workspace->sample[a]; + workspace->bucket[byte].count++; + } + return 1; }