sys_max_files在erlang beam里面2处地方消耗内存:
1.
static struct driver_data {
int port_num, ofd, packet_bytes;
ErtsSysReportExit *report_exit;
int pid;
int alive;
int status;
} *driver_data; /* indexed by fd */
7 WORDS
driver_data = (struct driver_data *)erts_alloc(ERTS_ALC_T_DRV_TAB, max_files * sizeof(struct driver_data));
2.
static struct fd_data {
char pbuf[4]; /* hold partial packet bytes */
int psz; /* size of pbuf */
char *buf;
char *cpos;
int sz;
int remain; /* for input on fd */
} *fd_data; /* indexed by fd */
5 WORDS + 4
fd_data = (struct fd_data *)
erts_alloc(ERTS_ALC_T_FD_TAB, max_files * sizeof(struct fd_data));
1个file消耗的内存为 13WORDS 左右, 32位机器大概是64个字节,假如你不小心把 ulimit -n 10000000 也就是说100w个句柄, 那光这个就消耗64M 内存.所以没有必须的时候, 最大文件句柄数还是够用就行。
1.
static struct driver_data {
int port_num, ofd, packet_bytes;
ErtsSysReportExit *report_exit;
int pid;
int alive;
int status;
} *driver_data; /* indexed by fd */
7 WORDS
driver_data = (struct driver_data *)erts_alloc(ERTS_ALC_T_DRV_TAB, max_files * sizeof(struct driver_data));
2.
static struct fd_data {
char pbuf[4]; /* hold partial packet bytes */
int psz; /* size of pbuf */
char *buf;
char *cpos;
int sz;
int remain; /* for input on fd */
} *fd_data; /* indexed by fd */
5 WORDS + 4
fd_data = (struct fd_data *)
erts_alloc(ERTS_ALC_T_FD_TAB, max_files * sizeof(struct fd_data));
1个file消耗的内存为 13WORDS 左右, 32位机器大概是64个字节,假如你不小心把 ulimit -n 10000000 也就是说100w个句柄, 那光这个就消耗64M 内存.所以没有必须的时候, 最大文件句柄数还是够用就行。