問題描述:
redis連接超時,然后定位到redis配置文件目錄被刪除,接著嘗試重啟redis,發現連接中斷,未啟動成功。
報錯:
查看redis的輸出日志。出現下圖所示的報錯:
根據提示在/etc/sysctl.conf文件中添加vm.overcommit_memory = 1,
修改其大透明頁,并將調整redis的timeout從300到500重啟正常;
(學習視頻分享:redis視頻教程)
echo?never?>?/sys/kernel/mm/transparent_hugepage/enabled
關于vm.overcommit_memory
它是?內存分配策略 可選值:0、1、2。0,?表示內核將檢查是否有足夠的可用內存供應用進程使用;如果有足夠的可用內存,內存申請允許;否則,內存申請失敗,并把錯誤返回給應用進程。1,?表示內核允許分配所有的物理內存,而不管當前的內存狀態如何。2,?表示內核允許分配超過所有物理內存和交換空間總和的內存
關于Overcommit和OOM
Linux對大部分申請內存的請求都回復"yes",以便能跑更多更大的程序。因為申請內存后,并不會馬上使用內存。這種技術叫做?Overcommit。 當linux發現內存不足時,會發生OOM?killer(OOM=out-of-memory)。它會選擇殺死一些進程(用戶態進程,不是內核線程),以便釋放內存。 當oom-killer發生時,linux會選擇殺死哪些進程?選擇進程的函數是oom_badness函數(在mm/oom_kill.c中),該?函數會計算每個進程的點數(0~1000)。 點數越高,這個進程越有可能被殺死。每個進程的點數跟oom_score_adj有關,而且?oom_score_adj可以被設置(-1000最低,1000最高)。
關于/sys/kernel/mm/transparent_hugepage/enabled
透明大頁介紹 Transparent?Huge?Pages的一些官方介紹資料: Transparent?Huge?Pages?(THP)?are?enabled?by?default?in?RHEL?6?for?all?applications.?The?kernel?attempts?to?allocate?hugepages?whenever?possible?and?any?Linux?process?will?receive?2MB?pages?if?the?mmap?region?is?2MB?naturally?aligned.?The?main?kernel?address?space?itself?is?mapped?with?hugepages,?reducing?TLB?pressure?from?kernel?code.?For?general?information?on?Hugepages,?see:?What?are?Huge?Pages?and?what?are?the?advantages?of?using?them? The?kernel?will?always?attempt?to?satisfy?a?memory?allocation?using?hugepages.?If?no?hugepages?are?available?(due?to?non?availability?of?physically?continuous?memory?for?example)?the?kernel?will?fall?back?to?the?regular?4KB?pages.?THP?are?also?swappable?(unlike?hugetlbfs).?This?is?achieved?by?breaking?the?huge?page?to?smaller?4KB?pages,?which?are?then?swapped?out?normally. But?to?use?hugepages?effectively,?the?kernel?must?find?physically?continuous?areas?of?memory?big?enough?to?satisfy?the?request,?and?also?properly?aligned.?For?this,?a?khugepaged?kernel?thread?has?been?added.?This?thread?will?occasionally?attempt?to?substitute?smaller?pages?being?used?currently?with?a?hugepage?allocation,?thus?maximizing?THP?usage. In?userland,?no?modifications?to?the?applications?are?necessary?(hence?transparent).?But?there?are?ways?to?optimize?its?use.?For?applications?that?want?to?use?hugepages,?use?of?posix_memalign()?can?also?help?ensure?that?large?allocations?are?aligned?to?huge?page?(2MB)?boundaries. Also,?THP?is?only?enabled?for?anonymous?memory?regions.?There?are?plans?to?add?support?for?tmpfs?and?page?cache.?THP?tunables?are?found?in?the?/sys?tree?under?/sys/kernel/mm/redhat_transparent_hugepage.
查看是否啟用透明大頁
cat?/sys/kernel/mm/transparent_hugepage/enabled [always]?madvise?never使用命令查看時,如果輸出結果為[always]表示透明大頁啟用了。[never]表示透明大頁禁用、[madvise]表示(只在MADV_HUGEPAGE標志的VMA中使用THP 如何HugePages_Total返回0,也意味著標準大頁禁用了(注意傳統/標準大頁和透明大頁的區別) 透明大頁(THP)管理和標準/傳統大頁(HP)管理都是操作系統為了減少頁表轉換消耗的資源而發布的新特性,雖然ORACLE建議利用大頁機制來提高數據庫的性能,但是ORACLE卻同時建議關閉透明大頁管理。這二者的區別在于大頁的分配機制,標準大頁管理是預分配的方式,而透明大頁管理則是動態分配的方式。 [root@appnode001?~]#?grep?-i?HugePages_Total?/proc/meminfo? HugePages_Total:???????0 cat?/proc/sys/vm/nr_hugepages返回0也意味著傳統大頁禁用了(傳統大頁和透明大頁)。[root@appnode001?~]#?cat?/proc/sys/vm/nr_hugepages 0
相關推薦:redis視頻教程
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦