Add rbtree backend for storing bitmaps
Hello,
this is my second attempt to introduce new e2fsprogs bitmap backed based on rbtree. In this second version a couple of thing got better. First of all I have fixed all the bugs I was able to fing in the rbtree backend itself and now it passed many smoke tests as well as "make check" cleanly.
The second change is that this set of patches does not actually set rbtree backend as default, but rather introduce new configuration interface (in PATCH 3) to set backend for each and every one bitmap used by e2fsprogs individually. This allows us to better see what backend might be more suitable for what particular bitmap, more sophisticated benchmarking and testing.
Also to enable even more detailed understanding of how e2fsprogs treats bitmaps I have iontroduced (in PATCH 4) new macro for enabling statistics gathering about bitmaps. If the macro is set (in compile time) the code is enabled and data is gathered. Then, when the bitmap is freed information is printed to the stderr, so we can clearly compare bitmaps with each other.
So far I have not done any comprehensive benchmarks other than last time
(http://www.spinics.net/lists/linux-ext4/msg22664.html). Rbtree still has good results (memory saved) with reasonable filesystems, but it can get much worse in case of very fragmented filesystem. Also note that enabling rbtree (for all bitmaps) cause cca 30% (instead of almost 60% in previous version) performance hit on regular filesystem, but it can really differ.
Important thing is that this commits should not change e2fsprogs behavior in any way, since neither rbtree backend, nor stats collection is enabled by default.
If there is anyone with some /unusual/ filesystem (huge, tons of files, really fragmented, etc..) willing to try it out and share the results it will be great!
Comments are highly appreciated!
Thanks!
-Lukas
---
[PATCH 1/4] e2fsprogs: Add rbtree library
[PATCH 2/4] e2fsprogs: Add rbtree backend for bitmaps, use it instead of bitarrays [PATCH 3/4] Add bitmap configuration interface
[PATCH 4/4] Add macro to enable collecting bitmap statistics
e2fsck/emptydir.c | 4 +- e2fsck/pass1.c | 18 +- e2fsck/pass1b.c | 2 +- e2fsck/pass3.c | 6 +- e2fsck/pass5.c | 4 +- e2fsck/unix.c | 7 + lib/ext2fs/Makefile.in | 28 ++- lib/ext2fs/bitmaps.c | 21 +- lib/ext2fs/blkmap64_ba.c | 8 + lib/ext2fs/blkmap64_rb.c | 829 +++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/bmap64.h | 32 ++ lib/ext2fs/check_desc.c | 2 +- lib/ext2fs/ext2fs.h | 40 ++- lib/ext2fs/ext2fsP.h | 7 +- lib/ext2fs/gen_bitmap64.c | 248 +++++++++++++- lib/ext2fs/icount.c | 5 +- lib/ext2fs/initialize.c | 18 +- lib/ext2fs/rbtree.c | 451 ++++++++++++++++++++++++ lib/ext2fs/rbtree.h | 179 ++++++++++ lib/ext2fs/rw_bitmaps.c | 17 +- lib/ext2fs/tst_iscan.c | 6 +- misc/e2image.c | 4 +- misc/tune2fs.c | 2 +- resize/resize2fs.c | 6 +- 24 files changed, 1869 insertions(+), 75 deletions(-)
PATCH v2 1/4 e2fsprogs: Add rbtree library
This commit adds rbtree library into e2fsprogs so it can be used for various internal data structures. The rbtree implementation is ripped of kernel rbtree implementation with small changes needed for it to work outside kernel.
--- lib/ext2fs/Makefile.in | 11 +- lib/ext2fs/rbtree.c | 451 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/rbtree.h | 179 +++++++++++++++++++ 3 files changed, 639 insertions(+), 2 deletions(-) create mode 100644 lib/ext2fs/rbtree.c create mode 100644 lib/ext2fs/rbtree.h
lib/ext2fs/Makefile.in +9 -2
@@ -80,7 +80,8 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ unix_io.o \ unlink.o \ valid_blk.o \ - version.o + version.o \ + rbtree.o SRCS= ext2_err.c \ $(srcdir)/alloc.c \
@@ -155,7 +156,8 @@ SRCS= ext2_err.c \ $(srcdir)/unlink.c \ $(srcdir)/valid_blk.c \ $(srcdir)/version.c \ - $(srcdir)/write_bb_file.c + $(srcdir)/write_bb_file.c \ + $(srcdir)/rbtree.c \ HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \ tdb.h
@@ -762,3 +764,8 @@ write_bb_file.o: $(srcdir)/write_bb_file.c $(srcdir)/ext2_fs.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h +rbtree.o: $(srcdir)/rbtree.c $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h
lib/ext2fs/rbtree.c new file +451 -0
451 lines not on this page · raw message
lib/ext2fs/rbtree.h new file +179 -0
179 lines not on this page · raw message
Signature · 1 line
1.7.4
Re: [PATCH 1/4 v2] e2fsprogs: Add rbtree library
lib/ext2fs/rbtree.h line 104
Quoted 6 lines · Lukas Czerner
lib/ext2fs/rbtree.h new file +6
-0+#undef offsetof +#ifdef __compiler_offsetof +#define offsetof (TYPE ,MEMBER ) __compiler_offsetof(TYPE,MEMBER) +#else +#define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) +#endif
This may as well go into a more common header like lib/ext2fs/ext2fs.h, since I see offsetof() is #defined 5 separate times in the e2fsprogs code already.
lib/ext2fs/rbtree.h line 108
Quoted 3 lines
lib/ext2fs/rbtree.h new file +3
-0+#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})
Same.
lib/ext2fs/rbtree.h line 143
Quoted 9 lines
lib/ext2fs/rbtree.h new file +9
-0+#define rb_parent (r) ((struct rb_node *)((r)->rb_parent_color & ~3)) +#define rb_color (r) ((r)->rb_parent_color & 1) +#define rb_is_red (r) (!rb_color(r)) +#define rb_is_black (r) rb_color(r) +#define rb_set_red (r) do { (r)->rb_parent_color &= ~1; } while (0) +#define rb_set_black (r) do { (r)->rb_parent_color |= 1; } while (0) + +#define RB_ROOT (struct rb_root) { NULL, } +#define rb_entry (ptr, type, member) container_of(ptr, type, member)
The indenting here is a bit broken, but I see it is the same in the upstream kernel code, so it probably shouldn't be changed just for e2fsprogs.
Cheers, Andreas
Re: [PATCH 1/4 v2] e2fsprogs: Add rbtree library
Quoted 29 lines · Andreas Dilger
lib/ext2fs/rbtree.h line 104
Quoted 6 lines · Lukas Czerner
lib/ext2fs/rbtree.h new file +6
-0+#undef offsetof +#ifdef __compiler_offsetof +#define offsetof (TYPE ,MEMBER ) __compiler_offsetof(TYPE,MEMBER) +#else +#define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) +#endif This may as well go into a more common header like
lib/ext2fs/ext2fs.h, since I seeoffsetof()is #defined 5 separate times in the e2fsprogs code already.lib/ext2fs/rbtree.h line 108
Quoted 3 lines
lib/ext2fs/rbtree.h new file +3
-0+#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})Same.
lib/ext2fs/rbtree.h line 143
Quoted 9 lines
lib/ext2fs/rbtree.h new file +9
-0+#define rb_parent (r) ((struct rb_node *)((r)->rb_parent_color & ~3)) +#define rb_color (r) ((r)->rb_parent_color & 1) +#define rb_is_red (r) (!rb_color(r)) +#define rb_is_black (r) rb_color(r) +#define rb_set_red (r) do { (r)->rb_parent_color &= ~1; } while (0) +#define rb_set_black (r) do { (r)->rb_parent_color |= 1; } while (0) + +#define RB_ROOT (struct rb_root) { NULL, } +#define rb_entry (ptr, type, member) container_of(ptr, type, member)The indenting here is a bit broken, but I see it is the same in the upstream kernel code, so it probably shouldn't be changed just for e2fsprogs.
Quoted 2 lines
Cheers, Andreas
Hi Andreas,
thank you for the review! You're right I'll move those macros into lib/ext2fs/ext2fs.h
Thanks!
-Lukas
PATCH v2 2/4 e2fsprogs: Add rbtree backend for bitmaps, use it instead of bitarrays
In reply to Lukas CzernerFor a long time we had a bitarray backend for storing filesystem metadata bitmaps, however today this approach might hit its limits with todays huge data storage devices, because of its memory utilization.
Bitarrays stores bitmaps as ..well, as bitmaps. But this is in most cases highly unefficient because we need to allocate memory even for the big parts of bitmaps we will never use, resulting in high memory utilization especially for huge filesystem, when bitmaps might occupy gigabytes of space.
This commit adds another backend to store bitmaps. It is based on rbtrees and it stores just used extents of bitmaps. It means that it can be more memory efficient in most cases.
I have done some limited benchmarking and it shows that rbtree backend consumes approx 65% less memory that bitarray on 312GB filesystem aged with Impression (default config). This number may grow significantly with the filesystem size, but also it may be a lot lower (even negative) with a lot bigger number of inodes (need more benchmarking).
This commit itself does not enable the use of rbtree backend.
--- lib/ext2fs/Makefile.in | 2 + lib/ext2fs/blkmap64_rb.c | 751 +++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/bmap64.h | 1 + lib/ext2fs/ext2fsP.h | 1 + lib/ext2fs/gen_bitmap64.c | 4 + 5 files changed, 759 insertions(+), 0 deletions(-) create mode 100644 lib/ext2fs/blkmap64_rb.c
lib/ext2fs/Makefile.in +2 -0
@@ -27,6 +27,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ bitmaps.o \ bitops.o \ blkmap64_ba.o \ + blkmap64_rb.o \ blknum.o \ block.o \ bmap.o \
@@ -94,6 +95,7 @@ SRCS= ext2_err.c \ $(srcdir)/bitmaps.c \ $(srcdir)/bitops.c \ $(srcdir)/blkmap64_ba.o \ + $(srcdir)/blkmap64_rb.c \ $(srcdir)/block.c \ $(srcdir)/bmap.c \ $(srcdir)/check_desc.c \
lib/ext2fs/blkmap64_rb.c new file +751 -0
751 lines not on this page · raw message
lib/ext2fs/bmap64.h +1 -0
@@ -59,3 +59,4 @@ struct ext2_bitmap_ops { };extern struct ext2_bitmap_ops ext2fs_blkmap64_bitarray; +extern struct ext2_bitmap_ops ext2fs_blkmap64_rbtree;
lib/ext2fs/ext2fsP.h +1 -0
@@ -108,6 +108,7 @@ extern void ext2fs_numeric_progress_close(ext2_filsys fs,*/ #define EXT2FS_BMAP64_BITARRAY 1 +#define EXT2FS_BMAP64_RBTREE 2 extern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, int type, __u64 start, __u64 end,
lib/ext2fs/gen_bitmap64.c +4 -0
@@ -91,6 +91,9 @@ errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,case EXT2FS_BMAP64_BITARRAY : ops = &ext2fs_blkmap64_bitarray;break ; +case EXT2FS_BMAP64_RBTREE : + ops = &ext2fs_blkmap64_rbtree; +break ;default :return EINVAL ; }
@@ -158,6 +161,7 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) bmap->description =0 ; } bmap->magic =0 ; +ext2fs_free_mem (&bmap); } errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
Signature · 1 line
1.7.4
Re: [PATCH 2/4 v2] e2fsprogs: Add rbtree backend for bitmaps, use it instead of bitarrays
lib/ext2fs/blkmap64_rb.c line 37
Quoted 6 lines · Lukas Czerner
+++
b/lib/ext2fs/blkmap64_rb.clib/ext2fs/blkmap64_rb.c new file +5
-0+struct bmap_rb_extent { +struct rb_node node; +__u64 start; +__u32 count; +};
On 32-bit machines (where memory consumption is even more critical) this will pack better by arranging it with "count" aligned with rb_parent_color:
struct bmap_rb_extent {
__u64 start;
__u32 count;
struct rb_node node;
};That will give a leaf size of 24 bytes on a 32-bit arch, instead of 32 bytes with padding. On a 64-bit arch it won't make any difference.
Quoted 13 lines
static
errcode_trb_resize_bmap(ext2fs_generic_bitmap bmap,lib/ext2fs/blkmap64_rb.c new file +12
-0+ __u64 new_end, __u64 new_real_end) +{ +struct ext2fs_rb_private *bp; + +if (new_real_end >= bmap->real_end) { + bmap->end = new_end; + bmap->real_end = new_real_end; +return 0 ; + } + + bp = (struct ext2fs_rb_private *) bmap->private; + *bp->rcursor =NULL ;
lib/ext2fs/blkmap64_rb.c line 301
Quoted 10 lines
lib/ext2fs/blkmap64_rb.c new file +10
-0+ *bp->wcursor =NULL ; + +/* truncate tree to new_real_end size */ +rb_truncate (new_real_end, &bp->root); + + bmap->end = new_end; + bmap->real_end = new_real_end; +return 0 ; + +}
This might be a bit better written as:
static errcode_t rb_resize_bmap(ext2fs_generic_bitmap bmap,
__u64 new_end, __u64 new_real_end)
{
struct ext2fs_rb_private *bp;
if (new_real_end < bmap->real_end) {
bp = (struct ext2fs_rb_private *)bmap->private;
*bp->rcursor = NULL;
*bp->wcursor = NULL;
/* truncate tree to new_real_end size */
rb_truncate(new_real_end, &bp->root);
}
bmap->end = new_end;
bmap->real_end = new_real_end;
return 0;}
Quoted 29 lines
lib/ext2fs/blkmap64_rb.c new file +29
-0+inline static int +rb_test_bit (struct ext2fs_rb_private *bp,__u64 bit) +{ +struct bmap_rb_extent *rcursor; +struct rb_node *parent =NULL ; +struct rb_node **n = &bp->root.rb_node; +struct bmap_rb_extent *ext; +int i=0 ; + + rcursor = *bp->rcursor; +if (!rcursor) + goto search_tree; + +if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) +return 1 ; + + rcursor = *bp->wcursor; +if (!rcursor) + goto search_tree; + +if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) +return 1 ; + +search_tree: + +while (*n) { + parent = *n; + ext = rb_entry(parent, struct bmap_rb_extent, node); +if (bit < ext->start)
lib/ext2fs/blkmap64_rb.c line 341
Quoted 10 lines
lib/ext2fs/blkmap64_rb.c new file +10
-0+ n = &(*n)->rb_left; + else if (bit >= (ext->start + ext->count)) + n = &(*n)->rb_right; + else { + *bp->rcursor = ext; +return 1 ; + } + } +return 0 ; +}
This seems quite large for a static inline? I guess it is only called by a single function, so maybe not a big deal.
lib/ext2fs/blkmap64_rb.c line 564
Quoted 10 lines
lib/ext2fs/blkmap64_rb.c new file +10
-0+inline +static int rb_test_bmap (ext2fs_generic_bitmap bitmap,__u64 arg) +{ +struct ext2fs_rb_private *bp; + + bp = (struct ext2fs_rb_private *) bitmap->private; + arg -= bitmap->start; + +return rb_test_bit (bp, arg); +}
This definitely doesn't make sense to be static inline, since its only use is by ext2_bitmap_ops table, so it can't possibly be inline...
lib/ext2fs/gen_bitmap64.c void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) · line 165
Quoted 6 lines
lib/ext2fs/gen_bitmap64.c +1
-0@@ -158,6 +161,7 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) bmap->description =0 ; } bmap->magic =0 ; +ext2fs_free_mem (&bmap); }
This is really a defect in the original e2fsprogs, so it might make sense to submit it independently in case Ted isn't going to apply this patch right away.
Cheers, Andreas
Re: [PATCH 2/4 v2] e2fsprogs: Add rbtree backend for bitmaps, use it instead of bitarrays
Quoted 10 lines · Andreas Dilger
lib/ext2fs/blkmap64_rb.c line 37
Quoted 6 lines · Lukas Czerner
+++
b/lib/ext2fs/blkmap64_rb.clib/ext2fs/blkmap64_rb.c new file +5
-0+struct bmap_rb_extent { +struct rb_node node; +__u64 start; +__u32 count; +};On 32-bit machines (where memory consumption is even more critical) this will pack better by arranging it with "count" aligned with
rb_parent_color:
Quoted 7 lines
struct bmap_rb_extent { __u64 start; __u32 count; struct rb_node node; };That will give a leaf size of 24 bytes on a 32-bit arch, instead of 32 bytes with padding. On a 64-bit arch it won't make any difference.
Oh, of course, do not know how I missed that.
Quoted 45 lines
Quoted 14 lines
static
errcode_trb_resize_bmap(ext2fs_generic_bitmap bmap,lib/ext2fs/blkmap64_rb.c new file +12
-0+ __u64 new_end, __u64 new_real_end) +{ +struct ext2fs_rb_private *bp; + +if (new_real_end >= bmap->real_end) { + bmap->end = new_end; + bmap->real_end = new_real_end; +return 0 ; + } + + bp = (struct ext2fs_rb_private *) bmap->private; + *bp->rcursor =NULL ;lib/ext2fs/blkmap64_rb.c line 301
Quoted 10 lines
lib/ext2fs/blkmap64_rb.c new file +10
-0+ *bp->wcursor =NULL ; + +/* truncate tree to new_real_end size */ +rb_truncate (new_real_end, &bp->root); + + bmap->end = new_end; + bmap->real_end = new_real_end; +return 0 ; + +}This might be a bit better written as:
static
errcode_trb_resize_bmap(ext2fs_generic_bitmap bmap,__u64 new_end, __u64 new_real_end) { struct ext2fs_rb_private *bp; if (new_real_end < bmap->real_end) { bp = (struct ext2fs_rb_private *)bmap->private; *bp->rcursor = NULL; *bp->wcursor = NULL; /* truncate tree to new_real_end size */ rb_truncate(new_real_end, &bp->root); } bmap->end = new_end; bmap->real_end = new_real_end; return 0;
Quoted 1 line
}
Right that's definitely better.
Quoted 34 lines
Quoted 34 lines
lib/ext2fs/blkmap64_rb.c new file +33
-0+inline static int +rb_test_bit (struct ext2fs_rb_private *bp,__u64 bit) +{ +struct bmap_rb_extent *rcursor; +struct rb_node *parent =NULL ; +struct rb_node **n = &bp->root.rb_node; +struct bmap_rb_extent *ext; +int i=0 ; + + rcursor = *bp->rcursor; +if (!rcursor) + goto search_tree; + +if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) +return 1 ; + + rcursor = *bp->wcursor; +if (!rcursor) + goto search_tree; + +if (bit >= rcursor->start && bit < rcursor->start + rcursor->count) +return 1 ; + +search_tree: + +while (*n) { + parent = *n; + ext = rb_entry(parent, struct bmap_rb_extent, node); +if (bit < ext->start) + n = &(*n)->rb_left; +else if (bit >= (ext->start + ext->count)) + n = &(*n)->rb_right; +else {
Quoted 8 lines
lib/ext2fs/blkmap64_rb.c line 341
Quoted 6 lines
lib/ext2fs/blkmap64_rb.c new file +6
-0+ *bp->rcursor = ext; +return 1 ; + } + } +return 0 ; +}This seems quite large for a static inline? I guess it is only called by a single function, so maybe not a big deal.
It is actually called for two functions and since this is the most called function, I think this it is worth it (there is approx. 1% performance boost bound with this).
Quoted 13 lines
lib/ext2fs/blkmap64_rb.c line 564
Quoted 11 lines
lib/ext2fs/blkmap64_rb.c new file +10
-0+inline +static int rb_test_bmap (ext2fs_generic_bitmap bitmap,__u64 arg) +{ +struct ext2fs_rb_private *bp; + + bp = (struct ext2fs_rb_private *) bitmap->private; + arg -= bitmap->start; + +return rb_test_bit (bp, arg); +}This definitely doesn't make sense to be static inline, since its only use is by
ext2_bitmap_opstable, so it can't possibly be inline...
Right, I'll fix that.
Quoted 9 lines
lib/ext2fs/gen_bitmap64.c void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) · line 165
Quoted 7 lines
lib/ext2fs/gen_bitmap64.c +1
-0@@ -158,6 +161,7 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) bmap->description =0 ; } bmap->magic =0 ; +ext2fs_free_mem (&bmap); }This is really a defect in the original e2fsprogs, so it might make sense to submit it independently in case Ted isn't going to apply this patch right away.
Yes, somehow I forgot about that. Thanks.
Quoted 3 lines
Cheers, Andreas
Thanks!
-Lukas
PATCH 3/4 Add bitmap configuration interface
In reply to Lukas CzernerAdd a possibility for user to configure what bitmap backed will be used for what bitmap. It is also useful for testing and benchmarking different bitmap backends and its behaviour.
Setting can be done via usual config file with new section [bitmaps] with subnames defining particular bitmaps. Argument is simply number of the backend. All backends are defined in ext2fsP.h like this:
enum ext2fs_bmap_backends {
EXT2FS_BMAP64_BITARRAY = 0,
EXT2FS_BMAP64_RBTREE,
EXT2FS_BMAP64_COUNT,
};Here is an example of bitmap configuration, with the list of all supported bitmaps.
[bitmaps]
generic_bitmap = 1
inode_used_map = 1
inode_bad_map = 1
inode_dir_map = 0
inode_bb_map = 1
inode_imagic_map = 0
inode_reg_map = 1
block_found_map = 0
block_dup_map = 1
block_ea_map = 0
empty_dir_blocks = 1
empty_dir_map = 0
block_bitmap = 0
inode_bitmap = 1
check_desc_map = 0
bad_block_map = 1
touched_map = 0
block_scramble_map = 1
block_to_move = 0
block_reserved = 1
block_meta_data = 0
inode_dup_map = 1
inode_done_map = 0
inode_loop_map = 1
Note that EXT2FS_BMAP64_BITARRAY is still left as a default bitmap backend, so nothing is changed for the user, unless bitmap configuration section is used.
This feature requires interface change of ext2fs_alloc_generic_bmap() and its definition now is:
errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
int type, __u64 start, __u64 end, __u64 real_end, ext2fs_generic_bitmap *ret)
Also note that this does work for 64-bit bitmaps only.
--- e2fsck/emptydir.c | 4 +- e2fsck/pass1.c | 18 ++++---- e2fsck/pass1b.c | 2 +- e2fsck/pass3.c | 6 ++- e2fsck/pass5.c | 4 +- e2fsck/unix.c | 7 +++ lib/ext2fs/Makefile.in | 17 ++++++- lib/ext2fs/bitmaps.c | 21 +++++---- lib/ext2fs/check_desc.c | 2 +- lib/ext2fs/ext2fs.h | 36 +++++++++++++- lib/ext2fs/ext2fsP.h | 8 ++- lib/ext2fs/gen_bitmap64.c | 118 ++++++++++++++++++++++++++++++++++++++++++++- lib/ext2fs/icount.c | 5 +- lib/ext2fs/initialize.c | 18 ++----- lib/ext2fs/rw_bitmaps.c | 17 ++----- lib/ext2fs/tst_iscan.c | 6 +- misc/e2image.c | 4 +- misc/tune2fs.c | 2 +- resize/resize2fs.c | 6 +- 19 files changed, 227 insertions(+), 74 deletions(-)
e2fsck/emptydir.c +2 -2
@@ -53,12 +53,12 @@ empty_dir_info init_empty_dir(e2fsck_t ctx)if (retval) goto errout; - retval =ext2fs_allocate_block_bitmap (ctx->fs,_ ("empty dirblocks" ), + retval =ext2fs_allocate_block_bitmap (ctx->fs,EXT2_EMPTY_DIR_BLOCKS , &edi->empty_dir_blocks);if (retval) goto errout; - retval =ext2fs_allocate_inode_bitmap (ctx->fs,_ ("empty dir map" ), + retval =ext2fs_allocate_inode_bitmap (ctx->fs,EXT2_EMPTY_DIR_MAP , &edi->dir_map);if (retval) goto errout;
e2fsck/pass1.c +9 -9
@@ -593,7 +593,7 @@ void e2fsck_pass1(e2fsck_t ctx)/* * Allocate bitmaps structures */ - pctx.errcode =ext2fs_allocate_inode_bitmap (fs,_ ("in-use inode map" ), + pctx.errcode =ext2fs_allocate_inode_bitmap (fs,EXT2_INODE_USED_MAP , &ctx->inode_used_map);if (pctx.errcode) { pctx.num =1 ;
@@ -602,7 +602,7 @@ void e2fsck_pass1(e2fsck_t ctx)return ; } pctx.errcode =ext2fs_allocate_inode_bitmap (fs, -_ ("directory inode map" ), &ctx->inode_dir_map); +EXT2_INODE_DIR_MAP , &ctx->inode_dir_map);if (pctx.errcode) { pctx.num =2 ;fix_problem (ctx,PR_1_ALLOCATE_IBITMAP_ERROR , &pctx);
@@ -610,14 +610,14 @@ void e2fsck_pass1(e2fsck_t ctx)return ; } pctx.errcode =ext2fs_allocate_inode_bitmap (fs, -_ ("regular file inode map" ), &ctx->inode_reg_map); +EXT2_INODE_REG_MAP , &ctx->inode_reg_map);if (pctx.errcode) { pctx.num =6 ;fix_problem (ctx,PR_1_ALLOCATE_IBITMAP_ERROR , &pctx); ctx->flags |=E2F_FLAG_ABORT ;return ; } - pctx.errcode =ext2fs_allocate_block_bitmap (fs,_ ("in-use block map" ), + pctx.errcode =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_FOUND_MAP , &ctx->block_found_map);if (pctx.errcode) { pctx.num =1 ;
@@ -1271,7 +1271,7 @@ static void mark_inode_bad(e2fsck_t ctx, ino_t ino)clear_problem_context (&pctx); pctx.errcode =ext2fs_allocate_inode_bitmap (ctx->fs, -_ ("bad inode map" ), &ctx->inode_bad_map); +EXT2_INODE_BAD_MAP , &ctx->inode_bad_map);if (pctx.errcode) { pctx.num =3 ;fix_problem (ctx,PR_1_ALLOCATE_IBITMAP_ERROR , &pctx);
@@ -1293,7 +1293,7 @@ static void alloc_bb_map(e2fsck_t ctx)clear_problem_context (&pctx); pctx.errcode =ext2fs_allocate_inode_bitmap (ctx->fs, -_ ("inode in bad block map" ), +EXT2_INODE_BB_MAP , &ctx->inode_bb_map);if (pctx.errcode) { pctx.num =4 ;
@@ -1313,7 +1313,7 @@ static void alloc_imagic_map(e2fsck_t ctx)clear_problem_context (&pctx); pctx.errcode =ext2fs_allocate_inode_bitmap (ctx->fs, -_ ("imagic inode map" ), +EXT2_INODE_IMAGIC_MAP , &ctx->inode_imagic_map);if (pctx.errcode) { pctx.num =5 ;
@@ -1340,7 +1340,7 @@ static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)if (ext2fs_fast_test_block_bitmap2 (ctx->block_found_map, block)) {if (!ctx->block_dup_map) { pctx.errcode =ext2fs_allocate_block_bitmap (ctx->fs, -_ ("multiply claimed block map" ), +EXT2_BLOCK_DUP_MAP , &ctx->block_dup_map);if (pctx.errcode) { pctx.num =3 ;
@@ -1440,7 +1440,7 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,/* If ea bitmap hasn't been allocated, create it */ if (!ctx->block_ea_map) { pctx->errcode =ext2fs_allocate_block_bitmap (fs, -_ ("ext attr block map" ), +EXT2_BLOCK_EA_MAP , &ctx->block_ea_map);if (pctx->errcode) { pctx->num =2 ;
e2fsck/pass1b.c +1 -1
@@ -217,7 +217,7 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)clear_problem_context (&pctx); pctx.errcode =ext2fs_allocate_inode_bitmap (fs, -_ ("multiply claimed inode map" ), &inode_dup_map); +EXT2_INODE_DUP_MAP , &inode_dup_map);if (pctx.errcode) {fix_problem (ctx,PR_1B_ALLOCATE_IBITMAP_ERROR , &pctx); ctx->flags |=E2F_FLAG_ABORT ;
e2fsck/pass3.c +4 -2
@@ -73,7 +73,7 @@ void e2fsck_pass3(e2fsck_t ctx)/* * Allocate some bitmaps to do loop detection. */ - pctx.errcode =ext2fs_allocate_inode_bitmap (fs,_ ("inode done bitmap" ), + pctx.errcode =ext2fs_allocate_inode_bitmap (fs,EXT2_INODE_DONE_MAP , &inode_done_map);if (pctx.errcode) { pctx.num =2 ;
@@ -317,7 +317,9 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir,if (inode_loop_detect)ext2fs_clear_inode_bitmap (inode_loop_detect);else { - pctx->errcode =ext2fs_allocate_inode_bitmap (fs,_ ("inode loop detection bitmap" ), &inode_loop_detect); + pctx->errcode =ext2fs_allocate_inode_bitmap (fs, +EXT2_INODE_LOOP_MAP , + &inode_loop_detect);if (pctx->errcode) { pctx->num =1 ; fix_problem(ctx,
e2fsck/pass5.c +2 -2
@@ -272,7 +272,7 @@ redo_counts:else bitmap =ext2fs_fast_test_block_bitmap2 (fs->block_map, i); -if (actual == bitmap) +if ((actual && bitmap) || (!actual && !bitmap)) goto do_counts;if (!actual && bitmap) {
@@ -504,7 +504,7 @@ redo_counts: bitmap = actual; else if (!skip_group) bitmap =ext2fs_fast_test_inode_bitmap2 (fs->inode_map, i); -if (actual == bitmap) +if ((actual && bitmap) || (!actual && !bitmap)) goto do_counts;if (!actual && bitmap) {
e2fsck/unix.c +7 -0
@@ -860,6 +860,13 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)profile_set_syntax_err_cb (syntax_err_report);profile_init (config_fn, &ctx->profile); + retval =ext2fs_prepare_bmap_definitions (ctx->profile); +if (retval) { +com_err ("ext2fs_prepare_bmap_definitions" , retval, +_ ("while setting bitmaps" )); +fatal_error (ctx,0 ); + } +if (flush) { fd =open (ctx->filesystem_name,O_RDONLY ,0 );if (fd <0 ) {
lib/ext2fs/Makefile.in +15 -2
@@ -82,7 +82,8 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ unlink.o \ valid_blk.o \ version.o \ - rbtree.o + rbtree.o \ + profile.o SRCS= ext2_err.c \ $(srcdir)/alloc.c \
@@ -160,6 +161,8 @@ SRCS= ext2_err.c \ $(srcdir)/version.c \ $(srcdir)/write_bb_file.c \ $(srcdir)/rbtree.c \ + $(top_srcdir)/e2fsck/profile.c + HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \ tdb.h
@@ -200,6 +203,15 @@ COMPILE_ET=../et/compile_et --build-tree DISTFILES= Makefile *.c *.h image +profile.o: + $(E) " CC $<" + $(Q) $(COMPILE_ET) $(top_srcdir)/e2fsck/prof_err.et + $(Q) $(CP) -f $(srcdir)/prof_err.h $(top_srcdir)/e2fsck/ + $(Q) $(CC) -c $(ALL_CFLAGS) $(top_srcdir)/e2fsck/profile.c -o $@ +@PROFILE_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/profile.o -c \ +@PROFILE_CMT@ $(top_srcdir)/e2fsck/profile.c + + ext2_err.et: $(DEP_SUBSTITUTE) $(srcdir)/ext2_err.et.in $(E) " SUBST $@" $(Q) $(SUBSTITUTE) $(srcdir)/ext2_err.et.in ext2_err.et
@@ -387,7 +399,8 @@ clean:: mostlyclean:: clean distclean:: clean $(RM) -f .depend ext2_err.c ext2_err.h Makefile ext2fs.pc \ - $(srcdir)/TAGS $(srcdir)/Makefile.in.old + $(srcdir)/TAGS $(srcdir)/Makefile.in.old \ + $(srcdir)/prof_err.h # # Hack to parallel makes recognize dependencies correctly. #
lib/ext2fs/bitmaps.c +12 -9
@@ -48,13 +48,15 @@ void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)ext2fs_set_generic_bmap_padding (map); } -errcode_t ext2fs_allocate_inode_bitmap (ext2_filsys fs, -const char *descr, +errcode_t ext2fs_allocate_inode_bitmap (ext2_filsys fs,int type,ext2fs_inode_bitmap *ret) {__u64 start, end, real_end; +int backend;EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS ); +if (type >=EXT2_BMAP_COUNT || type <0 ) +return EINVAL ; fs->write_bitmaps = ext2fs_write_bitmaps;
@@ -66,8 +68,7 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,if (fs->flags &EXT2_FLAG_64BITS )return (ext2fs_alloc_generic_bmap (fs,EXT2_ET_MAGIC_INODE_BITMAP64 , -EXT2FS_BMAP64_BITARRAY , - start, end, real_end, descr, ret)); + type, start, end, real_end, ret));/* Otherwise, check to see if the file system is small enough * to use old-style 32-bit bitmaps */
@@ -76,17 +77,20 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,return (ext2fs_make_generic_bitmap (EXT2_ET_MAGIC_INODE_BITMAP , fs, start, end, real_end, - descr,0 , +NULL ,0 , (ext2fs_generic_bitmap *) ret)); }errcode_t ext2fs_allocate_block_bitmap (ext2_filsys fs, -const char *descr, +int type,ext2fs_block_bitmap *ret) {__u64 start, end, real_end; +int backend;EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS ); +if (type >=EXT2_BMAP_COUNT || type <0 ) +return EINVAL ; fs->write_bitmaps = ext2fs_write_bitmaps;
@@ -98,15 +102,14 @@ errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,if (fs->flags &EXT2_FLAG_64BITS )return (ext2fs_alloc_generic_bmap (fs,EXT2_ET_MAGIC_BLOCK_BITMAP64 , -EXT2FS_BMAP64_BITARRAY , - start, end, real_end, descr, ret)); + type, start, end, real_end, ret));if ((end > ~0U ) || (real_end > ~0U ))return EXT2_ET_CANT_USE_LEGACY_BITMAPS ;return (ext2fs_make_generic_bitmap (EXT2_ET_MAGIC_BLOCK_BITMAP , fs, start, end, real_end, - descr,0 , +NULL ,0 , (ext2fs_generic_bitmap *) ret)); }
lib/ext2fs/check_desc.c +1 -1
@@ -41,7 +41,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS ); - retval =ext2fs_allocate_block_bitmap (fs,"check_desc map" , &bmap); + retval =ext2fs_allocate_block_bitmap (fs,EXT2_CHECK_DESC_MAP , &bmap);if (retval)return retval;
lib/ext2fs/ext2fs.h +33 -3
@@ -562,6 +562,37 @@ typedef struct ext2_icount *ext2_icount_t;#define EXT2_LIB_SOFTSUPP_INCOMPAT (0)#define EXT2_LIB_SOFTSUPP_RO_COMPAT (0) + +enum ext2_bitmap_type { +EXT2_GENERIC_MAP =0 , +EXT2_INODE_USED_MAP ,/* Inodes which are in use */ +EXT2_INODE_BAD_MAP ,/* Inodes which are bad somehow */ +EXT2_INODE_DIR_MAP ,/* Inodes which are directories */ +EXT2_INODE_BB_MAP ,/* Inodes which are in bad blocks */ +EXT2_INODE_IMAGIC_MAP ,/* AFS inodes */ +EXT2_INODE_REG_MAP ,/* Inodes which are regular files*/ +EXT2_INODE_MAP , +EXT2_INODE_DUP_MAP , +EXT2_INODE_DONE_MAP , +EXT2_INODE_LOOP_MAP , + +EXT2_BLOCK_FOUND_MAP ,/* Blocks which are in use */ +EXT2_BLOCK_DUP_MAP ,/* Blks referenced more than once */ +EXT2_BLOCK_EA_MAP ,/* Blocks which are used by EA's */ +EXT2_BLOCK_MAP , +EXT2_BLOCK_BAD_MAP , +EXT2_BLOCK_SCRAMBLE , +EXT2_BLOCK_TO_MOVE , +EXT2_BLOCK_RESERVED , +EXT2_BLOCK_METADATA , + +EXT2_EMPTY_DIR_BLOCKS , +EXT2_EMPTY_DIR_MAP , +EXT2_CHECK_DESC_MAP , +EXT2_TOUCHED_MAP , +EXT2_BMAP_COUNT ,/* Stop mark */ +}; +/* * function prototypes */
@@ -673,10 +704,10 @@ extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);extern errcode_t ext2fs_read_block_bitmap (ext2_filsys fs);extern errcode_t ext2fs_allocate_block_bitmap (ext2_filsys fs, -const char *descr, +int type,ext2fs_block_bitmap *ret);extern errcode_t ext2fs_allocate_inode_bitmap (ext2_filsys fs, -const char *descr, +int type,ext2fs_inode_bitmap *ret);extern errcode_t ext2fs_fudge_inode_bitmap_end (ext2fs_inode_bitmap bitmap,ext2_ino_t end,ext2_ino_t *oend);
@@ -1086,7 +1117,6 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);errcode_t ext2fs_alloc_generic_bmap (ext2_filsys fs,errcode_t magic,int type,__u64 start,__u64 end,__u64 real_end, -const char *descr,ext2fs_generic_bitmap *ret);errcode_t ext2fs_copy_generic_bmap (ext2fs_generic_bitmap src,ext2fs_generic_bitmap *dest);
lib/ext2fs/ext2fsP.h +5 -3
@@ -107,13 +107,15 @@ extern void ext2fs_numeric_progress_close(ext2_filsys fs,* 64-bit bitmap support */ -#define EXT2FS_BMAP64_BITARRAY 1 -#define EXT2FS_BMAP64_RBTREE 2 +enum ext2fs_bmap_backends { +EXT2FS_BMAP64_BITARRAY =0 , +EXT2FS_BMAP64_RBTREE , +EXT2FS_BMAP64_COUNT , +};extern errcode_t ext2fs_alloc_generic_bmap (ext2_filsys fs,errcode_t magic,int type,__u64 start,__u64 end,__u64 real_end, -const char * description,ext2fs_generic_bitmap *bmap);extern void ext2fs_free_generic_bmap (ext2fs_generic_bitmap bmap);
lib/ext2fs/gen_bitmap64.c +116 -2
151 lines not on this page · raw message
lib/ext2fs/icount.c +3 -2
@@ -103,12 +103,13 @@ static errcode_t alloc_icount(ext2_filsys fs, int flags, ext2_icount_t *ret)return retval;memset (icount,0 ,sizeof (struct ext2_icount )); - retval =ext2fs_allocate_inode_bitmap (fs,0 , &icount->single); + retval =ext2fs_allocate_inode_bitmap (fs,EXT2_GENERIC_MAP , + &icount->single);if (retval) goto errout;if (flags &EXT2_ICOUNT_OPT_INCREMENT ) { - retval =ext2fs_allocate_inode_bitmap (fs,0 , + retval =ext2fs_allocate_inode_bitmap (fs,EXT2_GENERIC_MAP , &icount->multiple);if (retval) goto errout;
lib/ext2fs/initialize.c +4 -14
@@ -96,7 +96,6 @@ errcode_t ext2fs_initialize(const char *name, int flags,int rsv_gdt;int csum_flag;int io_flags; -char *buf =0 ;char c;if (!param || !ext2fs_blocks_count (param))
@@ -359,24 +358,16 @@ ipg_retry:* count. */ - retval =ext2fs_get_mem (strlen (fs->device_name) +80 , &buf); + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_MAP , + &fs->block_map);if (retval) goto cleanup; -strcpy (buf,"block bitmap for " ); -strcat (buf, fs->device_name); - retval =ext2fs_allocate_block_bitmap (fs, buf, &fs->block_map); + retval =ext2fs_allocate_inode_bitmap (fs,EXT2_INODE_MAP , + &fs->inode_map);if (retval) goto cleanup; -strcpy (buf,"inode bitmap for " ); -strcat (buf, fs->device_name); - retval =ext2fs_allocate_inode_bitmap (fs, buf, &fs->inode_map); -if (retval) - goto cleanup; - -ext2fs_free_mem (&buf); - retval =ext2fs_get_array (fs->desc_blocks, fs->blocksize, &fs->group_desc);if (retval)
@@ -442,7 +433,6 @@ ipg_retry: *ret_fs = fs;return 0 ; cleanup: -free (buf);ext2fs_free (fs);return retval; }
lib/ext2fs/rw_bitmaps.c +4 -13
@@ -139,7 +139,6 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) {dgrp_t i;char *block_bitmap =0 , *inode_bitmap =0 ; -char *buf;errcode_t retval;int block_nbytes =EXT2_BLOCKS_PER_GROUP (fs->super) /8 ;int inode_nbytes =EXT2_INODES_PER_GROUP (fs->super) /8 ;
@@ -160,15 +159,11 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) csum_flag =1 ; - retval =ext2fs_get_mem (strlen (fs->device_name) +80 , &buf); -if (retval) -return retval;if (do_block) {if (fs->block_map)ext2fs_free_block_bitmap (fs->block_map); -strcpy (buf,"block bitmap for " ); -strcat (buf, fs->device_name); - retval =ext2fs_allocate_block_bitmap (fs, buf, &fs->block_map); + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_MAP , + &fs->block_map);if (retval) goto cleanup;if (do_image)
@@ -185,9 +180,8 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)if (do_inode) {if (fs->inode_map)ext2fs_free_inode_bitmap (fs->inode_map); -strcpy (buf,"inode bitmap for " ); -strcat (buf, fs->device_name); - retval =ext2fs_allocate_inode_bitmap (fs, buf, &fs->inode_map); + retval =ext2fs_allocate_inode_bitmap (fs,EXT2_INODE_MAP , + &fs->inode_map);if (retval) goto cleanup; retval = ext2fs_get_mem(do_image ? fs->blocksize :
@@ -196,7 +190,6 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) goto cleanup; }else inode_nbytes =0 ; -ext2fs_free_mem (&buf);if (fs->flags &EXT2_FLAG_IMAGE_FILE ) { blk = (fs->image_header->offset_inodemap / fs->blocksize);
@@ -306,8 +299,6 @@ cleanup:ext2fs_free_mem (&inode_bitmap);if (block_bitmap)ext2fs_free_mem (&block_bitmap); -if (buf) -ext2fs_free_mem (&buf);return retval; }
lib/ext2fs/tst_iscan.c +3 -3
@@ -95,21 +95,21 @@ static void setup(void) "While allocating tables for test filesystem");exit (1 ); } - retval =ext2fs_allocate_block_bitmap (test_fs,"bad block map" , + retval =ext2fs_allocate_block_bitmap (test_fs,EXT2_BLOCK_BAD_MAP , &bad_block_map);if (retval) {com_err ("setup" , retval,"While allocating bad_block bitmap" );exit (1 ); } - retval =ext2fs_allocate_block_bitmap (test_fs,"touched map" , + retval =ext2fs_allocate_block_bitmap (test_fs,EXT2_TOUCHED_MAP , &touched_map);if (retval) {com_err ("setup" , retval,"While allocating touched block bitmap" );exit (1 ); } - retval =ext2fs_allocate_inode_bitmap (test_fs,"bad inode map" , + retval =ext2fs_allocate_inode_bitmap (test_fs,EXT2_INODE_BAD_MAP , &bad_inode_map);if (retval) { com_err("setup", retval,
misc/e2image.c +2 -2
@@ -465,7 +465,7 @@ static void write_raw_image_file(ext2_filsys fs, int fd, int scramble_flag)errcode_t retval;char * block_buf; - retval =ext2fs_allocate_block_bitmap (fs,"in-use block map" , + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_FOUND_MAP , &meta_block_map);if (retval) {com_err (program_name, retval,"while allocating block bitmap" );
@@ -473,7 +473,7 @@ static void write_raw_image_file(ext2_filsys fs, int fd, int scramble_flag) }if (scramble_flag) { - retval =ext2fs_allocate_block_bitmap (fs,"scramble block map" , + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_SCRAMBLE , &scramble_block_map);if (retval) { com_err(program_name, retval,
misc/tune2fs.c +1 -1
@@ -1472,7 +1472,7 @@ static int resize_inode(ext2_filsys fs, unsigned long new_size)*/ fs->super->s_state &= ~EXT2_VALID_FS ; - retval =ext2fs_allocate_block_bitmap (fs,_ ("blocks to be moved" ), + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_TO_MOVE , &bmap);if (retval) { fputs(_("Failed to allocate block bitmap when "
resize/resize2fs.c +3 -3
@@ -580,7 +580,7 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)ext2fs_mark_bb_dirty (fs);ext2fs_mark_ib_dirty (fs); - retval =ext2fs_allocate_block_bitmap (fs,_ ("reserved blocks" ), + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_RESERVED , &rfs->reserve_blocks);if (retval)return retval;
@@ -788,12 +788,12 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)if (ext2fs_blocks_count (old_fs->super) >ext2fs_blocks_count (fs->super)) fs = rfs->old_fs; - retval =ext2fs_allocate_block_bitmap (fs,_ ("blocks to be moved" ), + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_TO_MOVE , &rfs->move_blocks);if (retval)return retval; - retval =ext2fs_allocate_block_bitmap (fs,_ ("meta-data blocks" ), + retval =ext2fs_allocate_block_bitmap (fs,EXT2_BLOCK_METADATA , &meta_bmap);if (retval)return retval;
Signature · 1 line
1.7.4
Re: [PATCH 3/4] Add bitmap configuration interface
Quoted 14 lines · Lukas Czerner
Add a possibility for user to configure what bitmap backed will be used for what bitmap. It is also useful for testing and benchmarking different bitmap backends and its behaviour.
Setting can be done via usual config file with new section [bitmaps] with subnames defining particular bitmaps. Argument is simply number of the backend. All backends are defined in
ext2fsP.hlike this:enum ext2fs_bmap_backends { EXT2FS_BMAP64_BITARRAY = 0, EXT2FS_BMAP64_RBTREE, EXT2FS_BMAP64_COUNT, };
Quoted 7 lines
Here is an example of bitmap configuration, with the list of all supported bitmaps.
[bitmaps]
generic_bitmap= 1
inode_used_map= 1
inode_bad_map= 1
I wonder if this is enough just for debugging (presumably very few people will actually set this) or if there should be some symbolic constants used, like "bitmap", "rbtree", ...? That avoids exposing arbitrary internal constants to userspace, that will need to be preserved indefinitely.
Also useful would be a "default =" option that changes all of the unspecified bitmap types at once, to avoid the need to list all bitmaps explicitly (which may change over time), or possibly if "inode_map=" and "block_map=" are specified they become the default types for all other unspecified inode and block bitmaps?
Quoted 7 lines
This feature requires interface change of
ext2fs_alloc_generic_bmap()and its definition now is:
errcode_text2fs_alloc_generic_bmap(ext2_filsys fs,errcode_tmagic,int type, __u64 start, __u64 end, __u64 real_end, ext2fs_generic_bitmap *ret)
I was going to write that this will break the ABI/API for e2fsprogs, so probably is not acceptable to Ted. However, looking at the "master" branch, I see that it already has an "int type" argument, along with 64-bit arguments.
What branch is this patch series against?
Quoted 5 lines
lib/ext2fs/bitmaps.c +1
-2-errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, - const char *descr, +errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, int type,
ext2fs_inode_bitmap*ret)
{
Ah, unlike your comment above, this is changing the ext2fs_allocate_{block,inode}_bitmap() functions, which definitely will break the ABI/API. The other confusing thing is that since the number of parameters hasn't changed (size unchanged on 32-bit) then this wouldn't break the ABI totally and it would only cause a crash if the bitmap allocation failed and "type" is interpreted as a char * pointer.
One option is to have a separate helper function that changes the default bitmap type in ext2_filsys (maybe separate defaults for inode and block bitmaps), and then call that before this function. Not ideal, but doesn't change the ABI/API, and is sufficient for most uses. Alternately, it would be possible to declare a new ext2fs_allocate_{block,inode}_bitmap2() function that has this new parameter, and make ext2fs_allocate_{block,inode}_bmap() call it with the default bitmap type.
Review
Quoted 3 lines
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);(quoted diff) +2
-0+ if (type >= EXT2_BMAP_COUNT || type < 0) + return EINVAL;
Is EINVAL a valid error return for libext2fs? Anything returning an errcode_t should probably be using a new EXT2_ET_INVALID_BITMAP_TYPE error defined in lib/ext2fs/ext2_err.et.in.
lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 572
Quoted 7 lines
lib/ext2fs/ext2fs.h +7
-0+enum ext2_bitmap_type { +EXT2_GENERIC_MAP =0 , +EXT2_INODE_USED_MAP ,/* Inodes which are in use */ +EXT2_INODE_BAD_MAP ,/* Inodes which are bad somehow */ +EXT2_INODE_DIR_MAP ,/* Inodes which are directories */ +EXT2_INODE_BB_MAP ,/* Inodes which are in bad blocks */ +EXT2_INODE_IMAGIC_MAP ,/* AFS inodes */
EXT2_INODE_IMAGIC_MAP, /* Inodes disconnected but used by AFS */
lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 577
Quoted 5 lines
lib/ext2fs/ext2fs.h +5
-0+EXT2_INODE_REG_MAP ,/* Inodes which are regular files*/ +EXT2_INODE_MAP , +EXT2_INODE_DUP_MAP , +EXT2_INODE_DONE_MAP , + EXT2_INODE_LOOP_MAP,
Would be nice to have comments for the rest of these as well. I renamed a couple to be consistent with _INODE_ or _BLOCK_ in each name. Let's see:
EXT2_INODE_MAP, /* Inodes in use */
EXT2_INODE_DUP_MAP, /* Inodes with duplicate block usage */
EXT2_INODE_DONE_MAP, /* Dirs linked to root during e2fsck */
EXT2_INODE_LOOP_MAP, /* Dirs hit in path walk for e2fsck*/
EXT2_BLOCK_MAP, /* Blocks in use */
EXT2_BLOCK_BAD_MAP, /* Blocks marked bad via badblocks */
EXT2_BLOCK_SCRAMBLE, /* Blocks scrambled for e2image */
EXT2_BLOCK_TO_MOVE, /* Blocks to move for resize2fs */
EXT2_BLOCK_RESERVED, /* Blocks reserved for resize2fs */
EXT2_BLOCK_METADATA, /* Blocks for metadata for resize2fs */
EXT2_BLOCK_EMPTY_DIR, /* Blocks for lost+found expansion */
EXT2_INODE_EMPTY_DIR_MAP, /* ??? */
EXT2_BLOCK_CHECK_DESC_MAP, /* Blocks used for group descriptors */
EXT2_BLOCK_TOUCHED_MAP, /* Blocks accessed during tst_iscan */
lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 594
Quoted 2 lines
lib/ext2fs/ext2fs.h +2
-0+ EXT2_BMAP_COUNT, /* Stop mark */ +};
It isn't quite clear whether we need to have explicit block bitmap definitions for programs like tst_iscan. If it isn't possible for a program to allocate arbitrary bitmaps without having to register them first, it will really be a pain. I'd instead suggest that the "type" just default to EXT2_BLOCK_MAP for obscure bitmaps like "TOUCHED_MAP", and again allow specifying a bitmap name.
lib/ext2fs/ext2fsP.h extern void ext2fs_numeric_progress_close(ext2_filsys fs, · line 113
Quoted 6 lines
lib/ext2fs/ext2fsP.h +4
-2-#define EXT2FS_BMAP64_BITARRAY 1 -#define EXT2FS_BMAP64_RBTREE 2 +enum ext2fs_bmap_backends { +EXT2FS_BMAP64_BITARRAY =0 , +EXT2FS_BMAP64_RBTREE , +EXT2FS_BMAP64_COUNT ,
For debugging purposes, it is preferable to have an enum not contain "0" as a valid value, since that allows one to see if the bitmap type is being specified correctly, or if it is unset. Maybe EXT2FS_BMAP64_UNSET = 0?
lib/ext2fs/gen_bitmap64.c static void warn_bitmap(ext2fs_generic_bitmap bitmap, · line 121
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c +10
-0+static char *ext2_bmap_profile_value[EXT2_BMAP_COUNT ] = { + [EXT2_GENERIC_MAP ] ="generic_bitmap" , + [EXT2_INODE_USED_MAP ] ="inode_used_map" , + [EXT2_INODE_BAD_MAP ] ="inode_bad_map" , + +const +static struct ext2_bmap_definition ext2_bmap_default[EXT2_BMAP_COUNT] = { + [EXT2_GENERIC_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"generic bitmap" }, + [EXT2_INODE_USED_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"in-use inode map" }, + [EXT2_INODE_BAD_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"bad inode map" },
It is cumbersome to have to update 3 places for each bitmap. Could we just get rid of ext2_bmap_profile_value[] and only use ext2_bmap_default[]? Also, the strings here have now lost their i18n for error messages.
Cheers, Andreas
Re: [PATCH 3/4] Add bitmap configuration interface
Quoted 18 lines · Andreas Dilger
Quoted 17 lines · Lukas Czerner
Add a possibility for user to configure what bitmap backed will be used for what bitmap. It is also useful for testing and benchmarking different bitmap backends and its behaviour.
Setting can be done via usual config file with new section [bitmaps] with subnames defining particular bitmaps. Argument is simply number of the backend. All backends are defined in
ext2fsP.hlike this:enum ext2fs_bmap_backends { EXT2FS_BMAP64_BITARRAY = 0, EXT2FS_BMAP64_RBTREE, EXT2FS_BMAP64_COUNT, };Here is an example of bitmap configuration, with the list of all supported bitmaps.
Quoted 6 lines
Quoted 4 lines
[bitmaps]
generic_bitmap= 1
inode_used_map= 1
inode_bad_map= 1I wonder if this is enough just for debugging (presumably very few people will actually set this) or if there should be some symbolic constants used, like "bitmap", "rbtree", ...? That avoids exposing arbitrary internal constants to userspace, that will need to be preserved indefinitely.
Yes, I thought about that, but it seemed unnecessary. However I can see your point, I'll change that.
Quoted 2 lines
Also useful would be a "default =" option that changes all of the unspecified bitmap types at once, to avoid the need to list all bitmaps explicitly (which may change over time), or possibly if "inode_map=" and "block_map=" are specified they become the default types for all other unspecified inode and block bitmaps?
Now that's very good idea, I'll take a look into it.
Quoted 4 lines
Quoted 4 lines
This feature requires interface change of
ext2fs_alloc_generic_bmap()and its definition now is:
Quoted 8 lines
Quoted 4 lines
errcode_text2fs_alloc_generic_bmap(ext2_filsys fs,errcode_tmagic,int type, __u64 start, __u64 end, __u64 real_end, ext2fs_generic_bitmap *ret)I was going to write that this will break the ABI/API for e2fsprogs, so probably is not acceptable to Ted. However, looking at the "master" branch, I see that it already has an "int type" argument, along with 64-bit arguments.
What branch is this patch series against?
It is based on master branch fromgit://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
Quoted 10 lines
Quoted 6 lines
lib/ext2fs/bitmaps.c +1
-2-errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, - const char *descr, +errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, int type,
ext2fs_inode_bitmap*ret)
{Ah, unlike your comment above, this is changing the ext2fs_allocate_{block,inode}_bitmap() functions, which definitely will break the ABI/API. The other confusing thing is that since the number of parameters hasn't changed (size unchanged on 32-bit) then this wouldn't break the ABI totally and it would only cause a crash if the bitmap allocation failed and "type" is interpreted as a char * pointer.
One option is to have a separate helper function that changes the default bitmap type in
ext2_filsys(maybe separate defaults for inode and block bitmaps), and then call that before this function. Not ideal, but doesn't change the ABI/API, and is sufficient for most uses. Alternately, it would be possible to declare a new ext2fs_allocate_{block,inode}_bitmap2() function that has this new parameter, and make ext2fs_allocate_{block,inode}_bmap() call it with the default bitmap type.
Well I know that this breaks ABI/API and if that matters I can fix that. However I have a question, is preserving ABI/API really that important in e2fsprogs ? I guess it is when you are mentioning it, but I can not really see why ?
Quoted 6 lines
Review
Quoted 4 lines
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);(quoted diff) +2
-0+ if (type >= EXT2_BMAP_COUNT || type < 0) + return EINVAL;Is EINVAL a valid error return for libext2fs? Anything returning an
errcode_tshould probably be using a newEXT2_ET_INVALID_BITMAP_TYPEerror defined inlib/ext2fs/ext2_err.et.in.
You're right I'll fix that.
Quoted 31 lines
lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 572
Quoted 8 lines
lib/ext2fs/ext2fs.h +7
-0+enum ext2_bitmap_type { +EXT2_GENERIC_MAP =0 , +EXT2_INODE_USED_MAP ,/* Inodes which are in use */ +EXT2_INODE_BAD_MAP ,/* Inodes which are bad somehow */ +EXT2_INODE_DIR_MAP ,/* Inodes which are directories */ +EXT2_INODE_BB_MAP ,/* Inodes which are in bad blocks */ +EXT2_INODE_IMAGIC_MAP ,/* AFS inodes */
EXT2_INODE_IMAGIC_MAP, /* Inodes disconnected but used by AFS */lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 577
Quoted 5 lines
lib/ext2fs/ext2fs.h +5
-0+EXT2_INODE_REG_MAP ,/* Inodes which are regular files*/ +EXT2_INODE_MAP , +EXT2_INODE_DUP_MAP , +EXT2_INODE_DONE_MAP , + EXT2_INODE_LOOP_MAP,Would be nice to have comments for the rest of these as well. I renamed a couple to be consistent with _INODE_ or _BLOCK_ in each name. Let's see:
EXT2_INODE_MAP, /* Inodes in use */
EXT2_INODE_DUP_MAP, /* Inodes with duplicate block usage */
EXT2_INODE_DONE_MAP, /* Dirs linked to root during e2fsck */
EXT2_INODE_LOOP_MAP, /* Dirs hit in path walk for e2fsck*/
EXT2_BLOCK_MAP, /* Blocks in use */
EXT2_BLOCK_BAD_MAP, /* Blocks marked bad via badblocks */
EXT2_BLOCK_SCRAMBLE, /* Blocks scrambled for e2image */
EXT2_BLOCK_TO_MOVE, /* Blocks to move for resize2fs */
EXT2_BLOCK_RESERVED, /* Blocks reserved for resize2fs */
EXT2_BLOCK_METADATA, /* Blocks for metadata for resize2fs */
Quoted 4 lines
EXT2_BLOCK_EMPTY_DIR, /* Blocks for lost+found expansion */
EXT2_INODE_EMPTY_DIR_MAP, /* ??? */
EXT2_BLOCK_CHECK_DESC_MAP, /* Blocks used for group descriptors */
EXT2_BLOCK_TOUCHED_MAP, /* Blocks accessed duringtst_iscan*/
Thanks!
Quoted 5 lines
lib/ext2fs/ext2fs.h typedef struct ext2_icount *ext2_icount_t; · line 594
Quoted 3 lines
lib/ext2fs/ext2fs.h +2
-0+ EXT2_BMAP_COUNT, /* Stop mark */ +};It isn't quite clear whether we need to have explicit block bitmap definitions for programs like
tst_iscan. If it isn't possible for a program to allocate arbitrary bitmaps without having to register them first, it will really be a pain. I'd instead suggest that the "type" just default toEXT2_BLOCK_MAPfor obscure bitmaps like "TOUCHED_MAP", and again allow specifying a bitmap name.
Well I tried to cover all bitmaps in e2fsprogs tools. Now, if someone would like to use some anonymous bitmap, or just do not want to create new bitmap definitions, one can easily use EXT2_GENERIC_BITMAP.
Quoted 9 lines
lib/ext2fs/ext2fsP.h extern void ext2fs_numeric_progress_close(ext2_filsys fs, · line 113
Quoted 7 lines
lib/ext2fs/ext2fsP.h +4
-2-#define EXT2FS_BMAP64_BITARRAY 1 -#define EXT2FS_BMAP64_RBTREE 2 +enum ext2fs_bmap_backends { +EXT2FS_BMAP64_BITARRAY =0 , +EXT2FS_BMAP64_RBTREE , +EXT2FS_BMAP64_COUNT ,For debugging purposes, it is preferable to have an enum not contain "0" as a valid value, since that allows one to see if the bitmap type is being specified correctly, or if it is unset. Maybe
EXT2FS_BMAP64_UNSET= 0?
Good point, I'll change that.
Quoted 13 lines
lib/ext2fs/gen_bitmap64.c static void warn_bitmap(ext2fs_generic_bitmap bitmap, · line 121
Quoted 11 lines
lib/ext2fs/gen_bitmap64.c +10
-0+static char *ext2_bmap_profile_value[EXT2_BMAP_COUNT ] = { + [EXT2_GENERIC_MAP ] ="generic_bitmap" , + [EXT2_INODE_USED_MAP ] ="inode_used_map" , + [EXT2_INODE_BAD_MAP ] ="inode_bad_map" , + +const +static struct ext2_bmap_definition ext2_bmap_default[EXT2_BMAP_COUNT] = { + [EXT2_GENERIC_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"generic bitmap" }, + [EXT2_INODE_USED_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"in-use inode map" }, + [EXT2_INODE_BAD_MAP ] = {EXT2_DEFAULT_BITMAP_BACKEND ,"bad inode map" },It is cumbersome to have to update 3 places for each bitmap. Could we just get rid of ext2_bmap_profile_value[] and only use ext2_bmap_default[]? Also, the strings here have now lost their i18n for error messages.
I was thinking about merging those two structures, maybe using macros, I'll look into it. Yes, is has lost their i18n for error messages, do you have any suggestion to preserve localization with statically declared strings ?
Quoted 3 lines
Cheers, Andreas
Thanks!
-Lukas
PATCH 4/4 Add macro to enable collecting bitmap statistics
In reply to Lukas CzernerThis commit adds a new preprocessor macro BMAP_STATS, which can be defined in ext2fs.h. Setting this macro, the code for statistic collection of bitmap handling is enabled and once the bitmap shall be freed collected information is printed to the stderr.
This feature is especially useful for better understanding how e2fsprogs tools (mainly e2fsck) treats bitmaps and what bitmap backend can be most suitable for particular bitmap. Backend itself (if implemented) can provide statistics of its own as well.
I was thinking about enabling this feature simply by setting program parameter, however collecting of the statistic, even conditional, means unnecessary overhead. And since information provided is usually relevant only for e2fsprogs developers, I decided to use preprocessor macro instead.
Obviously this feature is off by default.
--- lib/ext2fs/blkmap64_ba.c | 8 +++ lib/ext2fs/blkmap64_rb.c | 82 ++++++++++++++++++++++++++++- lib/ext2fs/bmap64.h | 31 +++++++++++ lib/ext2fs/ext2fs.h | 4 ++ lib/ext2fs/gen_bitmap64.c | 126 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 248 insertions(+), 3 deletions(-)
lib/ext2fs/blkmap64_ba.c +8 -0
@@ -309,6 +309,13 @@ static void ba_clear_bmap(ext2fs_generic_bitmap bitmap) (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); } +static void ba_print_stats (ext2fs_generic_bitmap bitmap) +{ +fprintf (stderr,"%16lu Bytes used by bitarray\n" , + ((bitmap->real_end - bitmap->start) >>3 ) +1 + +sizeof (struct ext2fs_ba_private_struct )); +} +struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = { .type =EXT2FS_BMAP64_BITARRAY , .new_bmap = ba_new_bmap,
@@ -324,4 +331,5 @@ struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = { .set_bmap_range = ba_set_bmap_range, .get_bmap_range = ba_get_bmap_range, .clear_bmap = ba_clear_bmap, + .print_stats = ba_print_stats, };
lib/ext2fs/blkmap64_rb.c +80 -2
118 lines not on this page · raw message
lib/ext2fs/bmap64.h +31 -0
@@ -9,6 +9,33 @@* %End-Header% */ +struct ext2_bmap_statistics { +int type; +struct timeval created; + struct timeval destroyed;; + +unsigned long copy_count; +unsigned long resize_count; +unsigned long mark_count; +unsigned long unmark_count; +unsigned long test_count; +unsigned long mark_ext_count; +unsigned long unmark_ext_count; +unsigned long test_ext_count; +unsigned long set_range_count; +unsigned long get_range_count; +unsigned long clear_count; + +blk64_t last_marked; +blk64_t last_tested; +blk64_t mark_back; +blk64_t test_back; + +unsigned long mark_seq; +unsigned long test_seq; +}; + +struct ext2fs_struct_generic_bitmap {errcode_t magic;ext2_filsys fs;
@@ -19,6 +46,9 @@ struct ext2fs_struct_generic_bitmap {char *description;void *private;errcode_t base_error_code; +#ifdef BMAP_STATS +struct ext2_bmap_statistics stats; +#endif };#define EXT2FS_IS_32_BITMAP (bmap) \
@@ -56,6 +86,7 @@ struct ext2_bitmap_ops {errcode_t (*get_bmap_range)(ext2fs_generic_bitmap bitmap,__u64 start,size_t num,void *out);void (*clear_bmap)(ext2fs_generic_bitmap bitmap); +void (*print_stats)(ext2fs_generic_bitmap ); };extern struct ext2_bitmap_ops ext2fs_blkmap64_bitarray;
lib/ext2fs/ext2fs.h +4 -0
@@ -1113,6 +1113,10 @@ extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, void *in);/* gen_bitmap64.c */ + +/* Generate and print bitmap usage statistics */ +/* #define BMAP_STATS */ +void ext2fs_free_generic_bmap (ext2fs_generic_bitmap bmap); errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, int type, __u64 start, __u64 end,
lib/ext2fs/gen_bitmap64.c +125 -1
217 lines not on this page · raw message
Signature · 1 line
1.7.4
Re: [PATCH 4/4] Add macro to enable collecting bitmap statistics
Quoted 10 lines · Lukas Czerner
This commit adds a new preprocessor macro
BMAP_STATS, which can be defined inext2fs.h. Setting this macro, the code for statistic collection of bitmap handling is enabled and once the bitmap shall be freed collected information is printed to the stderr.This feature is especially useful for better understanding how e2fsprogs tools (mainly e2fsck) treats bitmaps and what bitmap backend can be most suitable for particular bitmap. Backend itself (if implemented) can provide statistics of its own as well.
Quoted 5 lines
I was thinking about enabling this feature simply by setting program parameter, however collecting of the statistic, even conditional, means unnecessary overhead. And since information provided is usually relevant only for e2fsprogs developers, I decided to use preprocessor macro instead.
Being able to turn this on/off at runtime without needing to recompile is pretty important. It is fine to allow it to be #ifdef out entirely, but if it is enabled it is good to be able to turn it on/off via the command-line.
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, · line 264
Quoted 7 lines
lib/ext2fs/gen_bitmap64.c +1
-1@@ -245,8 +260,8 @@ errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, retval = bitmap->bitmap_ops->new_bmap (fs, bitmap);if (retval) { -ext2fs_free_mem (&bitmap);ext2fs_free_mem (&bitmap->description); +ext2fs_free_mem (&bitmap);
This looks like a bug in the upstream code that should be submitted separately. However, I don't see this bug in my tree (it is correctly ordered already), and I don't see it being introduced by your patches... It again makes me wonder which branch these patches are against.
Quoted 17 lines
lib/ext2fs/gen_bitmap64.c +17
-0+fprintf (stderr,"\n[+] %s bitmap\n" , bmap_defs[stats->type].descr); +fprintf (stderr,"=================================================\n" ); +fprintf (stderr,"%16d type\n%16d backend\n" , + stats->type, bmap_defs[stats->type].backend); +fprintf (stderr,"%16d bits long\n" , + bitmap->real_end - bitmap->start); +fprintf (stderr,"%16lu copy_bmap\n%16lu resize_bmap\n" , + stats->copy_count, stats->resize_count); +fprintf (stderr,"%16lu mark bmap\n%16lu unmark_bmap\n" , + stats->mark_count, stats->unmark_count); +fprintf (stderr,"%16lu test_bmap\n%16lu mark_bmap_extent\n" , + stats->test_count, stats->mark_ext_count); +fprintf (stderr,"%16lu unmark_bmap_extent\n" +"%16lu test_clear_bmap_extent\n" , + stats->unmark_ext_count, stats->test_ext_count); +fprintf (stderr,"%16lu set_bmap_range\n%16lu set_bmap_range\n" , + stats->set_range_count, stats->get_range_count);
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, · line 325
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c +10
-0+fprintf (stderr,"%16lu clear_bmap\n%16lu contiguous bit test (%.2f%)\n" , + stats->clear_count, stats->test_seq, test_seq_perc); +fprintf (stderr,"%16lu contiguous bit mark (%.2f%)\n" +"%16lu bits tested backwards (%.2f%)\n" , + stats->mark_seq, mark_seq_perc, + stats->test_back, test_back_perc); +fprintf (stderr,"%16lu bits marked backwards (%.2f%)\n" +"%16.2f seconds in use\n" , + stats->mark_back, mark_back_perc, inuse); +}
This should include the amount of memory used by the bitmap, which is one of the most important stats for this code.
Quoted 142 lines
(quoted diff) +2
-0+#endif +void
ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap){ if (!bmap)lib/ext2fs/gen_bitmap64.c +53
-0@@ -267,6 +338,16 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap)if (!EXT2FS_IS_64_BITMAP (bmap))return ; +#ifdef BMAP_STATS +if (gettimeofday (&bmap->stats.destroyed, + (struct timezone *)NULL ) ==-1 ) { +perror ("gettimeofday" ); +return ; + } +ext2fs_print_bmap_statistics (bmap); + bmap->bitmap_ops->print_stats (bmap); +#endif + bmap->bitmap_ops->free_bmap (bmap);if (bmap->description) {@@ -300,6 +381,17 @@ errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,return retval;memset (new_bmap,0 ,sizeof (struct ext2fs_struct_generic_bitmap )); + +#ifdef BMAP_STATS + src->stats.copy_count++; +if (gettimeofday (&new_bmap->stats.created, + (struct timezone *)NULL ) ==-1 ) { +perror ("gettimeofday" ); +return 1 ; + } + new_bmap->stats.type = src->stats.type; +#endif +/* Copy all the high-level parts over */ new_bmap->magic = src->magic; new_bmap->fs = src->fs;@@ -346,6 +438,8 @@ errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, resize_count); +return bmap->bitmap_ops->resize_bmap (bmap, new_end, new_real_end); }@@ -432,6 +526,15 @@ int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +#ifdef BMAP_STATS +if (arg == bitmap->stats.last_marked +1 ) + bitmap->stats.mark_seq++; +if (arg < bitmap->stats.last_marked) + bitmap->stats.mark_back++; + bitmap->stats.last_marked = arg; + bitmap->stats.mark_count++; +#endif +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_MARK_ERROR , arg);return 0 ;@@ -458,6 +561,8 @@ int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +INC_STAT (bitmap, unmark_count); +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_UNMARK_ERROR , arg);return 0 ;@@ -484,6 +589,15 @@ int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +#ifdef BMAP_STATS + bitmap->stats.test_count++; +if (arg == bitmap->stats.last_tested +1 ) + bitmap->stats.test_seq++; +if (arg < bitmap->stats.last_tested) + bitmap->stats.test_back++; + bitmap->stats.last_tested = arg; +#endif +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_TEST_ERROR , arg);return 0 ;@@ -512,6 +626,8 @@ errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, set_range_count); +return bmap->bitmap_ops->set_bmap_range (bmap, start, num, in); }@@ -535,6 +651,8 @@ errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, get_range_count); +return bmap->bitmap_ops->get_bmap_range (bmap, start, num, out); }@@ -606,6 +724,8 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, test_ext_count); +return bmap->bitmap_ops->test_clear_bmap_extent (bmap, block, num); }@@ -628,6 +748,8 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return ; +INC_STAT (bmap, mark_ext_count); +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_MARK , block, bmap->description);@@ -656,6 +778,8 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return ; +INC_STAT (bmap, unmark_ext_count); +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_UNMARK , block, bmap->description);Signature · 6 lines
1.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers, Andreas
Re: [PATCH 4/4] Add macro to enable collecting bitmap statistics
Quoted 11 lines · Andreas Dilger
Quoted 10 lines · Lukas Czerner
This commit adds a new preprocessor macro
BMAP_STATS, which can be defined inext2fs.h. Setting this macro, the code for statistic collection of bitmap handling is enabled and once the bitmap shall be freed collected information is printed to the stderr.This feature is especially useful for better understanding how e2fsprogs tools (mainly e2fsck) treats bitmaps and what bitmap backend can be most suitable for particular bitmap. Backend itself (if implemented) can provide statistics of its own as well.
Quoted 7 lines
Quoted 5 lines
I was thinking about enabling this feature simply by setting program parameter, however collecting of the statistic, even conditional, means unnecessary overhead. And since information provided is usually relevant only for e2fsprogs developers, I decided to use preprocessor macro instead.
Being able to turn this on/off at runtime without needing to recompile is pretty important. It is fine to allow it to be #ifdef out entirely, but if it is enabled it is good to be able to turn it on/off via the command-line.
The downside of this is that bitmaps are used by many tools, so it would require change in all of those tools to use command-line option.
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, · line 264
Quoted 8 lines
lib/ext2fs/gen_bitmap64.c +1
-1@@ -245,8 +260,8 @@ errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, retval = bitmap->bitmap_ops->new_bmap (fs, bitmap);if (retval) { -ext2fs_free_mem (&bitmap);ext2fs_free_mem (&bitmap->description); +ext2fs_free_mem (&bitmap);This looks like a bug in the upstream code that should be submitted separately. However, I don't see this bug in my tree (it is correctly ordered already), and I don't see it being introduced by your patches... It again makes me wonder which branch these patches are against.
I can see this bug in master branchgit://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
so I'll send it separately.
Quoted 22 lines
Quoted 22 lines
lib/ext2fs/gen_bitmap64.c +21
-0+fprintf (stderr,"\n[+] %s bitmap\n" , bmap_defs[stats->type].descr); +fprintf (stderr,"=================================================\n" ); +fprintf (stderr,"%16d type\n%16d backend\n" , + stats->type, bmap_defs[stats->type].backend); +fprintf (stderr,"%16d bits long\n" , + bitmap->real_end - bitmap->start); +fprintf (stderr,"%16lu copy_bmap\n%16lu resize_bmap\n" , + stats->copy_count, stats->resize_count); +fprintf (stderr,"%16lu mark bmap\n%16lu unmark_bmap\n" , + stats->mark_count, stats->unmark_count); +fprintf (stderr,"%16lu test_bmap\n%16lu mark_bmap_extent\n" , + stats->test_count, stats->mark_ext_count); +fprintf (stderr,"%16lu unmark_bmap_extent\n" +"%16lu test_clear_bmap_extent\n" , + stats->unmark_ext_count, stats->test_ext_count); +fprintf (stderr,"%16lu set_bmap_range\n%16lu set_bmap_range\n" , + stats->set_range_count, stats->get_range_count); +fprintf (stderr,"%16lu clear_bmap\n%16lu contiguous bit test (%.2f%)\n" , + stats->clear_count, stats->test_seq, test_seq_perc); + fprintf(stderr, "%16lu contiguous bit mark (%.2f%)\n" + "%16lu bits tested backwards (%.2f%)\n",
Quoted 8 lines
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, · line 325
Quoted 6 lines
lib/ext2fs/gen_bitmap64.c +6
-0+ stats->mark_seq, mark_seq_perc, + stats->test_back, test_back_perc); +fprintf (stderr,"%16lu bits marked backwards (%.2f%)\n" +"%16.2f seconds in use\n" , + stats->mark_back, mark_back_perc, inuse); +}This should include the amount of memory used by the bitmap, which is one of the most important stats for this code.
Yes, it is the most important, however at this level we can not know this kind of bitmap backend specific information. That's why there is new bitmap operation print_stats() which is called right after ext2fs_print_bmap_statistics() and should provide additional bitmap backed specific information. Rbtree and bitarray does that with this commit.
Quoted 139 lines
Quoted 139 lines
(quoted diff) +2
-0+#endif +void
ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap){ if (!bmap)lib/ext2fs/gen_bitmap64.c +53
-0@@ -267,6 +338,16 @@ void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap)if (!EXT2FS_IS_64_BITMAP (bmap))return ; +#ifdef BMAP_STATS +if (gettimeofday (&bmap->stats.destroyed, + (struct timezone *)NULL ) ==-1 ) { +perror ("gettimeofday" ); +return ; + } +ext2fs_print_bmap_statistics (bmap); + bmap->bitmap_ops->print_stats (bmap); +#endif + bmap->bitmap_ops->free_bmap (bmap);if (bmap->description) {@@ -300,6 +381,17 @@ errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,return retval;memset (new_bmap,0 ,sizeof (struct ext2fs_struct_generic_bitmap )); + +#ifdef BMAP_STATS + src->stats.copy_count++; +if (gettimeofday (&new_bmap->stats.created, + (struct timezone *)NULL ) ==-1 ) { +perror ("gettimeofday" ); +return 1 ; + } + new_bmap->stats.type = src->stats.type; +#endif +/* Copy all the high-level parts over */ new_bmap->magic = src->magic; new_bmap->fs = src->fs;@@ -346,6 +438,8 @@ errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, resize_count); +return bmap->bitmap_ops->resize_bmap (bmap, new_end, new_real_end); }@@ -432,6 +526,15 @@ int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +#ifdef BMAP_STATS +if (arg == bitmap->stats.last_marked +1 ) + bitmap->stats.mark_seq++; +if (arg < bitmap->stats.last_marked) + bitmap->stats.mark_back++; + bitmap->stats.last_marked = arg; + bitmap->stats.mark_count++; +#endif +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_MARK_ERROR , arg);return 0 ;@@ -458,6 +561,8 @@ int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +INC_STAT (bitmap, unmark_count); +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_UNMARK_ERROR , arg);return 0 ;@@ -484,6 +589,15 @@ int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,if (!EXT2FS_IS_64_BITMAP (bitmap))return 0 ; +#ifdef BMAP_STATS + bitmap->stats.test_count++; +if (arg == bitmap->stats.last_tested +1 ) + bitmap->stats.test_seq++; +if (arg < bitmap->stats.last_tested) + bitmap->stats.test_back++; + bitmap->stats.last_tested = arg; +#endif +if ((arg < bitmap->start) || (arg > bitmap->end)) {warn_bitmap (bitmap,EXT2FS_TEST_ERROR , arg);return 0 ;@@ -512,6 +626,8 @@ errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, set_range_count); +return bmap->bitmap_ops->set_bmap_range (bmap, start, num, in); }@@ -535,6 +651,8 @@ errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, get_range_count); +return bmap->bitmap_ops->get_bmap_range (bmap, start, num, out); }@@ -606,6 +724,8 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return EINVAL ; +INC_STAT (bmap, test_ext_count); +return bmap->bitmap_ops->test_clear_bmap_extent (bmap, block, num); }@@ -628,6 +748,8 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return ; +INC_STAT (bmap, mark_ext_count); +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_MARK , block, bmap->description);@@ -656,6 +778,8 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,if (!EXT2FS_IS_64_BITMAP (bmap))return ; +INC_STAT (bmap, unmark_ext_count); +if ((block < bmap->start) || (block+num-1 > bmap->end)) {ext2fs_warn_bitmap (EXT2_ET_BAD_BLOCK_UNMARK , block, bmap->description);Signature · 1 line
1.7.4
Quoted 8 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlCheers, Andreas
Thanks!
-Lukas