It is really overkill to do it twice. Still, it can be helpful prior to the unmounting of certain types of media with slow write speeds (such as some USB hard drives or PCMCIA storage media), but only because it delays the user from attempting to remove the media too soon, not because two syncs are better than one.

The tune2fs Command

With tune2fs, you can adjust the tunable file system parameters on an ext2 or ext3 file system. A few performance-related items of note are as follows:

> To disable file system checking, the -c 0 option sets the maximum mount count to zero.

> The interval between forced checks can be adjusted with the -I option.

> The -m option sets the reserved blocks percentage with a lower value, freeing more space at the expense of fsck having less space to write any recovered files.

> Decrease the number of superblocks to save space with the -O sparse_super option. (Modern file systems use this by default.) Always run e2fsck after you change this value.

> More space can be freed with the -r option, which sets the number of reserved (for root) blocks.

Note that most of these uses of tune2fs free up space on the drive at the expense of the capability of fsck to recover data. Unless you really need the space and can deal with the consequences, just accept the defaults; large drives are now relatively inexpensive.

The e2fsck Command

This utility checks an ext2/ext3 file system. Some useful arguments taken from man e2fsck are as follows:

-c — Checks for bad blocks and then marks them as bad

-f — Forces checking on a clean file system

-v — Verbose mode

The badblocks Command

Although not a performance-tuning program per se, the badblocks utility checks an (preferably) unmounted partition for bad blocks. It is not recommended that you run this command by itself, but rather allow it to be called by fsck. It should be used directly only if you specify the block size accurately — don't guess or assume anything.

The options available for badblocks are detailed in the man page. They allow for very low- level manipulation of the file system, which is useful for data recovery by file system experts or for file system hacking, but is beyond the scope of this chapter and the average user.

Disabling File Access Time

Whenever Linux reads a file, it changes the last access time — known as the atime. This is also true for your web server: If you are getting hit by 50 requests a second, your hard disk updates the atime 50 times a second. Do you really need to know the last time a file was accessed? If not, you can disable the atime setting for a directory by typing this:

$ chattr -R +A /path/to/directory

The chattr command changes file system attributes, of which 'don't update atime' is one. To set that attribute, use +A and specify -R so that it is recursively set. /path/to/directory gets changed, and so do all the files and subdirectories it contains.

If you want to change a whole drive so that it never updates the atime, edit the file /etc/fstab as root and look for the part that says defaults for the drive you want to change. It might say defaults or something more complex like defaults,errors=remount- ro; you need to change that to add noatime, as in defaults,noatime. Make sure you don't put any extra spaces in there!

Kernel

As the Linux kernel developed over time, developers sought a way to fine-tune some of the kernel parameters. Before sysctl, those parameters had to be changed in the kernel configuration and then the kernel had to be recompiled.

The sysctl command can change some parameters of a running kernel. It does this through the /proc file system, which is a 'virtual window' into the running kernel. Although it might appear that a group of directories and files exist under /proc, that is only a representation of parts of the kernel. You can read values from and write values to those 'files,' referred to as variables. You can display a list of the variables as shown in the following. (An annotated list is presented because roughly 250 items — or more — exist in the full list.)

# sysctl -A

net.ipv4.tcp_max_syn_backlog = 1024

net.ipv4.tcp_rfc1337 = 0

net.ipv4.tcp_stdurg = 0

net.ipv4.tcp_abort_on_overflow = 0

net.ipv4.tcp_tw_recycle = 0

net.ipv4.tcp_syncookies = 0

net.ipv4.tcp_fin_timeout = 60

net.ipv4.tcp_retries2 = 15

net.ipv4.tcp_retries1 = 3

net.ipv4.tcp_keepalive_intvl = 75

net.ipv4.tcp_keepalive_probes = 9

net.ipv4.tcp_keepalive_time = 7200

net.ipv4.ipfrag_time = 30

The items shown are networking parameters, and actually tweaking these values is beyond the scope of this book. If you want to change a value, however, the -w command is used:

# sysctl -w net.ipv4.tcp_retries 2=20

This increases the value of that particular kernel parameter.

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату