免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1521 | 回复: 3
打印 上一主题 下一主题

kern.maxusers的疑问? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-10 20:07 |只看该作者 |倒序浏览
kern.maxusers是什么意思,表示什么呢?最大用户数,是指连接到主机的最大用户数,那么,我的NAT服务器使用默认值kern.maxusers=384,而连接数达60000多,虽然连接数不一定等于用户数,比如一个用户可能有N个连接,但连接数多达60000,用户数应该也不止384吧,但是也不见NAT受什么影响。


另外kern.maxusers设置时,相应的还要设置哪些参数?


论坛徽章:
0
2 [报告]
发表于 2007-01-11 08:22 |只看该作者
要养成看handbook的习惯
As of FreeBSD 4.5, kern.maxusers is automatically sized at boot based on the amount of memory available in the system, and may be determined at run-time by inspecting the value of the read-only kern.maxusers sysctl. Some sites will require larger or smaller values of kern.maxusers and may set it as a loader tunable; values of 64, 128, and 256 are not uncommon. We do not recommend going above 256 unless you need a huge number of file descriptors; many of the tunable values set to their defaults by kern.maxusers may be individually overridden at boot-time or run-time in /boot/loader.conf (see the loader.conf(5) man page or the /boot/defaults/loader.conf file for some hints) or as described elsewhere in this document. Systems older than FreeBSD 4.4 must set this value via the kernel config(8) option maxusers instead.

In older releases, the system will auto-tune maxusers for you if you explicitly set it to 0[1]. When setting this option, you will want to set maxusers to at least 4, especially if you are using the X Window System or compiling software. The reason is that the most important table set by maxusers is the maximum number of processes, which is set to 20 + 16 * maxusers, so if you set maxusers to 1, then you can only have 36 simultaneous processes, including the 18 or so that the system starts up at boot time and the 15 or so you will probably create when you start the X Window System. Even a simple task like reading a manual page will start up nine processes to filter, decompress, and view it. Setting maxusers to 64 will allow you to have up to 1044 simultaneous processes, which should be enough for nearly all uses. If, however, you see the dreaded proc table full error when trying to start another program, or are running a server with a large number of simultaneous users (like ftp.FreeBSD.org), you can always increase the number and rebuild.

Note: maxusers does not limit the number of users which can log into your machine. It simply sets various table sizes to reasonable values considering the maximum number of users you will likely have on your system and how many processes each of them will be running. One keyword which does limit the number of simultaneous remote logins and X terminal windows is pseudo-device pty 16. With FreeBSD 5.X, you do not have to worry about this number since the pty(4) driver is “auto-cloning”; you simply use the line device pty in your configuration file.


还要养成看代码的习惯
  1. /*
  2. * Boot time overrides that are scaled against main memory
  3. */
  4. void
  5. init_param2(long physpages)
  6. {

  7.         /* Base parameters */
  8.         maxusers = MAXUSERS;
  9.         TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
  10.         if (maxusers == 0) {
  11.                 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
  12.                 if (maxusers < 32)
  13.                         maxusers = 32;
  14.                 if (maxusers > 384)
  15.                         maxusers = 384;
  16.         }
复制代码

论坛徽章:
0
3 [报告]
发表于 2007-01-11 10:17 |只看该作者
谢谢楼上老大的批评!

如果maxuser=0,由系统自动设置,最大值为384。

咋天我一家伙设置了6000,结果系统over了,呵呵……

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
4 [报告]
发表于 2007-01-14 12:38 |只看该作者
在solaris internals看到一句话:
The system first sets an internal variable called maxusers (which has absolutely nothing to do with the maximum number of the users in the system will support) ...

Solaris的,记录下来以供对比。
  1. [usr/src/uts/common/conf/param.c]
  2. #define        MIN_DEFAULT_MAXUSERS        8u
  3. #define        MAX_DEFAULT_MAXUSERS        2048u
  4. #define        MAX_MAXUSERS                4096u

  5. ...

  6. if (maxusers == 0) {
  7.         pgcnt_t physmegs = physmem >> (20 - PAGESHIFT);
  8.         pgcnt_t virtmegs = vmem_size(heap_arena, VMEM_FREE) >> 20;
  9.         maxusers = MIN(MAX(MIN(physmegs, virtmegs),
  10.                 MIN_DEFAULT_MAXUSERS), MAX_DEFAULT_MAXUSERS);
  11. }
  12. if (maxusers > MAX_MAXUSERS) {
  13.         maxusers = MAX_MAXUSERS;
  14.         cmn_err(CE_NOTE, "maxusers limited to %d", MAX_MAXUSERS);
  15. }

  16. ...

  17. /*
  18. * This allows platform-dependent code to constrain the maximum
  19. * number of processes allowed in case there are e.g. VM limitations
  20. * with how many contexts are available.
  21. */
  22. if (max_nprocs == 0)
  23.         max_nprocs = (10 + 16 * maxusers);
  24. if (platform_max_nprocs > 0 && max_nprocs > platform_max_nprocs)
  25.         max_nprocs = platform_max_nprocs;
  26. if (max_nprocs > maxpid)
  27.         max_nprocs = maxpid;

  28. if (maxuprc == 0)
  29.         maxuprc = (max_nprocs - reserved_procs);
复制代码

[ 本帖最后由 gvim 于 2007-1-14 13:10 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP