From patchwork Sat Mar 10 18:18:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273907 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 58411605D2 for ; Sat, 10 Mar 2018 18:21:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4768E28BAE for ; Sat, 10 Mar 2018 18:21:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C1A529759; Sat, 10 Mar 2018 18:21:16 +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 CA1E029106 for ; Sat, 10 Mar 2018 18:21:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4D7872263147C; Sat, 10 Mar 2018 10:14:52 -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::243; helo=mail-pg0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (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 C603E22631463 for ; Sat, 10 Mar 2018 10:14:50 -0800 (PST) Received: by mail-pg0-x243.google.com with SMTP id m19so4837675pgn.1 for ; Sat, 10 Mar 2018 10:21:09 -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=BWUMvKZ7IawUBw6tD95kbpZqSRDXmakoH2YrRIj9fAQ=; b=dJ2b03iljHGBLWv4wZJJxgW4ZGEfqf7OT28DNNJOnoc0SiwJZQTcWnSrTQspfcp19O 46IOP3gJddipQyua3VKM8QSBMtxjHDj5AU6W8KbQYEWd4nRKKodAhPaMQ+iCMVx1GahT FCNozVYJ14x4z6k7TNS0QquupiuxUE8C4YR0A= 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=BWUMvKZ7IawUBw6tD95kbpZqSRDXmakoH2YrRIj9fAQ=; b=EZ0KH09E0BpfM3KtjydwjpKH//UwUuq4Cti5C9QG/G+X/UaPS6x0vPDngq+8aQgB8h 7yXFLO9ZNFwqDCIGW1AXbv/on2r4rG8c1f3qtqkkrv9+Jqz9HmS/Uf8U0/e8KyM+nK3m c4HoDYlYMrQlZQF4uk2tA5MeJ/gJrwxGBZWjGXzZ8W4gHOa+r0YheSG5emxMHw9hdUyj F2VASofPyKY6Oh7RtI3u+XRuId62H5NKC+4dHfnsdj3YgT7zrKPIdOzaN4QmKDUwtP3K GwRFhaGL4wASHs7o9VQyStzApI2U+mDs8oF7C+wqCF5XcKixpyTmu/hSj2kZAd7svxMU JcXg== X-Gm-Message-State: AElRT7Hngx4vl9MeYFN1gUDATLrvaNN52mtb40C3FBG1QtijcAnOPTVT 2/XnuWR86BrpK9xFfwW/DOWo+A== X-Google-Smtp-Source: AG47ELtTCVJHu6crpL0gM79KLa0k2JbCcBO2m+GIVjx7hYyIiMd9ErjCUKIRmW6ccuvPcoV5ZqZFQg== X-Received: by 10.99.104.73 with SMTP id d70mr2205428pgc.107.1520706069235; Sat, 10 Mar 2018 10:21:09 -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.21.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:08 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 44/83] Log operation: invalidate log entries Date: Sat, 10 Mar 2018 10:18:25 -0800 Message-Id: <1520705944-6723-45-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 After new log entries are appended to the log, old log entries can be marked invalid to faciliate garbage collection. Signed-off-by: Andiry Xu --- fs/nova/log.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/log.h | 4 ++ fs/nova/nova.h | 12 +++++ 3 files changed, 176 insertions(+) diff --git a/fs/nova/log.c b/fs/nova/log.c index c8b7d2e..d150f2e 100644 --- a/fs/nova/log.c +++ b/fs/nova/log.c @@ -20,6 +20,88 @@ #include "inode.h" #include "log.h" +static int nova_execute_invalidate_reassign_logentry(struct super_block *sb, + void *entry, enum nova_entry_type type, int reassign, + unsigned int num_free) +{ + struct nova_file_write_entry *fw_entry; + int invalid = 0; + + switch (type) { + case FILE_WRITE: + fw_entry = (struct nova_file_write_entry *)entry; + if (reassign) + fw_entry->reassigned = 1; + if (num_free) + fw_entry->invalid_pages += num_free; + if (fw_entry->invalid_pages == fw_entry->num_pages) + invalid = 1; + break; + case DIR_LOG: + if (reassign) { + ((struct nova_dentry *)entry)->reassigned = 1; + } else { + ((struct nova_dentry *)entry)->invalid = 1; + invalid = 1; + } + break; + case SET_ATTR: + ((struct nova_setattr_logentry *)entry)->invalid = 1; + invalid = 1; + break; + case LINK_CHANGE: + ((struct nova_link_change_entry *)entry)->invalid = 1; + invalid = 1; + break; + default: + break; + } + + if (invalid) { + u64 addr = nova_get_addr_off(NOVA_SB(sb), entry); + + nova_inc_page_invalid_entries(sb, addr); + } + + nova_persist_entry(entry); + return 0; +} + +static int nova_invalidate_reassign_logentry(struct super_block *sb, + void *entry, enum nova_entry_type type, int reassign, + unsigned int num_free) +{ + nova_execute_invalidate_reassign_logentry(sb, entry, type, + reassign, num_free); + return 0; +} + +static int nova_invalidate_logentry(struct super_block *sb, void *entry, + enum nova_entry_type type, unsigned int num_free) +{ + return nova_invalidate_reassign_logentry(sb, entry, type, 0, num_free); +} + +static int nova_reassign_logentry(struct super_block *sb, void *entry, + enum nova_entry_type type) +{ + return nova_invalidate_reassign_logentry(sb, entry, type, 1, 0); +} + +static inline int nova_invalidate_write_entry(struct super_block *sb, + struct nova_file_write_entry *entry, int reassign, + unsigned int num_free) +{ + if (!entry) + return 0; + + if (num_free == 0 && entry->reassigned == 1) + return 0; + + return nova_invalidate_reassign_logentry(sb, entry, FILE_WRITE, + reassign, num_free); +} + static void nova_update_setattr_entry(struct inode *inode, struct nova_setattr_logentry *entry, struct nova_log_entry_info *entry_info) @@ -279,6 +361,27 @@ static int nova_append_setattr_entry(struct super_block *sb, return ret; } +/* Invalidate old setattr entry */ +static int nova_invalidate_setattr_entry(struct super_block *sb, + u64 last_setattr) +{ + struct nova_setattr_logentry *old_entry; + void *addr; + int ret; + + addr = (void *)nova_get_block(sb, last_setattr); + old_entry = (struct nova_setattr_logentry *)addr; + + /* Do not invalidate setsize entries */ + if (!old_entry_freeable(sb, old_entry->epoch_id) || + (old_entry->attr & ATTR_SIZE)) + return 0; + + ret = nova_invalidate_logentry(sb, old_entry, SET_ATTR, 0); + + return ret; +} + static int nova_can_inplace_update_setattr(struct super_block *sb, struct nova_inode_info_header *sih, u64 epoch_id) { @@ -358,9 +461,35 @@ int nova_handle_setattr_operation(struct super_block *sb, struct inode *inode, nova_update_inode(sb, inode, pi, &update); } + /* Invalidate old setattr entry */ + if (last_setattr) + nova_invalidate_setattr_entry(sb, last_setattr); + return 0; } +/* Invalidate old link change entry */ +int nova_invalidate_link_change_entry(struct super_block *sb, + u64 old_link_change) +{ + struct nova_link_change_entry *old_entry; + void *addr; + int ret; + + if (old_link_change == 0) + return 0; + + addr = (void *)nova_get_block(sb, old_link_change); + old_entry = (struct nova_link_change_entry *)addr; + + if (!old_entry_freeable(sb, old_entry->epoch_id)) + return 0; + + ret = nova_invalidate_logentry(sb, old_entry, LINK_CHANGE, 0); + + return ret; +} + static int nova_can_inplace_update_lcentry(struct super_block *sb, struct nova_inode_info_header *sih, u64 epoch_id) { @@ -481,6 +610,37 @@ int nova_append_file_write_entry(struct super_block *sb, struct nova_inode *pi, return ret; } +/* Create dentry and delete dentry must be invalidated together */ +int nova_invalidate_dentries(struct super_block *sb, + struct nova_inode_update *update) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct nova_dentry *create_dentry; + struct nova_dentry *delete_dentry; + u64 create_curr, delete_curr; + int ret; + + create_dentry = update->create_dentry; + delete_dentry = update->delete_dentry; + + if (!create_dentry) + return 0; + + nova_reassign_logentry(sb, create_dentry, DIR_LOG); + + if (!old_entry_freeable(sb, create_dentry->epoch_id)) + return 0; + + create_curr = nova_get_addr_off(sbi, create_dentry); + delete_curr = nova_get_addr_off(sbi, delete_dentry); + + nova_invalidate_logentry(sb, create_dentry, DIR_LOG, 0); + + ret = nova_invalidate_logentry(sb, delete_dentry, DIR_LOG, 0); + + return ret; +} + int nova_inplace_update_dentry(struct super_block *sb, struct inode *dir, struct nova_dentry *dentry, int link_change, u64 epoch_id) diff --git a/fs/nova/log.h b/fs/nova/log.h index 74891b3..2548083 100644 --- a/fs/nova/log.h +++ b/fs/nova/log.h @@ -367,6 +367,8 @@ static inline int is_dir_init_entry(struct super_block *sb, int nova_handle_setattr_operation(struct super_block *sb, struct inode *inode, struct nova_inode *pi, unsigned int ia_valid, struct iattr *attr, u64 epoch_id); +int nova_invalidate_link_change_entry(struct super_block *sb, + u64 old_link_change); int nova_append_link_change_entry(struct super_block *sb, struct nova_inode *pi, struct inode *inode, struct nova_inode_update *update, u64 *old_linkc, u64 epoch_id); @@ -376,6 +378,8 @@ int nova_inplace_update_write_entry(struct super_block *sb, int nova_append_file_write_entry(struct super_block *sb, struct nova_inode *pi, struct inode *inode, struct nova_file_write_item *item, struct nova_inode_update *update); +int nova_invalidate_dentries(struct super_block *sb, + struct nova_inode_update *update); int nova_inplace_update_dentry(struct super_block *sb, struct inode *dir, struct nova_dentry *dentry, int link_change, u64 epoch_id); diff --git a/fs/nova/nova.h b/fs/nova/nova.h index 03c4991..6cf3c33 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -328,6 +328,18 @@ struct inode_map { int freed; }; + +/* Old entry is freeable if it is appended after the latest snapshot */ +static inline int old_entry_freeable(struct super_block *sb, u64 epoch_id) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + + if (epoch_id == sbi->s_epoch_id) + return 1; + + return 0; +} + #include "balloc.h" static inline unsigned long