📄 1155.html
字号:
<TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
<TR>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22
src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>内核调整</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>purge觉得这篇文章不错,所以就贴出来了,大家参考参考。<br>
原文在 http://linuxperf.nl.linux.org/general/kerneltuning.html<br>
<br>
<br>
Kernel Tuning<br>
(This page is derived from other linuxperf pages and external sources - external references are noted where used)<br>
How to set kernel tunables<br>
The easiest method to set kernel parameters is by modifying the /proc filesystem (and hence the kernel directly) by using echo "value" > /proc/kernel/parameter. Then changes take effect immediately but must be reset at system boot up. Kernel tuning can be automated at boo time by putting the echo commands in /etc/rc.d/rc.local for Non-RedHat distributions or for RedHat derived distributions modify the /etc/sysctl.conf configuration file instead.<br>
<br>
Increasing System Limits<br>
Increasing the Maximum number of file handles and the inode cache<br>
NOTE:<br>
On all current versions of linux up to and including 2.2.10 and 2.3.9, inode caches DO NOT SHRINK like the file and dentry caches do when your applications need lots of ram.<br>
This means if you set a really large inode cache, then you can lose a significant amount of RAM over time. On a server machine, this is expected, normal and desired. On a workstation machine, doing a kernel compile when your inode-max is set at a very large number will probably give far too much to the inode cache.<br>
Empirical evidence suggests that 40960 entries in the inode cache will use up to 10 megabytes of ram. Your mileage may vary, and more data is necessary to confirm this number.<br>
Linux 2.0.x - file-max defaults to 1024 so increase the value of /proc/sys/kernel/file-max to something reasonable like 256 for every 4M of RAM you have: i.e.. for a 64 M machine, set it to 4096.<br>
The canonical command to change anything in the /proc hierarchy is (as root) echo "newvalue" >/proc/file/that/you/want/to/change, so for this item the command line is<br>
echo "4096" >/proc/sys/kernel/file-max<br>
Also increase /proc/sys/kernel/inode-max to a value roughly 3 to 4 times the number of open files. This is because the number of inodes open is at least one per open file, and often much larger than that for large files.<br>
(the following was written by Tani Hosokawa)<br>
Note: if you increase this beyond 1024, you may also have to edit include/linux/posix_types.h and increase this line:<br>
<br>
#define __FD_SETSIZE 1024<br>
<br>
That allows for a select to handle 1024 file descriptors. More than that, and stuff may break.<br>
<br>
Linux 2.2.x/2.3.x - increase the value of /proc/sys/fs/file-max to something reasonable like 256 for every 4M of RAM you have: i.e.. for a 64 M machine, set it to 4096. As above, also increase the /proc/sys/fs/inode-max as well<br>
<br>
Long Answer:<br>
The above technique or modifying the constants in the kernel sources. Not usually the right answer because that will not survive a new kernel source tree. One of the best techniques is to add the above commands to /etc/rc.d/rc.local.<br>
<br>
The exact number will vary from the above formula based on what you are actually doing with the machine. A file server or web server need a lot of open files, for instance, but a compute server does not.<br>
Very large memory systems, especially 512 Megabytes or larger, probably should not have more than 50,000 open files and 150,000 open inodes. Of course if you are Mindcraft, this is a cheap and effective way to waste kernel memory.<br>
<br>
Linux 2.4.x - ?<br>
<br>
Here is another method of increasing these limits from www.linuxraid.org:<br>
<br>
Aim: Increase the number of files that may be open simultaneously<br>
Changes to include/linux/fs.h:<br>
increase NR_FILE from 4096 to 65536<br>
increase NR_RESERVED_FILES from 10 to 128<br>
Changes to fs/inode.c:<br>
increase MAX_INODE from 16384 to 262144<br>
Note: MAX_INODE must be at least three times larger than NR_FILE.<br>
<br>
Increasing the number of processes/tasks allowed<br>
Linux 2.0.x - The default maximum is 512 tasks, half of which can be used by any single<br>
user. Here's an excerpt from /usr/src/linux/include/linux/tasks.h<br>
#define NR_TASKS 512 /* On x86 Max 4092, or 4090 w/APM configured. */<br>
<br>
#define MAX_TASKS_PER_USER (NR_TASKS/2)<br>
#define MIN_TASKS_LEFT_FOR_ROOT 4<br>
<br>
Just change the 512 to something higher. You can change MAX_TASKS_PER_USER to<br>
something else as well, although it's a nice precaution against simple process<br>
table attacks. Properly managed systems shouldn't be vulnerable to that<br>
though (you do set your MaxClients and whatnot, don't you?). Don't try to go<br>
above the maximums. Your machine will just keep rebooting and rebooting.<br>
(the preceding was written by Tani Hosokawa)<br>
<br>
Linux 2.2.x/2.3.x -Edit /usr/src/linux/include/linux/tasks.h, modify the "NR_TASKS" value and then rebuild and install the kernel. (One person recommended changing NR_TASKS from 512 to 2048, and changing MIN_TASKS_LEFT_FOR_ROOT to 24.)<br>
<br>
Linux 2.4.x - ?<br>
<br>
Decrease the time before disposing of unused TCP keepalive requests (from linuxraid.org)<br>
Changes to include/net/tcp.h:<br>
decrease TCP_KEEPALIVE_TIME from 2 hours to 5 minutes<br>
Download: http://www.linuxraid.org/tcp-keepalive.patch<br>
Increase the number of TCP/UDP ports that may be used simultaneously (from linuxraid.org)<br>
On 2.2 and 2.4 kernels, the local port range can be changed via sysctl<br>
echo 1024 25000 > /proc/sys/net/ipv4/ip_local_port_range<br>
Allows more local ports to be available. Generally not a issue, but in a benchmarking scenario you often need more ports available. A common example is clients running `ab` or `http_load` or similar software.<br>
Increasing the amount of memory associated with socket buffers<br>
Increasing the amount of memory associated with socket buffers can often improve performance. Things like NFS in particular, or apache setups with large buffer configured can benefit from this.<br>
echo 262143 > /proc/sys/net/core/rmem_max<br>
echo 262143 > /proc/sys/net/core/rmem_default<br>
This will increase the amount of memory available for socket input queues. The "wmem_*" values do the same for output queues.<br>
Note: With 2.4.x kernels, these values are supposed to "autotune" fairly well, and some people suggest just instead changing the values in:<br>
<br>
/proc/sys/net/ipv4/tcp_rmem<br>
/proc/sys/net/ipv4/tcp_wmem<br>
Increasing the amount of memory associated with socket buffers<br>
Increasing the amount of memory associated with socket buffers can often improve performance. Things like NFS in particular, or apache setups with large buffer configured can benefit from this.<br>
echo 262143 > /proc/sys/net/core/rmem_max<br>
echo 262143 > /proc/sys/net/core/rmem_default<br>
This will increase the amount of memory available for socket input queues. The "wmem_*" values do the same for output queues.<br>
Note: With 2.4.x kernels, these values are supposed to "autotune" fairly well, and some people suggest just instead changing the values in:<br>
<br>
/proc/sys/net/ipv4/tcp_rmem<br>
/proc/sys/net/ipv4/tcp_wmem<br>
There are three values here, "min default max".<br>
Turning off tcp_sack and tcp_timestamps<br>
These reduce the amount of work the TCP stack has to do:<br>
echo 0 > /proc/sys/net/ipv4/tcp_sack<br>
echo 0 > /proc/sys/net/ipv4/tcp_timestamps<br>
This disables "RFC2018 TCP Selective Acknowledgements", and "RFC1323 TCP timestamps"<br>
Increasing shared memory and ipc limits<br>
Some applications, databases in particular, sometimes need large amounts of SHM segments and semaphores. The default limit for the number of shm segments is 128 for 2.2.<br>
This limit is set in a couple of places in the kernel, and requires a modification of the kernel source and a recompile to increase them.<br>
<br>
A sample diff to bump them up:<br>
<br>
--- linux/include/linux/sem.h.save Wed Apr 12 20:28:37 2000<br>
+++ linux/include/linux/sem.h Wed Apr 12 20:29:03 2000<br>
@@ -60,7 +60,7 @@<br>
int semaem;<br>
};<br>
<br>
-#define SEMMNI 128 /* ? max # of semaphore identifiers */<br>
+#define SEMMNI 512 /* ? max # of semaphore identifiers */<br>
#define SEMMSL 250 /* <= 512 max num of semaphores per id */<br>
#define SEMMNS (SEMMNI*SEMMSL) /* ? max # of semaphores in system */<br>
#define SEMOPM 32 /* ~ 100 max num of ops per semop call */<br>
--- linux/include/asm-i386/shmparam.h.save Wed Apr 12 20:18:34 2000<br>
+++ linux/include/asm-i386/shmparam.h Wed Apr 12 20:28:11 2000<br>
@@ -21,7 +21,7 @@<br>
* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and<br>
* there is a static array of size SHMMNI.<br>
*/<br>
-#define _SHM_ID_BITS 7<br>
+#define _SHM_ID_BITS 10<br>
#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1)<br>
<br>
#define SHM_IDX_SHIFT (_SHM_ID_BITS)<br>
<br>
<br>
Theoretically, the _SHM_ID_BITS can go as high as 11. The rule is that _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on x86.<br>
In addition to the number of shared memory segments, you can control the maximum amount of memory allocated to shm at run time via the /proc interface. /proc/sys/kernel/shmmax indicates the current. Echo a new value to it to increase it.<br>
<br>
echo "67108864" > /proc/sys/kernel/shmmax<br>
To double the default value.<br>
A good resource on this is Tunings The Linux Kernel's Memory. Linux Maximus: How to Get Maximum Performance from Linux and Oracle also includes some useful about tuning shm for oracle, amongst other things.<br>
<br>
The best way to see what the current values are, is to issue the command:<br>
<br>
ipcs -l<br>
Ptys and ttys<br>
The number of ptys and ttys on a box can sometimes be a limiting factor for things like login servers and database servers.<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -