Skip to contentSkip to conversation

reiser4: discard support: simplified and race-free initial implementation.

PATCH In review Ivan Shapovalov 1 participant 8 messages Jul 31, 2014

lore
Share & tools
lore
#0 lore raw

v7 cover reiser4: discard support: simplified and race-free initial implementation.

v1: - initial implementation (patches 1, 2)

v2: - cleanup, fixes discovered in debug mode
- saner logging
- assertions
- enablement of discard through mount option

v3: - fixed the extent merge loop in discard_atom()

v4: - squashed fix-ups into the main patch (with exception of reiser4_debug())
- fixed bug in usage of division ops discovered while building on ARM

v5: - squashed mount option into the main patch
- refactor based on discussion (see commit msg)
- splitted off blocknr_list code
- replaced ->discard_set with ->delete_set and ->aux_delete_set

v6: - actualized in-code comments
- removed uber-verbose debug statements
- fixed code-to-patch mapping
- moved blocknrlist and blocknrset to kmem_cache instead of kmalloc/kfree (in a separate commit for ease of reviewing)
- dropped the RFC label

v7: - squashed with PATCHv2 "perform discard before all deallocations"
- dropped extent padding from discard_extent()
- completed in-code comments, cosmetic fixups
- added missing #include in block_alloc.c
- added missing spin_unlock_atom() in discard_atom()

Ivan Shapovalov (6):
reiser4: fix reiser4_post_{commit,write_back}_hook() and their invocations.
reiser4: make space_allocator's check_blocks() reusable.
reiser4: add an implementation of "block lists", splitted off the discard code.
reiser4: blocknr_list: use kmem_cache instead of kmalloc for allocating entries.
reiser4: blocknr_set: use kmem_cache instead of kmalloc for allocating entries.
reiser4: discard support: initial implementation using blocknr_list, without extent padding.

 fs/reiser4/Makefile                       |   2 +
 fs/reiser4/block_alloc.c                  |  62 +++---
 fs/reiser4/block_alloc.h                  |  14 +-
 fs/reiser4/blocknrlist.c                  | 336 ++++++++++++++++++++++++++++++
 fs/reiser4/blocknrset.c                   |  34 ++-
 fs/reiser4/dformat.h                      |   2 +
 fs/reiser4/discard.c                      | 179 ++++++++++++++++
 fs/reiser4/discard.h                      |  42 ++++
 fs/reiser4/forward.h                      |   1 +
 fs/reiser4/init_super.c                   |   2 +
 fs/reiser4/plugin/space/bitmap.c          |  82 +++++---
 fs/reiser4/plugin/space/bitmap.h          |   2 +-
 fs/reiser4/plugin/space/space_allocator.h |   4 +-
 fs/reiser4/super.h                        |   4 +-
 fs/reiser4/super_ops.c                    |  14 ++
 fs/reiser4/txnmgr.c                       |  90 +++++++-
 fs/reiser4/txnmgr.h                       |  60 +++++-
 fs/reiser4/wander.c                       |   6 +-
 fs/reiser4/znode.c                        |   9 +-
 19 files changed, 859 insertions(+), 86 deletions(-)
 create mode 100644 fs/reiser4/blocknrlist.c
 create mode 100644 fs/reiser4/discard.c
 create mode 100644 fs/reiser4/discard.h
Signature · 1 line
2.0.3
#1 lore raw

PATCH v7 1/6 reiser4: fix reiser4_post_{commit,write_back}_hook() and their invocations.

- let all hooks be called from one place (reiser4_write_logs())
- don't call reiser4_post_write_back_hook() twice
- fix reiser4_post_write_back_hook(): call the correct method of space allocator

---
 fs/reiser4/block_alloc.c | 2 +-
 fs/reiser4/wander.c      | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
fs/reiser4/block_alloc.c +1 -1
index 81ed96f..3a4b667 100644
@@ -1150,7 +1150,7 @@ void reiser4_post_write_back_hook(void)
 {
 	assert("zam-504", get_current_super_private() != NULL);
 
-	sa_post_commit_hook();
+	sa_post_write_back_hook();
 }
 
 /*
fs/reiser4/wander.c +1 -2
index 0b518c3..4e29de8 100644
@@ -1140,7 +1140,6 @@ static int write_tx_back(struct commit_handle * ch)
 	int ret;
 	int barrier;
 
-	reiser4_post_commit_hook();
 	fq = get_fq_for_current_atom();
 	if (IS_ERR(fq))
 		return  PTR_ERR(fq);
@@ -1165,7 +1164,6 @@ static int write_tx_back(struct commit_handle * ch)
 		if (ret)
 			return ret;
 	}
-	reiser4_post_write_back_hook();
 	return 0;
 }
 
@@ -1251,6 +1249,7 @@ int reiser4_write_logs(long *nr_submitted)
 	spin_lock_atom(atom);
 	reiser4_atom_set_stage(atom, ASTAGE_POST_COMMIT);
 	spin_unlock_atom(atom);
+	reiser4_post_commit_hook();
 
 	ret = write_tx_back(&ch);
 	reiser4_post_write_back_hook();
Signature · 1 line
2.0.3
#2 lore raw

PATCH v7 2/6 reiser4: make space_allocator's check_blocks() reusable.

In reply to Ivan Shapovalov

Make check_blocks() return a boolean value (whether did the extent's state match our expectations) instead of asserting success and crashing system otherwise.
Also make it possible to check extents spanning multiple bitmap blocks.

The only user of reiser4_check_block() in its previous form has been updated to assert on true return value.

Thus check_blocks() can now be reused by various parts of reiser4, e. g. by the discard subsystem which will be added in next commits.

---
 fs/reiser4/block_alloc.c                  | 16 +------
 fs/reiser4/block_alloc.h                  | 14 +++---
 fs/reiser4/plugin/space/bitmap.c          | 79 +++++++++++++++++++++----------
 fs/reiser4/plugin/space/bitmap.h          |  2 +-
 fs/reiser4/plugin/space/space_allocator.h |  4 +-
 fs/reiser4/znode.c                        |  9 ++--
 6 files changed, 70 insertions(+), 54 deletions(-)
fs/reiser4/block_alloc.c +2 -14
index 3a4b667..59515c3 100644
@@ -962,26 +962,14 @@ static void used2free(reiser4_super_info_data * sbinfo, __u64 count)
 	spin_unlock_reiser4_super(sbinfo);
 }
 
-#if REISER4_DEBUG
-
 /* check "allocated" state of given block range */
-static void
+int
 reiser4_check_blocks(const reiser4_block_nr * start,
 		     const reiser4_block_nr * len, int desired)
 {
-	sa_check_blocks(start, len, desired);
+	return sa_check_blocks(start, len, desired);
 }
 
-/* check "allocated" state of given block */
-void reiser4_check_block(const reiser4_block_nr * block, int desired)
-{
-	const reiser4_block_nr one = 1;
-
-	reiser4_check_blocks(block, &one, desired);
-}
-
-#endif
-
 /* Blocks deallocation function may do an actual deallocation through space
    plugin allocation or store deleted block numbers in atom's delete_set data
    structure depend on @defer parameter. */
fs/reiser4/block_alloc.h +7 -7
index 689efc1..a4e98af 100644
@@ -150,15 +150,15 @@ extern void cluster_reserved2free(int count);
 
 extern int reiser4_check_block_counters(const struct super_block *);
 
-#if REISER4_DEBUG
 
-extern void reiser4_check_block(const reiser4_block_nr *, int);
+extern int reiser4_check_blocks(const reiser4_block_nr *start,
+                                const reiser4_block_nr *len, int desired);
 
-#else
-
-#  define reiser4_check_block(beg, val)        noop
-
-#endif
+static inline int reiser4_check_block(const reiser4_block_nr *start,
+                                      int desired)
+{
+	return reiser4_check_blocks(start, NULL, desired);
+}
 
 extern int reiser4_pre_commit_hook(void);
 extern void reiser4_post_commit_hook(void);
fs/reiser4/plugin/space/bitmap.c +53 -26

101 lines not on this page · raw message

fs/reiser4/plugin/space/bitmap.h +1 -1
index be867f1..4590498 100644
@@ -19,7 +19,7 @@ extern int reiser4_alloc_blocks_bitmap(reiser4_space_allocator *,
 				       reiser4_blocknr_hint *, int needed,
 				       reiser4_block_nr * start,
 				       reiser4_block_nr * len);
-extern void reiser4_check_blocks_bitmap(const reiser4_block_nr *,
+extern int reiser4_check_blocks_bitmap(const reiser4_block_nr *,
 					const reiser4_block_nr *, int);
 extern void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator *,
 					  reiser4_block_nr,
fs/reiser4/plugin/space/space_allocator.h +2 -2
index 5bfa9a3..71bfd11 100644
@@ -29,9 +29,9 @@ static inline void sa_dealloc_blocks (reiser4_space_allocator * al, reiser4_bloc
 	reiser4_dealloc_blocks_##allocator (al, start, len);								\
 }															\
 															\
-static inline void sa_check_blocks (const reiser4_block_nr * start, const reiser4_block_nr * end, int desired) 		\
+static inline int sa_check_blocks (const reiser4_block_nr * start, const reiser4_block_nr * end, int desired) 		\
 {															\
-	reiser4_check_blocks_##allocator (start, end, desired);							        \
+	return reiser4_check_blocks_##allocator (start, end, desired);							        \
 }															\
 															\
 static inline void sa_pre_commit_hook (void)										\
fs/reiser4/znode.c +5 -4
index 4ff9714..08eab3d 100644
@@ -534,10 +534,11 @@ znode *zget(reiser4_tree * tree,
 
 		write_unlock_tree(tree);
 	}
-#if REISER4_DEBUG
-	if (!reiser4_blocknr_is_fake(blocknr) && *blocknr != 0)
-		reiser4_check_block(blocknr, 1);
-#endif
+
+	assert("intelfx-6",
+	       ergo(!reiser4_blocknr_is_fake(blocknr) && *blocknr != 0,
+	            reiser4_check_block(blocknr, 1)));
+
 	/* Check for invalid tree level, return -EIO */
 	if (unlikely(znode_get_level(result) != level)) {
 		warning("jmacd-504",
Signature · 1 line
2.0.3
#3 lore raw

PATCH v7 3/6 reiser4: add an implementation of "block lists", splitted off the discard code.

In reply to Ivan Shapovalov

The block list is a less memory efficient, but ordered (and thus sortable) implementation of the same concept as the blocknr_set.

---
 fs/reiser4/Makefile      |   1 +
 fs/reiser4/blocknrlist.c | 311 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/reiser4/forward.h     |   1 +
 fs/reiser4/txnmgr.h      |  19 +++
 4 files changed, 332 insertions(+)
 create mode 100644 fs/reiser4/blocknrlist.c
fs/reiser4/Makefile +1 -0
index ff73d43..9f07194 100644
@@ -46,6 +46,7 @@ reiser4-y := \
 		   status_flags.o \
 		   init_super.o \
 		   safe_link.o \
+		   blocknrlist.o \
            \
 		   plugin/plugin.o \
 		   plugin/plugin_set.o \
fs/reiser4/blocknrlist.c new file +311 -0

311 lines not on this page · raw message

fs/reiser4/forward.h +1 -0
index 15dbfdc..9170c2b 100644
@@ -38,6 +38,7 @@ typedef struct reiser4_dir_entry_desc reiser4_dir_entry_desc;
 typedef struct reiser4_context reiser4_context;
 typedef struct carry_level carry_level;
 typedef struct blocknr_set_entry blocknr_set_entry;
+typedef struct blocknr_list_entry blocknr_list_entry;
 /* super_block->s_fs_info points to this */
 typedef struct reiser4_super_info_data reiser4_super_info_data;
 /* next two objects are fields of reiser4_super_info_data */
fs/reiser4/txnmgr.h +19 -0
index 034a3fe..18ca23d 100644
@@ -485,6 +485,25 @@ extern int blocknr_set_iterator(txn_atom * atom, struct list_head * bset,
 				blocknr_set_actor_f actor, void *data,
 				int delete);
 
+/* This is the block list interface (see blocknrlist.c) */
+extern void blocknr_list_init(struct list_head *blist);
+extern void blocknr_list_destroy(struct list_head *blist);
+extern void blocknr_list_merge(struct list_head *from, struct list_head *to);
+extern void blocknr_list_sort_and_join(struct list_head *blist);
+/**
+ * The @atom should be locked.
+ */
+extern int blocknr_list_add_extent(txn_atom *atom,
+                                   struct list_head *blist,
+                                   blocknr_list_entry **new_entry,
+                                   const reiser4_block_nr *start,
+                                   const reiser4_block_nr *len);
+extern int blocknr_list_iterator(txn_atom *atom,
+                                 struct list_head *blist,
+                                 blocknr_set_actor_f actor,
+                                 void *data,
+                                 int delete);
+
 /* flush code takes care about how to fuse flush queues */
 extern void flush_init_atom(txn_atom * atom);
 extern void flush_fuse_queues(txn_atom * large, txn_atom * small);
Signature · 1 line
2.0.3
#4 lore raw

PATCH v7 4/6 reiser4: blocknr_list: use kmem_cache instead of kmalloc for allocating entries.

In reply to Ivan Shapovalov
---
 fs/reiser4/blocknrlist.c | 31 ++++++++++++++++++++++++++++---
 fs/reiser4/super_ops.c   |  7 +++++++
 fs/reiser4/txnmgr.h      |  2 ++
 3 files changed, 37 insertions(+), 3 deletions(-)
fs/reiser4/blocknrlist.c +28 -3
index 2868771..39a4a9b 100644
@@ -9,10 +9,13 @@
 #include "dformat.h"
 #include "txnmgr.h"
 #include "context.h"
+#include "super.h"
 
 #include <linux/slab.h>
 #include <linux/list_sort.h>
 
+static struct kmem_cache *blocknr_list_slab = NULL;
+
 /**
  * Represents an extent range [@start; @end).
  */
@@ -36,8 +39,8 @@ static blocknr_list_entry *blocknr_list_entry_alloc(void)
 {
 	blocknr_list_entry *entry;
 
-	entry = (blocknr_list_entry *)kmalloc(sizeof(blocknr_list_entry),
-	                                      reiser4_ctx_gfp_mask_get());
+	entry = (blocknr_list_entry *)kmem_cache_alloc(blocknr_list_slab,
+	                                               reiser4_ctx_gfp_mask_get());
 	if (entry == NULL) {
 		return NULL;
 	}
@@ -51,7 +54,7 @@ static void blocknr_list_entry_free(blocknr_list_entry *entry)
 {
 	assert("intelfx-12", entry != NULL);
 
-	kfree(entry);
+	kmem_cache_free(blocknr_list_slab, entry);
 }
 
 /**
@@ -142,6 +145,28 @@ static int blocknr_list_entry_compare(void* priv UNUSED_ARG,
 	return 0;
 }
 
+int blocknr_list_init_static(void)
+{
+	assert("intelfx-54", blocknr_list_slab == NULL);
+
+	blocknr_list_slab = kmem_cache_create("blocknr_list_entry",
+	                                      sizeof(blocknr_list_entry),
+	                                      0,
+	                                      SLAB_HWCACHE_ALIGN |
+	                                      SLAB_RECLAIM_ACCOUNT,
+	                                      NULL);
+	if (blocknr_list_slab == NULL) {
+		return RETERR(-ENOMEM);
+	}
+
+	return 0;
+}
+
+void blocknr_list_done_static(void)
+{
+	destroy_reiser4_cache(&blocknr_list_slab);
+}
+
 void blocknr_list_init(struct list_head* blist)
 {
 	assert("intelfx-24", blist != NULL);
fs/reiser4/super_ops.c +7 -0
index 81773b3..a63ceb5 100644
@@ -678,11 +678,17 @@ static int __init init_reiser4(void)
 	if ((result = reiser4_init_d_cursor()) != 0)
 		goto failed_init_d_cursor;
 
+	/* initialize cache of blocknr list entries */
+	if ((result = blocknr_list_init_static()) != 0)
+		goto failed_init_blocknr_list;
+
 	if ((result = register_filesystem(&reiser4_fs_type)) == 0) {
 		reiser4_debugfs_root = debugfs_create_dir("reiser4", NULL);
 		return 0;
 	}
 
+	blocknr_list_done_static();
+ failed_init_blocknr_list:
 	reiser4_done_d_cursor();
  failed_init_d_cursor:
 	reiser4_done_file_fsdata();
@@ -718,6 +724,7 @@ static void __exit done_reiser4(void)
 	debugfs_remove(reiser4_debugfs_root);
 	result = unregister_filesystem(&reiser4_fs_type);
 	BUG_ON(result != 0);
+	blocknr_list_done_static();
 	reiser4_done_d_cursor();
 	reiser4_done_file_fsdata();
 	reiser4_done_dentry_fsdata();
fs/reiser4/txnmgr.h +2 -0
index 18ca23d..3515de9 100644
@@ -486,6 +486,8 @@ extern int blocknr_set_iterator(txn_atom * atom, struct list_head * bset,
 				int delete);
 
 /* This is the block list interface (see blocknrlist.c) */
+extern int blocknr_list_init_static(void);
+extern void blocknr_list_done_static(void);
 extern void blocknr_list_init(struct list_head *blist);
 extern void blocknr_list_destroy(struct list_head *blist);
 extern void blocknr_list_merge(struct list_head *from, struct list_head *to);
Signature · 1 line
2.0.3
#5 lore raw

PATCH v7 5/6 reiser4: blocknr_set: use kmem_cache instead of kmalloc for allocating entries.

In reply to Ivan Shapovalov
---
 fs/reiser4/blocknrset.c | 34 +++++++++++++++++++++++++++++++---
 fs/reiser4/super_ops.c  |  7 +++++++
 fs/reiser4/txnmgr.h     |  2 ++
 3 files changed, 40 insertions(+), 3 deletions(-)
fs/reiser4/blocknrset.c +31 -3
index bf57c17..2f18cbc 100644
@@ -8,6 +8,7 @@ reiser4/README */
 #include "dformat.h"
 #include "txnmgr.h"
 #include "context.h"
+#include "super.h"
 
 #include <linux/slab.h>
 
@@ -42,6 +43,8 @@ reiser4/README */
 	sizeof(struct list_head)) /		\
 	sizeof(reiser4_block_nr))
 
+static struct kmem_cache *blocknr_set_slab = NULL;
+
 /* An entry of the blocknr_set */
 struct blocknr_set_entry {
 	unsigned nr_singles;
@@ -82,8 +85,8 @@ static blocknr_set_entry *bse_alloc(void)
 {
 	blocknr_set_entry *e;
 
-	if ((e = (blocknr_set_entry *) kmalloc(sizeof(blocknr_set_entry),
-					   reiser4_ctx_gfp_mask_get())) == NULL)
+	if ((e = (blocknr_set_entry *) kmem_cache_alloc(blocknr_set_slab,
+							reiser4_ctx_gfp_mask_get())) == NULL)
 		return NULL;
 
 	bse_init(e);
@@ -95,7 +98,7 @@ static blocknr_set_entry *bse_alloc(void)
 /* Audited by: green(2002.06.11) */
 static void bse_free(blocknr_set_entry * bse)
 {
-	kfree(bse);
+	kmem_cache_free(blocknr_set_slab, bse);
 }
 
 /* Add a block number to a blocknr_set_entry */
@@ -225,6 +228,31 @@ blocknr_set_add_pair(txn_atom * atom,
 	return blocknr_set_add(atom, bset, new_bsep, a, b);
 }
 
+/* Initialize slab cache of blocknr_set_entry objects. */
+int blocknr_set_init_static(void)
+{
+	assert("intelfx-55", blocknr_set_slab == NULL);
+
+	blocknr_set_slab = kmem_cache_create("blocknr_set_entry",
+					     sizeof(blocknr_set_entry),
+					     0,
+					     SLAB_HWCACHE_ALIGN |
+					     SLAB_RECLAIM_ACCOUNT,
+					     NULL);
+
+	if (blocknr_set_slab == NULL) {
+		return RETERR(-ENOMEM);
+	}
+
+	return 0;
+}
+
+/* Destroy slab cache of blocknr_set_entry objects. */
+void blocknr_set_done_static(void)
+{
+	destroy_reiser4_cache(&blocknr_set_slab);
+}
+
 /* Initialize a blocknr_set. */
 void blocknr_set_init(struct list_head *bset)
 {
fs/reiser4/super_ops.c +7 -0
index a63ceb5..bcd7fd6 100644
@@ -678,6 +678,10 @@ static int __init init_reiser4(void)
 	if ((result = reiser4_init_d_cursor()) != 0)
 		goto failed_init_d_cursor;
 
+	/* initialize cache of blocknr set entries */
+	if ((result = blocknr_set_init_static()) != 0)
+		goto failed_init_blocknr_set;
+
 	/* initialize cache of blocknr list entries */
 	if ((result = blocknr_list_init_static()) != 0)
 		goto failed_init_blocknr_list;
@@ -689,6 +693,8 @@ static int __init init_reiser4(void)
 
 	blocknr_list_done_static();
  failed_init_blocknr_list:
+	blocknr_set_done_static();
+ failed_init_blocknr_set:
 	reiser4_done_d_cursor();
  failed_init_d_cursor:
 	reiser4_done_file_fsdata();
@@ -725,6 +731,7 @@ static void __exit done_reiser4(void)
 	result = unregister_filesystem(&reiser4_fs_type);
 	BUG_ON(result != 0);
 	blocknr_list_done_static();
+	blocknr_set_done_static();
 	reiser4_done_d_cursor();
 	reiser4_done_file_fsdata();
 	reiser4_done_dentry_fsdata();
fs/reiser4/txnmgr.h +2 -0
index 3515de9..0dee787 100644
@@ -465,6 +465,8 @@ int capture_bulk(jnode **, int count);
 
 /* See the comment on the function blocknrset.c:blocknr_set_add for the
    calling convention of these three routines. */
+extern int blocknr_set_init_static(void);
+extern void blocknr_set_done_static(void);
 extern void blocknr_set_init(struct list_head * bset);
 extern void blocknr_set_destroy(struct list_head * bset);
 extern void blocknr_set_merge(struct list_head * from, struct list_head * into);
Signature · 1 line
2.0.3
#6 lore raw

PATCH v7 6/6 reiser4: discard support: initial implementation using blocknr_list, without extent padding.

In reply to Ivan Shapovalov

Now reiser4_post_write_back_hook() is used for discarding and completing deferred deallocations. The invocation of this hook has been moved past immediate deallocations in the wandered logs code. Also, when discard is enabled, immediate deallocations are made deferred, and discard procedure takes place before any deallocations are completed. This allows to avoid costly bitmap checks at discard time.

Implementation details:

- before discarding, the delete set is sorted and extents are merged
- each extent is submitted to discard as-is (blocks in all extents are still marked as allocated at this point, so there can be no races)
- processing stops at first failure (this does not fail atom commit)

For now (shortcomings):

- extents are not padded to erase unit boundaries

---
 fs/reiser4/Makefile              |   1 +
 fs/reiser4/block_alloc.c         |  44 +++++++---
 fs/reiser4/dformat.h             |   2 +
 fs/reiser4/discard.c             | 179 +++++++++++++++++++++++++++++++++++++++
 fs/reiser4/discard.h             |  42 +++++++++
 fs/reiser4/init_super.c          |   2 +
 fs/reiser4/plugin/space/bitmap.c |   3 +-
 fs/reiser4/super.h               |   4 +-
 fs/reiser4/txnmgr.c              |  90 ++++++++++++++++++--
 fs/reiser4/txnmgr.h              |  37 +++++++-
 fs/reiser4/wander.c              |   3 +-
 11 files changed, 381 insertions(+), 26 deletions(-)
 create mode 100644 fs/reiser4/discard.c
 create mode 100644 fs/reiser4/discard.h
fs/reiser4/Makefile +1 -0
index 9f07194..f50bb96 100644
@@ -47,6 +47,7 @@ reiser4-y := \
 		   init_super.o \
 		   safe_link.o \
 		   blocknrlist.o \
+		   discard.o \
            \
 		   plugin/plugin.o \
 		   plugin/plugin_set.o \
fs/reiser4/block_alloc.c +31 -13

84 lines not on this page · raw message

fs/reiser4/dformat.h +2 -0
index 7943762..7316754 100644
@@ -14,6 +14,8 @@
 #if !defined(__FS_REISER4_DFORMAT_H__)
 #define __FS_REISER4_DFORMAT_H__
 
+#include "debug.h"
+
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
 #include <linux/types.h>
fs/reiser4/discard.c new file +179 -0

179 lines not on this page · raw message

fs/reiser4/discard.h new file +42 -0

42 lines not on this page · raw message

fs/reiser4/init_super.c +2 -0
index 620a0f5..1ff8dad 100644
@@ -494,6 +494,8 @@ int reiser4_init_super_data(struct super_block *super, char *opt_string)
 	PUSH_BIT_OPT("atomic_write", REISER4_ATOMIC_WRITE);
 	/* disable use of write barriers in the reiser4 log writer. */
 	PUSH_BIT_OPT("no_write_barrier", REISER4_NO_WRITE_BARRIER);
+	/* enable issuing of discard requests */
+	PUSH_BIT_OPT("discard", REISER4_DISCARD);
 
 	PUSH_OPT(p, opts,
 	{
fs/reiser4/plugin/space/bitmap.c +1 -2
index bd41fb9..3da3f6b 100644
@@ -1458,8 +1458,7 @@ int reiser4_pre_commit_hook_bitmap(void)
 		}
 	}
 
-	blocknr_set_iterator(atom, &atom->delete_set, apply_dset_to_commit_bmap,
-			     &blocks_freed, 0);
+	atom_dset_deferred_apply(atom, apply_dset_to_commit_bmap, &blocks_freed, 0);
 
 	blocks_freed -= atom->nr_blocks_allocated;
 
fs/reiser4/super.h +3 -1
index 0c73845..895c3f3 100644
@@ -51,7 +51,9 @@ typedef enum {
 	/* enforce atomicity during write(2) */
 	REISER4_ATOMIC_WRITE = 6,
 	/* don't use write barriers in the log writer code. */
-	REISER4_NO_WRITE_BARRIER = 7
+	REISER4_NO_WRITE_BARRIER = 7,
+	/* enable issuing of discard requests */
+	REISER4_DISCARD = 8
 } reiser4_fs_flag;
 
 /*
fs/reiser4/txnmgr.c +84 -6

132 lines not on this page · raw message

fs/reiser4/txnmgr.h +34 -3
index 0dee787..72b84a2 100644
@@ -245,9 +245,24 @@ struct txn_atom {
 	/* Start time. */
 	unsigned long start_time;
 
-	/* The atom's delete set. It collects block numbers of the nodes
-	   which were deleted during the transaction. */
-	struct list_head delete_set;
+	/* The atom's delete sets.
+	   "simple" are blocknr_set instances and are used when discard is disabled.
+	   "discard" are blocknr_list instances and are used when discard is enabled. */
+	union {
+		struct {
+		/* The atom's delete set. It collects block numbers of the nodes
+		   which were deleted during the transaction. */
+			struct list_head delete_set;
+		} nodiscard;
+
+		struct {
+			/* The atom's delete set. It collects all blocks that have been
+			   deallocated (both immediate and deferred) during the transaction.
+			   These blocks are considered for discarding at commit time.
+			   For details see discard.c */
+			struct list_head delete_set;
+		} discard;
+	};
 
 	/* The atom's wandered_block mapping. */
 	struct list_head wandered_map;
@@ -508,6 +523,22 @@ extern int blocknr_list_iterator(txn_atom *atom,
                                  void *data,
                                  int delete);
 
+/* These are wrappers for accessing and modifying atom's delete lists,
+   depending on whether discard is enabled or not.
+   If it is enabled, (less memory efficient) blocknr_list is used for delete
+   list storage. Otherwise, blocknr_set is used for this purpose. */
+extern void atom_dset_init(txn_atom *atom);
+extern void atom_dset_destroy(txn_atom *atom);
+extern void atom_dset_merge(txn_atom *from, txn_atom *to);
+extern int atom_dset_deferred_apply(txn_atom* atom,
+                                    blocknr_set_actor_f actor,
+                                    void *data,
+                                    int delete);
+extern int atom_dset_deferred_add_extent(txn_atom *atom,
+                                         void **new_entry,
+                                         const reiser4_block_nr *start,
+                                         const reiser4_block_nr *len);
+
 /* flush code takes care about how to fuse flush queues */
 extern void flush_init_atom(txn_atom * atom);
 extern void flush_fuse_queues(txn_atom * large, txn_atom * small);
fs/reiser4/wander.c +2 -1
index 4e29de8..04ddec6 100644
@@ -1252,7 +1252,6 @@ int reiser4_write_logs(long *nr_submitted)
 	reiser4_post_commit_hook();
 
 	ret = write_tx_back(&ch);
-	reiser4_post_write_back_hook();
 
       up_and_ret:
 	if (ret) {
@@ -1265,6 +1264,8 @@ int reiser4_write_logs(long *nr_submitted)
 	dealloc_tx_list(&ch);
 	dealloc_wmap(&ch);
 
+	reiser4_post_write_back_hook();
+
 	put_overwrite_set(&ch);
 
 	done_commit_handle(&ch);
Signature · 1 line
2.0.3
#7 lore raw
In reply to Ivan Shapovalov
Quoted 11 lines · Ivan Shapovalov

[...]

Ivan Shapovalov (6):
reiser4: fix reiser4_post_{commit,write_back}_hook() and their invocations.
reiser4: make space_allocator's check_blocks() reusable.
reiser4: add an implementation of "block lists", splitted off the discard code.
reiser4: blocknr_list: use kmem_cache instead of kmalloc for allocating entries.
reiser4: blocknr_set: use kmem_cache instead of kmalloc for allocating entries.
reiser4: discard support: initial implementation using blocknr_list, without extent padding.

[...]

This is a diff between previous two patchsets and this one, for ease of reviewing.

fs/reiser4/block_alloc.c +2 -1
index 98080a1..324b11c 100644
@@ -9,6 +9,7 @@ reiser4/README */
 #include "block_alloc.h"
 #include "tree.h"
 #include "super.h"
+#include "discard.h"
 
 #include <linux/types.h>	/* for __u??  */
 #include <linux/fs.h>		/* for struct super_block  */
@@ -1144,7 +1145,7 @@ void reiser4_post_write_back_hook(void)
 	} while (ret == -E_REPEAT);
 
 	if (ret) {
-		warning("intelfx-8", "discard atom failed (%ld)", ret);
+		warning("intelfx-8", "discard atom failed (%d)", ret);
 	}
 
 	atom = get_current_atom_locked();
fs/reiser4/discard.c +10 -83

131 lines not on this page · raw message

fs/reiser4/plugin/space/bitmap.c +3 -5
index 03bc5e7..3da3f6b 100644
@@ -1259,8 +1259,7 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
 
 	reiser4_block_nr end;
 	bmap_nr_t bmap, end_bmap;
-	bmap_off_t offset;
-	bmap_off_t end_offset;
+	bmap_off_t offset, end_offset;
 	const bmap_off_t max_offset = bmap_bit_count(super->s_blocksize);
 
 	assert("intelfx-9", start != NULL);
@@ -1270,9 +1269,8 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
 		check_block_range(start, len);
 		end = *start + *len - 1;
 	} else {
-		/* end is used as temporary len here */
-		end = 1;
-		check_block_range(start, &end);
+		/* on next line, end is used as temporary len for check_block_range() */
+		end = 1; check_block_range(start, &end);
 		end = *start;
 	}
 
fs/reiser4/txnmgr.h +4 -2
index 05990d8..72b84a2 100644
@@ -256,8 +256,10 @@ struct txn_atom {
 		} nodiscard;
 
 		struct {
-			/* The atom's delete set. It collects block numbers which were
-			   deallocated with BA_DEFER, i. e. of ordinary nodes. */
+			/* The atom's delete set. It collects all blocks that have been
+			   deallocated (both immediate and deferred) during the transaction.
+			   These blocks are considered for discarding at commit time.
+			   For details see discard.c */
 			struct list_head delete_set;
 		} discard;
 	};

Thanks,

Signature · 1 line
Ivan Shapovalov / intelfx /