Skip to contentSkip to conversation

ext2resize

linux-lvm Admin 3 participants 3 messages Jun 30, 1999 – Jul 5, 1999

lore
Share & tools
lore

Admin

author
#0 lore raw
Quoted 11 lines
Quoted 9 lines · Lennert Buytenhek

Correct. ext2 is divided into block groups, which are 8mb big when using 1k blocks. A block group looks like this:

1 block superblock
? blocks group descriptor table
1 block block bitmap
1 block inode bitmap
? blocks inode table
? blocks data blocks (the bulk of the group)

Quoted 7 lines

I was emailing with Mike Field about this, and according to the definition of ext2_super_block in ext2_fs.h, it should be possible to set the location of the block bitmap, inode bitmap, and inode table anywhere in the group, and have the datablocks follow. If you set the pointers to these structures to start, say, 33 blocks into the group, this would allow you to grow the GDT to handle an 8GB filesystem before a reorg (block moving) is necessary.

I mailed with Mike about this too. He said: "First guess is that is that it would require one more field in the superblock - how many blocks are reserved for group descriptors....". I replied with: "In the group descriptor
table there are pointers to the start of the block/inode bitmap and inode table for each group. So you don't have to put any info in the superblock. You can just leave free blocks between the gd table and the block bitmap. I guess. But ext2 works in mysterious ways.... :-)"

He said: "Still, reserving extra blocks would only be a hack..."

I replied: "Depending on who you talk to of course. :-) The max. number of groups for ext2 is 1024 I believe. One extra gd block per block gives you room for 32*8=256mb expansion (assuming 1kb blocks). This will cost you at most 1 meg of reserved gd blocks. Seems like a fair price. The max. number of gd blocks is 32. So doing this when making an fs will cost you at most 32*1024 blocks, which is 32mb with 1k blocks. On modern drives, you'll probably not even notice a 32mb loss. Unless you have a lot of partitions, of course...."

Then I said: "You could always throw the fs down, free the soon-to- be-needed gs blocks, do some moves, and mount it again, all very quickly. Then you could do the add-another-group thingy. You don't need to do the whole operation while unmounted. (Hey, resizing mounted fs'es is tricky anyway, so why not be extra tricky.... :-)"

Quoted 8 lines

[time passes]
I looked into the code in e2fsprogs/lib/ext2fs (openfs.c, initialize.c) and the kernel (fs/ext2/balloc.c). It looks like, while an ext2 reader will only (currently) calculate desc_blocks based on the number of group descriptors and the block size, it will gladly use the values supplied in the superblock for the location of the block bitmap, inode bitmap, inode table, and the number of data blocks - leaving a "gap" after the GDT for future growth (NB - need to check e2fsck for what it does). If

e2fsck prolly does the same. Make a small (~64mb) filesystem and mkfs it with the sparse superblocks flag on. Then run dumpe2fs on it. This will bring enlightenment w.r.t. metadata pointers.

Quoted 5 lines

you "fix" initialize.c to have a larger number of desc_blocks than the minimum needed, existing kernels and e2fsck should work OK with this, which is a big plus. Your ext2_resize could also do this without actually "growing" the filesystem - just get it ready to do so if needed.

I suggested Mike putting the 'reserving extra blocks' feature in mke2fs.

Quoted 3 lines

mke2fs which says "start writing X groups into the FS". The only real issue is the last group, which appears to be able to NOT have a superblock or GDT, which is a BIG problem...

Huh? I thought a group must _always_ have an sb, gd table, block bitmap, inode bitmap and inode table. Or am I wrong here?

Quoted 10 lines
Quoted 4 lines

This is what ext2resize basically does (when enlarging). But you'll need a way to get this through to the kernel (it has it's own superblock copy). I haven't really looked at the volume patch very well.

As I suggested to Mike, it may be desirable to have two different implementations - an online resize which will not do much (if any) block moving, and can only resize up to the next 256MB boundary (or pre-allocated GDT size), and an offline resize which will do things like renumber inode and data blocks, remove inodes, add GDT blocks, etc.

So: add a flag that will cancel the resize if the gd table growth needs to move blocks/metadata?

Quoted 4 lines

Mike had also suggested that when we are doing a major FS (offline) reorg, we could start removing blocks from the inode table instead of data blocks as there are usually free inodes in each group, but not always data blocks...

I think it's not worth the complexity. First of all all your inodes will be renumbered. You'll need a full directory scan-and-replace for inodes which is very crash-sensitive. On the other hand, relocating a block is atomic.

Quoted 6 lines
Quoted 1 line

You can remount an fs RO, ext2resize it, and remount it RW methinks.

This would likely break many programs, as they would fail for the time it is in RO mode. A more pleasant solution is to only allow growth to a pre-determined limit online (with a kernel lock), and then force the user to unmount the FS to do block shuffling.

Yes, well, the remounting it RO and then remounting it RW will probably not work, since (as Rolf has already mentioned) the kernel will not reread metadata upon a remount.

Quoted 8 lines
Quoted 5 lines

About shrinking an existing fs: this would be even messier. (Involves moving inodes around, and those inodes might be in core. Et cetera. Hell on earth :-) But growing an fs might be messy too, because of the growing group descriptor table.

I don't think shrinking a FS online is as big a need as growing it, and this can be left for a utility that works when the FS is unmounted.

Yep.

Quoted 1 line

Cheers, Andreas

Lennert Buytenhek
<[email protected]>

#1 lore raw
Quoted 9 lines · Lennert Buytenhek

I mailed with Mike about this too. He said: "First guess is that is that it would require one more field in the superblock - how many blocks are reserved for group descriptors....". I replied with: "In the group descriptor table there are pointers to the start of the block/inode bitmap and inode table for each group. So you don't have to put any info in the superblock. You can just leave free blocks between the gd table and the block bitmap. I guess. But ext2 works in mysterious ways.... :-)"

He said: "Still, reserving extra blocks would only be a hack..."

I agree that reserving GDT blocks would be a small hack for v0 of ext2, but we could add a "COMPATIBLE" extension to v1 of ext2 that gave the number of GDT blocks reserved. Also, since the v1 sparse superblock filesystems leave a gap between the structures, there should not be a real problem. We just have to make sure that we agree (for example) that all the blocks from the start of the group to the block bitmap are reserved for the GDT. This is not a big strech, since this is already how v0 ext2 filesystems are.

If we really don't want to do this (I haven't seen any reason not to, however), then we could always allocate the initial datablocks in each group to a reserved inode (7 is unused in my ext2_fs.h) so they aren't available to any files. Then we don't need to worry about moving user data around when we want to resize.

Quoted 7 lines

One extra gd block per block gives
you room for 32*8=256mb expansion (assuming 1kb blocks). This will cost you at most 1 meg of reserved gd blocks. Seems like a fair price. The max. number of gd blocks is 32. So doing this when making an fs will cost you at most 32*1024 blocks, which is 32mb with 1k blocks. On modern drives, you'll probably not even notice a 32mb loss. Unless you have a lot of partitions, of course...."

The good news is that the "reserved" GDT blocks are a constant percentage of the filesystem size, as you are not allocating GDT blocks in the groups that don't exist yet.

Quoted 2 lines

I suggested Mike putting the 'reserving extra blocks' feature in mke2fs.

I've worked on a change to mke2fs to give it a new parameter (-e) which will set the "expansion limit" in a new FS. It needs a change to libext2fs in initialize.c to do a "set_field(desc_blocks,...)" to take the set value or fill it in with the default value. One issue I had was whether the -e parameter should be in blocks/GDT (easier to code) or total FS blocks (easier for a user to understand)?

Quoted 2 lines

Huh? I thought a group must _always_ have an sb, gd table, block bitmap, inode bitmap and inode table. Or am I wrong here?

If you look at alloc_tables.c in libext2fs, there are several parts like

        start_blk = group_blk + 3 + fs->desc_blocks;
        if (start_blk > last_blk)
                start_blk = group_blk;

I take this to mean that if there isn't enough room for the superblock, GDT, inode bitmap, and block bitmap, then don't put one in the last group. The last group will start directly with the inode table. However, this is easily "fixed" so that the last group will require a complete set of these tables, or it won't be allocated and the FS size will be reduced.

The savings in doing this the old way was very small anyways - for a 256MB or smaller FS, it was the difference between maybe 3 datablocks at the most, increasing by 1 datablock for each 256MB.

start_blk = group_blk + 3 + 1 > last_blk

We need one of the remaining 4 blocks for the inode_table, and only 3 blocks left. This is hardly worth the savings compared to the difficulty in moving all of the blocks around when we want to expand a filesystem.

Quoted 2 lines

So: add a flag that will cancel the resize if the gd table growth needs to move blocks/metadata?

I don't think it should be a flag. If the FS is mounted and we need to move blocks, then cancel the operation automatically. It shouldn't be a problem to move blocks if the filesystem is unmounted.

Cheers, Andreas

Signature · 4 lines
Andreas Dilger  University of Calgary \ "If a man ate a pound of pasta and
                Micronet Research Group \ a pound of antipasto, would they
Dept of Electrical & Computer Engineering \  cancel out, leaving him still
http://www-mddsp.enel.ucalgary.ca/People/adilger/      hungry?" -- Dogbert
#2 lore raw

Hi,

Quoted 7 lines · Andreas Dilger

I agree that reserving GDT blocks would be a small hack for v0 of ext2, but we could add a "COMPATIBLE" extension to v1 of ext2 that gave the number of GDT blocks reserved. Also, since the v1 sparse superblock filesystems leave a gap between the structures, there should not be a real problem. We just have to make sure that we agree (for example) that all the blocks from the start of the group to the block bitmap are reserved for the GDT. This is not a big strech, since this is already how v0 ext2 filesystems are.

If you're going to be moving user data around anyway (and you have to be able to do this for the shrink case anyway), then relocating the inode/bitmap blocks is really not that much harder.

--Stephen