I don't know why the default LVM setup was chosen, but I can offer some background on how LVM works.
Without LVM, you divide a disk in partitions, and each partition contains a filesystem (/
, /home
, etc.) or something else such as swap space.
LVM introduces a layer of insulation between the disk structures and the content-bearing structures. I'll refer you to the Wikipedia article for a more in-depth presentation, but in a nutshell, each disk partition is an LVM physical volume, while each filesystem or swap area is an LVM logical volume. There's no relationship between the extent of logical and physical volumes: the space in a physical volume can be divided between several logical volumes, and a logical volume can be stored across multiple physical volumes.
This explains why you're seeing two views. At the disk partitioning level, you have a disk with two partitions, one of which happens to be an LVM physical volume. At the content level, you have several filesystems, some of which happen to be on LVM logical volumes.
Parted isn't showing the LVM logical volumes. Either this version of Parted doesn't support LVM (hmm, I thought it did), or you need to tell it to switch to a different view, or you have already created partitions but not logical volumes yet.
I don't know where you're seeing 4MB wasted. I see 17MB unallocated, and I don't know why. Up to 4MB unused could happen with LVM: the size of each logical volume is a multiple of 4MB.
I don't know for sure what the 255MB ext2 partition is for, but I guess it's meant to be /boot
. It used to be that Grub, the default Ubuntu bootloader, couldn't boot from LVM. But Grub 2, the default bootloader for new installation since Ubuntu 9.10, supports an all-LVM installation, so you probably don't need that boot partition. (There are rare cases where an ext2 boot partition is still useful, for example if you're dual-booting with another operating system that doesn't support loading a kernel from LVM or ext4.)
I think I've addressed everything except the amount of swap. (Aside: you shouldn't ask unrelated questions in one question. The amount of swap has nothing to do with your interrogations about LVM. But the topic has already been done to death, so don't ask it separately, just search the site.) Since disk space is cheap, don't hesitate to have ample swap. The machine I'm posting this from has 4GB of RAM and 16GB of swap. Having low or not swap space will absolutely not “force the OS to use faster RAM”, this is completely wrong and I advise treating any source that says this with deep suspicion. (As far as I know this applies to Windows as well.) The OS will use RAM whenever it can. Swap is only used as a last resort, when there isn't enough RAM. Note that on a normal system, you should expect to see some swap in use. That's because RAM isn't just for storing the memory of running processes, it's also for caching disk contents. In fact, it's quite common to have about half the RAM used by the disk cache, and to have some process memory swapped out. If your system didn't do this, it would be running slower, because it would waste more time reloading the same files from disk again and again.
Best Answer
The short answer:
Set your swap file to:
round(sqrt(RAM))
if you don't use hibernationRAM+round(sqrt(RAM))
if you do use hibernationSet your
swappiness
to 10 on a desktop, but not on a server!The long answer:
In the past:
The rule of thumb in use for the last 25 years has been a minimum of 1xRAM and maximum 2xRAM so that is what you'll see quoted all the time.
That minimum was set back in the stone age
when I was a teenager and dinosaurs still roamed the Earth andbecause RAM was just too expensive and you absolutely needed that swap space to be able to accomplish anything.The maximum was set at that time because of diminishing returns: it's just too slow to have to swap so much memory as HDD access is a factor of 1000 slower then RAM: good in an emergency, but not really good for everyday use! At the time, when you ran out of swap space, it was time to add more RAM! (which is still true today).
In the present:
If you do not use hibernation and your memory is in excess of 1GByte the new rule of thumb is
round(sqrt(RAM))
whereRAM
is obviously your RAM size in GB andsqrt
the square root. :-)If you use hibernation, you need to be able to swap the entire amount of RAM+already swapped RAM to disk, thus the formula becomes:
RAM+round(sqrt(RAM))
The rule of diminishing returns still holds today for the maximum, but unless you test your actual usage, taking 2xRAM is just a waste of disk space, so don't use the maximum Unless you run out of swap space using the other methodologies.
All of these together give you the following table: (last 3 columns denoting swap space)
The above is just a rule of thumb; it's not the law of gravity!
You can break this rule (unlike the law of gravity) if your particular use case is different!
Pro tip: Always allocate SWAP at the start of a HDD as the heads need to move less on the inside of the disk.
Yes: On SSDs, it doesn't really matter any more where you locate the swap area as they use quantum-tunnelling instead of moving heads and modern SSDs use all of their memory cells (even the unallocated space) to prevent quantum degradation.
How to test if your usage of swap is different from the "generic" rule:
Just execute:
which will give you a list of all running programs that are swapped out (with the one using the most swap space on top)
If you're using more then a few KB: resize to more then the minimum, otherwise, don't bother...
If you're on a server, stop reading now: you're all set!
If you're on a desktop/laptop client (not server), you want your GUI to be as responsive as possible and only swap when you really need to. Ubuntu has been optimised to swap early for server use, but on your client you want editing that huge 250 Mega-pixel raw picture in
gimp
to be speedy, so setting yourswappiness
to 10 will keep the kernel from swapping too early, while ensuring it doesn't swap too late:If you have a
sysctl.conf
file,OR
If you have a
sysctl.d
directory but nosysctl.conf
file, create a new file:and in both cases add:
to the end of the file, save the file (Ctrl+XY+Enter in nano) and execute a:
to reload the parameter or take the Window$ approach and reboot... :-)