From patchwork Sat Mar 10 18:18:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273851 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 50BBB602BD for ; Sat, 10 Mar 2018 18:20:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FBCE28BAE for ; Sat, 10 Mar 2018 18:20:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34498296E5; Sat, 10 Mar 2018 18:20:46 +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 D242C28BAE for ; Sat, 10 Mar 2018 18:20:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4143022603AEA; Sat, 10 Mar 2018 10:14:26 -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:c00::244; helo=mail-pf0-x244.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (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 4EF892258AF16 for ; Sat, 10 Mar 2018 10:14:23 -0800 (PST) Received: by mail-pf0-x244.google.com with SMTP id h19so2612350pfd.12 for ; Sat, 10 Mar 2018 10:20:42 -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=vkvaVrVwUmA+Gb85ZYAqs2iVltGBdaprIHG6d9xdn28=; b=EPQyFqRb//wXuDYIK7/9S9jlhyX2WjAeyrGWVk/uxRHAgfOW7lx46tHJEY27dPp/pw 1Tty8c6SZAfXnbXxzWD48oWquL0TTyzcusltO5+8se/D/kd+fYwY0TI52Qux+6k2GyxZ xUOVbhAK1rmzYgpSC4NVmpmyc3QiW4NBMyJno= 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=vkvaVrVwUmA+Gb85ZYAqs2iVltGBdaprIHG6d9xdn28=; b=gWZq8MhegUlrGvcTg7K745494uIhGQlJrWvftfA98joUYi0098CpUMGAI1cV9TISUr C9rmur/zInPlZU19+iohUOKWvd0sVXFyOlJawy/L+iYn9+41uyZ0FWwRU8wWxi1pAyM1 qodXMPWHJ5eXotx+rflkH17HAZ9X43ji0lbdYT/iPtKRwNj+3bKklR7Z2Y10lZqD8SRE 3XojsGLeIStjX4Jc5X/bI8jbnMnrRtacE+9GKK/+nVf0BQAoUceCIQGnp9dSbaWRF4E+ ejDIxfouHj6d7DfRNqRqmpG3s0vcNlwpxyl0f2Xr4ZXhecvU80bNJEdKFSw9HF0wGnB2 aGpA== X-Gm-Message-State: AElRT7GR7yTcUG1xTu5Apt5Hl6laW0IU4aUvMmtPg3epKysu/Mr2lKJd zb3TFRQPTH6d5vJsmEanQQe4qA== X-Google-Smtp-Source: AG47ELuk4zAKNt8Buqk4FCt8bk86FO8tAmYFS8u5EJZfZ6jZQkuc81sesl+DuF0Y4xyPvqyy3msOwQ== X-Received: by 10.98.19.146 with SMTP id 18mr2682318pft.3.1520706041634; Sat, 10 Mar 2018 10:20:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:41 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 21/83] Add log structure. Date: Sat, 10 Mar 2018 10:18:02 -0800 Message-Id: <1520705944-6723-22-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 log is a singly linked list of 4KB pmem pages. Each log page consists of two parts: 4064 bytes for log entries, and 32 bytes for page tail structure. Page tail contains metadata about the log page and the address of the next log page in the linked list. Signed-off-by: Andiry Xu --- fs/nova/log.h | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/nova.h | 1 + 2 files changed, 188 insertions(+) create mode 100644 fs/nova/log.h diff --git a/fs/nova/log.h b/fs/nova/log.h new file mode 100644 index 0000000..61586a3 --- /dev/null +++ b/fs/nova/log.h @@ -0,0 +1,187 @@ +#ifndef __LOG_H +#define __LOG_H + +#include "balloc.h" +#include "inode.h" + +/* ======================= Log entry ========================= */ +/* Inode entry in the log */ + +#define MAIN_LOG 0 +#define ALTER_LOG 1 + +#define PAGE_OFFSET_MASK 4095 +#define BLOCK_OFF(p) ((p) & ~PAGE_OFFSET_MASK) + +#define ENTRY_LOC(p) ((p) & PAGE_OFFSET_MASK) + +#define LOG_BLOCK_TAIL 4064 +#define PAGE_TAIL(p) (BLOCK_OFF(p) + LOG_BLOCK_TAIL) + +/* + * Log page state and pointers to next page and the replica page + */ +struct nova_inode_page_tail { + __le32 invalid_entries; + __le32 num_entries; + __le64 epoch_id; /* For snapshot list page */ + __le64 padding; + __le64 next_page; +} __attribute((__packed__)); + +/* Fit in PAGE_SIZE */ +struct nova_inode_log_page { + char padding[LOG_BLOCK_TAIL]; + struct nova_inode_page_tail page_tail; +} __attribute((__packed__)); + + +enum nova_entry_type { + FILE_WRITE = 1, + DIR_LOG, + SET_ATTR, + LINK_CHANGE, + NEXT_PAGE, +}; + +static inline u8 nova_get_entry_type(void *p) +{ + u8 type; + int rc; + + rc = memcpy_mcsafe(&type, p, sizeof(u8)); + if (rc) + return rc; + + return type; +} + +static inline void nova_set_entry_type(void *p, enum nova_entry_type type) +{ + *(u8 *)p = type; +} + +static inline u64 next_log_page(struct super_block *sb, u64 curr) +{ + struct nova_inode_log_page *curr_page; + u64 next = 0; + int rc; + + curr = BLOCK_OFF(curr); + curr_page = (struct nova_inode_log_page *)nova_get_block(sb, curr); + rc = memcpy_mcsafe(&next, &curr_page->page_tail.next_page, + sizeof(u64)); + if (rc) + return rc; + + return next; +} + +static inline void nova_set_next_page_flag(struct super_block *sb, u64 curr_p) +{ + void *p; + + if (ENTRY_LOC(curr_p) >= LOG_BLOCK_TAIL) + return; + + p = nova_get_block(sb, curr_p); + nova_set_entry_type(p, NEXT_PAGE); + nova_flush_buffer(p, CACHELINE_SIZE, 1); +} + +static inline void nova_set_next_page_address(struct super_block *sb, + struct nova_inode_log_page *curr_page, u64 next_page, int fence) +{ + curr_page->page_tail.next_page = next_page; + nova_flush_buffer(&curr_page->page_tail, + sizeof(struct nova_inode_page_tail), 0); + if (fence) + PERSISTENT_BARRIER(); +} + +static inline void nova_set_page_num_entries(struct super_block *sb, + struct nova_inode_log_page *curr_page, int num, int flush) +{ + curr_page->page_tail.num_entries = num; + if (flush) + nova_flush_buffer(&curr_page->page_tail, + sizeof(struct nova_inode_page_tail), 0); +} + +static inline void nova_set_page_invalid_entries(struct super_block *sb, + struct nova_inode_log_page *curr_page, int num, int flush) +{ + curr_page->page_tail.invalid_entries = num; + if (flush) + nova_flush_buffer(&curr_page->page_tail, + sizeof(struct nova_inode_page_tail), 0); +} + +static inline void nova_inc_page_num_entries(struct super_block *sb, + u64 curr) +{ + struct nova_inode_log_page *curr_page; + + curr = BLOCK_OFF(curr); + curr_page = (struct nova_inode_log_page *)nova_get_block(sb, curr); + + curr_page->page_tail.num_entries++; + nova_flush_buffer(&curr_page->page_tail, + sizeof(struct nova_inode_page_tail), 0); +} + +static inline void nova_inc_page_invalid_entries(struct super_block *sb, + u64 curr) +{ + struct nova_inode_log_page *curr_page; + + curr = BLOCK_OFF(curr); + curr_page = (struct nova_inode_log_page *)nova_get_block(sb, curr); + + curr_page->page_tail.invalid_entries++; + if (curr_page->page_tail.invalid_entries > + curr_page->page_tail.num_entries) { + nova_dbg("Page 0x%llx has %u entries, %u invalid\n", + curr, + curr_page->page_tail.num_entries, + curr_page->page_tail.invalid_entries); + } + + nova_flush_buffer(&curr_page->page_tail, + sizeof(struct nova_inode_page_tail), 0); +} + +static inline bool is_last_entry(u64 curr_p, size_t size) +{ + unsigned int entry_end; + + entry_end = ENTRY_LOC(curr_p) + size; + + return entry_end > LOG_BLOCK_TAIL; +} + +static inline bool goto_next_page(struct super_block *sb, u64 curr_p) +{ + void *addr; + u8 type; + int rc; + + /* Each kind of entry takes at least 32 bytes */ + if (ENTRY_LOC(curr_p) + 32 > LOG_BLOCK_TAIL) + return true; + + addr = nova_get_block(sb, curr_p); + rc = memcpy_mcsafe(&type, addr, sizeof(u8)); + + if (rc < 0) + return true; + + if (type == NEXT_PAGE) + return true; + + return false; +} + + + +#endif diff --git a/fs/nova/nova.h b/fs/nova/nova.h index 0992f50..f5b4ec8 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -301,6 +301,7 @@ static inline u64 nova_get_epoch_id(struct super_block *sb) } #include "inode.h" +#include "log.h" /* A node in the RB tree representing a range of pages */ struct nova_range_node {