From patchwork Sat Mar 10 18:18:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273861 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 B5A90602BD for ; Sat, 10 Mar 2018 18:20:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4EDA28BAE for ; Sat, 10 Mar 2018 18:20:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99510293FC; Sat, 10 Mar 2018 18:20:51 +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 5693A28BAE for ; Sat, 10 Mar 2018 18:20:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0D2B622603B01; Sat, 10 Mar 2018 10:14:32 -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:c01::241; helo=mail-pl0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::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 3DCCC22603AE2 for ; Sat, 10 Mar 2018 10:14:28 -0800 (PST) Received: by mail-pl0-x241.google.com with SMTP id d9-v6so7016786plo.8 for ; Sat, 10 Mar 2018 10:20:47 -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=ANvV4FGsSahsH/F08alqlQHRFiyb2r1ho/EiFwaMnwg=; b=NjFJXa2J7Z8HUteylVEaRtJgEsA7iR7bp8BhjAqcHZ9pXk/SeorcD5oThPPs6luKw6 ZBMd8OVUssuUBohN6vPe32SeXQ91/TPFMYTCGlMAjzswNQaWiKtKbL0CzBrXdbqPNlNH gHNKZW1tUA/VDB7a4co1m9W6VwgNx6IZQLwbc= 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=ANvV4FGsSahsH/F08alqlQHRFiyb2r1ho/EiFwaMnwg=; b=Wm76nDecrcqwrdw/urs62s6gqD4KYuE9XoOOV0E2ScY12BYoIB4ZoEN+M0sHrI7am5 kW2JwCaqg0uQNMuXbISSALwfdtoUy3bf7SigjwbZhKareRvHursXIcbXIsNdORluJ/PI IaOs8KsUgL1099mvgE8dSkB7LMgJKe0Gm+9Rp03I5FaiqrYAp8Gv0G/p12nfDF4aoiKp sXafhozLfiWfAE6GRt0Sa0Yr8NNccHRFx8RlG6NxtoWmZ6Gr6MbrOBhzdh7H1NnhkIFs PI88lyu9/Rtwtw7OdX1UzAljqpePJGs5UOFWUNoeVE7Diram6VEADarLXchrUZjZ6MV3 BCxQ== X-Gm-Message-State: AElRT7EfenbqjaHKZGhpNKFHmMaJt/c7+cOnPufV8xm9i71WcrVNZV4o LbI3PoC5wxY99qQ19hcsNOVBmQ== X-Google-Smtp-Source: AG47ELtJbqcQFzn42WT51zByu52Z6IDueQQKBXyo5ZpExq/Jhcwxu6zPxOgcWW74dBoNcQmD0tkg8w== X-Received: by 2002:a17:902:365:: with SMTP id 92-v6mr2794916pld.127.1520706046686; Sat, 10 Mar 2018 10:20:46 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:46 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 25/83] Support get normal inode address and inode table extentsion. Date: Sat, 10 Mar 2018 10:18:06 -0800 Message-Id: <1520705944-6723-26-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 Inodes are assigned to per-CPU inode tables in a round-robin way: If there are four cores, then CPU 0's inode table contains inode 0, inode 4, inode 8, ... CPU 1's inode table contains inode 1, inode 5, inode 9, ... CPU 2's inode table contains inode 2, inode 6, inode 10, ... CPU 3's inode table contains inode 3, inode 7, inode 11, ... So given an inode number, the inode table and inode position can be easily calculated. If NOVA runs out of 2MB inode table size, it will allocate a new 2MB log page and links it to the tail of the previous inode table. Signed-off-by: Andiry Xu --- fs/nova/inode.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/fs/nova/inode.c b/fs/nova/inode.c index 42816ff..4e2842d 100644 --- a/fs/nova/inode.c +++ b/fs/nova/inode.c @@ -167,18 +167,81 @@ static int nova_read_inode(struct super_block *sb, struct inode *inode, return ret; } -/* Get the address in PMEM of an inode by inode number. Allocate additional +/* + * Get the address in PMEM of an inode by inode number. Allocate additional * block to store additional inodes if necessary. */ int nova_get_inode_address(struct super_block *sb, u64 ino, u64 *pi_addr, int extendable) { + struct nova_sb_info *sbi = NOVA_SB(sb); + struct nova_inode_info_header sih; + struct inode_table *inode_table; + unsigned int data_bits; + unsigned int num_inodes_bits; + u64 curr; + unsigned int superpage_count; + u64 internal_ino; + int cpuid; + int extended = 0; + unsigned int index; + unsigned int i = 0; + unsigned long blocknr; + unsigned long curr_addr; + int allocated; + if (ino < NOVA_NORMAL_INODE_START) { *pi_addr = nova_get_reserved_inode_addr(sb, ino); return 0; } - *pi_addr = 0; + sih.ino = NOVA_INODETABLE_INO; + sih.i_blk_type = NOVA_BLOCK_TYPE_2M; + data_bits = blk_type_to_shift[sih.i_blk_type]; + num_inodes_bits = data_bits - NOVA_INODE_BITS; + + cpuid = ino % sbi->cpus; + internal_ino = ino / sbi->cpus; + + inode_table = nova_get_inode_table(sb, cpuid); + superpage_count = internal_ino >> num_inodes_bits; + index = internal_ino & ((1 << num_inodes_bits) - 1); + + curr = inode_table->log_head; + if (curr == 0) + return -EINVAL; + + for (i = 0; i < superpage_count; i++) { + if (curr == 0) + return -EINVAL; + + curr_addr = (unsigned long)nova_get_block(sb, curr); + /* Next page pointer in the last 8 bytes of the superpage */ + curr_addr += nova_inode_blk_size(&sih) - 8; + curr = *(u64 *)(curr_addr); + + if (curr == 0) { + if (extendable == 0) + return -EINVAL; + + extended = 1; + + allocated = nova_new_log_blocks(sb, &sih, &blocknr, + 1, ALLOC_INIT_ZERO, cpuid, ALLOC_FROM_HEAD); + + if (allocated != 1) + return allocated; + + curr = nova_get_block_off(sb, blocknr, + NOVA_BLOCK_TYPE_2M); + *(u64 *)(curr_addr) = curr; + nova_flush_buffer((void *)curr_addr, + NOVA_INODE_SIZE, 1); + } + } + + *pi_addr = curr + index * NOVA_INODE_SIZE; + return 0; }