当前位置:网站首页>MySQL master database operation large table DDL, slave database crash and system parameter error setting

MySQL master database operation large table DDL, slave database crash and system parameter error setting

2022-06-10 12:43:00 51CTO

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _ Applications


Here's the thing , A user test UAT library , Frequent error reports from the database without any reason

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _mysql_02

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _ Applications _03

Memory itself is OK Of . But why MYSQL The version of is official 8.011

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _ Memory allocation _04


First of all, I am getting this question , Want to pass PERCONA Tool set pt-pmp To analyze , But it's starting pt-pmp It was found that it could not run , Direct report virtual memory exhausted


MYSQL Main library operation table DDL , From the library crash and system parameter error settings _mysql_05


But the problem is that the memory is not used up , We also have SWAP ah , In the end how can not be divided into pieces of memory . I suddenly think of an article I saw before , Is it because overcommit_memory There is a problem with the configuration of , This leads to the obvious memory , But the problem is that it can't be allocated .


First of all, let's get familiar with overcommit  The value of is 0 1 2 

By default, most systems choose 0 , The official documentation is described as applicable to a typical system , Allocations of memory that are significantly larger than expected are rejected , And will use as little as possible SWAP Of memory space

 1   Is a special Liezi , He doesn't care if the memory of the system has been over allocated , This configuration is only applicable to some special applications .

2   And 1 Counter examples of , The memory allocation provided by him will only affect the overall system 50% Distribute , SWAP + Overall memory 50% Is the most he can allocate , When memory cannot be allocated to an application , The system does not OOM application , But the application will receive a memory allocation error .


My first reaction is to query /proc/sys/vm/overcommit_memory , Sure enough, the state inside is 2 . 

Modify the parameters now   sudo  vi /etc/sysctl.conf

And then in the sysctl -p  


Start again PT-PMP command


pt-pmp --binary mysqld --iterations 2 --interval 1  --save-samples mysql.txt

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _mysql_06

After modification

MYSQL Main library operation table DDL , From the library crash and system parameter error settings _ Applications _07


In the view MYSQL Error log for ,, After modification , There are no errors in the system .  Later others DBA I think it was to test the impact of this parameter on the database , And adjusted the parameters .  Forgot to change it back . But it's good , Through this matter, we can also thoroughly understand overcommit If the parameter is set to... By default 2 ,MYSQL Possible problems .


Related code


  1. int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
  2. {
  3. unsigned long free, allowed;

  4. vm_acct_memory(pages);

  5. /*
  6. * Sometimes we want to use more memory than we have
  7. */
  8. if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS) //overcommit_memory=1, Go straight back to success , No restrictions .
  9. return 0;

  10. if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) { //overcommit_memory=0, Heuristics , Determine whether memory can be allocated according to the free memory status in the current system .
  11. unsigned long n;

  12. free= global_page_state(NR_FILE_PAGES);
  13. free+= nr_swap_pages;

  14. /*
  15. * Any slabs which are created with the
  16. * SLAB_RECLAIM_ACCOUNT flag claim to have contents
  17. * which are reclaimable, under pressure. The dentry
  18. * cache and most inode caches should fall into this
  19. */
  20. free+= global_page_state(NR_SLAB_RECLAIMABLE)

  21. /*
  22. * Leave the last 3% for root
  23. */
  24. if (!cap_sys_admin)
  25. free-= free / 32; //root Users can go to free less (3%) When , Allocate memory .

  26. if (free > pages) // pages The size of memory to be allocated ,free It is calculated according to certain rules “ Free memory size ”, for the first time free Only for NR_FILE_PAGES+NR_SLAB_RECLAIMABLE, Directly or in the system “ Actual idle ” The memory cost is relatively high , So make a step-by-step judgment , Increase of efficiency .
  27. return 0;

  28. /*
  29. * nr_free_pages() is very expensive on large systems,
  30. * only call if we're about to fail.
  31. */
  32. n = nr_free_pages(); // When the memory allocation condition is not satisfied for the first time , Proceed again “ Actual idle ” Memory acquisition operation .

  33. /*
  34. * Leave reserved pages. The pages are not for anonymous pages.
  35. */
  36. if (n <= totalreserve_pages)
  37. goto error;
  38. else
  39. n -= totalreserve_pages;

  40. /*
  41. * Leave the last 3% for root
  42. */
  43. if (!cap_sys_admin)
  44. n -= n / 32;
  45. free += n;

  46. if (free > pages)
  47. return 0;

  48. goto error;
  49. }

  50. allowed = (totalram_pages - hugetlb_total_pages()) // When overcommit_memory=2 when , It is limited according to the total amount of virtual address space in the system .
  51. * sysctl_overcommit_ratio / 100;
  52. /*
  53. * Leave the last 3% for root
  54. */
  55. if (!cap_sys_admin)
  56. allowed -= allowed / 32;
  57. allowed += total_swap_pages;

  58. /* Don't let a single process grow too big:
  59. leave 3% of the size of this process for other processes */
  60. if (mm)
  61. allowed-= mm->total_vm / 32;

  62. if (percpu_counter_read_positive(&vm_committed_as) < allowed)
  63. return 0;
  64. error:
  65. vm_unacct_memory(pages);

  66. return-ENOMEM;
  67. }


MYSQL Main library operation table DDL , From the library crash and system parameter error settings _mysql_08


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101233452458.html