mkfs.gfs2: Free unnecessary cached pages, disable readahead
PATCH 1/3 mkfs.gfs2: Free unnecessary cached pages, disable readahead
With a 300T file system, cached pages built up quite heavily and could be left over from previous io on the device. Use POSIX_FADV_DONTNEED where appropriate.
Also, readahead isn't required as mkfs.gfs2 mainly writing full block ranges at unpredictable locations so use POSIX_FADV_RANDOM to minimise the overhead from that.
--- gfs2/mkfs/main_mkfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
gfs2/mkfs/main_mkfs.c +7 -1
@@ -817,6 +817,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_optsgfs2_progress_update (&progress, (sdp->rgrps)); }gfs2_progress_close (&progress,_ ("Done\n" )); +posix_fadvise (sdp->device_fd,0 , sdp->fssize * sdp->bsize,POSIX_FADV_DONTNEED );return 0 ; }
@@ -909,6 +910,11 @@ static void open_dev(struct mkfs_dev *dev, int withprobe)exit (1 ); } +/* Freshen up the cache */ +posix_fadvise (dev->fd,0 ,0 ,POSIX_FADV_DONTNEED ); +/* Turn off readahead, we're just writing new blocks */ +posix_fadvise (dev->fd,0 ,0 ,POSIX_FADV_RANDOM ); + error =fstat (dev->fd, &dev->stat);if (error <0 ) {perror (dev->path);
@@ -1075,7 +1081,7 @@ int main(int argc, char *argv[])perror (opts.dev.path);exit (EXIT_FAILURE ); } - +posix_fadvise (opts.dev.fd,0 ,0 ,POSIX_FADV_DONTNEED ); error =close (opts.dev.fd);if (error){perror (opts.dev.path);
Signature · 1 line
2.9.3
PATCH 2/3 mkfs.gfs2: Fix resource group alignment issue
Make sure the resource groups created when allocating the journals have an aligned length to avoid subsequent resource groups start addresses getting misaligned. This can cause read-modify-write issues during mkfs and likely in other situations, harming performance.
Test case included.
--- gfs2/mkfs/main_mkfs.c | 1 + tests/mkfs.at | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
gfs2/mkfs/main_mkfs.c +1 -0
@@ -721,6 +721,7 @@ static int place_journals(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_oif (mkfs_journals ==NULL )return 1 ; *rgaddr =lgfs2_rgrp_align_addr (rgs, sdp->sb_addr +1 ); + rgsize =lgfs2_rgrp_align_len (rgs, rgsize);for (j =0 ; j < opts->journals; j++) {int result;
tests/mkfs.at +14 -0
@@ -102,6 +102,13 @@ AT_CHECK([$GFS_MKFS -p lock_dlm -t "financial_cluster:this_time_we_test_fs_namin GFS_FSCK_CHECK([$GFS_MKFS -p lock_dlm -t "a_really_long_named_cluster_here:concurrently_lets_check_fs_len" $GFS_TGT]) AT_CLEANUP +# -o test_topology order: +# alignment_offset, +# logical_sector_size, +# minimum_io_size, +# optimal_io_size, +# physical_sector_size + AT_SETUP([Device i/o limits handling]) AT_KEYWORDS(mkfs.gfs2 mkfs) AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=0:0:0:0:0 $GFS_TGT], 0, [ignore], [ignore])
@@ -109,3 +116,10 @@ AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=7168:512:0:33553920:512 $GFS AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=7168:512:8192:33553920:512 $GFS_TGT], 0, [ignore], [Warning: device is not properly aligned. This may harm performance. ]) AT_CLEANUP + +AT_SETUP([Resource group alignment]) +AT_KEYWORDS(mkfs.gfs2 mkfs) +AT_CHECK([$GFS_MKFS -p lock_nolock -o test_topology=0:512:65536:393216:512 $GFS_TGT], 0, [ignore], [ignore]) +# Check rgrp alignment to minimum_io_size: 65536 / 4096 == 16 +AT_CHECK([gfs2_edit -p rindex $GFS_TGT | grep ri_addr | awk '{print $2, $2 % 16; if ($2 % 16 != 0) { exit 1 }}'], 0, [ignore], [ignore]) +AT_CLEANUP
Signature · 1 line
2.9.3
PATCH 3/3 libgfs2: Issue one write per rgrp when creating them
In reply to Andrew PricePreviously mkfs.gfs2 issued a write for each block of an rgrp. On systems where the page size is much larger than the block size, this incurs a read-modify-write overhead and can slow down mkfs.gfs2 considerably. Instead, allocate a single, aligned buffer for the bitmap blocks and write them all in one go.
On a system with 64K pages and a 300TB block device, this speeds up mkfs.gfs2 from over an hour to less than 3 minutes.
--- gfs2/libgfs2/rgrp.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-)
gfs2/libgfs2/rgrp.c +32 -19
@@ -11,6 +11,7 @@#include "rgrp.h" #define RG_SYNC_TOLERANCE 1000 +#define ROUND_UP (N ,S ) ((((N) + (S) - 1) / (S)) * (S))static void compute_bitmaps (lgfs2_rgrp_t rg,const unsigned bsize) {
@@ -109,23 +110,30 @@ struct rgrp_tree *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk)int lgfs2_rgrp_bitbuf_alloc (lgfs2_rgrp_t rg) {struct gfs2_sbd *sdp = rg->rgrps->sdp; +struct gfs2_buffer_head *bhs; +size_t len = rg->ri.ri_length * sdp->bsize; +unsigned long io_align = sdp->bsize;unsigned i;char *bufs; - bufs =calloc (rg->ri.ri_length,sizeof (struct gfs2_buffer_head ) + sdp->bsize); -if (bufs ==NULL ) +if (rg->rgrps->align >0 ) { + len =ROUND_UP (len, rg->rgrps->align * sdp->bsize); + io_align = rg->rgrps->align_off * sdp->bsize; + } + bhs =calloc (rg->ri.ri_length,sizeof (struct gfs2_buffer_head )); +if (bhs ==NULL )return 1 ; - rg->bits[0 ].bi_bh = (struct gfs2_buffer_head *)bufs; - rg->bits[0 ].bi_bh->iov.iov_base = (char *)(rg->bits[0 ].bi_bh +1 ); - rg->bits[0 ].bi_bh->iov.iov_len = sdp->bsize; - rg->bits[0 ].bi_bh->b_blocknr = rg->ri.ri_addr; - rg->bits[0 ].bi_bh->sdp = sdp; +if (posix_memalign ((void **)&bufs, io_align, len) !=0 ) { + errno =ENOMEM ; +free (bhs); +return 1 ; + } +memset (bufs,0 , len); -for (i =1 ; i < rg->ri.ri_length; i++) { -char *nextbuf = rg->bits[i -1 ].bi_bh->b_data + sdp->bsize; - rg->bits[i].bi_bh = (struct gfs2_buffer_head *)(nextbuf); - rg->bits[i].bi_bh->iov.iov_base = (char *)(rg->bits[i].bi_bh +1 ); +for (i =0 ; i < rg->ri.ri_length; i++) { + rg->bits[i].bi_bh = bhs + i; + rg->bits[i].bi_bh->iov.iov_base = bufs + (i * sdp->bsize); rg->bits[i].bi_bh->iov.iov_len = sdp->bsize; rg->bits[i].bi_bh->b_blocknr = rg->ri.ri_addr + i; rg->bits[i].bi_bh->sdp = sdp;
@@ -143,6 +151,7 @@ int lgfs2_rgrp_bitbuf_alloc(lgfs2_rgrp_t rg)void lgfs2_rgrp_bitbuf_free (lgfs2_rgrp_t rg) {unsigned i; +free (rg->bits[0 ].bi_bh->iov.iov_base);free (rg->bits[0 ].bi_bh);for (i =0 ; i < rg->ri.ri_length; i++) rg->bits[i].bi_bh =NULL ;
@@ -618,7 +627,7 @@ lgfs2_rgrp_t lgfs2_rgrps_append(lgfs2_rgrps_t rgs, struct gfs2_rindex *entry)*/ int lgfs2_rgrp_write (int fd,const lgfs2_rgrp_t rg) { -int ret =0 ; +struct gfs2_sbd *sdp = rg->rgrps->sdp;unsigned int i;const struct gfs2_meta_header bmh = { .mh_magic =GFS2_MAGIC ,
@@ -626,25 +635,29 @@ int lgfs2_rgrp_write(int fd, const lgfs2_rgrp_t rg) .mh_format = GFS2_FORMAT_RB, };int freebufs =0 ; +ssize_t ret; +size_t len;if (rg->bits[0 ].bi_bh ==NULL ) { freebufs =1 ;if (lgfs2_rgrp_bitbuf_alloc (rg) !=0 )return -1 ; } -gfs2_rgrp_out (&rg->rg, rg->bits[0 ].bi_bh->b_data); - ret =bwrite (rg->bits[0 ].bi_bh); - -for (i =1 ; ret ==0 && i < rg->ri.ri_length; i++) { +for (i =1 ; i < rg->ri.ri_length; i++)gfs2_meta_header_out (&bmh, rg->bits[i].bi_bh->b_data); - ret =bwrite (rg->bits[i].bi_bh); - } + + len = sdp->bsize * rg->ri.ri_length; +if (rg->rgrps->align >0 ) + len =ROUND_UP (len, rg->rgrps->align * sdp->bsize); + + ret =pwrite (sdp->device_fd, rg->bits[0 ].bi_bh->b_data, len, + rg->bits[0 ].bi_bh->b_blocknr * sdp->bsize);if (freebufs)lgfs2_rgrp_bitbuf_free (rg); -return ret; +return ret == len ?0 :-1 ; }lgfs2_rgrp_t lgfs2_rgrp_first (lgfs2_rgrps_t rgs)
Signature · 1 line
2.9.3
PATCH 1/3 mkfs.gfs2: Free unnecessary cached pages, disable readahead
In reply to Andrew Price----- Original Message -----
| With a 300T file system, cached pages built up quite heavily and could | be left over from previous io on the device. Use POSIX_FADV_DONTNEED | where appropriate. | | Also, readahead isn't required as mkfs.gfs2 mainly writing full block | ranges at unpredictable locations so use POSIX_FADV_RANDOM to minimise | the overhead from that. | | Signed-off-by: Andrew Price <[email protected]>
Hi Andy,
Looks good. ACK to the series.
Regards,
Bob Peterson
Red Hat File Systems