{"id":202384,"date":"2020-10-20T10:34:56","date_gmt":"2020-10-20T02:34:56","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=202384"},"modified":"2020-10-09T09:42:08","modified_gmt":"2020-10-09T01:42:08","slug":"linux-process-freeze","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-process-freeze.html","title":{"rendered":"\u5206\u4eabLinux\u8fdb\u7a0b\u51bb\u7ed3\u6280\u672f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fdb\u7a0b\u51bb\u7ed3\u6280\u672f\uff08freezing of tasks\uff09\u662f\u6307\u5728\u7cfb\u7edfhibernate\u6216\u8005suspend\u7684\u65f6\u5019\uff0c\u5c06\u7528\u6237\u8fdb\u7a0b\u548c\u90e8\u5206\u5185\u6838\u7ebf\u7a0b\u7f6e\u4e8e\u201c\u53ef\u63a7\u201d\u7684\u6682\u505c\u72b6\u6001\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

1 \u4ec0\u4e48\u662f\u8fdb\u7a0b\u51bb\u7ed3<\/strong><\/div>\n

\u8fdb\u7a0b\u51bb\u7ed3\u6280\u672f\uff08freezing of tasks\uff09\u662f\u6307\u5728\u7cfb\u7edfhibernate\u6216\u8005suspend\u7684\u65f6\u5019\uff0c\u5c06\u7528\u6237\u8fdb\u7a0b\u548c\u90e8\u5206\u5185\u6838\u7ebf\u7a0b\u7f6e\u4e8e\u201c\u53ef\u63a7\u201d\u7684\u6682\u505c\u72b6\u6001\u3002<\/p>\n

2 \u4e3a\u4ec0\u4e48\u9700\u8981\u51bb\u7ed3\u6280\u672f<\/strong><\/div>\n

\u5047\u8bbe\u6ca1\u6709\u51bb\u7ed3\u6280\u672f\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u5728\u4efb\u610f\u53ef\u8c03\u5ea6\u7684\u70b9\u6682\u505c\uff0c\u800c\u4e14\u76f4\u5230cpu_down\u624d\u4f1a\u6682\u505c\u5e76\u8fc1\u79fb\u3002\u8fd9\u4f1a\u7ed9\u7cfb\u7edf\u5e26\u6765\u5f88\u591a\u95ee\u9898\uff1a<\/p>\n

\uff081\uff09\u6709\u53ef\u80fd\u7834\u574f\u6587\u4ef6\u7cfb\u7edf\u3002\u5728\u7cfb\u7edf\u521b\u5efahibernate image\u5230cpu down\u4e4b\u95f4\uff0c\u5982\u679c\u6709\u8fdb\u7a0b\u8fd8\u5728\u4fee\u6539\u6587\u4ef6\u7cfb\u7edf\u7684\u5185\u5bb9\uff0c\u8fd9\u5c06\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u6062\u590d\u4e4b\u540e\u65e0\u6cd5\u5b8c\u5168\u6062\u590d\u6587\u4ef6\u7cfb\u7edf\uff1b<\/p>\n

\uff082\uff09\u6709\u53ef\u80fd\u5bfc\u81f4\u521b\u5efahibernation image\u5931\u8d25\u3002\u521b\u5efahibernation image\u9700\u8981\u8db3\u591f\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u4f46\u662f\u5728\u8fd9\u671f\u95f4\u5982\u679c\u8fd8\u6709\u8fdb\u7a0b\u5728\u7533\u8bf7\u5185\u5b58\uff0c\u5c31\u53ef\u80fd\u5bfc\u81f4\u521b\u5efa\u5931\u8d25\uff1b<\/p>\n

\uff083\uff09\u6709\u53ef\u80fd\u5e72\u6270\u8bbe\u5907\u7684suspend\u548cresume\u3002\u5728cpu down\u4e4b\u524d\uff0cdevice suspend\u671f\u95f4\uff0c\u5982\u679c\u8fdb\u7a0b\u8fd8\u5728\u8bbf\u95ee\u8bbe\u5907\uff0c\u5c24\u5176\u662f\u8bbf\u95ee\u7ade\u4e89\u8d44\u6e90\uff0c\u5c31\u6709\u53ef\u80fd\u5f15\u8d77\u8bbe\u5907suspend\u5f02\u5e38\uff1b<\/p>\n

\uff084\uff09\u6709\u53ef\u80fd\u5bfc\u81f4\u8fdb\u7a0b\u611f\u77e5\u7cfb\u7edf\u4f11\u7720\u3002\u7cfb\u7edf\u4f11\u7720\u7684\u7406\u60f3\u72b6\u6001\u662f\u6240\u6709\u4efb\u52a1\u5bf9\u4f11\u7720\u8fc7\u7a0b\u65e0\u611f\u77e5\uff0c\u7761\u9192\u4e4b\u540e\u5168\u90e8\u81ea\u52a8\u6062\u590d\u5de5\u4f5c\uff0c\u4f46\u662f\u6709\u4e9b\u8fdb\u7a0b\uff0c\u6bd4\u5982\u67d0\u4e2a\u8fdb\u7a0b\u9700\u8981\u6240\u6709cpu online\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u5982\u679c\u8fdb\u7a0b\u4e0d\u51bb\u7ed3\uff0c\u90a3\u4e48\u5728\u4f11\u7720\u8fc7\u7a0b\u4e2d\u5c06\u4f1a\u5de5\u4f5c\u5f02\u5e38\u3002<\/p>\n

3 \u4ee3\u7801\u5b9e\u73b0\u6846\u67b6<\/strong><\/div>\n

\u51bb\u7ed3\u7684\u5bf9\u8c61\u662f\u5185\u6838\u4e2d\u53ef\u4ee5\u88ab\u8c03\u5ea6\u6267\u884c\u7684\u5b9e\u4f53\uff0c\u5305\u62ec\u7528\u6237\u8fdb\u7a0b\u3001\u5185\u6838\u7ebf\u7a0b\u548cwork_queue\u3002\u7528\u6237\u8fdb\u7a0b\u9ed8\u8ba4\u662f\u53ef\u4ee5\u88ab\u51bb\u7ed3\u7684\uff0c\u501f\u7528\u4fe1\u53f7\u5904\u7406\u673a\u5236\u5b9e\u73b0\uff1b\u5185\u6838\u7ebf\u7a0b\u548cwork_queue\u9ed8\u8ba4\u662f\u4e0d\u80fd\u88ab\u51bb\u7ed3\u7684\uff0c\u5c11\u6570\u5185\u6838\u7ebf\u7a0b\u548cwork_queue\u5728\u521b\u5efa\u65f6\u6307\u5b9a\u4e86freezable\u6807\u5fd7\uff0c\u8fd9\u4e9b\u4efb\u52a1\u9700\u8981\u5bf9freeze\u72b6\u6001\u8fdb\u884c\u5224\u65ad\uff0c\u5f53\u7cfb\u7edf\u8fdb\u5165freezing\u65f6\uff0c\u4e3b\u52a8\u6682\u505c\u8fd0\u884c\u3002<\/p>\n

kernel threads\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528kthread_freezable_should_stop\u6765\u5224\u65adfreezing\u72b6\u6001\uff0c\u5e76\u4e3b\u52a8\u8c03\u7528__refrigerator\u8fdb\u5165\u51bb\u7ed3\uff1bwork_queue\u901a\u8fc7\u5224\u65admax_active\u5c5e\u6027\uff0c\u5982\u679cmax_active=0\uff0c\u5219\u4e0d\u80fd\u5165\u961f\u65b0\u7684work\uff0c\u6240\u6709work\u5ef6\u540e\u6267\u884c\u3002<\/p>\n

\u6807\u8bb0\u7cfb\u7edffreeze\u72b6\u6001\u7684\u6709\u4e09\u4e2a\u91cd\u8981\u7684\u5168\u5c40\u53d8\u91cf\uff1apm_freezing\u3001system_freezing_cnt\u548cpm_nosig_freezing\uff0c\u5982\u679c\u5168\u4e3a0\uff0c\u8868\u793a\u7cfb\u7edf\u672a\u8fdb\u5165\u51bb\u7ed3\uff1bsystem_freezing_cnt\u300b0\u8868\u793a\u7cfb\u7edf\u8fdb\u5165\u51bb\u7ed3\uff0cpm_freezing=true\u8868\u793a\u51bb\u7ed3\u7528\u6237\u8fdb\u7a0b\uff0cpm_nosig_freezing=true\u8868\u793a\u51bb\u7ed3\u5185\u6838\u7ebf\u7a0b\u548cworkqueue\u3002\u5b83\u4eec\u4f1a\u5728freeze_processes\u548cfreeze_kernel_threads\u4e2d\u7f6e\u4f4d\uff0c\u5728thaw_processes\u548cthaw_kernel_threads\u4e2d\u6e05\u96f6\u3002<\/p>\n

fake_signal_wake_up\u51fd\u6570\u5de7\u5999\u7684\u5229\u7528\u4e86\u4fe1\u53f7\u5904\u7406\u673a\u5236\uff0c\u53ea\u8bbe\u7f6e\u4efb\u52a1\u7684TIF_SIGPENDING\u4f4d\uff0c\u4f46\u4e0d\u4f20\u9012\u4efb\u4f55\u4fe1\u53f7\uff0c\u7136\u540e\u5524\u9192\u4efb\u52a1\uff1b\u8fd9\u6837\u4efb\u52a1\u5728\u8fd4\u56de\u7528\u6237\u6001\u65f6\u4f1a\u8fdb\u5165\u4fe1\u53f7\u5904\u7406\u6d41\u7a0b\uff0c\u68c0\u67e5\u7cfb\u7edf\u7684freeze\u72b6\u6001\uff0c\u5e76\u505a\u76f8\u5e94\u5904\u7406\u3002<\/p>\n

\u4efb\u52a1\u4e3b\u52a8\u8c03\u7528try_to_freeze\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

static inline bool try_to_freeze_unsafe\uff08void\uff09\r\n\r\n{\r\n\r\nif \uff08likely\uff08\uff01freezing\uff08current\uff09\uff09\uff09 \/\/\u68c0\u67e5\u7cfb\u7edf\u662f\u5426\u5904\u4e8efreezing\u72b6\u6001\r\n\r\nreturn false;\r\n\r\nreturn __refrigerator\uff08false\uff09; \/\/\u4e3b\u52a8\u8fdb\u5165\u51bb\u7ed3\r\n\r\n}\r\n\r\nstatic inline bool freezing\uff08struct task_struct *p\uff09\r\n\r\n{\r\n\r\nif \uff08likely\uff08\uff01atomic_read\uff08&system_freezing_cnt\uff09\uff09\uff09 \/\/\u7cfb\u7edf\u603b\u4f53\u8fdb\u5165freezing\r\n\r\nreturn false;\r\n\r\nreturn freezing_slow_path\uff08p\uff09;\r\n\r\n}\r\n\r\nbool freezing_slow_path\uff08struct task_struct *p\uff09\r\n\r\n{\r\n\r\nif \uff08p-\u300bflags & PF_NOFREEZE\uff09 \/\/\u5f53\u524d\u8fdb\u7a0b\u662f\u5426\u5141\u8bb8\u51bb\u7ed3\r\n\r\nreturn false;\r\n\r\nif \uff08pm_nosig_freezing || cgroup_freezing\uff08p\uff09\uff09 \/\/\u7cfb\u7edf\u51bb\u7ed3kernel threads\r\n\r\nreturn true;\r\n\r\nif \uff08pm_freezing && \uff01\uff08p-\u300bflags & PF_KTHREAD\uff09\uff09 \/\/\u7cfb\u7edf\u51bb\u7ed3\u7528\u6237\u8fdb\u7a0b\r\n\r\nreturn true;\r\n\r\nreturn false;\r\n\r\n}\r\n\u8fdb\u5165\u51bb\u7ed3\u72b6\u6001\u76f4\u5230\u6062\u590d\u7684\u4e3b\u8981\u51fd\u6570\uff1abool __refrigerator\uff08bool check_kthr_stop\uff09\r\n{\r\n\r\n\u3002..\r\n\r\nfor \uff08;;\uff09 {\r\nset_current_state\uff08TASK_UNINTERRUPTIBLE\uff09; \/\/\u8bbe\u7f6e\u8fdb\u7a0b\u4e3aUNINTERRUPTIBLE\u72b6\u6001\r\nspin_lock_irq\uff08&freezer_lock\uff09;\r\n\r\ncurrent-\u300bflags |= PF_FROZEN; \/\/\u8bbe\u7f6e\u5df2\u51bb\u7ed3\u72b6\u6001\r\n\r\nif \uff08\uff01freezing\uff08current\uff09 ||\r\n\r\n\uff08check_kthr_stop && kthread_should_stop\uff08\uff09\uff09\uff09 \/\/\u5224\u65ad\u7cfb\u7edf\u662f\u5426\u8fd8\u5904\u4e8e\u51bb\u7ed3\r\n\r\ncurrent-\u300bflags &= ~PF_FROZEN; \/\/\u5982\u679c\u7cfb\u7edf\u5df2\u89e3\u51bb\uff0c\u5219\u53d6\u6d88\u51bb\u7ed3\u72b6\u6001\r\n\r\nspin_unlock_irq\uff08&freezer_lock\uff09;\r\n\r\nif \uff08\uff01\uff08current-\u300bflags & PF_FROZEN\uff09\uff09 \/\/\u5982\u679c\u5df2\u53d6\u6d88\u51bb\u7ed3\uff0c\u8df3\u51fa\u5faa\u73af\uff0c\u6062\u590d\u6267\u884c\r\n\r\nbreak;\r\n\r\nwas_frozen = true;\r\n\r\nschedule\uff08\uff09;\r\n\r\n}\r\n\r\n\u3002..\u3002..\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u8fdb\u7a0b\u51bb\u7ed3\u6280\u672f\uff08freezing of tasks\uff09\u662f\u6307\u5728\u7cfb\u7edfhibernate\u6216\u8005suspend\u7684\u65f6\u5019\uff0c\u5c06\u7528\u6237 […]<\/p>\n","protected":false},"author":310,"featured_media":202687,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-202384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=202384"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202384\/revisions"}],"predecessor-version":[{"id":202689,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202384\/revisions\/202689"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/202687"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=202384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=202384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=202384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}