Skip to contentSkip to conversation

Keeping swap in the middle of the disk

linux-lvm Andreas Dilger 3 participants 4 messages Jan 26, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · Chris Wilson

I've just bought a pair of 46 gig UDMA 100 IDE disks and I'd like to stripe data across them for speed. I'd also like to have some swap space. Naturally I'd like this too to be fast, the linux kernel already stripes data across swap partitions with the same priority - so problem solved, one partition on each drive. Now the problem - in order to keep seek times down for the swap partitions, it's got to sit in the middle of the disk (so average distance from the disk-head to the swap partition is low).

If you are expecting to swap a lot on this system, you are tuning for the wrong thing. To improve performance far more than "correct swap placement", you should get more RAM instead.

Quoted 4 lines

Each disk is partitioned as follows:

hda1 hda2 hda3 hda4
<32 meg> <22 gig> <256 meg> <22 gig>

So what you do is:

    pvcreate /dev/hd[ac][234]

then create 1 or 2 volume groups. You may want 2 VGs because you can't have different PE sizes within a single VG, and for small partitions you may end up losing a fair percent of disk space if you make the PEs large enough for your other partitions. So continuing:

vgcreate -s 1M vgswap /dev/hd[ac]3
vgcreate -s 32M vgdata /dev/hd[ac][24]

lvcreate -n lvswap1 -l <approx 255 PEs, see pvdisplay > vgswap /dev/hda3 lvcreate -n lvswap2 -l <approx 255 PEs, see pvdisplay > vgswap /dev/hdc3

Let the kernel do the swap striping. This way you have some flexibility in case you have too much swap space you can remove one of the swaps, or if you need more, you can add it in (can't do that with LVM without adding #disks == #stipes to the swap LV or performance will again suck).

lvcreate -n lvbig -i 2 -I 64k -L <whatever> vgdata /dev/hd[ac]2

I would suggest NOT creating the whole thing as a single LV and putting a filesystem on it. That _severely_ limits your flexibility, and chances are you don't need 88GB of space all at once anyways. When you need more space, simply extend the LV and resize the filesystem. Reiserfs can do that while it is mounted. You could also create another LV+filesystem and mount it somewhere else, which is usually more convenient. Don't get stuck in the old "DOS partition" mindframe where you need to set everything up at the beginning. With LVM you can change your mind if you want, and you don't have to "use" all of your PEs when you start, save some for later.

You should specify the stripes to be on separate disks, like above, otherwise your performance will suck really badly. I'm not sure you will get a performance gain even with striping. You may also want to run bonnie++ with and without striping, and try different stripe sizes (maybe up to 256k) and to see what is good. If you reported your performance back to us, it would be even better.

lvextend -n lvbig -i 2 -I 64k -L <whatever> vgdata /dev/hd[ac]4

If you DO want to make a huge 88GB filesystem (against all common sense), you should do it in 2 steps (filling the first two partitions, and then moving on to the second partitions) so that you are sure the stripes are across disks, instead of across partitions in the same disk. I'm not sure whether the LVM user tools check this (or even can).

Quoted 4 lines

The two drives are hda and hdc. I'd hoped it might be possible to create a Logical Volume from hda2 and hda4, and one from hdc2 and hdc4. Then use them as Physical Volumes to create an 88gig Logical Volume for my reiser filesystem.

There is no reason whatsoever to make an LV into a PV. You would just be adding more overhead to the system. You can use the PEs from a PV in any way you want (although the current LVM doesn't let you specify this very well). In AIX, you can give a "map" to lvcreate and it will use only specific PEs, so you wouldn't need to do the hokey partitioning to get swap in the middle of the disk.

Quoted 4 lines

My options after trying quite a few things and typing to 'roadrunner [email protected]' on IRC appear to be:
- Move the swap partition to one end of the disk and live with higher seek times.

Probably the easiest. You don't want to be swapping anyways.

Quoted 1 line

- Not bother striping across the two disks

Probably won't help anyways.

Quoted 1 line

- Stripe across all 4 partitions [sloooow...]

Yuck.

Quoted 2 lines

- Use MD to do linear append of hda2, hda4 and hdc2, hdc4 then use LVM with the md0 and md1.

I think MD will also let you do append + stripe, but I'm not sure. If you are just going to create a huge 88GB filesystem, you may as well not be using LVM.

Quoted 2 lines

Please someone tell me there's another way!!! Surely this isn't such an unreasonable request?

Yes, no.

Cheers, Andreas

Signature · 3 lines
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
#1 lore raw
Quoted 10 lines · Andreas Dilger
Quoted 8 lines · Chris Wilson

I've just bought a pair of 46 gig UDMA 100 IDE disks and I'd like to stripe data across them for speed. I'd also like to have some swap space. Naturally I'd like this too to be fast, the linux kernel already stripes data across swap partitions with the same priority - so problem solved, one partition on each drive. Now the problem - in order to keep seek times down for the swap partitions, it's got to sit in the middle of the disk (so average distance from the disk-head to the swap partition is low).

Quoted 3 lines

If you are expecting to swap a lot on this system, you are tuning for the wrong thing. To improve performance far more than "correct swap placement", you should get more RAM instead.

I'm expecting to swap very rarely, but when I do possibly quite a lot. I can't really justify more ram (but point taken).

Quoted 20 lines
Quoted 4 lines

Each disk is partitioned as follows:

hda1 hda2 hda3 hda4
<32 meg> <22 gig> <256 meg> <22 gig>

So what you do is:

    pvcreate /dev/hd[ac][234]

then create 1 or 2 volume groups. You may want 2 VGs because you can't have different PE sizes within a single VG, and for small partitions you may end up losing a fair percent of disk space if you make the PEs large enough for your other partitions. So continuing:

vgcreate -s 1M vgswap /dev/hd[ac]3
vgcreate -s 32M vgdata /dev/hd[ac][24]

lvcreate -n lvswap1 -l <approx 255 PEs, see pvdisplay > vgswap /dev/hda3 lvcreate -n lvswap2 -l <approx 255 PEs, see pvdisplay > vgswap /dev/hdc3

Quoted 6 lines

Let the kernel do the swap striping. This way you have some flexibility in case you have too much swap space you can remove one of the swaps, or if you need more, you can add it in (can't do that with LVM without adding #disks == #stipes to the swap LV or performance will again suck).

lvcreate -n lvbig -i 2 -I 64k -L <whatever> vgdata /dev/hd[ac]2

All sounds very sensible up to here.

Quoted 11 lines

I would suggest NOT creating the whole thing as a single LV and putting a filesystem on it. That _severely_ limits your flexibility, and chances are you don't need 88GB of space all at once anyways. When you need more space, simply extend the LV and resize the filesystem. Reiserfs can do that while it is mounted. You could also create another LV+filesystem and mount it somewhere else, which is usually more convenient. Don't get stuck in the old "DOS partition" mindframe where you need to set everything up at the beginning. With LVM you can change your mind if you want, and you don't have to "use" all of your PEs when you start, save some for later.

You should specify the stripes to be on separate disks, like above,

But if I do want to have one big 88GB filesystem (which I do) then there doesn't seem to be a way to prevent it striping /dev/hda2 and /dev/hda4.

Quoted 9 lines

otherwise your performance will suck really badly. I'm not sure you will get a performance gain even with striping. You may also want to run bonnie++ with and without striping, and try different stripe sizes (maybe up to 256k) and to see what is good. If you reported your performance back to us, it would be even better.

lvextend -n lvbig -i 2 -I 64k -L <whatever> vgdata /dev/hd[ac]4

If you DO want to make a huge 88GB filesystem (against all common sense),

'fraid so...

Quoted 4 lines

you should do it in 2 steps (filling the first two partitions, and then moving on to the second partitions) so that you are sure the stripes are across disks, instead of across partitions in the same disk. I'm not sure whether the LVM user tools check this (or even can).

Okay, but as soon as I start deleting some of the data in the first 46gig and replacing it then we're back with the striping across two partitions on the same disk problem aren't we?

Quoted 7 lines
Quoted 4 lines

The two drives are hda and hdc. I'd hoped it might be possible to create a Logical Volume from hda2 and hda4, and one from hdc2 and hdc4. Then use them as Physical Volumes to create an 88gig Logical Volume for my reiser filesystem.

There is no reason whatsoever to make an LV into a PV. You would just be adding more overhead to the system.

True, I'd be adding more overhead to the system. But I'd also be preventing the possibility of trying to stripe across two partitions on the same disk.

Quoted 19 lines

You can use the PEs from a PV in any
way you want (although the current LVM doesn't let you specify this very well). In AIX, you can give a "map" to lvcreate and it will use only specific PEs, so you wouldn't need to do the hokey partitioning to get swap in the middle of the disk.

Quoted 4 lines

My options after trying quite a few things and typing to 'roadrunner [email protected]' on IRC appear to be:
- Move the swap partition to one end of the disk and live with higher seek times.

Probably the easiest. You don't want to be swapping anyways.

Quoted 1 line

- Not bother striping across the two disks

Probably won't help anyways.

Quoted 1 line

- Stripe across all 4 partitions [sloooow...]

Quoted 8 lines

Yuck.

Quoted 2 lines

- Use MD to do linear append of hda2, hda4 and hdc2, hdc4 then use LVM with the md0 and md1.

I think MD will also let you do append + stripe, but I'm not sure. If you are just going to create a huge 88GB filesystem, you may as well not be using LVM.

I will be creating a huge 88GB and would like to use LVM rather than MD (so that I've got the option of adding another pair of drives and generating a 172GB filesystem [I imagine you're 'yucking' as you read this! sorry!]). I'd still be interested to hear whether anyone has sucessfully used a /dev/md0 as PV for LVM?

Cheers,

Chris

Signature · 1 line
[email protected]
#2 lore raw
Quoted 7 lines · Chris Wilson
Quoted 3 lines · Andreas Dilger

If you are expecting to swap a lot on this system, you are tuning for the wrong thing. To improve performance far more than "correct swap placement", you should get more RAM instead.

I'm expecting to swap very rarely, but when I do possibly quite a lot. I can't really justify more ram (but point taken).

OK, seems fair, but you should probably just stick the swap at the beginning and save a lot of effort. I doubt the optimization would help performance much anyways - once you start swapping heavily, you are mostly dead...

Quoted 3 lines
Quoted 1 line

lvcreate -n lvbig -i 2 -I 64k -L <whatever> vgdata /dev/hd[ac]2

All sounds very sensible up to here.

I'm glad you think so.

Quoted 7 lines
Quoted 4 lines

I would suggest NOT creating the whole thing as a single LV and putting a filesystem on it.

You should specify the stripes to be on separate disks, like above,

But if I do want to have one big 88GB filesystem (which I do) then there doesn't seem to be a way to prevent it striping /dev/hda2 and /dev/hda4.

The point is that you don't want to have your filesystem blocks look like:

hda2 hda4 hda2 hda4 hda2 hda4 hdc2 hdc4 hdc2 hdc4 hdc2 hdc4.....

(i.e. alternate blocks striped between the two PVs on the same disk). That would cause a lot of seeking. It is OK if it looks like:

hda2 hdc2 hda2 hdc2 hda2 hdc2 hdc4 hda4 hdc4 hda4 hdc4 hda4.....

because this is basically the same as if you had a single large disk.

Quoted 8 lines
Quoted 4 lines

you should do it in 2 steps (filling the first two partitions, and then moving on to the second partitions) so that you are sure the stripes are across disks, instead of across partitions in the same disk. I'm not sure whether the LVM user tools check this (or even can).

Okay, but as soon as I start deleting some of the data in the first 46gig and replacing it then we're back with the striping across two partitions on the same disk problem aren't we?

But that's OK, because it is no different than if you had just two larger PVs and the data was striped across both of them. Any sane filesystem (ext2 at least) works very hard to keep related inodes/bitmaps/file data on the same part of the disk (i.e. little fragmentation). The fact that you have data on different parts of the disk is natural and unavoidable.

What you REALLY don't want is that the fs thinks block X, X+1, X+2, X+3 are close to each other, when in fact they alternate between opposite ends of the disk.

However, striping is only really useful if you are doing large sequential reads or writes (few seeks). If you are doing random I/O, you are probably better off NOT striping the disk, because then the disk heads can be on opposite ends of the disk, rather than always locked together.

If you do some I/O testing you will be able to see whether striping will actually speed up I/O on your system or not. Don't just speculate.

Quoted 6 lines
Quoted 2 lines

There is no reason whatsoever to make an LV into a PV. You would just be adding more overhead to the system.

True, I'd be adding more overhead to the system. But I'd also be preventing the possibility of trying to stripe across two partitions on the same disk.

As long as you create your LV correctly, then it will behave as if you had done this, but without the overhead. Force the creation of the LV on PVs /dev/hd[ac]2 first, until they are full (they should both fill at the same time if they are the same size). Then extend the LV to /dev/hd[ac]4 next. This will give you the correct behaviour. This is why lvcreate lets you specify the PVs to create on. Otherwise (I suspect) it would allocate the striped PEs in PV order, which would be hda2 and hda4.

It is difficult for LVM to verify if the PVs in a stripe are different disks, because some devices have many minors per disk (partitions), and some have a single disk per minor. Some have mutliple disks for a single minor (MD, hw RAID). The sysadmin should know what's up.

Quoted 4 lines

I will be creating a huge 88GB and would like to use LVM rather than MD (so that I've got the option of adding another pair of drives and generating a 172GB filesystem [I imagine you're 'yucking' as you read this! sorry!]).

I don't mind what you do. If you really need 88GB of space, great. If you want to extend it to 172GB, even better. What I was cautioning against is just creating the whole thing at the start, when you don't really need it. That is a DOSism that I got away from when I worked with LVM a lot on AIX and HPUX. We almost always had spare PEs around for when you just _had_ to increase /var or /tmp or /home or whatever, and can't add a disk.

Also, reiserfs isn't perfect (as you would know if you've been reading the reiserfs mailing list recently), so the larger the filesystem the longer it will take to check. Journalling is no protection against code errors. At least with smaller filesystems a blowup should only ruin one filesystem.

Quoted 2 lines

I'd still be interested to hear whether anyone has sucessfully used a /dev/md0 as PV for LVM?

I think Luca Berra (on this list) is doing so. You needed some patches for the LVM user tools to do this, but I think they are in LVM beta3. However, MD is not worth it for striping (which LVM can do), only for RAID1 or RAID5.

Cheers, Andreas

Signature · 3 lines
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
#3 lore raw
In reply to Chris Wilson
Quoted 4 lines · Chris Wilson

On Fri, 26 Jan 2001, Andreas Dilger wrote:

[cut some stuff]

Quoted 8 lines
Quoted 4 lines

you should do it in 2 steps (filling the first two partitions, and then moving on to the second partitions) so that you are sure the stripes are across disks, instead of across partitions in the same disk. I'm not sure whether the LVM user tools check this (or even can).

Okay, but as soon as I start deleting some of the data in the first 46gig and replacing it then we're back with the striping across two partitions on the same disk problem aren't we?

Yes and no. The harddisk has to seek to the beginning (or the general direction), but this would have happend also if the filesystem was on one partition. Note that LVM does not _stripe_ data unless instructed to (lvcreate -i) but does "linear append" (well, not exactly) instead.

greetings,

Nils

Quoted 3 lines
  Nils Juergens  | [email protected] | icq 7090774   <
 If we all work hard, we can turn this company  <
     around 360 degrees -- gruntbert(LOTD)      <