About system parameters: Vm.overcommit_memory and Vm.overcommit_ratio;

Source: Internet
Author: User

overcomit_memory :

0 : When the user requests the memory, the system will determine how much memory is left, and if not enough, it will fail.

1 : When the user requests the memory, the system does not make any check of the task memory enough to use the memory more than the available memory.

2 : The amount of memory requested by the user at one time does not allow more than Available Memory the size.

Overcommit_ratio :

when overcomot_memory = 2 This parameter is valid, this parameter determines the system Available Memory the size.

Calculation formula: ( physical-ram-size ) *ratio/100 + (swap-size) ;

Current memory usage of the machine

[[email protected]/]# free-m (m)
Total used free shared buffers Cached
mem:5792 513 5279 0 40 158
-/+ buffers/cache:314 5478
swap:1983 0 1983
[Email protected]/]#

Test code:

#include <stdio.h> #include <stdlib.h>size_t max_num = 0;int main (int argc, char **argv) {void *block;        void *tmp_block;        size_t block_size[] = {1024*1024, 1024, 1};        int i=0;        int count; For (i=0, i<3; i++) {for (count = 1;; count + +) {block = Ma                        Lloc (Max_num + block_size[i]*count);                                if (block) {Tmp_block = block;                                Max_num + = Block_size[i]*count;                                printf ("Max_num current malloc size =%lf gb\n", max_num*1.0/1024.0/1024.0/1024.0);                        Free (block);                        } else {break;        }}} printf ("max_num malloc size =%lf gb\n", max_num*1.0/1024.0/1024.0/1024.0); printf ("The address Is%x \ n ", Tmp_block);        printf ("The address End is%x\n", Tmp_block + max_num); while (1);}


Situation ①

overcomot_memory = 0 , Vm.overcommit_ratio = 50 = " max_num malloc size = 7.137890GB

Situation ②

overcomot_memory = 2 , Vm.overcommit_ratio = 50 = " max_num malloc size = 3.958923GB

Situation ③

overcomot_memory = 2 , vm.overcommit_ratio = 99 = "Max_nummalloc size = 6.722099 GB

About system parameters: Vm.overcommit_memory and Vm.overcommit_ratio;

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.