reiser4: batch discard support (FITRIM ioctl): initial implementation.
v5 cover reiser4: batch discard support (FITRIM ioctl): initial implementation.
This patch series implements FITRIM ioctl support in reiser4.
The FITRIM ioctl is supposed to be applied to any directory inside the target filesystem. At least, this can be deduced from fstrim utility behavior on mainstream filesystems (e. g. ext2/3/4).
The idea of implementation is per Edward's advices: FITRIM handler iteratively grabs a portion of disk space, sequentially allocates extents within grabbed space and commits the resulting atom. This way we avoid starving concurrent processes of the disk space. This process is repeated until the partition has been fully scanned and processed.
Points I'm really uncertain of:
- creation of empty atoms (reiser4_create_atom())
- handling of empty atoms in commit_current_atom()
v2: - fix PATCH 5/7 "reiser4: txnmgr: call reiser4_post_write_back_hook() for empty atoms."
* fix a typo
* release atom spinlock before calling reiser4_post_write_back_hook()
v3: - use bitwise shift instead of integer division by 4 to calculate 25%
- honor "minlen" of ioctl parameters (minimal extent length to consider for discarding)
- fix a stupidity in reiser4_trim_fs() (two local variables holding the same superblock pointer)
v4: - refactor BA_SOME_SPACE implementation, fix calculation of space-to-grab if !BA_RESERVED
- rename reiser4_blocknr_hint's "forward" to "monotonic_forward"
- move free space accounting by pre-commit hook to block_alloc.c
- explain BA_DEFER flag behavior in comments
- fix "minlen" addition to alloc_blocks_forward() (use minlen in both calls)
- refactor (equivalent at this time ;)) reiser4_trim_fs()
- move "capture_count == 0" shortcut in commit_current_atom() below current_atom_complete_writes() in order to finish the atom's flush_queues
v5: - return -ENOTTY instead of -ENOSYS in the unsupported ioctl path
of reiser4_ioctl_dir_common()
Ivan Shapovalov (10):
reiser4: block_alloc: add BA_SOME_SPACE flag for grabbing a fixed amount of space.
reiser4: block_alloc: add a "monotonic_forward" parameter to reiser4_blocknr_hint to allocate blocks only in forward direction.
reiser4: block_alloc: move block accounting by pre-commit hook into block_alloc.c and document BA_DEFER behavior.
reiser4: txnmgr: free allocated but unneeded atom in atom_begin_and_assign_to_txnh().
reiser4: txnmgr: add reiser4_create_atom() which creates an empty atom without capturing any nodes.
reiser4: txnmgr: move "empty atom" shortcut slightly below.
reiser4: batch discard support: add a dummy FITRIM ioctl handler for directories.
reiser4: batch discard support: actually implement the FITRIM ioctl handler.
reiser4: block_alloc: add a "min_len" parameter to reiser4_blocknr_hint to limit allocated extent length from below.
reiser4: batch discard support: honor minimal extent length passed from the userspace.
fs/reiser4/block_alloc.c | 66 +++++++++++++++++-- fs/reiser4/block_alloc.h | 12 +++- fs/reiser4/plugin/dir/dir.h | 2 + fs/reiser4/plugin/file_ops.c | 62 ++++++++++++++++++ fs/reiser4/plugin/object.c | 6 +- fs/reiser4/plugin/space/bitmap.c | 53 +++++++--------- fs/reiser4/super_ops.c | 134 +++++++++++++++++++++++++++++++++++++++ fs/reiser4/txnmgr.c | 57 +++++++++++------ fs/reiser4/txnmgr.h | 2 + 9 files changed, 336 insertions(+), 58 deletions(-)
Signature · 1 line
2.3.0
PATCH v5 1/10 reiser4: block_alloc: add BA_SOME_SPACE flag for grabbing a fixed amount of space.
This is used for FITRIM ioctl which will iteratively grab, allocate and trim disk space bit by bit to avoid starving the rest of system.
--- fs/reiser4/block_alloc.c | 22 ++++++++++++++++++---- fs/reiser4/block_alloc.h | 5 ++++- 2 files changed, 22 insertions(+), 5 deletions(-)
fs/reiser4/block_alloc.c +18 -4
@@ -264,7 +264,7 @@ int reiser4_check_block_counters(const struct super_block *super)static int reiser4_grab (reiser4_context * ctx,__u64 count,reiser4_ba_flags_t flags) { -__u64 free_blocks; +__s64 allowed_blocks;int ret =0 , use_reserved = flags &BA_RESERVED ;reiser4_super_info_data *sbinfo;
@@ -280,10 +280,24 @@ reiser4_grab(reiser4_context * ctx, __u64 count, reiser4_ba_flags_t flags)spin_lock_reiser4_super (sbinfo); - free_blocks = sbinfo->blocks_free; + allowed_blocks = use_reserved ? sbinfo->blocks_free + : sbinfo->blocks_free - sbinfo->blocks_reserved; -if ((use_reserved && free_blocks < count) || - (!use_reserved && free_blocks < count + sbinfo->blocks_reserved)) { +if (flags &BA_SOME_SPACE ) { +/* Reserve 25% of all free space */ +if (allowed_blocks <=0 ) { +/* No space at all */ + ret =RETERR (-ENOSPC ); + goto unlock_and_ret; + } + + count = allowed_blocks >>2 ; +if (count ==0 ) { +/* Less than 4 free blocks */ + count = allowed_blocks; + } + }else if (count > allowed_blocks) { +/* Not enough space */ ret =RETERR (-ENOSPC ); goto unlock_and_ret; }
fs/reiser4/block_alloc.h +4 -1
@@ -79,7 +79,10 @@ enum reiser4_ba_flags {BA_FORCE = (1 <<5 ),/* use default start value for free blocks search. */ - BA_USE_DEFAULT_SEARCH_START = (1 << 6) +BA_USE_DEFAULT_SEARCH_START = (1 <<6 ), + +/* reserve some fixed amount of space */ + BA_SOME_SPACE = (1 << 7), };typedef enum reiser4_ba_flags reiser4_ba_flags_t ;
Signature · 1 line
2.3.0
PATCH v5 2/10 reiser4: block_alloc: add a "monotonic_forward" parameter to reiser4_blocknr_hint to allocate blocks only in forward direction.
In reply to Ivan Shapovalov--- fs/reiser4/block_alloc.c | 4 ++-- fs/reiser4/block_alloc.h | 5 +++-- fs/reiser4/plugin/space/bitmap.c | 10 ++++++---- 3 files changed, 11 insertions(+), 8 deletions(-)
fs/reiser4/block_alloc.c +2 -2
@@ -264,7 +264,7 @@ int reiser4_check_block_counters(const struct super_block *super)static int reiser4_grab (reiser4_context * ctx,__u64 count,reiser4_ba_flags_t flags) { -__s64 allowed_blocks; +__u64 allowed_blocks;int ret =0 , use_reserved = flags &BA_RESERVED ;reiser4_super_info_data *sbinfo;
@@ -285,7 +285,7 @@ reiser4_grab(reiser4_context * ctx, __u64 count, reiser4_ba_flags_t flags)if (flags &BA_SOME_SPACE ) {/* Reserve 25% of all free space */ -if (allowed_blocks <=0 ) { +if (allowed_blocks ==0 ) {/* No space at all */ ret =RETERR (-ENOSPC ); goto unlock_and_ret;
fs/reiser4/block_alloc.h +3 -2
@@ -51,9 +51,10 @@ struct reiser4_blocknr_hint {/* block allocator assumes that blocks, which will be mapped to disk, are in this specified block_stage */ block_stage_t block_stage; -/* If direction = 1 allocate blocks in backward direction from the end -* of disk to the beginning of disk. */ +/* allocate blocks in backward direction */ unsigned int backward:1; +/* allocate blocks only in forward direction starting from blk */ + unsigned int monotonic_forward:1; };
fs/reiser4/plugin/space/bitmap.c +6 -4
@@ -1124,10 +1124,12 @@ static int alloc_blocks_forward(reiser4_blocknr_hint *hint, int needed, actual_len =bitmap_alloc_forward (&search_start, &search_end,1 , needed); -/* There is only one bitmap search if max_dist was specified or first -pass was from the beginning of the bitmap. We also do one pass for -scanning bitmap in backward direction. */ -if (!(actual_len !=0 || hint->max_dist !=0 || search_start ==0 )) { +/* There is only one bitmap search if max_dist was specified, first +pass was from the beginning of the bitmap, or if the monotonic flag +has been set. Otherwise we also do one pass for scanning bitmap in +backward direction. */ +if (actual_len ==0 && search_start !=0 && + hint->max_dist ==0 && !hint->monotonic_forward) {/* next step is a scanning from 0 to search_start */ search_end = search_start; search_start =0 ;
Signature · 1 line
2.3.0
PATCH v5 3/10 reiser4: block_alloc: move block accounting by pre-commit hook into block_alloc.c and document BA_DEFER behavior.
In reply to Ivan ShapovalovBA_DEFER deallocations ignore target_stage and other flags and use some implied values for these parameters. Document these values and where they do matter.
Also move deallocated block accounting into block_alloc.c because
1) it is allocator-independent;
2) it allows discard code to rely on that accounting is done in pre-commit hook and not later, so that discard code should not use BA_PERMANENT in its allocations.
--- fs/reiser4/block_alloc.c | 44 +++++++++++++++++++++++++++++++++++++++- fs/reiser4/plugin/space/bitmap.c | 23 ++------------------- 2 files changed, 45 insertions(+), 22 deletions(-)
fs/reiser4/block_alloc.c +43 -1
@@ -998,6 +998,19 @@ reiser4_check_blocks(const reiser4_block_nr * start,/* BA_FORMATTED bit is only used when BA_DEFER in not present: it is used to distinguish blocks allocated for unformatted and formatted nodes */ +/* if BA_DEFER is enabled, @target_stage and other @flags are ignored. +* +* @target_stage is implied to be BLOCK_NOT_COUNTED. +* (assumption is used in reiser4_post_write_back_hook() and apply_dset()) +* +* @flags are implied to have BA_PERMANENT. +* (assumption is used in reiser4_pre_commit_hook() which counts deallocated +* blocks) +* +* That is, if a deferred deallocation is done after reiser4_pre_commit_hook(), +* then BA_PERMANENT is implied to be disabled. +*/ + int reiser4_dealloc_blocks(const reiser4_block_nr * start, const reiser4_block_nr * len,
@@ -1089,10 +1102,39 @@ reiser4_dealloc_blocks(const reiser4_block_nr * start,return 0 ; } +/* an actor for counting blocks that are going to be deallocated */ +static int +count_dset_blocks (txn_atom * atom,const reiser4_block_nr * start, +const reiser4_block_nr * len,void *data) +{ +reiser4_block_nr *blocks_freed_p = data; + +if (len !=NULL ) { + (*blocks_freed_p) += *len; + }else { + (*blocks_freed_p)++; + } +return 0 ; +} +/* wrappers for block allocator plugin methods */ int reiser4_pre_commit_hook (void ) { -assert ("zam-502" ,get_current_super_private () !=NULL ); +reiser4_block_nr blocks_freed =0 ; +reiser4_super_info_data *sbinfo =get_current_super_private (); +txn_atom *atom =get_current_atom_locked (); + +assert ("zam-502" , sbinfo !=NULL ); + +assert ("zam-876" , atom->stage ==ASTAGE_PRE_COMMIT ); +spin_unlock_atom (atom); + +atom_dset_deferred_apply (atom, count_dset_blocks, &blocks_freed,0 ); + +spin_lock_reiser4_super (sbinfo); + sbinfo->blocks_free_committed += blocks_freed - atom->nr_blocks_allocated; +spin_unlock_reiser4_super (sbinfo); +sa_pre_commit_hook ();return 0 ; }
fs/reiser4/plugin/space/bitmap.c +2 -21
@@ -1322,15 +1322,13 @@ static void cond_add_to_overwrite_set(txn_atom * atom, jnode * node)pages in a single-linked list */ static int apply_dset_to_commit_bmap (txn_atom * atom,const reiser4_block_nr * start, -const reiser4_block_nr * len,void *data) + const reiser4_block_nr * len, void *data UNUSED_ARG) {bmap_nr_t bmap;bmap_off_t offset;int ret; -long long *blocks_freed_p = data; -struct bitmap_node *bnode;struct super_block *sb =reiser4_get_current_sb ();
@@ -1366,11 +1364,8 @@ apply_dset_to_commit_bmap(txn_atom * atom, const reiser4_block_nr * start,assert ("zam-443" , offset + *len <=bmap_bit_count (sb->s_blocksize));reiser4_clear_bits (data, offset, (bmap_off_t) (offset + *len)); - - (*blocks_freed_p) += *len; }else {reiser4_clear_bit (offset, data); - (*blocks_freed_p)++; }bnode_set_commit_crc (bnode,bnode_calc_crc (bnode, sb->s_blocksize));
@@ -1393,8 +1388,6 @@ int reiser4_pre_commit_hook_bitmap(void)struct super_block *super =reiser4_get_current_sb ();txn_atom *atom; -long long blocks_freed =0 ; - atom =get_current_atom_locked ();assert ("zam-876" , atom->stage ==ASTAGE_PRE_COMMIT );spin_unlock_atom (atom);
@@ -1460,19 +1453,7 @@ int reiser4_pre_commit_hook_bitmap(void) } } -atom_dset_deferred_apply (atom, apply_dset_to_commit_bmap, &blocks_freed,0 ); - - blocks_freed -= atom->nr_blocks_allocated; - - { -reiser4_super_info_data *sbinfo; - - sbinfo =get_super_private (super); - -spin_lock_reiser4_super (sbinfo); - sbinfo->blocks_free_committed += blocks_freed; -spin_unlock_reiser4_super (sbinfo); - } +atom_dset_deferred_apply (atom, apply_dset_to_commit_bmap,NULL ,0 );return 0 ; }
Signature · 1 line
2.3.0
PATCH v5 4/10 reiser4: txnmgr: free allocated but unneeded atom in atom_begin_and_assign_to_txnh().
In reply to Ivan ShapovalovIt is unclear why it hasn't been done before, as there was a corresponding notice, and such change apparently does not carry any side effects.
Do this to avoid duplicating code in the next commit.
--- fs/reiser4/txnmgr.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
fs/reiser4/txnmgr.c +5 -15
@@ -709,6 +709,9 @@ static int atom_begin_and_assign_to_txnh(txn_atom ** atom_alloc, txn_handle * txreturn RETERR (-ENOMEM ); } + atom = *atom_alloc; + *atom_alloc =NULL ; +/* and, also, txnmgr spin lock should be taken before jnode and txnh locks. */ mgr = &get_super_private (reiser4_get_current_sb ())->tmgr;
@@ -717,18 +720,14 @@ static int atom_begin_and_assign_to_txnh(txn_atom ** atom_alloc, txn_handle * tx/* Check whether new atom still needed */ if (txnh->atom !=NULL ) { -/* NOTE-NIKITA probably it is rather better to free -* atom_alloc here than thread it up to reiser4_try_capture() */ -spin_unlock_txnh (txnh);spin_unlock_txnmgr (mgr); +kmem_cache_free (_atom_slab, atom); +return -E_REPEAT ; } - atom = *atom_alloc; - *atom_alloc =NULL ; -atom_init (atom);assert ("jmacd-17" ,atom_isclean (atom));
@@ -2031,15 +2030,6 @@ int reiser4_try_capture(jnode *node, znode_lock_mode lock_mode, goto repeat; } -/* free extra atom object that was possibly allocated by -try_capture_block(). - -Do this before acquiring jnode spin lock to -minimize time spent under lock. --nikita */ -if (atom_alloc !=NULL ) { -kmem_cache_free (_atom_slab, atom_alloc); - } -if (ret !=0 ) {if (ret == -E_BLOCK ) { assert("nikita-3360",
Signature · 1 line
2.3.0
PATCH v5 5/10 reiser4: txnmgr: add reiser4_create_atom() which creates an empty atom without capturing any nodes.
In reply to Ivan Shapovalov--- fs/reiser4/txnmgr.c | 24 ++++++++++++++++++++++++ fs/reiser4/txnmgr.h | 2 ++ 2 files changed, 26 insertions(+)
fs/reiser4/txnmgr.c +24 -0
@@ -2050,6 +2050,30 @@ int reiser4_try_capture(jnode *node, znode_lock_mode lock_mode,return ret; } +/* This function ensures that the current transcrash has an atom without +* capturing anything. If needed, an empty atom is created and assigned. +*/ +int reiser4_create_atom (void ) +{ +txn_atom *atom_alloc =NULL ; +txn_handle *txnh =get_current_context ()->trans; +int ret; + +do { +spin_lock_txnh (txnh); +if (txnh->atom ==NULL ) { +spin_unlock_txnh (txnh); +/* assign empty atom to the txnh and repeat */ + ret =atom_begin_and_assign_to_txnh (&atom_alloc, txnh); + }else { +spin_unlock_txnh (txnh); + ret =0 ; + } + }while (ret == -E_REPEAT ); + +return ret; +} +static void release_two_atoms (txn_atom *one,txn_atom *two) {spin_unlock_atom (one);
fs/reiser4/txnmgr.h +2 -0
@@ -437,6 +437,8 @@ extern void reiser4_uncapture_jnode(jnode *);extern int reiser4_capture_inode (struct inode *);extern int reiser4_uncapture_inode (struct inode *); +extern int reiser4_create_atom (void ); +extern txn_atom *get_current_atom_locked_nocheck (void );#if REISER4_DEBUG
Signature · 1 line
2.3.0
PATCH v5 6/10 reiser4: txnmgr: move "empty atom" shortcut slightly below.
In reply to Ivan Shapovalovreiser4_trim_fs() generate empty (atom->capture_count == 0) atoms which still have non-empty delete sets. That is, such atoms take a "goto done" shortcut in commit_current_atom().
First, this shortcut must not preclude calling current_atom_complete_writes() to process and detach atom's flush queues (otherwise atom_isclean() will return false).
Second, reiser4_post_write_back_hook() needs to be called explicitly to process atom's delete sets.
--- fs/reiser4/txnmgr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/reiser4/txnmgr.c +9 -4
@@ -1064,9 +1064,6 @@ static int commit_current_atom(long *nr_submitted, txn_atom ** atom)return RETERR (-E_REPEAT ); } -if ((*atom)->capture_count ==0 ) - goto done; -/* Up to this point we have been flushing and after flush is called we return -E_REPEAT. Now we can commit. We cannot return -E_REPEAT at this point, commit should be successful. */
@@ -1078,6 +1075,14 @@ static int commit_current_atom(long *nr_submitted, txn_atom ** atom)if (ret)return ret; +if ((*atom)->capture_count ==0 ) { +/* Process the atom's delete set. +* Even if the atom has no captured nodes, the delete set may +* still be non-empty (see e. g. reiser4_trim_fs()). */ +reiser4_post_write_back_hook (); + goto done; + } +assert ("zam-906" ,list_empty (ATOM_WB_LIST (*atom)));/* isolate critical code path which should be executed by only one
@@ -1100,8 +1105,8 @@ static int commit_current_atom(long *nr_submitted, txn_atom ** atom)reiser4_invalidate_list (ATOM_WB_LIST (*atom));assert ("zam-927" ,list_empty (&(*atom)->inodes)); +done:spin_lock_atom (*atom); - done:reiser4_atom_set_stage (*atom,ASTAGE_DONE );ON_DEBUG ((*atom)->committer =NULL );
Signature · 1 line
2.3.0
PATCH v5 7/10 reiser4: batch discard support: add a dummy FITRIM ioctl handler for directories.
In reply to Ivan Shapovalov--- fs/reiser4/plugin/dir/dir.h | 2 ++ fs/reiser4/plugin/file_ops.c | 27 +++++++++++++++++++++++++++ fs/reiser4/plugin/object.c | 6 +++++- 3 files changed, 34 insertions(+), 1 deletion(-)
fs/reiser4/plugin/dir/dir.h +2 -0
@@ -10,6 +10,8 @@#include <linux/fs.h>*/ +long reiser4_ioctl_dir_common (struct file *file,unsigned int cmd,unsigned long arg); +/* declarations of functions implementing HASHED_DIR_PLUGIN_ID dir plugin */ /* "hashed" directory methods of dir plugin */
fs/reiser4/plugin/file_ops.c +27 -0
@@ -107,6 +107,33 @@ int reiser4_sync_file_common(struct file *file, loff_t start, loff_t end, int dareturn 0 ; } +/** reiser4_ioctl_dir_common - ioctl of struct file_operations for typical directory +*/ +long reiser4_ioctl_dir_common (struct file *file,unsigned int cmd,unsigned long arg) +{ +struct inode *inode =file_inode (file); +struct super_block *super = inode->i_sb; +reiser4_context *ctx; +int ret; + + ctx =reiser4_init_context (super); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + +switch (cmd) { +case FITRIM : +warning ("intelfx-62" ,"FITRIM ioctl not implemented" ); +/* fall-through to -ENOTTY */ + +default : + ret =RETERR (-ENOTTY ); +break ; + } + +reiser4_exit_context (ctx); +return ret; +} +/* * Local variables: * c-indentation-style: "K&R"
fs/reiser4/plugin/object.c +5 -1
@@ -251,7 +251,11 @@ static struct file_operations directory_f_ops = { .read = generic_read_dir, .iterate = reiser4_iterate_common, .release = reiser4_release_dir_common, - .fsync = reiser4_sync_common + .fsync = reiser4_sync_common, +#ifdef CONFIG_COMPAT + .compat_ioctl = reiser4_ioctl_dir_common, +#endif + .unlocked_ioctl = reiser4_ioctl_dir_common };static struct address_space_operations directory_a_ops = { .writepage = writepage_bugop,
Signature · 1 line
2.3.0
PATCH v5 8/10 reiser4: batch discard support: actually implement the FITRIM ioctl handler.
In reply to Ivan ShapovalovIt works in an iterative way, grabbing some fixed amount of space and allocating blocks until grabbed space is exhausted or partition's end is reached.
Blocks are scheduled for discard by allocating them and immediately adding them to the atom's delete set, which is read and processed at atom commit time.
After reaching the allocation stop condition, the atom is force-committed and, if the allocation has been stopped due to grabbed space exhaustion (not due to reaching end of partition), another iteration happens.
--- fs/reiser4/plugin/file_ops.c | 41 ++++++++++++- fs/reiser4/super_ops.c | 135 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 3 deletions(-)
fs/reiser4/plugin/file_ops.c +38 -3
@@ -8,6 +8,9 @@#include "../inode.h" #include "object.h" +#include <linux/fs.h> +#include <linux/blkdev.h> +/* file operations */ /* implementation of vfs's llseek method of struct file_operations for
@@ -20,6 +23,9 @@ loff_t reiser4_llseek_dir_common(struct file *, loff_t, int origin);*/ int reiser4_iterate_common (struct file *,struct dir_context *); +/* this function is implemented in super_ops.c */ +int reiser4_trim_fs (struct super_block *super,struct fstrim_range * range); +/** * reiser4_release_dir_common - release of struct file_operations * @inode: inode of released file
@@ -121,9 +127,38 @@ long reiser4_ioctl_dir_common(struct file *file, unsigned int cmd, unsigned longreturn PTR_ERR (ctx);switch (cmd) { -case FITRIM : -warning ("intelfx-62" ,"FITRIM ioctl not implemented" ); -/* fall-through to -ENOTTY */ +case FITRIM : { +struct request_queue *q =bdev_get_queue (super->s_bdev); +struct fstrim_range range; + +if (!capable (CAP_SYS_ADMIN )) { + ret =RETERR (-EPERM ); +break ; + } + +if (!blk_queue_discard (q)) { + ret =RETERR (-EOPNOTSUPP ); +break ; + } + +if (copy_from_user (&range, (struct fstrim_range __user *)arg, +sizeof (range))) { + ret =RETERR (-EFAULT ); +break ; + } + + range.minlen =max ((unsigned int )range.minlen, + q->limits.discard_granularity); + + ret =reiser4_trim_fs (super, &range); + +if (copy_to_user ((struct fstrim_range __user *)arg, &range, +sizeof (range))) { + ret =RETERR (-EFAULT ); + } + +break ; + }default : ret =RETERR (-ENOTTY );
fs/reiser4/super_ops.c +135 -0
141 lines not on this page · raw message
Signature · 1 line
2.3.0
PATCH v5 9/10 reiser4: block_alloc: add a "min_len" parameter to reiser4_blocknr_hint to limit allocated extent length from below.
In reply to Ivan ShapovalovThe default has been 1, that is, the first encountered free extent with any length from 1 to requested is allocated and returned.
So, allow changing minimal extent length to allocate.
--- fs/reiser4/block_alloc.h | 2 ++ fs/reiser4/plugin/space/bitmap.c | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
fs/reiser4/block_alloc.h +2 -0
@@ -45,6 +45,8 @@ struct reiser4_blocknr_hint {reiser4_block_nr blk;/* if not zero, it is a region size we search for free blocks in */ reiser4_block_nr max_dist; +/* if not zero, minimal length of an extent to allocate */ +reiser4_block_nr min_len;/* level for allocation, may be useful have branch-level and higher write-optimized. */ tree_level level;
fs/reiser4/plugin/space/bitmap.c +15 -5
@@ -1101,7 +1101,7 @@ static int alloc_blocks_forward(reiser4_blocknr_hint *hint, int needed, reiser4_block_nr *start, reiser4_block_nr *len) {struct super_block *super =get_current_context ()->super; -int actual_len; +int min_len, actual_len;reiser4_block_nr search_start;reiser4_block_nr search_end;
@@ -1117,12 +1117,17 @@ static int alloc_blocks_forward(reiser4_blocknr_hint *hint, int needed,LIMIT (hint->blk + hint->max_dist,reiser4_block_count (super)); +if (hint->min_len ==0 ) + min_len =1 ; +else + min_len = (int )hint->min_len; +/* We use @hint -> blk as a search start and search from it to the end of the disk or in given region if @hint -> max_dist is not zero */ search_start = hint->blk; actual_len = -bitmap_alloc_forward (&search_start, &search_end,1 , needed); +bitmap_alloc_forward (&search_start, &search_end, min_len, needed);/* There is only one bitmap search if max_dist was specified, first pass was from the beginning of the bitmap, or if the monotonic flag
@@ -1134,7 +1139,7 @@ static int alloc_blocks_forward(reiser4_blocknr_hint *hint, int needed, search_end = search_start; search_start =0 ; actual_len = -bitmap_alloc_forward (&search_start, &search_end,1 , needed); +bitmap_alloc_forward (&search_start, &search_end, min_len, needed); }if (actual_len ==0 )return RETERR (-ENOSPC );
@@ -1151,7 +1156,7 @@ static int alloc_blocks_backward(reiser4_blocknr_hint * hint, int needed, {reiser4_block_nr search_start;reiser4_block_nr search_end; -int actual_len; +int min_len, actual_len; ON_DEBUG(struct super_block *super = reiser4_get_current_sb());
@@ -1165,8 +1170,13 @@ static int alloc_blocks_backward(reiser4_blocknr_hint * hint, int needed,else search_end = search_start - hint->max_dist; +if (hint->min_len ==0 ) + min_len =1 ; +else + min_len = (int )hint->min_len; + actual_len = -bitmap_alloc_backward (&search_start, &search_end,1 , needed); +bitmap_alloc_backward (&search_start, &search_end, min_len, needed);if (actual_len ==0 )return RETERR (-ENOSPC );if (actual_len <0 )
Signature · 1 line
2.3.0
PATCH v5 10/10 reiser4: batch discard support: honor minimal extent length passed from the userspace.
In reply to Ivan Shapovalov--- fs/reiser4/super_ops.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/reiser4/super_ops.c +2 -3
@@ -487,7 +487,7 @@ static int reiser4_show_options(struct seq_file *m, struct dentry *dentry)int reiser4_trim_fs (struct super_block *super,struct fstrim_range * range) {reiser4_blocknr_hint hint; -reiser4_block_nr start, end, len, minlen, discarded_count =0 ; +reiser4_block_nr start, end, len, discarded_count =0 ;reiser4_context *ctx;txn_atom *atom;int ret, finished =0 ;
@@ -501,11 +501,11 @@ int reiser4_trim_fs(struct super_block *super, struct fstrim_range* range)*/ hint.blk = range->start >> super->s_blocksize_bits; hint.max_dist = range->len >> super->s_blocksize_bits; + hint.min_len = range->minlen >> super->s_blocksize_bits; hint.block_stage =BLOCK_GRABBED ; hint.monotonic_forward =1 ; end = hint.blk + hint.max_dist; - minlen = range->minlen >> super->s_blocksize_bits;/* * We will perform the process in iterations in order not to starve
@@ -538,7 +538,6 @@ int reiser4_trim_fs(struct super_block *super, struct fstrim_range* range) do { /* * Allocate no more than is grabbed. - * FIXME: use minlen. * * NOTE: we do not use BA_PERMANENT in our allocations * even though we deallocate with BA_DEFER.
Signature · 1 line
2.3.0
When is the patch set included in the reiser4-for-3.x... release ?
In reply to Ivan ShapovalovHello.
- When is the patch set [1] included in the reiser4-for-3.x... release ?
- Do all the 10 patches go in at the one time ?
--Glenn
[1]
[PATCHv5 00/10] reiser4: batch discard support (FITRIM ioctl): initial implementation.
Re: When is the patch set included in the reiser4-for-3.x... release ?
Quoted 2 lines · On 2015-02-13 at 13:11 +1100, [email protected] wrote:
Hello.
- When is the patch set [1] included in the reiser4-for-3.x... release ?
Hello,
this patchset is not yet included in any of the releases. I have just sent it for a review.
It is to be applied on top of any recent reiser4 patch, if you want to help with testing.
Quoted 1 line
- Do all the 10 patches go in at the one time ?
Yes, they do not make much sense without each other. The latter ones depend on the former ones, so they are applied in order.
Signature · 1 line
Ivan Shapovalov / intelfx /
help with testing
Hello,
Regards "if you want to help with testing."
I could help with tests after a r4 partition/disk is recovered, using #fsck.reiser4 --build-fs /dev/sdb
-But I need a patch to fix this problem first [see below]
--Cheers Glenn
--------------
Details:
--------
# fsck.reiser4 --build-fs --force /dev/sdb . .
Quoted 12 lines
Quoted 12 lines
LOOKING FOR UNCONNECTED NODES
FSCK:
node.c: 108:repair_node_items_check: Node (43828275), items (0) and
(1): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (52697435), items (79) and (80): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (63227569), items (24) and (25): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (63227571), items (73) and (74): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (116595727), items
(20)
Quoted 2 lines
Quoted 2 lines
and (21): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (227923161), items
(22)
Quoted 2 lines
Quoted 2 lines
and (23): Wrong order of keys.
FSCK:node.c: 108:repair_node_items_check: Node (284305753), items
(61)
Quoted 11 lines
Quoted 11 lines
and (62): Wrong order of keys.
Read nodes 1481038 Good nodes 471512 Leaves of them 466164, Twigs of them 5348 Time interval: Wed Aug 27 03:35:57 2014 - Wed Aug 27 03:39:46 2014***** fsck.reiser4 finished at Wed Aug 27 03:39:46 2014 Closing fs...done
Quoted 8 lines
Quoted 1 line
FS is consistent.
This is a bug in fsck: it jumps to wrong branch for some reasons. Not yet fixed.
Edward.
--
other info:
-----------
# fsck.reiser4 --print-profile /dev/sdb Default profile: create: "ccreg40" (id:0x4 type:0x0) [Regular file plugin for creat(2)] key: "key_large" (id:0x1 type:0xb) [Key plugin] compress: "lzo1" (id:0x0 type:0xc) [Compression plugin] compressMode: "conv" (id:0x4 type:0xd) [Compression Mode plugin] cluster: "64K" (id:0x0 type:0x10) [Cluster plugin] hash: "r5_hash" (id:0x1 type:0x3) [Directory entry hash plugin] fibration: "ext_1_fibre" (id:0x2 type:0x4) [Key fibration plugin] formatting: "smart" (id:0x2 type:0x5) [File body formatting plugin]
reiser4progs-1.0.9 # find . |sort |grep -i fsck
./doc/fsck.reiser4.8
./progs/fsck
./progs/fsck/Makefile.am
./progs/fsck/Makefile.in./progs/fsck/backup.c./progs/fsck/backup.h./progs/fsck/fsck.c./progs/fsck/fsck.h
# which fsck.reiser4 /usr/sbin/fsck.reiser4
# rpm -qlp reiser4progs-1.0.9-1.2.x86_64.rpm /usr/sbin/debugfs.reiser4 /usr/sbin/fsck.reiser4 /usr/sbin/make_reiser4 /usr/sbin/measurefs.reiser4 /usr/sbin/mkfs.reiser4 /usr/share/doc/packages/reiser4progs /usr/share/doc/packages/reiser4progs/BUGS /usr/share/doc/packages/reiser4progs/COPYING /usr/share/doc/packages/reiser4progs/ChangeLog /usr/share/doc/packages/reiser4progs/NEWS /usr/share/doc/packages/reiser4progs/README /usr/share/doc/packages/reiser4progs/TODO /usr/share/man/man8/debugfs.reiser4.8.gz /usr/share/man/man8/fsck.reiser4.8.gz /usr/share/man/man8/measurefs.reiser4.8.gz /usr/share/man/man8/mkfs.reiser4.8.gz
--installation
# rpm -ivhU reiser4progs-1.0.9-1.2.x86_64.rpm
# r4 partition recovery /dev/sdb http://www.spinics.net/lists/reiserfs-devel/msg04596.html
Quoted 14 lines · Ivan Shapovalov
[...]
Ivan Shapovalov (10):
reiser4:block_alloc: addBA_SOME_SPACEflag for grabbing a fixed amount of space.
reiser4:block_alloc: add a "monotonic_forward" parameter toreiser4_blocknr_hintto allocate blocks only in forward direction.
reiser4:block_alloc: move block accounting by pre-commit hook intoblock_alloc.cand documentBA_DEFERbehavior.
reiser4: txnmgr: free allocated but unneeded atom inatom_begin_and_assign_to_txnh().
reiser4: txnmgr: addreiser4_create_atom()which creates an empty atom without capturing any nodes.
reiser4: txnmgr: move "empty atom" shortcut slightly below.
reiser4: batch discard support: add a dummy FITRIM ioctl handler for directories.
reiser4: batch discard support: actually implement the FITRIM ioctl handler.
reiser4:block_alloc: add a "min_len" parameter toreiser4_blocknr_hintto limit allocated extent length from below.
reiser4: batch discard support: honor minimal extent length passed from the userspace.
Quoted 1 line
[...]
This is a diff between v4 and v5, for ease of reviewing.
fs/reiser4/plugin/file_ops.c +1 -1
@@ -161,7 +161,7 @@ long reiser4_ioctl_dir_common(struct file *file, unsigned int cmd, unsigned long }default : - ret =RETERR (-ENOSYS ); + ret =RETERR (-ENOTTY );break ; }
Signature · 1 line
Ivan Shapovalov / intelfx /