gfs2_edit savemeta: Don't read rgrps twice
PATCH 1/1 gfs2_edit savemeta: Don't read rgrps twice
By the time savemeta() is called the rindex has already been read into memory, and before savemeta() processes each resource group it calls gfs2_rgrp_read() to read in the rgrp header. It frees the rgrp once it's done with it.
Strangely, before processing the resource groups, savemeta() reads the superblock a second time and calls ri_update() which reads the rindex again, as well as reading in every rgrp header to be kept in memory for the duration. This caused high memory usage and a noticeable performance reduction when saving metadata of large file systems.
To solve these problems, this patch removes the code which re-reads the superblock, rindex and the rgrps. The code which reads the rindex has been reorganised for clarity and the sbd.fssize field is now set properly at that point.
With this patch, using a large fs, I'm seeing improvements similar to:
Before: 43:36.12elapsed 10822268maxresident k After: 28:44.67elapsed 226980maxresident k
--- gfs2/edit/hexedit.c | 15 ++++++++++++-- gfs2/edit/savemeta.c | 58 +++++++--------------------------------------------- tests/edit.at | 4 ++-- 3 files changed, 22 insertions(+), 55 deletions(-)
gfs2/edit/hexedit.c +13 -2
@@ -966,8 +966,6 @@ static int block_has_extended_info(void)/* ------------------------------------------------------------------------ */ static void read_superblock (int fd) { -int count, sane; - sbd1 = (struct gfs_sb *)&sbd.sd_sb;ioctl (fd,BLKFLSBUF ,0 );memset (&sbd,0 ,sizeof (struct gfs2_sbd ));
@@ -1033,9 +1031,20 @@ static void read_superblock(int fd)gfs2_lookupi (sbd.master_dir,"rindex" ,6 , &sbd.md.riinode); } } +} + +static int read_rindex (void ) +{ +struct gfs2_rindex *ri; +int count, sane; + sbd.fssize = sbd.device.length;if (sbd.md.riinode)/* If we found the rindex */ rindex_read (&sbd,0 , &count, &sane); + + ri = &((struct rgrp_tree *)osi_last (&sbd.rgtree))->ri; + sbd.fssize = ri->ri_data0 + ri->ri_data; +return 0 ; }/* ------------------------------------------------------------------------ */
@@ -2539,6 +2548,8 @@ int main(int argc, char *argv[]) max_block =lseek (fd,0 ,SEEK_END ) / sbd.bsize;read_superblock (fd); +if (read_rindex ()) +exit (-1 ); max_block =lseek (fd,0 ,SEEK_END ) / sbd.bsize;if (sbd.gfs1) edit_row[GFS2_MODE ]++;
gfs2/edit/savemeta.c +7 -51
92 lines not on this page · raw message
tests/edit.at +2 -2
@@ -6,8 +6,8 @@ AT_KEYWORDS(gfs2_edit edit) GFS_TGT_REGEN AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore]) AT_CHECK([gfs2_edit savemeta $GFS_TGT test.meta > savemeta.log], 0, [ignore], [ignore]) -AT_CHECK([head -2 savemeta.log], 0, [There are 2621440 blocks of 4096 bytes in the destination device. -Reading resource groups...Done. File system size: 4.1023GB +AT_CHECK([head -2 savemeta.log], 0, [There are 1310718 blocks of 4096 bytes in the filesystem. +Filesystem size: 4.1023GB ], [ignore]) GFS_TGT_REGEN AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
Signature · 1 line
1.9.3