reiser4: discard support: "precise discard" aka padding of extents to erase unit boundaries.
cover reiser4: discard support: "precise discard" aka padding of extents to erase unit boundaries.
So, this patchset uses your algorithm of padding/gluing extents to be discarded. I've added exact allocation primitives (is it what you've been talking about?), made the discard procedure allocate blocks of all paddings it performs and fixed an apparent bug in extent gluing which triggered the "edward-1635" assertion.
Edward Shishkin (1):
reiser4: iterate over extents in discard_atom
Ivan Shapovalov (5):
reiser4: block_alloc: split block allocation accounting logic into separate functions for re-use.
reiser4: block_alloc, plugin/space/bitmap: add a method for "exact" block allocation.
reiser4: discard: don't be overly smart when gluing extents in discard_sorted_merged_extents().
reiser4: blocknrlist: add operations blocknr_list_del() and blocknr_list_update_extent().
reiser4: discard: allocate extent paddings.
fs/reiser4/block_alloc.c | 175 +++++++++---- fs/reiser4/block_alloc.h | 3 + fs/reiser4/blocknrlist.c | 38 +++ fs/reiser4/discard.c | 410 +++++++++++++++++++++++++++--- fs/reiser4/discard.h | 8 +- fs/reiser4/forward.h | 1 + fs/reiser4/init_super.c | 4 + fs/reiser4/plugin/space/bitmap.c | 94 +++++-- fs/reiser4/plugin/space/bitmap.h | 3 + fs/reiser4/plugin/space/space_allocator.h | 10 +- fs/reiser4/super.h | 4 + fs/reiser4/txnmgr.h | 6 + 12 files changed, 647 insertions(+), 109 deletions(-)
Signature · 1 line
2.1.3
PATCH 1/6 reiser4: block_alloc: split block allocation accounting logic into separate functions for re-use.
This logic is also needed for the "exact" block allocation function which will be added in the next commit.
--- fs/reiser4/block_alloc.c | 139 +++++++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 52 deletions(-)
fs/reiser4/block_alloc.c +87 -52
@@ -634,6 +634,76 @@ void get_blocknr_hint_default(reiser4_block_nr * result)spin_unlock_reiser4_super (sbinfo); } +static int reiser4_alloc_blocks_pre (reiser4_block_nr len, +block_stage_t block_stage, +reiser4_ba_flags_t flags) +{ +int ret =0 ; + +/* VITALY: allocator should grab this for internal/tx-lists/similar +only. */ +/* VS-FIXME-HANS: why is this comment above addressed to vitaly (from vitaly)?*/ +if (block_stage ==BLOCK_NOT_COUNTED ) { + ret =reiser4_grab_space_force (len, flags); + } + +return ret; +} + +static void reiser4_alloc_blocks_post_success (reiser4_block_nr blk, +reiser4_block_nr len, +block_stage_t block_stage, +reiser4_ba_flags_t flags) +{ +reiser4_context *ctx; +reiser4_super_info_data *sbinfo; + + ctx =get_current_context (); + sbinfo =get_super_private (ctx->super); + +assert ("zam-680" , blk <reiser4_block_count (ctx->super)); +assert ("zam-681" , blk + len <=reiser4_block_count (ctx->super)); + +if (flags &BA_PERMANENT ) { +/* we assume that current atom exists at this moment */ +txn_atom *atom =get_current_atom_locked (); + atom->nr_blocks_allocated += len; +spin_unlock_atom (atom); + } + +switch (block_stage) { +case BLOCK_NOT_COUNTED : +case BLOCK_GRABBED : +grabbed2used (ctx, sbinfo, len); +break ; +case BLOCK_UNALLOCATED : +fake_allocated2used (sbinfo, len, flags); +break ; +case BLOCK_FLUSH_RESERVED : + { +txn_atom *atom =get_current_atom_locked (); +flush_reserved2used (atom, len); +spin_unlock_atom (atom); + } +break ; +default : +impossible ("zam-531" ,"wrong block stage" ); + } +} + +static void reiser4_alloc_blocks_post_failure (reiser4_block_nr len, +block_stage_t block_stage) +{ +reiser4_context *ctx; +reiser4_super_info_data *sbinfo; + + ctx =get_current_context (); + sbinfo =get_super_private (ctx->super); + +if (block_stage ==BLOCK_NOT_COUNTED ) +grabbed2free (ctx, sbinfo, len); +} +/* Allocate "real" disk blocks by calling a proper space allocation plugin * method. Blocks are allocated in one contiguous disk region. The plugin * independent part accounts blocks by subtracting allocated amount from grabbed
@@ -651,74 +721,39 @@ void get_blocknr_hint_default(reiser4_block_nr * result)* * @return -- 0 if success, error code otherwise. */ -int -reiser4_alloc_blocks (reiser4_blocknr_hint * hint,reiser4_block_nr * blk, -reiser4_block_nr * len,reiser4_ba_flags_t flags) +int reiser4_alloc_blocks (reiser4_blocknr_hint * hint,reiser4_block_nr * blk, +reiser4_block_nr * len,reiser4_ba_flags_t flags) { -__u64 needed = *len; -reiser4_context *ctx; -reiser4_super_info_data *sbinfo;int ret; +reiser4_context *ctx;assert ("zam-986" , hint !=NULL ); +assert ("intelfx-68" , blk !=NULL ); +assert ("intelfx-69" , len !=NULL ); ctx =get_current_context (); - sbinfo =get_super_private (ctx->super);/* For write-optimized data we use default search start value, which is * close to last write location. */ if (flags &BA_USE_DEFAULT_SEARCH_START )get_blocknr_hint_default (&hint->blk); -/* VITALY: allocator should grab this for internal/tx-lists/similar -only. */ -/* VS-FIXME-HANS: why is this comment above addressed to vitaly (from vitaly)?*/ -if (hint->block_stage ==BLOCK_NOT_COUNTED ) { - ret =reiser4_grab_space_force (*len, flags); -if (ret !=0 ) -return ret; + ret =reiser4_alloc_blocks_pre (*len, hint->block_stage, flags); + +if (ret !=0 ) { +return ret; } - ret = -sa_alloc_blocks (reiser4_get_space_allocator (ctx->super), - hint, (int )needed, blk, len); + ret =sa_alloc_blocks (reiser4_get_space_allocator (ctx->super), + hint, (int )*len, blk, len); -if (!ret) { -assert ("zam-680" , *blk <reiser4_block_count (ctx->super)); -assert ("zam-681" , - *blk + *len <=reiser4_block_count (ctx->super)); - -if (flags &BA_PERMANENT ) { -/* we assume that current atom exists at this moment */ -txn_atom *atom =get_current_atom_locked (); - atom->nr_blocks_allocated += *len; -spin_unlock_atom (atom); - } - -switch (hint->block_stage) { -case BLOCK_NOT_COUNTED : -case BLOCK_GRABBED : -grabbed2used (ctx, sbinfo, *len); -break ; -case BLOCK_UNALLOCATED : -fake_allocated2used (sbinfo, *len, flags); -break ; -case BLOCK_FLUSH_RESERVED : - { -txn_atom *atom =get_current_atom_locked (); -flush_reserved2used (atom, *len); -spin_unlock_atom (atom); - } -break ; -default : -impossible ("zam-531" ,"wrong block stage" ); - } +if (ret ==0 ) { +reiser4_alloc_blocks_post_success (*blk, *len, hint->block_stage, + flags); }else { -assert ("zam-821" , -ergo (hint->max_dist ==0 - && !hint->backward, ret != -ENOSPC )); -if (hint->block_stage ==BLOCK_NOT_COUNTED ) -grabbed2free (ctx, sbinfo, needed); +assert ("zam-821" ,ergo (hint->max_dist ==0 && !hint->backward, + ret != -ENOSPC )); +reiser4_alloc_blocks_post_failure (*len, hint->block_stage); }return ret;
Signature · 1 line
2.1.3
PATCH 2/6 reiser4: block_alloc, plugin/space/bitmap: add a method for "exact" block allocation.
In reply to Ivan ShapovalovThis allows to allocate exact count of blocks at exact position. In particular, 'precise discard' implementation will need this interface to perform padding of the discard extents.
--- fs/reiser4/block_alloc.c | 36 ++++++++++++ fs/reiser4/block_alloc.h | 3 + fs/reiser4/plugin/space/bitmap.c | 94 +++++++++++++++++++++++-------- fs/reiser4/plugin/space/bitmap.h | 3 + fs/reiser4/plugin/space/space_allocator.h | 10 +++- 5 files changed, 120 insertions(+), 26 deletions(-)
fs/reiser4/block_alloc.c +36 -0
@@ -759,6 +759,42 @@ int reiser4_alloc_blocks(reiser4_blocknr_hint * hint, reiser4_block_nr * blk,return ret; } +/* This is a version of reiser4_alloc_blocks() for use in special conditions, +* where an allocation must have exact length and position. +* +* It does not use reiser4_blocknr_hint; instead, all parameters are passed +* directly. +*/ +int reiser4_alloc_blocks_exact (const reiser4_block_nr * blk, +const reiser4_block_nr * len, +block_stage_t stage,reiser4_ba_flags_t flags) +{ +int ret; +reiser4_context *ctx; + +assert ("intelfx-70" , blk !=NULL ); +assert ("intelfx-71" , len !=NULL ); + + ctx =get_current_context (); + + ret =reiser4_alloc_blocks_pre (*len, stage, flags); + +if (ret !=0 ) { +return ret; + } + + ret =sa_alloc_blocks_exact (reiser4_get_space_allocator (ctx->super), + blk, len); + +if (ret ==0 ) { +reiser4_alloc_blocks_post_success (*blk, *len, stage, flags); + }else { +reiser4_alloc_blocks_post_failure (*len, stage); + } + +return ret; +} +/** * ask block allocator for some unformatted blocks */
fs/reiser4/block_alloc.h +3 -0
@@ -109,6 +109,9 @@ int reiser4_alloc_blocks(reiser4_blocknr_hint * hint,int reiser4_dealloc_blocks (const reiser4_block_nr *,const reiser4_block_nr *,block_stage_t ,reiser4_ba_flags_t flags); +int reiser4_alloc_blocks_exact (const reiser4_block_nr * start, +const reiser4_block_nr * len, +block_stage_t stage,reiser4_ba_flags_t flags); static inline int reiser4_alloc_block(reiser4_blocknr_hint * hint, reiser4_block_nr * start,
fs/reiser4/plugin/space/bitmap.c +70 -24
133 lines not on this page · raw message
fs/reiser4/plugin/space/bitmap.h +3 -0
@@ -19,6 +19,9 @@ extern int reiser4_alloc_blocks_bitmap(reiser4_space_allocator *, reiser4_blocknr_hint *, int needed, reiser4_block_nr * start, reiser4_block_nr * len); +extern int reiser4_alloc_blocks_exact_bitmap (reiser4_space_allocator *, +const reiser4_block_nr * start, +const reiser4_block_nr * len);extern int reiser4_check_blocks_bitmap (const reiser4_block_nr *,const reiser4_block_nr *,int ); extern void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator *,
fs/reiser4/plugin/space/space_allocator.h +8 -2
@@ -29,9 +29,15 @@ static inline void sa_dealloc_blocks (reiser4_space_allocator * al, reiser4_bloc reiser4_dealloc_blocks_##allocator (al, start, len); \ } \ \ -static inline int 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) \ { \ - return reiser4_check_blocks_##allocator (start, end, desired); \ + return reiser4_check_blocks_##allocator (start, end, desired); \ +} \ + \ +static inline int sa_alloc_blocks_exact (reiser4_space_allocator * al, const reiser4_block_nr * start, \ + const reiser4_block_nr * len) \ +{ \ + return reiser4_alloc_blocks_exact_##allocator (al, start, len); \ } \ \ static inline void sa_pre_commit_hook (void) \
Signature · 1 line
2.1.3
Re: [PATCH 2/6] reiser4: block_alloc, plugin/space/bitmap: add a method for "exact" block allocation.
Yes, this is exactly what I wanted,
Thanks!
Edward.
Quoted 252 lines · Ivan Shapovalov
This allows to allocate exact count of blocks at exact position. In particular, 'precise discard' implementation will need this interface to perform padding of the discard extents.
Signed-off-by Ivan Shapovalov <[email protected]>--- fs/reiser4/block_alloc.c | 36 ++++++++++++ fs/reiser4/block_alloc.h | 3 + fs/reiser4/plugin/space/bitmap.c | 94 +++++++++++++++++++++++-------- fs/reiser4/plugin/space/bitmap.h | 3 + fs/reiser4/plugin/space/space_allocator.h | 10 +++- 5 files changed, 120 insertions(+), 26 deletions(-)fs/reiser4/block_alloc.c +36
-0@@ -759,6 +759,42 @@ int reiser4_alloc_blocks(reiser4_blocknr_hint * hint, reiser4_block_nr * blk,return ret; } +/* This is a version of reiser4_alloc_blocks() for use in special conditions, +* where an allocation must have exact length and position. +* +* It does not use reiser4_blocknr_hint; instead, all parameters are passed +* directly. +*/ +int reiser4_alloc_blocks_exact (const reiser4_block_nr * blk, +const reiser4_block_nr * len, +block_stage_t stage,reiser4_ba_flags_t flags) +{ +int ret; +reiser4_context *ctx; + +assert ("intelfx-70" , blk !=NULL ); +assert ("intelfx-71" , len !=NULL ); + + ctx =get_current_context (); + + ret =reiser4_alloc_blocks_pre (*len, stage, flags); + +if (ret !=0 ) { +return ret; + } + + ret =sa_alloc_blocks_exact (reiser4_get_space_allocator (ctx->super), + blk, len); + +if (ret ==0 ) { +reiser4_alloc_blocks_post_success (*blk, *len, stage, flags); + }else { +reiser4_alloc_blocks_post_failure (*len, stage); + } + +return ret; +} +/** * ask block allocator for some unformatted blocks */ fs/reiser4/block_alloc.h +3
-0@@ -109,6 +109,9 @@ int reiser4_alloc_blocks(reiser4_blocknr_hint * hint,int reiser4_dealloc_blocks (const reiser4_block_nr *,const reiser4_block_nr *,block_stage_t ,reiser4_ba_flags_t flags); +int reiser4_alloc_blocks_exact (const reiser4_block_nr * start, +const reiser4_block_nr * len, +block_stage_t stage,reiser4_ba_flags_t flags); static inline int reiser4_alloc_block(reiser4_blocknr_hint * hint, reiser4_block_nr * start,fs/reiser4/plugin/space/bitmap.c +70
-24@@ -1222,8 +1222,14 @@ void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator * allocator,release_and_unlock_bnode (bnode); } +typedef enum { +CHECK_FREE , +CHECK_FREE_AND_ALLOC , +CHECK_BUSY +}check_blocks_mode ; +static int check_blocks_one_bitmap (bmap_nr_t bmap,bmap_off_t start_offset, -bmap_off_t end_offset,int desired) +bmap_off_t end_offset,check_blocks_mode mode) {struct super_block *super =reiser4_get_current_sb ();struct bitmap_node *bnode =get_bnode (super, bmap);@@ -1236,14 +1242,29 @@ static int check_blocks_one_bitmap(bmap_nr_t bmap, bmap_off_t start_offset,assert ("nikita-2216" ,jnode_is_loaded (bnode->wjnode)); -if (desired) { +switch (mode) { +case CHECK_BUSY : ret =reiser4_find_next_zero_bit (bnode_working_data (bnode), - end_offset, start_offset) - >= end_offset; - }else { - ret =reiser4_find_next_set_bit (bnode_working_data (bnode), end_offset, start_offset) >= end_offset; + +break ; + +case CHECK_FREE : +case CHECK_FREE_AND_ALLOC : + ret =reiser4_find_next_set_bit (bnode_working_data (bnode), + end_offset, start_offset) + >= end_offset; + +if (mode ==CHECK_FREE_AND_ALLOC && ret) { +reiser4_set_bits (bnode_working_data (bnode), + start_offset, end_offset); + } + +break ; + +default : +impossible ("intelfx-67" ,"wrong block check/alloc mode: %d" , mode); }release_and_unlock_bnode (bnode);@@ -1251,9 +1272,8 @@ static int check_blocks_one_bitmap(bmap_nr_t bmap, bmap_off_t start_offset,return ret; } -/* plugin->u.space_allocator.check_blocks(). */ -int reiser4_check_blocks_bitmap (const reiser4_block_nr * start, -const reiser4_block_nr * len,int desired) +static int check_blocks_bitmap (reiser4_block_nr start,reiser4_block_nr len, +check_blocks_mode mode) {struct super_block *super =reiser4_get_current_sb ();@@ -1262,21 +1282,13 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,bmap_off_t offset, 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 )); +assert ("intelfx-10" , len >0 ); -if (len !=NULL ) { -check_block_range (start, len); - end = *start + *len -1 ; - }else { -/* on next line, end is used as temporary len for check_block_range() */ - end =1 ;check_block_range (start, &end); - end = *start; - } +check_block_range (&start, &len); +parse_blocknr (&start, &bmap, &offset); -parse_blocknr (start, &bmap, &offset); - -if (end == *start) { + end = start + len -1 ; +if (end == start) { end_bmap = bmap; end_offset = offset; }else {@@ -1288,11 +1300,45 @@ int reiser4_check_blocks_bitmap(const reiser4_block_nr * start,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)) { +if (!check_blocks_one_bitmap (bmap, offset, max_offset, mode)) {return 0 ; } } -return check_blocks_one_bitmap (bmap, offset, end_offset, desired); +return check_blocks_one_bitmap (bmap, offset, end_offset, mode); +} + +/* plugin->u.space_allocator.alloc_blocks_exact() */ +int reiser4_alloc_blocks_exact_bitmap (reiser4_space_allocator * allocator, +const reiser4_block_nr * start, +const reiser4_block_nr * len) +{ +int ret; + +assert ("intelfx-66" , start !=NULL ); + +if (len !=NULL ) + ret =check_blocks_bitmap (*start, *len,CHECK_FREE_AND_ALLOC ); +else + ret =check_blocks_bitmap (*start,1 ,CHECK_FREE_AND_ALLOC ); + +if (ret ==0 ) +return RETERR (-ENOSPC ); +else +return 0 ; +} + +/* plugin->u.space_allocator.check_blocks(). */ +int reiser4_check_blocks_bitmap (const reiser4_block_nr * start, +const reiser4_block_nr * len,int desired) +{ +check_blocks_mode mode = desired ?CHECK_BUSY :CHECK_FREE ; + +assert ("intelfx-9" , start !=NULL ); + +if (len !=NULL ) +return check_blocks_bitmap (*start, *len, mode); +else +return check_blocks_bitmap (*start,1 , mode); }/* conditional insertion of @node into atom's overwrite set if it was not there */ fs/reiser4/plugin/space/bitmap.h +3
-0@@ -19,6 +19,9 @@ extern int reiser4_alloc_blocks_bitmap(reiser4_space_allocator *, reiser4_blocknr_hint *, int needed, reiser4_block_nr * start, reiser4_block_nr * len); +extern int reiser4_alloc_blocks_exact_bitmap (reiser4_space_allocator *, +const reiser4_block_nr * start, +const reiser4_block_nr * len);extern int reiser4_check_blocks_bitmap (const reiser4_block_nr *,const reiser4_block_nr *,int ); extern void reiser4_dealloc_blocks_bitmap(reiser4_space_allocator *,fs/reiser4/plugin/space/space_allocator.h +8
-2@@ -29,9 +29,15 @@ static inline void sa_dealloc_blocks (reiser4_space_allocator * al, reiser4_bloc reiser4_dealloc_blocks_##allocator (al, start, len); \ } \ \ -static inline int 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) \ { \ - return reiser4_check_blocks_##allocator (start, end, desired); \ + return reiser4_check_blocks_##allocator (start, end, desired); \ +} \ + \ +static inline int sa_alloc_blocks_exact (reiser4_space_allocator * al, const reiser4_block_nr * start, \ + const reiser4_block_nr * len) \ +{ \ + return reiser4_alloc_blocks_exact_##allocator (al, start, len); \ } \ \ static inline void sa_pre_commit_hook (void) \
PATCH 3/6 reiser4: iterate over extents in discard_atom
In reply to Ivan ShapovalovFrom: Edward Shishkin <[email protected]>
. add discard_sorted_merged_extents();
. add mount options to specify erase unit and alignment; . verify and set discard params to the super-block at mount time;
--- fs/reiser4/blocknrlist.c | 10 ++ fs/reiser4/discard.c | 378 +++++++++++++++++++++++++++++++++++++++++++---- fs/reiser4/discard.h | 8 +- fs/reiser4/forward.h | 1 + fs/reiser4/init_super.c | 4 + fs/reiser4/super.h | 4 + fs/reiser4/txnmgr.h | 2 + 7 files changed, 377 insertions(+), 30 deletions(-)
fs/reiser4/blocknrlist.c +10 -0
@@ -26,6 +26,16 @@ struct blocknr_list_entry {#define blocknr_list_entry (ptr) list_entry(ptr, blocknr_list_entry, link) +reiser4_block_nr blocknr_list_entry_start (struct list_head *ptr) +{ +return blocknr_list_entry (ptr)->start; +} + +reiser4_block_nr blocknr_list_entry_len (struct list_head *ptr) +{ +return blocknr_list_entry (ptr)->len; +} +static void blocknr_list_entry_init (blocknr_list_entry *entry) {assert ("intelfx-11" , entry !=NULL );
fs/reiser4/discard.c +350 -28
423 lines not on this page · raw message
fs/reiser4/discard.h +6 -2
@@ -6,8 +6,12 @@#if !defined(__FS_REISER4_DISCARD_H__)#define __FS_REISER4_DISCARD_H__ -#include "forward.h" -#include "dformat.h" +struct discard_params { +int offset;/* discard offset in blocks */ +int unit;/* erase unit size in blocks */ +}; + +extern void check_discard_params (struct super_block *sb);/** * Issue discard requests for all block extents recorded in @atom's delete sets,
fs/reiser4/forward.h +1 -0
@@ -34,6 +34,7 @@ typedef struct reiser4_journal reiser4_journal;typedef struct txn_atom txn_atom ;typedef struct txn_handle txn_handle ;typedef struct txn_mgr txn_mgr ; +typedef struct discard_params discard_params ;typedef struct reiser4_dir_entry_desc reiser4_dir_entry_desc ;typedef struct reiser4_context reiser4_context ;typedef struct carry_level carry_level ;
fs/reiser4/init_super.c +4 -0
@@ -407,6 +407,9 @@ static noinline void push_sb_field_opts(struct opt_desc **p,/* carry flags used for insert operations */ PUSH_SB_FIELD_OPT (tree.carry.insert_flags,"%u" ); +PUSH_SB_FIELD_OPT (discard.unit,"%u" ); +PUSH_SB_FIELD_OPT (discard.offset,"%u" ); +#ifdef CONFIG_REISER4_BADBLOCKS /* * Alternative master superblock location in case if it's original
@@ -573,6 +576,7 @@ int reiser4_init_super_data(struct super_block *super, char *opt_string)warning ("nikita-2497" ,"optimal_io_size is too small" );return RETERR (-EINVAL ); } +check_discard_params (super);return result; }
fs/reiser4/super.h +4 -0
@@ -12,6 +12,7 @@#include "entd.h" #include "wander.h" #include "fsdata.h" +#include "discard.h" #include "plugin/object.h" #include "plugin/space/space_allocator.h"
@@ -206,6 +207,9 @@ struct reiser4_super_info_data {/* transaction manager */ txn_mgr tmgr; +/* discard params */ +discard_params discard; +/* ent thread */ entd_context entd;
fs/reiser4/txnmgr.h +2 -0
@@ -509,6 +509,8 @@ 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); +extern reiser4_block_nr blocknr_list_entry_start (struct list_head *blist); +extern reiser4_block_nr blocknr_list_entry_len (struct list_head *blist);/** * The @atom should be locked. */
Signature · 1 line
2.1.3
PATCH 4/6 reiser4: discard: don't be overly smart when gluing extents in discard_sorted_merged_extents().
In reply to Ivan Shapovalov@tailp, @alen and @end must be updated simultaneously because there are expressions involving combinations of these variables.
--- fs/reiser4/discard.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
fs/reiser4/discard.c +2 -10
@@ -366,18 +366,10 @@ static int discard_sorted_merged_extents(struct list_head *head)/* * jump to the glued extent */ -if (end + tailp < next_start + next_len) { -/* -* the glued extent doesn't -* fit into the tail padding, -* so update the last one -*/ - tailp =extent_get_tailp (next_start + next_len, - d_off, d_uni); - alen += (next_start + next_len - end); - } pos = next; + alen += (next_start + next_len - end); end = next_start + next_len; + tailp =extent_get_tailp (end, d_off, d_uni);/* * try to glue more extents */
Signature · 1 line
2.1.3
Re: [PATCH 4/6] reiser4: discard: don't be overly smart when gluing extents in discard_sorted_merged_extents().
Agreed.
This is absolutely not needed "if".
Thanks!
Edward.
Quoted 33 lines · Ivan Shapovalov
@tailp, @alen and @end must be updated simultaneously because there are expressions involving combinations of these variables.
Signed-off-by Ivan Shapovalov <[email protected]>--- fs/reiser4/discard.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)fs/reiser4/discard.c +2
-10@@ -366,18 +366,10 @@ static int discard_sorted_merged_extents(struct list_head *head)/* * jump to the glued extent */ -if (end + tailp < next_start + next_len) { -/* -* the glued extent doesn't -* fit into the tail padding, -* so update the last one -*/ - tailp =extent_get_tailp (next_start + next_len, - d_off, d_uni); - alen += (next_start + next_len - end); - } pos = next; + alen += (next_start + next_len - end); end = next_start + next_len; + tailp =extent_get_tailp (end, d_off, d_uni);/* * try to glue more extents */
PATCH 5/6 reiser4: blocknrlist: add operations blocknr_list_del() and blocknr_list_update_extent().
In reply to Ivan Shapovalov--- fs/reiser4/blocknrlist.c | 28 ++++++++++++++++++++++++++++ fs/reiser4/txnmgr.h | 4 ++++ 2 files changed, 32 insertions(+)
fs/reiser4/blocknrlist.c +28 -0
@@ -243,6 +243,17 @@ void blocknr_list_sort_and_join(struct list_head *blist) } } +void blocknr_list_del (struct list_head *blist) +{ +struct blocknr_list_entry *entry; + +assert ("intelfx-72" , blist !=NULL ); + + entry =blocknr_list_entry (blist); +list_del_init (blist); +blocknr_list_entry_free (entry); +} + int blocknr_list_add_extent(txn_atom *atom, struct list_head *blist, blocknr_list_entry **new_entry,
@@ -287,6 +298,23 @@ int blocknr_list_add_extent(txn_atom *atom,return 0 ; } +void blocknr_list_update_extent (struct list_head *blist, +const reiser4_block_nr *start, +const reiser4_block_nr *len) +{ +blocknr_list_entry *entry; + +assert ("intelfx-73" , blist !=NULL ); + + entry =blocknr_list_entry (blist); +if (start !=NULL ) { + entry->start = *start; + } +if (len !=NULL ) { + entry->len = *len; + } +} + int blocknr_list_iterator(txn_atom *atom, struct list_head *blist, blocknr_set_actor_f actor,
fs/reiser4/txnmgr.h +4 -0
@@ -509,6 +509,7 @@ 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); +extern void blocknr_list_del (struct list_head *blist);extern reiser4_block_nr blocknr_list_entry_start (struct list_head *blist);extern reiser4_block_nr blocknr_list_entry_len (struct list_head *blist);/**
@@ -519,6 +520,9 @@ extern int blocknr_list_add_extent(txn_atom *atom,blocknr_list_entry **new_entry, const reiser4_block_nr *start, const reiser4_block_nr *len); +extern void blocknr_list_update_extent (struct list_head *blist, +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,
Signature · 1 line
2.1.3
PATCH 6/6 reiser4: discard: allocate extent paddings.
In reply to Ivan ShapovalovSubsequent deallocation of newly allocated padding blocks is ensured by writing the actual discarded extents back to the discard set.
--- fs/reiser4/discard.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-)
fs/reiser4/discard.c +44 -6
@@ -221,7 +221,15 @@ static inline struct list_head *get_next_at(struct list_head *pos,static inline int check_free_blocks (const reiser4_block_nr start,const reiser4_block_nr len) { -return reiser4_check_blocks (&start, &len,0 ); +/* +* NOTE: we do not use BA_PERMANENT in out allocations +* even though these blocks are later deallocated with BA_DEFER +* (via updating the delete set with newly allocated blocks). +* The discard code is ran after the pre-commit hook so deallocated block +* accounting is already done. +*/ +return reiser4_alloc_blocks_exact (&start, &len,BLOCK_NOT_COUNTED , +BA_FORMATTED ) ==0 ; }/* Make sure that extents are sorted and merged */
@@ -255,6 +263,8 @@ static inline void check_blocknr_list_at(struct list_head *pos,* extent in the working space map. Try to "glue" the nearby * extents. Discard the (glued) extents with padded (or cut) * head and tail. +* The paddings, if any, are allocated before discarding, and the list +* is updated to contain all new allocations. * * Pre-conditions: @head points to the list of sorted and * merged extents.
@@ -274,6 +284,9 @@ static inline void check_blocknr_list_at(struct list_head *pos,* astart - actual start to discard (offset of the head padding); * alen - actual length to discard (length of glued aligned and padded extents). * +* estart - start of extent to be written back to the list +* eend - end (last block + 1) of extent to be written back to the list +* * Terminology in the comments: * * head - a part of extent at the beginning;
@@ -299,11 +312,14 @@ static int discard_sorted_merged_extents(struct list_head *head)reiser4_block_nr len;reiser4_block_nr end;reiser4_block_nr astart;__s64 alen; +reiser4_block_nr estart, eend;check_blocknr_list_at (pos, head); start =blocknr_list_entry_start (pos); len =blocknr_list_entry_len (pos); + estart = start; +/* * Step I. Cut or pad the head of extent *
@@ -326,6 +342,7 @@ static int discard_sorted_merged_extents(struct list_head *head)*/ astart = start - headp; alen = len + headp; + estart -= headp; }else {/* * head padding is dirty,
@@ -341,10 +358,11 @@ static int discard_sorted_merged_extents(struct list_head *head)* Cut or pad the tail of the last extent. */ end = start + len; + eend = end; tailp =extent_get_tailp (end, d_off, d_uni);/* -* This "gluing" loop updates @pos, @end, @tailp, @alen +* This "gluing" loop updates @end, @tailp, @alen, @eend */ while (1 ) {struct list_head *next;
@@ -366,10 +384,17 @@ static int discard_sorted_merged_extents(struct list_head *head)/* * jump to the glued extent */ - pos = next; alen += (next_start + next_len - end); end = next_start + next_len; tailp =extent_get_tailp (end, d_off, d_uni); + eend = end; +/* +* remove the glued extent from the list +* +* (don't update pos, current next->next +* will become pos->next) +*/ +blocknr_list_del (next);/* * try to glue more extents */
@@ -395,13 +420,14 @@ static int discard_sorted_merged_extents(struct list_head *head)*/ if (tailp ==0 )break ; -else if (check_free_blocks (end, tailp)) +else if (check_free_blocks (end, tailp)) {/* * tail padding is clean, * pad the tail */ alen += tailp; -else + eend += tailp; + }else /* * tail padding is dirty, * cut the tail
@@ -415,6 +441,18 @@ static int discard_sorted_merged_extents(struct list_head *head)* Step III. Discard the result */ if (alen >0 ) { +assert ("intelfx-74" , estart < eend); +assert ("intelfx-75" , estart <= start); +assert ("intelfx-76" , estart <= astart); +assert ("intelfx-77" , start + len <= eend); +assert ("intelfx-78" , astart + alen <= eend); + +/* here @eend becomes length */ + eend -= estart; +assert ("intelfx-79" , +reiser4_check_blocks (&estart, &eend,1 )); +blocknr_list_update_extent (pos, &estart, &eend); + ret =__discard_extent (sb->s_bdev, astart * (sb->s_blocksize >>9 ), alen * (sb->s_blocksize >>9 ));
@@ -453,7 +491,7 @@ int discard_atom(txn_atom *atom, struct list_head *processed_set)/* Sort the discard list, joining adjacent and overlapping extents. */ blocknr_list_sort_and_join (&discard_set); -/* Perform actual dirty work. */ +/* Perform actual dirty work. The discard set may change at this point. */ ret =discard_sorted_merged_extents (&discard_set);/* Add processed extents to the temporary list. */
Signature · 1 line
2.1.3
Quoted 2 lines · Ivan Shapovalov
So, this patchset uses your algorithm of padding/gluing extents to be discarded. I've added exact allocation primitives (is it what you've been talking about?
So, we found out that the old bitmap primitives don't allow us to implement precise discard, and I asked for new ones. Also we wanted to implement the general case, when precise discard works for any pair (offset, unit). Currently it works only for ones determined by the function convert_lattice_params(). For some reasons (that I don't remember) I was sure, that the general case should be obtained from this partial case by a small transformation of the function discard_sorted_merged_extents().
Well, I'll try to dive into details and generalize things on the holidays. If generalization is impossible, then we'll switch to non-precise discard every time when convert_lattice_params() fails.
Thanks!
Edward.
Quoted 29 lines
),
made the discard procedure allocate blocks of all paddings it performs and fixed an apparent bug in extent gluing which triggered the "edward-1635" assertion.Edward Shishkin (1):
reiser4: iterate over extents indiscard_atomIvan Shapovalov (5):
reiser4:block_alloc: split block allocation accounting logic into separate functions for re-use.
reiser4:block_alloc, plugin/space/bitmap: add a method for "exact" block allocation.
reiser4: discard: don't be overly smart when gluing extents indiscard_sorted_merged_extents().
reiser4: blocknrlist: add operationsblocknr_list_del()andblocknr_list_update_extent().
reiser4: discard: allocate extent paddings.fs/reiser4/block_alloc.c | 175 +++++++++---- fs/reiser4/block_alloc.h | 3 + fs/reiser4/blocknrlist.c | 38 +++ fs/reiser4/discard.c | 410 +++++++++++++++++++++++++++--- fs/reiser4/discard.h | 8 +- fs/reiser4/forward.h | 1 + fs/reiser4/init_super.c | 4 + fs/reiser4/plugin/space/bitmap.c | 94 +++++-- fs/reiser4/plugin/space/bitmap.h | 3 + fs/reiser4/plugin/space/space_allocator.h | 10 +- fs/reiser4/super.h | 4 + fs/reiser4/txnmgr.h | 6 + 12 files changed, 647 insertions(+), 109 deletions(-)
Quoted 15 lines · Edward Shishkin
Quoted 2 lines · Ivan Shapovalov
So, this patchset uses your algorithm of padding/gluing extents to be discarded. I've added exact allocation primitives (is it what you've been talking about?
So, we found out that the old bitmap primitives don't allow us to implement precise discard, and I asked for new ones. Also we wanted to implement the general case, when precise discard works for any pair (offset, unit). Currently
it works only for ones determined by the functionconvert_lattice_params(). For some reasons (that I don't remember) I was sure, that the general case should be obtained from this partial case by a small transformation of the functiondiscard_sorted_merged_extents().
Quoted 4 lines
Well, I'll try to dive into details and generalize things on the holidays. If generalization is impossible, then we'll switch to non-precise discard every
time whenconvert_lattice_params()fails.
I don't quite understand you here... Do you mean that some non-insane combinations of discard unit, discard offset and blocksize are not handled (but worth handling)?
TBH, convert_lattice_params() looks magic-ish to me...
Thanks,
Signature · 1 line
Ivan Shapovalov / intelfx /
Quoted 14 lines · Ivan Shapovalov
Quoted 13 lines · Edward Shishkin
Quoted 2 lines · Ivan Shapovalov
So, this patchset uses your algorithm of padding/gluing extents to be discarded. I've added exact allocation primitives (is it what you've been talking about?
So, we found out that the old bitmap primitives don't allow us to implement precise discard, and I asked for new ones. Also we wanted to implement the general case, when precise discard works for any pair (offset, unit). Currently
it works only for ones determined by the functionconvert_lattice_params(). For some reasons (that I don't remember) I was sure, that the general case should be obtained from this partial case by a small transformation of the functiondiscard_sorted_merged_extents().
Quoted 7 lines
Quoted 4 lines
Well, I'll try to dive into details and generalize things on the holidays. If generalization is impossible, then we'll switch to non-precise discard every
time whenconvert_lattice_params()fails.I don't quite understand you here... Do you mean that some non-insane combinations of discard unit, discard offset and blocksize are not handled (but worth handling)?
Yes. As you can see, if (discard_offset % block_size != 0), then we don't issue discard requests. Neither precise, nor non-precise.
It is hard to implement the precise discard support in the generic case straight away.
Quoted 2 lines
TBH,
convert_lattice_params()looks magic-ish to me...
OK, I'll try to provide some background (geometric minimum).
Edward.
Quoted 15 lines · Edward Shishkin
Quoted 14 lines · Ivan Shapovalov
Quoted 13 lines · Edward Shishkin
Quoted 2 lines · Ivan Shapovalov
So, this patchset uses your algorithm of padding/gluing extents to be discarded. I've added exact allocation primitives (is it what you've been talking about?
So, we found out that the old bitmap primitives don't allow us to implement precise discard, and I asked for new ones. Also we wanted to implement the general case, when precise discard works for any pair (offset, unit). Currently
it works only for ones determined by the functionconvert_lattice_params(). For some reasons (that I don't remember) I was sure, that the general case should be obtained from this partial case by a small transformation of the functiondiscard_sorted_merged_extents().
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Well, I'll try to dive into details and generalize things on the holidays. If generalization is impossible,
Hopefully this is possible,
I'll try to send the patch in short.
Edward.
Quoted 20 lines
Quoted 6 lines
Quoted 3 lines
then we'll switch to non-precise
discard every
time whenconvert_lattice_params()fails.I don't quite understand you here... Do you mean that some non-insane combinations of discard unit, discard offset and blocksize are not handled (but worth handling)?
Yes. As you can see, if (
discard_offset%block_size!= 0), then we don't issue discard requests. Neither precise, nor non-precise.
It is hard to implement the precise discard support in the generic case straight away.Quoted 2 lines
TBH,
convert_lattice_params()looks magic-ish to me...OK, I'll try to provide some background (geometric minimum).
Edward.