From patchwork Sat Mar 10 18:17:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273839 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 7DF52602BD for ; Sat, 10 Mar 2018 18:20:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D47628BAE for ; Sat, 10 Mar 2018 18:20:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61CB1293FC; Sat, 10 Mar 2018 18:20:39 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 041F928BAE for ; Sat, 10 Mar 2018 18:20:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 232C72258AF1C; Sat, 10 Mar 2018 10:14:20 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::241; helo=mail-pg0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1CBB22258AF1A for ; Sat, 10 Mar 2018 10:14:17 -0800 (PST) Received: by mail-pg0-x241.google.com with SMTP id r26so4828161pgv.13 for ; Sat, 10 Mar 2018 10:20:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gCOc/n9fK4CUfp0RS2P03HBOKNEuZ+C8j+HlKjcgT/4=; b=NtiLXxxa76t94qDFy6AnGro2WM36sU/hB1Jc4tbLAKePJI11cLg2keB8rFgcIqn77r TO0sBc5g/B7TwANVPDoNuAJuJkq6IDnQZNarKdH2J8MqF/DiXBG8LPKV7dNgF+ejQttt xF/Reb2R9czgP2yl/1CH4l4JbyIH//yYp+N3s= 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=gCOc/n9fK4CUfp0RS2P03HBOKNEuZ+C8j+HlKjcgT/4=; b=L9Ud3YXk/n3a1Qjl2Jx6c76CHwWBmi1LcD1wyRL8JNkjXDDT9ad96VEy5YHAA2/IYA 86E/M9OrCzd8WGQUt+/I7Facg5uKonSc6H8aL+Cl4tbbQ4yCn6m6TkhBDTvylbs1o//1 ET1yNCKuQ1JgyFtFMwus8hyIKaWva/VvKZj1hKSTEVy+fhaQyz1tivgnLDm/rjt6q420 NWjQy3siECrtZBoutLo54/lzUoKCTucgALMuLp4BQl9URW11C4xRTB6AzaM9IdBUHQfT ZkR0U/qHt3xaOyenDYjeW0bhcC818L8OoktQz9mcrkD1mRh89r5oEm9h3NdC9Y3mAFai 4Sfw== X-Gm-Message-State: AElRT7Fsnrwnpnbn056W/s8EfBzxpde2uiUnBQJwwgKQGzID4YzDZBwN N9PcDglDiNJX0fGwaYfB7PK2hw== X-Google-Smtp-Source: AG47ELuI0rrtqekL3RRSj4vgfHfQ44IU7NC9jIkl7So4M1OORVFmaD3bs+1y2KO0umr5VmhfnFJx9Q== X-Received: by 10.99.60.72 with SMTP id i8mr2163592pgn.399.1520706035499; Sat, 10 Mar 2018 10:20:35 -0800 (PST) Received: from brienza-desktop.8.8.4.4 (andxu.ucsd.edu. [132.239.17.134]) by smtp.gmail.com with ESMTPSA id h80sm9210167pfj.181.2018.03.10.10.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:34 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 16/83] Initialize block map and free lists in nova_init(). Date: Sat, 10 Mar 2018 10:17:57 -0800 Message-Id: <1520705944-6723-17-git-send-email-jix024@eng.ucsd.edu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coughlan@redhat.com, miklos@szeredi.hu, Andiry Xu , david@fromorbit.com, jack@suse.com, swanson@cs.ucsd.edu, swhiteho@redhat.com, andiry.xu@gmail.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Andiry Xu NOVA divides the pmem range equally among per-CPU free lists, and format the red-black trees by inserting the initial free range. Signed-off-by: Andiry Xu --- fs/nova/balloc.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/balloc.h | 13 ++++- fs/nova/super.c | 2 + 3 files changed, 175 insertions(+), 1 deletion(-) diff --git a/fs/nova/balloc.c b/fs/nova/balloc.c index 450c942..cb627db 100644 --- a/fs/nova/balloc.c +++ b/fs/nova/balloc.c @@ -55,4 +55,165 @@ void nova_delete_free_lists(struct super_block *sb) sbi->free_lists = NULL; } +// Initialize a free list. Each CPU gets an equal share of the block space to +// manage. +static void nova_init_free_list(struct super_block *sb, + struct free_list *free_list, int index) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + unsigned long per_list_blocks; + + per_list_blocks = sbi->num_blocks / sbi->cpus; + + free_list->block_start = per_list_blocks * index; + free_list->block_end = free_list->block_start + + per_list_blocks - 1; + if (index == 0) + free_list->block_start += sbi->head_reserved_blocks; + if (index == sbi->cpus - 1) + free_list->block_end -= sbi->tail_reserved_blocks; +} + +inline struct nova_range_node *nova_alloc_blocknode(struct super_block *sb) +{ + return nova_alloc_range_node(sb); +} + +inline void nova_free_blocknode(struct super_block *sb, + struct nova_range_node *node) +{ + nova_free_range_node(node); +} + +void nova_init_blockmap(struct super_block *sb, int recovery) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct rb_root *tree; + struct nova_range_node *blknode; + struct free_list *free_list; + int i; + int ret; + + /* Divide the block range among per-CPU free lists */ + sbi->per_list_blocks = sbi->num_blocks / sbi->cpus; + for (i = 0; i < sbi->cpus; i++) { + free_list = nova_get_free_list(sb, i); + tree = &(free_list->block_free_tree); + nova_init_free_list(sb, free_list, i); + + /* For recovery, update these fields later */ + if (recovery == 0) { + free_list->num_free_blocks = free_list->block_end - + free_list->block_start + 1; + + blknode = nova_alloc_blocknode(sb); + if (blknode == NULL) + return; + blknode->range_low = free_list->block_start; + blknode->range_high = free_list->block_end; + ret = nova_insert_blocktree(sbi, tree, blknode); + if (ret) { + nova_err(sb, "%s failed\n", __func__); + nova_free_blocknode(sb, blknode); + return; + } + free_list->first_node = blknode; + free_list->last_node = blknode; + free_list->num_blocknode = 1; + } + + nova_dbgv("%s: free list %d: block start %lu, end %lu, %lu free blocks\n", + __func__, i, + free_list->block_start, + free_list->block_end, + free_list->num_free_blocks); + } +} + +static inline int nova_rbtree_compare_rangenode(struct nova_range_node *curr, + unsigned long range_low) +{ + if (range_low < curr->range_low) + return -1; + if (range_low > curr->range_high) + return 1; + return 0; +} + +int nova_find_range_node(struct nova_sb_info *sbi, + struct rb_root *tree, unsigned long range_low, + struct nova_range_node **ret_node) +{ + struct nova_range_node *curr = NULL; + struct rb_node *temp; + int compVal; + int ret = 0; + + temp = tree->rb_node; + + while (temp) { + curr = container_of(temp, struct nova_range_node, node); + compVal = nova_rbtree_compare_rangenode(curr, range_low); + + if (compVal == -1) { + temp = temp->rb_left; + } else if (compVal == 1) { + temp = temp->rb_right; + } else { + ret = 1; + break; + } + } + + *ret_node = curr; + return ret; +} + + +int nova_insert_range_node(struct rb_root *tree, + struct nova_range_node *new_node) +{ + struct nova_range_node *curr; + struct rb_node **temp, *parent; + int compVal; + + temp = &(tree->rb_node); + parent = NULL; + + while (*temp) { + curr = container_of(*temp, struct nova_range_node, node); + compVal = nova_rbtree_compare_rangenode(curr, + new_node->range_low); + parent = *temp; + + if (compVal == -1) { + temp = &((*temp)->rb_left); + } else if (compVal == 1) { + temp = &((*temp)->rb_right); + } else { + nova_dbg("%s: entry %lu - %lu already exists: %lu - %lu\n", + __func__, new_node->range_low, + new_node->range_high, curr->range_low, + curr->range_high); + return -EINVAL; + } + } + + rb_link_node(&new_node->node, parent, temp); + rb_insert_color(&new_node->node, tree); + + return 0; +} + +inline int nova_insert_blocktree(struct nova_sb_info *sbi, + struct rb_root *tree, struct nova_range_node *new_node) +{ + int ret; + + ret = nova_insert_range_node(tree, new_node); + if (ret) + nova_dbg("ERROR: %s failed %d\n", __func__, ret); + + return ret; +} diff --git a/fs/nova/balloc.h b/fs/nova/balloc.h index e7c7a1d..57a93e4 100644 --- a/fs/nova/balloc.h +++ b/fs/nova/balloc.h @@ -62,5 +62,16 @@ enum alloc_type { int nova_alloc_block_free_lists(struct super_block *sb); void nova_delete_free_lists(struct super_block *sb); - +inline struct nova_range_node *nova_alloc_blocknode(struct super_block *sb); +inline void nova_free_blocknode(struct super_block *sb, + struct nova_range_node *bnode); +extern void nova_init_blockmap(struct super_block *sb, int recovery); +inline int nova_insert_blocktree(struct nova_sb_info *sbi, + struct rb_root *tree, struct nova_range_node *new_node); + +extern int nova_insert_range_node(struct rb_root *tree, + struct nova_range_node *new_node); +extern int nova_find_range_node(struct nova_sb_info *sbi, + struct rb_root *tree, unsigned long range_low, + struct nova_range_node **ret_node); #endif diff --git a/fs/nova/super.c b/fs/nova/super.c index 43b24a7..9762f26 100644 --- a/fs/nova/super.c +++ b/fs/nova/super.c @@ -376,6 +376,8 @@ static struct nova_inode *nova_init(struct super_block *sb, pi->nova_ino = NOVA_BLOCKNODE_INO; nova_flush_buffer(pi, CACHELINE_SIZE, 1); + nova_init_blockmap(sb, 0); + sbi->nova_sb->s_size = cpu_to_le64(size); sbi->nova_sb->s_blocksize = cpu_to_le32(blocksize); sbi->nova_sb->s_magic = cpu_to_le32(NOVA_SUPER_MAGIC);