From patchwork Sat Jan 2 03:08:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanidhya Solanki X-Patchwork-Id: 7940481 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 730459F387 for ; Sat, 2 Jan 2016 07:11:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75B2020490 for ; Sat, 2 Jan 2016 07:11:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F7F120481 for ; Sat, 2 Jan 2016 07:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751462AbcABHLB (ORCPT ); Sat, 2 Jan 2016 02:11:01 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:37079 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbcABHLA (ORCPT ); Sat, 2 Jan 2016 02:11:00 -0500 Received: by mail-wm0-f52.google.com with SMTP id f206so151881323wmf.0; Fri, 01 Jan 2016 23:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=vvgBY1VodBFCITxwegzcjyyulp69ow+D1R4fAfnHVDg=; b=lxVF9wB6bqMOtjWDEsZRyiXrbxuhL4ri2FJG5zw0i6tyd2loCCUSi3SOErhUzyvN/Q /UgIGTgZUCtH6kchCkCZ6gEJnu1BcY+aunTNrXiP+M9tb7ePWqZic+0zZ0ZCooSmkRCV W9/GvtHsJJe4zaE2+qVQZ6E0HePZ9eRP/BX88LgAz3OsrbF+jWQvawFkp9kIVkDmeY7O p0yHl4oWs4XrE/veebuj8CtNSP3ttfGdyygaHg152PCOKTPlWP5VhCmCLe6XzDIEervR M9vOg7Yq/brVRcfnUJf5Y/LfDUoozDcMV+RDFTZ8lePRQrUCg1DFE1rGkplpjc94HAQG FvuQ== X-Received: by 10.194.94.41 with SMTP id cz9mr68851324wjb.169.1451718658417; Fri, 01 Jan 2016 23:10:58 -0800 (PST) Received: from localhost.censurfridns.dk (KD121105133187.ppp-bb.dion.ne.jp. [121.105.133.187]) by smtp.gmail.com with ESMTPSA id bh6sm76227854wjb.0.2016.01.01.23.10.41 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 01 Jan 2016 23:10:57 -0800 (PST) From: Sanidhya Solanki To: clm@fb.com, jbacik@fb.com, dsterba@suse.com, jpage.lkml@gmail.com Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH] BTRFS: Adds the files and options needed for Hybrid Storage Date: Fri, 1 Jan 2016 22:08:32 -0500 Message-Id: <1451704112-25463-1-git-send-email-jpage.lkml@gmail.com> X-Mailer: git-send-email 2.5.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DATE_IN_PAST_03_06, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the file required for Hybrid Storage. It contains the memory, time and size limits for the cache and the statistics that will be provided while the cache is operating. It also adds the Makefile changes needed to add the Hybrid Storage. Signed-off-by: Sanidhya Solanki --- fs/btrfs/Makefile | 2 +- fs/btrfs/cache.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/cache.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 6d1d0b9..dc56ae4 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -9,7 +9,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ export.o tree-log.o free-space-cache.o zlib.o lzo.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ - uuid-tree.o props.o hash.o + uuid-tree.o props.o hash.o cache.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o diff --git a/fs/btrfs/cache.c b/fs/btrfs/cache.c new file mode 100644 index 0000000..0ece7a1 --- /dev/null +++ b/fs/btrfs/cache.c @@ -0,0 +1,58 @@ +/* + * (c) Sanidhya Solanki, 2016 + * + * Licensed under the FSF's GNU Public License v2 or later. + */ +#include + +/* Cache size configuration )in MiB).*/ +#define MAX_CACHE_SIZE = 10000 +#define MIN_CACHE_SIZE = 10 + +/* Time (in seconds)before retrying to increase the cache size.*/ +#define CACHE_RETRY = 10 + +/* Space required to be free (in MiB) before increasing the size of the + * cache. If cache size is less than cache_grow_limit, a block will be freed + * from the cache to allow the cache to continue growning. + */ +#define CACHE_GROW_LIMIT = 100 + +/* Size required to be free (in MiB) after we shrink the cache, so that it + * does not grow in size immediately. + */ +#define CACHE_SHRINK_FREE_SPACE_LIMIT = 100 + +/* Age (in seconds) of oldest and newest block in the cache.*/ +#define MAX_AGE_LIMIT = 300 /* Five Minute Rule recommendation, + * optimum size depends on size of data + * blocks. + */ +#define MIN_AGE_LIMIT = 15 /* In case of cache stampede.*/ + +/* Memory constraints (in percentage) before we stop caching.*/ +#define MIN_MEM_FREE = 10 + +/* Cache statistics. */ +struct cache_stats { + u64 cache_size; + u64 maximum_cache_size_attained; + int cache_hit_rate; + int cache_miss_rate; + u64 cache_evicted; + u64 duplicate_read; + u64 duplicate_write; + int stats_update_interval; +}; + +#define cache_size CACHE_SIZE /* Current cache size.*/ +#define max_cache_size MAX_SIZE /* Max cache limit. */ +#define min_cache_size MIN_SIZE /* Min cache limit.*/ +#define cache_time MAX_TIME /* Maximum time to keep data in cache.*/ +#define evicted_csum EVICTED_CSUM /* Checksum of the evited data + * (to avoid repeatedly caching + * data that was just evicted. + */ +#define read_csum READ_CSUM /* Checksum of the read data.*/ +#define write_csum WRITE_CSUM /* Checksum of the written data.*/ +#define evict_interval EVICT_INTERVAL /* Time to keep data before eviction.*/