Linux fragment record ulimit [stack size, stack size, process count limit, file handle limit, Linux user space limit]

Source: Internet
Author: User

A small Program was originally intended to write a hash table, but a "segment error" occurred.

# Include <stdio. h
StructA {
CharA [4096];
CharA1 [4096];
CharA2 [4096];
CharA3 [4096];
};
IntMain (){
StructA B [1500];
IntI =0;
For(; I <1500; I ++)
Memset (B .a, oxff,4096);
Sleep (2000);
}

I was wondering, isn't it just allocating some space?

It turns out that this is an error when the size of the stack size heap reaches the maximum.

In Linux, this can be set.

You can use the ulimit command to set this setting. You can also set many other limits. You can use ulimit-a to view the current setting.

Ayanmw @ ayanmw-desktop :~ /Server_epoll $ ulimit-
Core File size (blocks,-C) 0
Data seg size (Kbytes,-d) Unlimited
Scheduling Priority (-E) 20
File size (blocks,-f) Unlimited
Pending signals (-I) 16382
Max locked memory (Kbytes,-l) 64
Max memory size (Kbytes,-m) Unlimited
Open files (-N) 1024
Pipe size ( 512 Bytes,-P) 8
POSIX message queues (bytes,-q) 819200
Real-time priority (-R) 0
Stack size (Kbytes,-S) 4096
CPU time (seconds,-T) Unlimited
Max user processes (-u) Unlimited
Virtual Memory (Kbytes,-v) Unlimited
File locks (-x) Unlimited

 

The stack size is 8192kb.

Programs are generally divided into heap and stack. heap is the place where variable names are stored. For example, a pointer occupies 4 bytes and points to a 32-bit address (the 64-bit system doubles ), A common variable, such as int A, is also a variable, pointing to the space address of a with a value.

Stack is where data is stored. As long as there is still memory, it can be allocated all the time. If you don't believe it, you can use a pointer and then the malloc (599999) size, the process occupies dozens of MB of memory.

You can also set the file size and the number of opened files in Linux. And so on.

========================================================== ====

Previously, we found that normal users could not modify ulimit. root users can.

Baidu search:

/Etc/security/limits. conf

Add

* Soft nofile 8192
* Hard nofile 8192

It can be modified.

The path of the centos or RedHat file seems to be:

[Oracle @ qs-xezf-db2 ~] $ CAT/etc/sysconfig/limits. conf

Oracle soft nproc 2047

Hard nproc 16384

Oracle soft nofile 1024

Oracle hard nofile 65536

You can modify the file to achieve the effect.

Some people say: Add the following in/root/. bashrc:
Ulimit-u Unlimited
Ulimit-N 10240
Not necessarily .--

Sysctl-A can view more system configuration information.

 

 

1. CAT/proc/sys/fs/file-Max can obtain the number of file handles of the entire system. It is generally 8192. To increase the total number of handles, run the script/etc/rc. d/RC .. add a line in local: Echo 10240>;/proc/sys/fs/file-max (example)

Puzzled: Use lsof-f | WC-L to view the total number of opened files in the current system. One of my mail servers output a value of 40 thousand in the most crazy time !!! That is to say, 40 thousand file links are opened (or not completely closed) at the same time. But the file-max value is 8192. Why ??

2. Set/etc/security/limits. conf to control the number of file handles for each process.

Add two lines: * Soft nofile 1024
* Hard nofile 8192

Check that the/etc/PAM. d/system-auth file contains the following line: session required/lib/security/pam_limits.so

If the number of file handles that a process can open is limited to 8192, then the number of file handles opened by the thread generated by the process is limited to 8192? Or another 8192?

 

Finally, a simple method is adopted:
Add the following to/boot/. bashrc:
Ulimit-u Unlimited
Ulimit-N 20480

Then, all the open files of common users are changed to 20480, and the maximum number of user processes is changed to ulimited.

 

I can see that the number of processes required by as3 can only be
1. Set the maximum number supported by fd_set.
A. Modify/usr/include/bits/typesizes. h.
# DEFINE _ fd_setsize 1024 --->; 65536
B. Modify/usr/src/Linux/include/Linux/posix_types.h.
# DEFINE _ fd_setsize 1024 --->; 65536

2. Modify/usr/src/Linux/include/Linux/fs. h.
Set the maximum number of opened files (number of TCP connections)
# Define inr_open 1024 --->; 65536
# Define nr_file 8192 --->; 65536
# Define nr_reserved_files 10 --->; 128
3. Modify/usr/src/Linux/include/NET/tcp. h.
A. Set the timeout time to 1 second.
# Define tcp_timewait_len (60 * Hz) 60 --->; 1 * Hz
B. Set the number of semi-join retries in the backlog queue. Each time, the corresponding time is spent, which is essentially to reduce the retry time.
# Define tcp_synack_retries 5 --->; 3

Then, you can compile the kernel to increase the number of kernel parameters, which is more direct than ulimit, because the kernel is compiled.

 

Stress testing:

Yuan @ Yuan-desktop :~ $ AB-N 30000-C 5000 http: // localhost/
This is apachetings, version 2.0.40-dev <$ revision: 1.146 $> APACHE-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 the Apache Software Foundation, http://www.apache.org/

Benchmarking localhost [through 218.19.166.24: 3129] (Be patient)
Socket: Too program open files (24)
When an error occurs, the system reports an error when the default value of socket is 1024 or greater.

 

Reference: http://www.chinaunix.net/jh/4/563088.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.