From: Mark Fasheh <mfasheh@suse.de>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org, Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Subject: Re: [PATCH v10 03/21] btrfs: dedupe: Introduce function to add hash into in-memory tree
Date: Wed, 1 Jun 2016 12:37:41 -0700 [thread overview]
Message-ID: <20160601193741.GF7633@wotan.suse.de> (raw)
In-Reply-To: <1459492512-31435-4-git-send-email-quwenruo@cn.fujitsu.com>
On Fri, Apr 01, 2016 at 02:34:54PM +0800, Qu Wenruo wrote:
> From: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
>
> Introduce static function inmem_add() to add hash into in-memory tree.
> And now we can implement the btrfs_dedupe_add() interface.
>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
> ---
> fs/btrfs/dedupe.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 151 insertions(+)
>
> diff --git a/fs/btrfs/dedupe.c b/fs/btrfs/dedupe.c
> index 2211588..4e8455e 100644
> --- a/fs/btrfs/dedupe.c
> +++ b/fs/btrfs/dedupe.c
> @@ -32,6 +32,14 @@ struct inmem_hash {
> u8 hash[];
> };
>
> +static inline struct inmem_hash *inmem_alloc_hash(u16 type)
> +{
> + if (WARN_ON(type >= ARRAY_SIZE(btrfs_dedupe_sizes)))
> + return NULL;
> + return kzalloc(sizeof(struct inmem_hash) + btrfs_dedupe_sizes[type],
> + GFP_NOFS);
> +}
> +
> static int init_dedupe_info(struct btrfs_dedupe_info **ret_info, u16 type,
> u16 backend, u64 blocksize, u64 limit)
> {
> @@ -152,3 +160,146 @@ enable:
> fs_info->dedupe_enabled = 1;
> return ret;
> }
> +
> +static int inmem_insert_hash(struct rb_root *root,
> + struct inmem_hash *hash, int hash_len)
> +{
> + struct rb_node **p = &root->rb_node;
> + struct rb_node *parent = NULL;
> + struct inmem_hash *entry = NULL;
> +
> + while (*p) {
> + parent = *p;
> + entry = rb_entry(parent, struct inmem_hash, hash_node);
> + if (memcmp(hash->hash, entry->hash, hash_len) < 0)
> + p = &(*p)->rb_left;
> + else if (memcmp(hash->hash, entry->hash, hash_len) > 0)
> + p = &(*p)->rb_right;
> + else
> + return 1;
> + }
> + rb_link_node(&hash->hash_node, parent, p);
> + rb_insert_color(&hash->hash_node, root);
> + return 0;
> +}
> +
> +static int inmem_insert_bytenr(struct rb_root *root,
> + struct inmem_hash *hash)
> +{
> + struct rb_node **p = &root->rb_node;
> + struct rb_node *parent = NULL;
> + struct inmem_hash *entry = NULL;
> +
> + while (*p) {
> + parent = *p;
> + entry = rb_entry(parent, struct inmem_hash, bytenr_node);
> + if (hash->bytenr < entry->bytenr)
> + p = &(*p)->rb_left;
> + else if (hash->bytenr > entry->bytenr)
> + p = &(*p)->rb_right;
> + else
> + return 1;
> + }
> + rb_link_node(&hash->bytenr_node, parent, p);
> + rb_insert_color(&hash->bytenr_node, root);
> + return 0;
> +}
> +
> +static void __inmem_del(struct btrfs_dedupe_info *dedupe_info,
> + struct inmem_hash *hash)
> +{
> + list_del(&hash->lru_list);
> + rb_erase(&hash->hash_node, &dedupe_info->hash_root);
> + rb_erase(&hash->bytenr_node, &dedupe_info->bytenr_root);
> +
> + if (!WARN_ON(dedupe_info->current_nr == 0))
> + dedupe_info->current_nr--;
> +
> + kfree(hash);
> +}
> +
> +/*
> + * Insert a hash into in-memory dedupe tree
> + * Will remove exceeding last recent use hash.
> + *
> + * If the hash mathced with existing one, we won't insert it, to
> + * save memory
> + */
> +static int inmem_add(struct btrfs_dedupe_info *dedupe_info,
> + struct btrfs_dedupe_hash *hash)
> +{
> + int ret = 0;
> + u16 type = dedupe_info->hash_type;
> + struct inmem_hash *ihash;
> +
> + ihash = inmem_alloc_hash(type);
> +
> + if (!ihash)
> + return -ENOMEM;
> +
> + /* Copy the data out */
> + ihash->bytenr = hash->bytenr;
> + ihash->num_bytes = hash->num_bytes;
> + memcpy(ihash->hash, hash->hash, btrfs_dedupe_sizes[type]);
> +
> + mutex_lock(&dedupe_info->lock);
Can you describe somewhere in a comment why we need this mutex? It is
unclear just based on reading the code why we need a sleeping lock here.
--Mark
--
Mark Fasheh
next prev parent reply other threads:[~2016-06-01 19:37 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-01 6:34 [PATCH v10 00/21] Btrfs dedupe framework Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 01/21] btrfs: dedupe: Introduce dedupe framework and its header Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 02/21] btrfs: dedupe: Introduce function to initialize dedupe info Qu Wenruo
2016-04-01 9:59 ` kbuild test robot
2016-05-11 0:00 ` Mark Fasheh
2016-05-11 0:21 ` Qu Wenruo
2016-05-11 2:24 ` Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 03/21] btrfs: dedupe: Introduce function to add hash into in-memory tree Qu Wenruo
2016-06-01 19:37 ` Mark Fasheh [this message]
2016-06-02 0:49 ` Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 04/21] btrfs: dedupe: Introduce function to remove hash from " Qu Wenruo
2016-06-01 19:40 ` Mark Fasheh
2016-06-02 1:01 ` Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 05/21] btrfs: delayed-ref: Add support for increasing data ref under spinlock Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 06/21] btrfs: dedupe: Introduce function to search for an existing hash Qu Wenruo
2016-04-01 6:34 ` [PATCH v10 07/21] btrfs: dedupe: Implement btrfs_dedupe_calc_hash interface Qu Wenruo
2016-05-17 13:15 ` David Sterba
2016-04-01 6:34 ` [PATCH v10 08/21] btrfs: ordered-extent: Add support for dedupe Qu Wenruo
2016-06-01 22:06 ` Mark Fasheh
2016-06-02 1:08 ` Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 09/21] btrfs: dedupe: Inband in-memory only de-duplication implement Qu Wenruo
2016-06-01 22:08 ` Mark Fasheh
2016-06-02 1:12 ` Qu Wenruo
2016-06-03 14:27 ` Josef Bacik
2016-06-04 10:26 ` Qu Wenruo
2016-06-06 19:54 ` Mark Fasheh
2016-06-07 0:42 ` Qu Wenruo
2016-06-07 16:55 ` Mark Fasheh
2016-06-03 14:43 ` Josef Bacik
2016-06-04 10:28 ` Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 10/21] btrfs: try more times to alloc metadata reserve space Qu Wenruo
2016-05-17 13:20 ` David Sterba
2016-05-18 0:57 ` Qu Wenruo
2016-06-01 22:14 ` Mark Fasheh
2016-04-01 6:35 ` [PATCH v10 11/21] btrfs: dedupe: Add ioctl for inband dedupelication Qu Wenruo
2016-04-27 1:29 ` Qu Wenruo
2016-05-17 13:14 ` David Sterba
2016-05-18 0:54 ` Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 12/21] btrfs: dedupe: add an inode nodedupe flag Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 13/21] btrfs: dedupe: add a property handler for online dedupe Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 14/21] btrfs: dedupe: add per-file online dedupe control Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 15/21] btrfs: relocation: Enhance error handling to avoid BUG_ON Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 16/21] btrfs: dedupe: Add basic tree structure for on-disk dedupe method Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 17/21] btrfs: dedupe: Introduce interfaces to resume and cleanup dedupe info Qu Wenruo
2016-06-03 14:54 ` Josef Bacik
2016-04-01 6:35 ` [PATCH v10 18/21] btrfs: dedupe: Add support for on-disk hash search Qu Wenruo
2016-06-03 14:57 ` Josef Bacik
2016-04-01 6:35 ` [PATCH v10 19/21] btrfs: dedupe: Add support to delete hash for on-disk backend Qu Wenruo
2016-04-01 6:35 ` [PATCH v10 20/21] btrfs: dedupe: Add support for adding " Qu Wenruo
2016-06-03 15:03 ` Josef Bacik
2016-04-01 6:35 ` [PATCH v10 21/21] btrfs: dedupe: Preparation for compress-dedupe co-work Qu Wenruo
2016-04-01 8:53 ` [PATCH v10 16/21] btrfs: dedupe: Add basic tree structure for on-disk dedupe method Qu Wenruo
2016-06-03 15:20 ` [PATCH v10 00/21] Btrfs dedupe framework Josef Bacik
2016-06-04 10:37 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160601193741.GF7633@wotan.suse.de \
--to=mfasheh@suse.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo@cn.fujitsu.com \
--cc=wangxg.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).