Skip to contentSkip to conversation

reiser4: discard support: initial implementation, refactored.

RFC PATCH Superseded Ivan Shapovalov 2 participants 9 messages Jun 20, 2014 – Jun 22, 2014

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover reiser4: discard support: initial implementation, refactored.

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

Ivan Shapovalov (4):
reiser4: make space_allocator's check_blocks() reusable.
reiser4: add an implementation of "block lists", splitted off the discard code.
reiser4: add reiser4_debug(): a conditional equivalent of reiser4_log().
reiser4: discard support: initial implementation using linked lists.

 fs/reiser4/Makefile                       |   2 +
 fs/reiser4/block_alloc.c                  |  49 ++---
 fs/reiser4/block_alloc.h                  |  14 +-
 fs/reiser4/blocknrlist.c                  | 315 ++++++++++++++++++++++++++++++
 fs/reiser4/debug.h                        |   4 +
 fs/reiser4/dformat.h                      |   2 +
 fs/reiser4/discard.c                      | 247 +++++++++++++++++++++++
 fs/reiser4/discard.h                      |  31 +++
 fs/reiser4/forward.h                      |   1 +
 fs/reiser4/init_super.c                   |   2 +
 fs/reiser4/plugin/space/bitmap.c          |  84 +++++---
 fs/reiser4/plugin/space/bitmap.h          |   2 +-
 fs/reiser4/plugin/space/space_allocator.h |   4 +-
 fs/reiser4/super.h                        |   4 +-
 fs/reiser4/txnmgr.c                       | 125 +++++++++++-
 fs/reiser4/txnmgr.h                       |  63 +++++-
 fs/reiser4/znode.c                        |   9 +-
 17 files changed, 884 insertions(+), 74 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.0
#1 lore raw

RFC PATCH v5 1/4 reiser4: make space_allocator's check_blocks() reusable.

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          | 77 ++++++++++++++++++++-----------
 fs/reiser4/plugin/space/bitmap.h          |  2 +-
 fs/reiser4/plugin/space/space_allocator.h |  4 +-
 fs/reiser4/znode.c                        |  9 ++--
 6 files changed, 68 insertions(+), 54 deletions(-)
fs/reiser4/block_alloc.c +2 -14
index 81ed96f..57b0836 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 +51 -26

99 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.0
#2 lore raw

RFC PATCH v5 2/4 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 | 315 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/reiser4/forward.h     |   1 +
 fs/reiser4/txnmgr.h      |  19 +++
 4 files changed, 336 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 +315 -0

315 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.0
#3 lore raw

RFC PATCH v5 3/4 reiser4: add reiser4_debug(): a conditional equivalent of reiser4_log().

In reply to Ivan Shapovalov
---
 fs/reiser4/debug.h | 4 ++++
 1 file changed, 4 insertions(+)
fs/reiser4/debug.h +4 -0
index 060921f..281bf78 100644
@@ -46,6 +46,9 @@
 /* version of info that only actually prints anything when _d_ebugging
     is on */
 #define dinfo(format, ...) printk(format , ## __VA_ARGS__)
+/* a conditional equivalent of reiser4_log */
+#define reiser4_debug(label, format, ...)				\
+	reiser4_log(label, format, ## __VA_ARGS__)
 /* macro to catch logical errors. Put it into `default' clause of
     switch() statement. */
 #define impossible(label, format, ...) 			\
@@ -77,6 +80,7 @@ extern void call_on_each_assert(void);
 #else
 
 #define dinfo(format, args...) noop
+#define reiser4_debug(label, format, args...) noop
 #define impossible(label, format, args...) noop
 #define assert(label, cond) noop
 #define check_me(label, expr)	((void) (expr))
Signature · 1 line
2.0.0
#4 lore raw

RFC PATCH v5 4/4 reiser4: discard support: initial implementation using linked lists.

In reply to Ivan Shapovalov

Implementation details:

- candidate extents are stored during the transaction to a linked list
- if an extent being added is adjacent to the last one, they are merged to prevent another allocation
- at commit time, the log is further sorted and extents are merged
- extents are further processed to align discard requests to erase unit boundaries, extending them to neighbour blocks if needed
- each erase unit is checked to be deallocated and submitted to discard
- processing stops at first failure (this does not fail atom commit)

For now (shortcomings):

- kernel-reported erase unit granularity and alignment offset are used as-is without any override (it may make sense in order to mitigate bogus values sometimes reported by kernel/hardware)
- processing each erase unit makes its own bitmap query to check allocation status; this is suboptimal when granularity is less than the block size (should not matter in practice as granularity almost never is that small)

Note on candidate block collection:

Another per-atom block set, ->aux_delete_set, has been added, containing extents deallocated without BA_DEFER (i. e. blocks of the wandered journal). When discard is enabled, storage of both delete sets is enabled. They are stored using blocknr_lists, then spliced and sorted before discarding, so all blocks that have been deallocated during the transaction are considered for discarding.

Otherwise, only ->delete_set is maintained, and it is stored using blocknr_set which is more memory efficient but inherently unordered (so it cannot be used for the discard algorithm).

The only semantic-significant change to existing code is that reiser4_post_commit_hook() does not clear ->delete_set (instead, it is cleared either by discard_atom() or as part of atom's destruction). This is OK because ->delete_set is not accessed after reiser4_post_commit_hook().

---
 fs/reiser4/Makefile              |   1 +
 fs/reiser4/block_alloc.c         |  33 ++++--
 fs/reiser4/dformat.h             |   2 +
 fs/reiser4/discard.c             | 247 +++++++++++++++++++++++++++++++++++++++
 fs/reiser4/discard.h             |  31 +++++
 fs/reiser4/init_super.c          |   2 +
 fs/reiser4/plugin/space/bitmap.c |  11 +-
 fs/reiser4/super.h               |   4 +-
 fs/reiser4/txnmgr.c              | 125 +++++++++++++++++++-
 fs/reiser4/txnmgr.h              |  44 ++++++-
 10 files changed, 478 insertions(+), 22 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 +25 -8
index 57b0836..9e44e8b 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  */
@@ -992,6 +993,7 @@ reiser4_dealloc_blocks(const reiser4_block_nr * start,
 	int ret;
 	reiser4_context *ctx;
 	reiser4_super_info_data *sbinfo;
+	void *new_entry = NULL;
 
 	ctx = get_current_context();
 	sbinfo = get_super_private(ctx->super);
@@ -1007,17 +1009,13 @@ reiser4_dealloc_blocks(const reiser4_block_nr * start,
 	}
 
 	if (flags & BA_DEFER) {
-		blocknr_set_entry *bsep = NULL;
-
-		/* storing deleted block numbers in a blocknr set
-		   datastructure for further actual deletion */
+		/* store deleted block numbers in the atom's deferred delete set
+		   for further actual deletion */
 		do {
 			atom = get_current_atom_locked();
 			assert("zam-430", atom != NULL);
 
-			ret =
-			    blocknr_set_add_extent(atom, &atom->delete_set,
-						   &bsep, start, len);
+			ret = atom_dset_deferred_add_extent(atom, &new_entry, start, len);
 
 			if (ret == -ENOMEM)
 				return ret;
@@ -1031,6 +1029,25 @@ reiser4_dealloc_blocks(const reiser4_block_nr * start,
 		spin_unlock_atom(atom);
 
 	} else {
+		/* store deleted block numbers in the atom's immediate delete set
+		   for further processing */
+		do {
+			atom = get_current_atom_locked();
+			assert("intelfx-51", atom != NULL);
+
+			ret = atom_dset_immediate_add_extent(atom, &new_entry, start, len);
+
+			if (ret == -ENOMEM)
+				return ret;
+
+			/* This loop might spin at most two times */
+		} while (ret == -E_REPEAT);
+
+		assert("intelfx-52", ret == 0);
+		assert("intelfx-53", atom != NULL);
+
+		spin_unlock_atom(atom);
+
 		assert("zam-425", get_current_super_private() != NULL);
 		sa_dealloc_blocks(reiser4_get_space_allocator(ctx->super),
 				  *start, *len);
@@ -1128,7 +1145,7 @@ void reiser4_post_commit_hook(void)
 
 	/* do the block deallocation which was deferred
 	   until commit is done */
-	blocknr_set_iterator(atom, &atom->delete_set, apply_dset, NULL, 1);
+	atom_dset_deferred_apply(atom, apply_dset, NULL, 0);
 
 	assert("zam-504", get_current_super_private() != NULL);
 	sa_post_commit_hook();
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 +247 -0

247 lines not on this page · raw message

fs/reiser4/discard.h new file +31 -0
new file mode 100644
index 0000000..ea46334
@@ -0,0 +1,31 @@
+/* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by
+ * reiser4/README */
+
+/* TRIM/discard interoperation subsystem for reiser4. */
+
+#if !defined(__FS_REISER4_DISCARD_H__)
+#define __FS_REISER4_DISCARD_H__
+
+#include "forward.h"
+#include "dformat.h"
+
+/**
+ * Issue discard requests for all block extents recorded in @atom's delete sets,
+ * if discard is enabled. In this case the delete sets are cleared.
+ *
+ * @atom should be locked on entry and is unlocked on exit.
+ */
+extern int discard_atom(txn_atom *atom);
+
+/* __FS_REISER4_DISCARD_H__ */
+#endif
+
+/* Make Linus happy.
+   Local variables:
+   c-indentation-style: "K&R"
+   mode-name: "LC"
+   c-basic-offset: 8
+   tab-width: 8
+   fill-column: 120
+   End:
+*/
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 +7 -4
index 5bfa71b..03bc5e7 100644
@@ -1263,12 +1263,16 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
 	bmap_off_t end_offset;
 	const bmap_off_t max_offset = bmap_bit_count(super->s_blocksize);
 
+	assert("intelfx-9", start != NULL);
+	assert("intelfx-10", ergo(len != NULL, *len > 0));
+
 	if (len != NULL) {
 		check_block_range(start, len);
 		end = *start + *len - 1;
 	} else {
 		/* end is used as temporary len here */
-		check_block_range(start, &(end = 1));
+		end = 1;
+		check_block_range(start, &end);
 		end = *start;
 	}
 
@@ -1283,7 +1287,7 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,
 	++end_offset;
 
 	assert("intelfx-4", end_bmap >= bmap);
-	assert("intelfx-5", ergo(end_bmap == bmap, end_offset > offset));
+	assert("intelfx-5", ergo(end_bmap == bmap, end_offset >= offset));
 
 	for (; bmap < end_bmap; bmap++, offset = 0) {
 		if (!check_blocks_one_bitmap(bmap, offset, max_offset, desired)) {
@@ -1456,8 +1460,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 +119 -6

173 lines not on this page · raw message

fs/reiser4/txnmgr.h +41 -3

56 lines not on this page · raw message

Signature · 1 line
2.0.0
#5 lore raw
In reply to Ivan Shapovalov
Quoted 36 lines · Ivan Shapovalov

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

Ivan Shapovalov (4):
reiser4: make space_allocator's check_blocks() reusable.
reiser4: add an implementation of "block lists", splitted off the discard code.
reiser4: add reiser4_debug(): a conditional equivalent of reiser4_log().
reiser4: discard support: initial implementation using linked lists.

 fs/reiser4/Makefile                       |   2 +
 fs/reiser4/block_alloc.c                  |  49 ++---
 fs/reiser4/block_alloc.h                  |  14 +-
 fs/reiser4/blocknrlist.c                  | 315 ++++++++++++++++++++++++++++++
 fs/reiser4/debug.h                        |   4 +
 fs/reiser4/dformat.h                      |   2 +
 fs/reiser4/discard.c                      | 247 +++++++++++++++++++++++
 fs/reiser4/discard.h                      |  31 +++
 fs/reiser4/forward.h                      |   1 +
 fs/reiser4/init_super.c                   |   2 +
 fs/reiser4/plugin/space/bitmap.c          |  84 +++++---
 fs/reiser4/plugin/space/bitmap.h          |   2 +-
 fs/reiser4/plugin/space/space_allocator.h |   4 +-
Quoted 8 lines
 fs/reiser4/super.h                        |   4 +-
 fs/reiser4/txnmgr.c                       | 125 +++++++++++-
 fs/reiser4/txnmgr.h                       |  63 +++++-
 fs/reiser4/znode.c                        |   9 +-
 17 files changed, 884 insertions(+), 74 deletions(-)
 create mode 100644 fs/reiser4/blocknrlist.c
 create mode 100644 fs/reiser4/discard.c
 create mode 100644 fs/reiser4/discard.h

Also I would like if this code could be given a review. :)

Thanks,

Signature · 1 line
Ivan Shapovalov / intelfx /
#6 lore raw
Quoted 45 lines · Ivan Shapovalov
Quoted 41 lines · Ivan Shapovalov

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

Ivan Shapovalov (4):
reiser4: make space_allocator's check_blocks() reusable.
reiser4: add an implementation of "block lists", splitted off the discard code.
reiser4: add reiser4_debug(): a conditional equivalent of reiser4_log().
reiser4: discard support: initial implementation using linked lists.

  fs/reiser4/Makefile                       |   2 +
  fs/reiser4/block_alloc.c                  |  49 ++---
  fs/reiser4/block_alloc.h                  |  14 +-
  fs/reiser4/blocknrlist.c                  | 315 ++++++++++++++++++++++++++++++
  fs/reiser4/debug.h                        |   4 +
  fs/reiser4/dformat.h                      |   2 +
  fs/reiser4/discard.c                      | 247 +++++++++++++++++++++++
  fs/reiser4/discard.h                      |  31 +++
  fs/reiser4/forward.h                      |   1 +
  fs/reiser4/init_super.c                   |   2 +
  fs/reiser4/plugin/space/bitmap.c          |  84 +++++---
  fs/reiser4/plugin/space/bitmap.h          |   2 +-
  fs/reiser4/plugin/space/space_allocator.h |   4 +-
  fs/reiser4/super.h                        |   4 +-
  fs/reiser4/txnmgr.c                       | 125 +++++++++++-
  fs/reiser4/txnmgr.h                       |  63 +++++-
  fs/reiser4/znode.c                        |   9 +-
  17 files changed, 884 insertions(+), 74 deletions(-)
Quoted 3 lines

create mode 100644 fs/reiser4/blocknrlist.c
create mode 100644 fs/reiser4/discard.c
create mode 100644 fs/reiser4/discard.h

Quoted 1 line

Also I would like if this code could be given a review. :)

Great! Looks nice for me, thanks!
There are 2 issues, though...

1) kmalloc/kfree a huge number of 32-byte chunks (blocknr_list entries) is suboptimal. There is a special low-level memory allocator for such purposes. Take a look how we initialize so-called "slab cache" for jnodes (_jnode_slab), atoms (_atom_slab), etc, and allocate memory for them (kmem_cache_alloc()).

2) A lot of blocknr_list entries are allocated at flush time, when the high-level allocator (txmod.c) makes "relocation decisions" (especially when txmod=wa). The problem is that the flush (with the following commit) usually is the file system response to memory pressure notifications, when additional memory allocation is not desirable.

I think that with the fixed (1) we'll include the discard support (if everything will be OK in the next 1-2 weeks).

As to (2): that is a common problem of all Linux subsystems which want memory to free memory. It is unresolvable, however, we can improve the situation. It would be nice to implement a per-atom pool of memory (as a list of kmalloc-ed buffers with "cursors") with an optional possibility to pre-allocate 1-2 such buffers at atom initialization time. But this is for the future...

I don't see other urgent improvements. Yes, overall scalability of rb-trees is better, as we found, however, merging rb-trees is more expensive, plus atom's fusion is not a background process, so it can lead to performance drop. There are rb-trees with fingers, however I haven't seen their implementation on C language (it can be not so simple).

Thanks!
Edward.

#7 lore raw
Quoted 43 lines · Edward Shishkin
Quoted 2 lines · Ivan Shapovalov

[...]
Also I would like if this code could be given a review. :)

Great! Looks nice for me, thanks!
There are 2 issues, though...

1) kmalloc/kfree a huge number of 32-byte chunks (blocknr_list entries) is suboptimal. There is a special low-level memory allocator for such purposes. Take a look how we initialize so-called "slab cache" for jnodes (_jnode_slab),
atoms (_atom_slab), etc, and allocate memory for them (kmem_cache_alloc()).

2) A lot of blocknr_list entries are allocated at flush time, when the high-level
allocator (txmod.c) makes "relocation decisions" (especially when txmod=wa). The problem is that the flush (with the following commit) usually is the file system
response to memory pressure notifications, when additional memory allocation is not desirable.

I think that with the fixed (1) we'll include the discard support (if everything will
be OK in the next 1-2 weeks).

As to (2): that is a common problem of all Linux subsystems which want memory
to free memory. It is unresolvable, however, we can improve the situation. It
would be nice to implement a per-atom pool of memory (as a list of kmalloc-ed
buffers with "cursors") with an optional possibility to pre-allocate 1-2 such buffers
at atom initialization time. But this is for the future...

I don't see other urgent improvements. Yes, overall scalability of rb-trees is better,
as we found, however, merging rb-trees is more expensive, plus atom's fusion is not a background process, so it can lead to performance drop. There are rb-trees with fingers, however I haven't seen their implementation on C language
(it can be not so simple).

Quoted 3 lines

Thanks!
Edward.

Thanks for the review!

(1) surely seems trivial. Do we need something similar for blocknr_set as well?

For (2) I don't quite understand you. How such a pool should be organized?

Do you mean blocknr_list_entry **pool of size N * sizeof(void*) filled with kmem_cache_alloc()'d pointers, or just blocknr_list_entry *pool of size N * sizeof(blocknr_list_entry)?

Signature · 1 line
Ivan Shapovalov / intelfx /
#8 lore raw
Quoted 44 lines · Ivan Shapovalov
Quoted 43 lines · Edward Shishkin
Quoted 2 lines · Ivan Shapovalov

[...]
Also I would like if this code could be given a review. :)

Great! Looks nice for me, thanks!
There are 2 issues, though...

1) kmalloc/kfree a huge number of 32-byte chunks (blocknr_list entries) is suboptimal. There is a special low-level memory allocator for such purposes. Take a look how we initialize so-called "slab cache" for jnodes (_jnode_slab),
atoms (_atom_slab), etc, and allocate memory for them (kmem_cache_alloc()).

2) A lot of blocknr_list entries are allocated at flush time, when the high-level
allocator (txmod.c) makes "relocation decisions" (especially when txmod=wa). The problem is that the flush (with the following commit) usually is the file system
response to memory pressure notifications, when additional memory allocation is not desirable.

I think that with the fixed (1) we'll include the discard support (if everything will
be OK in the next 1-2 weeks).

As to (2): that is a common problem of all Linux subsystems which want memory
to free memory. It is unresolvable, however, we can improve the situation. It
would be nice to implement a per-atom pool of memory (as a list of kmalloc-ed
buffers with "cursors") with an optional possibility to pre-allocate 1-2 such buffers
at atom initialization time. But this is for the future...

I don't see other urgent improvements. Yes, overall scalability of rb-trees is better,
as we found, however, merging rb-trees is more expensive, plus atom's fusion is not a background process, so it can lead to performance drop. There are rb-trees with fingers, however I haven't seen their implementation on C language
(it can be not so simple).

Quoted 7 lines
Quoted 3 lines

Thanks!
Edward.

Thanks for the review!

(1) surely seems trivial. Do we need something similar for blocknr_set as well?

...I suppose yes, because there is at least one blocknr_set_entry per each txn_atom, while the latter is already allocated with slab allocator).

Signature · 1 line
Ivan Shapovalov / intelfx /
Quoted 8 lines

For (2) I don't quite understand you. How such a pool should be organized?

Do you mean blocknr_list_entry **pool of size N * sizeof(void*) filled with kmem_cache_alloc()'d pointers, or just blocknr_list_entry *pool of size N * sizeof(blocknr_list_entry)?