Received: by 10.223.185.111 with SMTP id b44csp1649513wrg; Sat, 10 Mar 2018 10:35:04 -0800 (PST) X-Google-Smtp-Source: AG47ELuHlVqlRjHfSK5BZacIFnsAuXwobBT8cHU3JskSwRLv239OB+oTFyMJA34EzxapaEpgbgn0 X-Received: by 10.98.206.1 with SMTP id y1mr2707114pfg.196.1520706903996; Sat, 10 Mar 2018 10:35:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706903; cv=none; d=google.com; s=arc-20160816; b=VZ3ZguE19045CxandoRjEcRz4UJ93CKrwFrD4FI9JBQPh0kn0ISPxeYIwKtWxVODQz 7XC1GFqPM9o/eyvx2sTmVL4Kqu21ggv/mOQ0nK/fE4svZHbEZ9NPF/V5sxhSsYNN1+jD dwcPJkoOxPrZ4HtXGvmAyld31I1kV0cbX9KBwbp5TmXWRu614wX8ROesZDSgknf2iP6Q /8pJjXfJo7ZQj8tQfdKBybctGU/qbckOlz8Ed6OCTQxU3zcqGRgCKvXm1bJBtnVj/G7w eq2XWbATi+EeQpy4P8MFAk1BopFolFo5m006aNCzhU/iRLADYx4MngdXQWI1cz96vAAN /2cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BWUMvKZ7IawUBw6tD95kbpZqSRDXmakoH2YrRIj9fAQ=; b=jHmUebkZ0ef1fMCMe1PZeXJMOFsvUbBcll9ZmtjRWkKcOC0k9JcLaxdZjjmTXJDFRv kLrtNhSOjOzHa4QTpsfgcOachdLXNYPsRExpdrdnTX/JdLDOTbiLkeb7AlUNGu2em8mq CyHWVhYzOvmIyKJkMtDjBgvIOCBiwyC0/wkG7euucYyCKtCFLbjVIhp2cSOaVKtkfIV1 xBtxKm35jP8a/l5bpeNcjs8KMECvAFqI5obHOWGZh5XltHAKybGDMsdDS79Gp7HbpNP0 v7ybMjWY66UPYI/1epgFgtsmng5J2trl1lD5kiKuffvLWsOui1XPAz2mgy50vSkvnEiJ rpQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=dJ2b03il; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z31-v6si3044682plb.613.2018.03.10.10.34.49; Sat, 10 Mar 2018 10:35:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=dJ2b03il; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932670AbeCJSd4 (ORCPT + 99 others); Sat, 10 Mar 2018 13:33:56 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:46189 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932589AbeCJSVJ (ORCPT ); Sat, 10 Mar 2018 13:21:09 -0500 Received: by mail-pg0-f66.google.com with SMTP id r26so4828519pgv.13 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=ODyr1PhR8OPAktDchmmltR5R4v2AMpwaweGUcEnkHN/pWujxcUikd4ZFyINpkyQ4Fs 03bcvF5id5gvrFOv5MoZuqF+l+OmKdJYf+vz0GBaQAkfRh9TgCxXYEF1BX+BdchjSCfq zieb354J63tphFbZu80+Z8HpjrHEfdDDnB2lmax9xigwYcl+KvZgDHeJMtwGX/plI6oF E0JmxenNd+AkbOiaDP5FnRdf/mf3cMV8fOeBbTtvekrYZ0uzspWZAXkr9OUZXJFeNJTN Nc4x443UO3EuNyc4hag8ypR0bACJTOMSegy0R/x8y0D4a2WR4TFdf+56DUs6RpCl0XOs gUdg== X-Gm-Message-State: AElRT7FbTB/TyRvVFzHNF45nguIbSJxzERY2AdZAjKEhkXMWKg0kpErr 27/YmB7OThNXZ7LjEhZPchQoqA== 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 Cc: dan.j.williams@intel.com, andy.rudoff@intel.com, coughlan@redhat.com, swanson@cs.ucsd.edu, david@fromorbit.com, jack@suse.com, swhiteho@redhat.com, miklos@szeredi.hu, andiry.xu@gmail.com, Andiry Xu 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.7.4