{"id":5782,"date":"2024-09-01T15:01:01","date_gmt":"2024-09-01T07:01:01","guid":{"rendered":""},"modified":"2024-09-01T15:01:01","modified_gmt":"2024-09-01T07:01:01","slug":"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5782.html","title":{"rendered":"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u524d\u8a00<\/h2>\n

\u4e0a\u4e00\u7bc7\u6211\u4eec\u8c08\u8bba\u4e86task_struct\u8fd9\u4e2a\u7ed3\u6784\u4f53\uff0c\u5b83\u88ab\u53eb\u505a\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff0c\u5185\u90e8\u6210\u5458\u5305\u542b\u4e86\u5f88\u591a\u4e0e\u8fdb\u7a0b\u76f8\u5173\u7684\u4fe1\u606f\uff0c\u4eca\u5929\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5176\u4e2d\u4e00\u4e2a\u88ab\u53eb\u505a\u5185\u5b58\u63cf\u8ff0\u7b26\u7684\u7ed3\u6784\u4f53\u2014\u2014mm_struct\uff0c\u62bd\u8c61\u7684\u6765\u63cf\u8ff0linux\u4e0b\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7684\u6240\u6709\u7684\u4fe1\u606f\u3002<\/p>\n

1.\u6982\u8ff0<\/h2>\n
\n

\u4e00\u4e2a\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e3b\u8981\u7531\u4e24\u4e2a\u6570\u636e\u7ed3\u6765\u63cf\u8ff0\u3002\u4e00\u4e2a\u662f\u6700\u9ad8\u5c42\u6b21\u7684\uff1amm_struct\uff0c\u4e00\u4e2a\u662f\u8f83\u9ad8\u5c42\u6b21\u7684\uff1avm_area_structs\u3002\u6700\u9ad8\u5c42\u6b21\u7684mm_struct\u7ed3\u6784\u63cf\u8ff0\u4e86\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6574\u4e2a\u865a\u62df\u5730\u5740\u7a7a\u95f4\u3002\u8f83\u9ad8\u5c42\u6b21\u7684\u7ed3\u6784vm_area_truct\u63cf\u8ff0\u4e86\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7684\u4e00\u4e2a\u533a\u95f4\uff08\u7b80\u79f0\u865a\u62df\u533a\uff09\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u53ea\u6709\u4e00\u4e2amm_struct\u7ed3\u6784\uff0c\u5728\u6bcf\u4e2a\u8fdb\u7a0b\u7684task_struct\u7ed3\u6784\u4e2d\uff0c\u6709\u4e00\u4e2a\u6307\u5411\u8be5\u8fdb\u7a0b\u7684\u7ed3\u6784\u3002\u53ef\u4ee5\u8bf4\uff0cmm_struct\u7ed3\u6784\u662f\u5bf9\u6574\u4e2a\u7528\u6237\u7a7a\u95f4\u7684\u63cf\u8ff0\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u6765\u5b9a\u4f4dmm_struct\u6587\u4ef6\u6240\u5728\u4f4d\u7f6e\u548ctask_struct\u6240\u5728\u8def\u5f84\u662f\u4e00\u6837\u7684\uff0c\u4e0d\u8fc7\u4ed6\u4eec\u6240\u5728\u6587\u4ef6\u662f\u4e0d\u4e00\u6837\u7684\uff0cmm_struct\u6240\u5728\u7684\u6587\u4ef6\u662fmm_types.h\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u6765\u5206\u6790\u8fd9\u4e2a\u7ed3\u6784\u597d\u4e86\u3002<\/p>\n

\u9996\u5148\u6211\u4eec\u6765\u770b\u4e0b\u8fd9\u4e2a\uff1a
\"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5<\/p>\n

\u8fd9\u5c31\u662f\u6211\u4eec\u6240\u8bf4\u7684\u7531task_struct\u5230mm_struct\uff0c\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7684\u5206\u5e03\u3002<\/p>\n

\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u6709\u81ea\u5df1\u72ec\u7acb\u7684mm_struct\uff0c\u8fd9\u6837\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u8fd9\u6837\u624d\u80fd\u4e92\u4e0d\u5e72\u6270\u3002\u5f53\u8fdb\u7a0b\u4e4b\u95f4\u7684\u5730\u5740\u7a7a\u95f4\u88ab\u5171\u4eab\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\u4e3a\u8fd9\u4e2a\u65f6\u5019\u662f\u591a\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u4e00\u4efd\u5730\u5740\u7a7a\u95f4\uff0c\u8fd9\u5c31\u662f\u7ebf\u7a0b\u3002<\/p>\n

\"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5<\/p>\n

\u5176\u5b9e\u591a\u4e2a\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u5206\u5e03\u5c31\u662f\u4e0a\u9762\u8fd9\u5f20\u56fe\u4e00\u6837\uff0c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u7684\u7528\u6237\u7a7a\u95f4\u572832\u4f4d\u7684\u5e73\u53f0\u4e0a\u5c31\u662f\u4e0a\u9762\u8fd9\u4e2a\u56fe\u7684\u60c5\u51b5\uff0c\u5bf9\u4e8e\u7269\u7406\u5185\u5b58\u5f53\u4e2d\u7684\u5185\u6838kernel\uff0c\u662f\u53ea\u5b58\u5728\u4e00\u4efd\uff0c\u6240\u6709\u7684\u8fdb\u7a0b\u662f\u7528\u6765\u5171\u4eab\u7684\uff0c\u5185\u6838\u5f53\u4e2d\u4f1a\u5229\u7528PCB\uff08\u8fdb\u7a0b\u63a7\u5236\u5757\uff09\u6765\u7ba1\u7406\u4e0d\u540c\u7684\u8fdb\u7a0b\u3002\u5bf9\u4e8elinux\u7684\u4f53\u7cfb\u7ed3\u6784\u6765\u8bf4\uff0clinux\u5f53\u4e2d\u4e3a\u4e86\u4fdd\u62a4\u865a\u62df\u5185\u6838\u7a7a\u95f4\u4e0d\u88ab\u4fee\u6539\uff0c\u6240\u4ee5linux\u4f53\u7cfb\u7ed3\u6784\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n

\u8fd9\u79cd\u4e09\u5c42\u7684\u4f53\u7cfb\u7ed3\u6784\uff0c\u4fdd\u8bc1\u8fdb\u7a0b\u53ea\u80fd\u5bf9\u6700\u5916\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u4fee\u6539\uff0c\u4fdd\u8bc1\u4e86\u5185\u5b58\u7684\u5b89\u5168\u6027\u3002<\/p>\n

\"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5<\/p>\n

\u53e6\u5916\uff0c\u6211\u4eec\u4ece\u7b2c\u4e00\u5f20\u56fe\u4e0a\u53ef\u4ee5\u53d1\u5c04\u7ebf\uff0c\u6bcf\u4e2a\u533a\u57df\u662f\u4f9d\u9760\u7740\u4e24\u4e2a\u6307\u9488\u8fdb\u884c\u7ef4\u62a4\u7684\uff0c\u6bd4\u5982[start_data,end_data)\u662f\u7528\u6765\u7ef4\u62a4data\u6bb5\uff0c[start_code,end_data)\u7528\u6765\u7ef4\u62a4code\u6bb5\uff0c[start_brk,brk)\uff0c\u7528\u6765\u7ef4\u62a4heap\u548cheap\u7684\u6307\u9488\u3002[start_stack,end_stack)\u662f\u7528\u6765\u7ef4\u62a4stack\u6bb5\u7a7a\u95f4\u8303\u56f4\u3002mmap_base\u662f\u7ef4\u62a4\u5171\u4eab\u6620\u5c04\u533a\u7684\u8d77\u59cb\u5730\u5740\u3002bss\u6bb5\u8868\u793a\u7684\u662f\u6240\u6709\u7684\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u4e3a\u4e86\u6548\u7387\uff0c\u5bf9\u5904\u5728bss\u6bb5\u7684\u53d8\u91cf\uff0c\u5c06\u5b83\u4eec\u533f\u540d\u6620\u5c04\u5230\u201c\u96f6\u9875\u201d\uff0c\u8fd9\u6837\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u52a0\u8f7d\u6548\u7387\u3002<\/p>\n

 \/\/\u6307\u5411\u7ebf\u6027\u533a\u5bf9\u8c61\u7684\u94fe\u8868\u5934<\/span> struct<\/span> vm_area_struct * mmap; \/* list of VMAs *\/<\/span> \/\/\u6307\u5411\u7ebf\u6027\u533a\u5bf9\u8c61\u7684\u7ea2\u9ed1\u6811<\/span> struct<\/span> rb_root mm_rb;<\/code><\/pre>\n

\u5728\u5730\u5740\u7a7a\u95f4\u4e2d\uff0cmmap\u4e3a\u5730\u5740\u7a7a\u95f4\u7684\u5185\u5b58\u533a\u57df\uff08\u7528vm_area_struct\u7ed3\u6784\u6765\u8868\u793a\uff09\u94fe\u8868\uff0cmm_rb\u7528\u7ea2\u9ed1\u6811\u6765\u5b58\u50a8\uff0c\u94fe\u8868\u8868\u793a\u8d77\u6765\u66f4\u52a0\u65b9\u4fbf\uff0c\u7ea2\u9ed1\u6811\u8868\u793a\u8d77\u6765\u66f4\u52a0\u65b9\u4fbf\u67e5\u627e\u3002\u533a\u522b\u662f\uff0c\u5f53\u865a\u62df\u533a\u8f83\u5c11\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u65f6\u5019\u91c7\u7528\u5355\u94fe\u8868\uff0c\u7531mmap\u6307\u5411\u8fd9\u4e2a\u94fe\u8868\uff0c\u5f53\u865a\u62df\u533a\u591a\u65f6\u6b64\u65f6\u91c7\u7528\u7ea2\u9ed1\u6811\u7684\u7ed3\u6784\uff0c\u7531mm_rb\u6307\u5411\u8fd9\u68f5\u7ea2\u9ed1\u6811\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u5927\u91cf\u6570\u636e\u7684\u65f6\u5019\u6548\u7387\u66f4\u9ad8\u3002\u6240\u6709\u7684mm_struct\u7ed3\u6784\u4f53\u901a\u8fc7\u81ea\u8eab\u7684mm_list\u57df\u94fe\u63a5\u5728\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u4e0a\uff0c\u8be5\u94fe\u8868\u7684\u9996\u5143\u7d20\u662finit_mm\u5185\u5b58\u63cf\u8ff0\u7b26\uff0c\u4ee3\u8868init\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u3002<\/p>\n

 atomic_t mm_users; atomic_t mm_count;<\/code><\/pre>\n

\u8fd9\u4e24\u4e2a\u5185\u5bb9\u8868\u793a\u7684\u5404\u6709\u4e0d\u540c\u3002<\/p>\n\n\n\n\n\n\n
\u6210\u5458<\/th>\n\u5185\u5bb9<\/th>\n<\/tr>\n<\/thead>\n
mm_users<\/td>\n\u8fdb\u7a0b\u6570\u91cf\u503c\uff08\u5728\u591a\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u5c24\u4e3a\u9002\u7528\uff09<\/td>\n<\/tr>\n
mm_count<\/td>\n\u5f15\u7528\u8ba1\u6570\uff08\u5f53\u8ba1\u6570\u4e3a0\u7684\u65f6\u5019\u8868\u793a\u6ca1\u6709\u518d\u88ab\u4f7f\u7528\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f7f\u7528mm_users\u548cmm_count\u4e24\u4e2a\u8ba1\u6570\u5668\u662f\u4e3a\u4e86\u533a\u522b\u4e3b\u4f7f\u7528\u8ba1\u6570\u5668\u548c\u4f7f\u7528\u8be5\u5730\u5740\u7a7a\u95f4\u7684\u8fdb\u7a0b\u7684\u6570\u76ee\u3002<\/p>\n

\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u53ef\u4ee5\u88ab\u522b\u7684\u8fdb\u7a0b\u6765\u5171\u4eab\uff0c\u4e5f\u5c31\u662f\u548c\u522b\u7684\u8fdb\u7a0b\u6765\u5171\u4eabmm_struct.<\/p>\n

\u6240\u6709\u7684mm_struct\u7ed3\u6784\u4ee5\u94fe\u8868\u7684\u5f62\u5f0f\u5b58\u5728mm_struct\u7684\u3002<\/p>\n

\u53e6\u5916\u9700\u8981\u8bf4\u660e\u7684\u5c31\u662fkernel\u7ebf\u7a0b\u662f\u6ca1\u6709\u5730\u5740\u7a7a\u95f4\u7684\uff0c\u4e5f\u5c31\u6ca1\u6709\u5bf9\u5e94\u7684mm_struct\uff0ckernel\u7ebf\u7a0b\u4f7f\u7528\u4e4b\u524d\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002<\/p>\n

\u7a0b\u5e8f\u4e2d\u901a\u5e38\u7528\u5230\u7684\u5730\u5740\u5e38\u5e38\u5177\u6709\u5c40\u90e8\u6027\uff0c\u5f53\u524d\u6700\u8fd1\u4e00\u6b21\u7528\u86cb\u7cd5\u7684\u865a\u62df\u5730\u5740\u533a\u95f4\u5f88\u53ef\u80fd\u4e0b\u4e00\u6b21\u8fd8\u662f\u9700\u8981\u7528\u5230\uff0c\u6240\u4ee5\u6211\u4eec\u91c7\u7528\u5c40\u90e8\u6027\u539f\u7406\uff0c\u901a\u5e38\u65f6\u5019\u6211\u4eec\u53bb\u5427\u5f53\u524d\u5730\u5740\u5468\u56f4\u4e00\u4e2a\u533a\u95f4\u7684\u5185\u5b58\u653e\u5165\u9ad8\u901f\u7f13\u5b58\u5f53\u4e2d\uff0c\u8fd9\u4e2a\u533a\u95f4\u5728mm_struct\u5f53\u4e2d\u5c31\u662f\u7531mmap_cache\u6765\u7ef4\u62a4\u3002<\/p>\n

2.\u5173\u4e8e\u9875\u8868<\/h2>\n

linux kernel \u4f7f\u7528\u5185\u5b58\u7ba1\u7406\u7684\u65f6\u5019\uff0c\u91c7\u53d6\u7684\u662f\u9875\u5f0f\u7684\u7ba1\u7406\u65b9\u5f0f\uff0c\u5e94\u7528\u7a0b\u5e8f\u7ed9\u51fa\u7684\u5185\u5b58\u5730\u5740\u662f\u865a\u62df\u5730\u5740\uff0c\u662f\u7ecf\u8fc7\u82e5\u5e72\u5c42\u7684\u9875\u8868\u7684\u8f6c\u6362\u624d\u80fd\u5f97\u5230\u771f\u6b63\u7684\u7269\u7406\u5730\u5740\uff0c\u6240\u4ee5\u76f8\u5bf9\u6765\u8bf4\uff0c\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u662f\u4e00\u4efd\u865a\u62df\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u6bcf\u4e00\u4e2a\u5730\u5740\u901a\u8fc7\u9875\u8868\u7684\u8f6c\u6362\u6620\u5c04\u5230\u6240\u8c13\u7684\u7269\u7406\u5730\u5740\u7a7a\u95f4\u4e0a\u3002\u5728\u8fd9\u91cc\u6240\u5171\u4eab\u76841G\u7684kernel\u5728\u5185\u5b58\u5730\u5740\u662f\u53ea\u5b58\u4e00\u4efd\u7684\uff0c\u4f46\u662f\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u5176\u4ed6\u76843G\u7684\u7a7a\u95f4\uff0c\u662f\u5b58\u50a8\u5176\u4ed6\u4e0d\u540c\u7684\u4e1c\u897f\uff0c\u53e6\u5916\uff0c\u9875\u8868\u5177\u6709\u6743\u9650\u9650\u5b9a\uff0c\u8fd9\u6837\u4e5f\u5c31\u63d0\u4f9b\u7ed9\u4e86\u6bcf\u5757\u5185\u5b58\u533a\u57df\uff0c\u6bd4\u5982\u6211\u5b9a\u4e49\u4e86\uff1a<\/p>\n

char<\/span> * p=\"12342\"<\/span>;<\/code><\/pre>\n

\u8fd9\u91cc\u7684\u201c12342\u201d\u662f\u4e00\u4e2a\u5e38\u91cf\u5b57\u7b26\u4e32\uff0c\u5b83\u88ab\u5b58\u653e\u5728\u53ea\u8bfb\u5e38\u91cf\u5b58\u50a8\u533a\uff0c\u6240\u4ee5\u8fd9\u4e2a\u533a\u57df\u7684\u9875\u8868\u7684\u5c5e\u6027\u5c31\u662f\u53ea\u8bfb\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u9ad8\u6548\u7684\u7ef4\u62a4\u6574\u4e2a\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u3002<\/p>\n

\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u6709\u4e00\u4e2a\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff0ctask_struct\uff0ctask_strust\u5f53\u4e2d\u7684mm\u6307\u9488\u6307\u5411\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\uff0c\u800c\u5bf9\u4e8e\u6bcf\u4e2amm\uff0c\u6709\u90fd\u4f1a\u6709\u5355\u72ec\u7684\u9875\u8868\uff0c<\/p>\n

pgt\u533a\u95f4\u662f\u7528\u6765\u7ef4\u62a4\u9875\u8868\u7684\u76ee\u5f55\uff0c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u7684\u90fd\u6709\u81ea\u5df1\u7684\u9875\u8868\u76ee\u5f55\uff0c\u9700\u8981\u6ce8\u610f\u8fdb\u7a0b\u7684\u9875\u76ee\u5f55\u548c\u5185\u6838\u7684\u9875\u76ee\u5f55\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u5f53\u7a0b\u5e8f\u8c03\u5ea6\u5668\u8c03\u5ea6\u7a0b\u5e8f\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u65f6\u5019\u8fd9\u4e2a\u5730\u5740\u5c31\u4f1a\u8f6c\u6362\u6210\u4e3a\u7269\u7406\u5730\u5740\uff0clinux\u4e00\u822c\u91c7\u7528\u4e09\u7ea7\u9875\u8868\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n

3.task_struct\u548cmm_strcuct\u7684\u8054\u7cfb<\/h2>\n

\u4e0d\u77e5\u9053\u4f60\u662f\u5426\u8fd8\u8bb0\u5f97\u5728task_struct\u5f53\u4e2d\u7684<\/p>\n

 \/\/\u5173\u4e8e\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u6307\u5411\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u3002\uff08\u94fe\u8868\u548c\u7ea2\u9ed1\u6811\uff09<\/span> struct<\/span> mm_struct *mm, *active_mm;<\/code><\/pre>\n

task_struct\u548cmm_strcut\u901a\u8fc7\u8fd9\u4e24\u4e2a\u6210\u5458\u8fdb\u884c\u548cmm_struct\u8054\u7cfb\uff0c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u6709\u552f\u4e00\u7684mm_struct\u7ed3\u6784\u4f53\u3002<\/p>\n

  struct<\/span> mm_struct { \/\/\u6307\u5411\u7ebf\u6027\u533a\u5bf9\u8c61\u7684\u94fe\u8868\u5934<\/span> struct<\/span> vm_area_struct * mmap; \/* list of VMAs *\/<\/span> \/\/\u6307\u5411\u7ebf\u6027\u533a\u5bf9\u8c61\u7684\u7ea2\u9ed1\u6811<\/span> struct<\/span> rb_root mm_rb; \/\/\u6307\u5411\u6700\u8fd1\u627e\u5230\u7684\u865a\u62df\u533a\u95f4<\/span> struct<\/span> vm_area_struct * mmap_cache; \/* last find_vma result *\/<\/span> \/\/\u7528\u6765\u5728\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e2d\u641c\u7d22\u6709\u6548\u7684\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u7684\u51fd\u6570<\/span> unsigned<\/span> long<\/span> (*get_unmapped_area) (struct<\/span> file *filp, unsigned<\/span> long<\/span> addr, unsigned<\/span> long<\/span> len, unsigned<\/span> long<\/span> pgoff, unsigned<\/span> long<\/span> flags); unsigned<\/span> long<\/span> (*get_unmapped_exec_area) (struct<\/span> file *filp, unsigned<\/span> long<\/span> addr, unsigned<\/span> long<\/span> len, unsigned<\/span> long<\/span> pgoff, unsigned<\/span> long<\/span> flags); \/\/\u91ca\u653e\u7ebf\u6027\u533a\u65f6\u8c03\u7528\u7684\u65b9\u6cd5\uff0c <\/span> void<\/span> (*unmap_area) (struct<\/span> mm_struct *mm, unsigned<\/span> long<\/span> addr); \/\/\u6807\u8bc6\u7b2c\u4e00\u4e2a\u5206\u914d\u6587\u4ef6\u5185\u5b58\u6620\u5c04\u7684\u7ebf\u6027\u5730\u5740<\/span> unsigned<\/span> long<\/span> mmap_base; \/* base of mmap area *\/<\/span> unsigned<\/span> long<\/span> task_size; \/* size of task vm space *\/<\/span> \/* * RHEL6 special for bug : this same variable can mean * two different things. If sysctl_unmap_area_factor is zero, * this means the largest hole below free_area_cache. If the * sysctl is set to a positive value, this variable is used * to count how much memory has been munmapped from this process * since the last time free_area_cache was reset back to mmap_base. * This is ugly, but necessary to preserve kABI. *\/<\/span> unsigned<\/span> long<\/span> cached_hole_size; \/\/\u5185\u6838\u8fdb\u7a0b\u641c\u7d22\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e2d\u7ebf\u6027\u5730\u5740\u7684\u7a7a\u95f4\u7a7a\u95f4<\/span> unsigned<\/span> long<\/span> free_area_cache; \/* first hole of size cached_hole_size or larger *\/<\/span> \/\/\u6307\u5411\u9875\u8868\u7684\u76ee\u5f55<\/span> pgd_t * pgd; \/\/\u5171\u4eab\u8fdb\u7a0b\u65f6\u7684\u4e2a\u6570<\/span> atomic_t mm_users; \/* How many users with user space? *\/<\/span> \/\/\u5185\u5b58\u63cf\u8ff0\u7b26\u7684\u4e3b\u4f7f\u7528\u8ba1\u6570\u5668\uff0c\u91c7\u7528\u5f15\u7528\u8ba1\u6570\u7684\u539f\u7406\uff0c\u5f53\u4e3a0\u65f6\u4ee3\u8868\u65e0\u7528\u6237\u518d\u6b21\u4f7f\u7528<\/span> atomic_t mm_count; \/* How many references to \"struct mm_struct\" (users count as 1) *\/<\/span> \/\/\u7ebf\u6027\u533a\u7684\u4e2a\u6570<\/span> int<\/span> map_count; \/* number of VMAs *\/<\/span> struct<\/span> rw_semaphore mmap_sem; \/\/\u4fdd\u62a4\u4efb\u52a1\u9875\u8868\u548c\u5f15\u7528\u8ba1\u6570\u7684\u9501<\/span> spinlock_t page_table_lock; \/* Protects page tables and some counters *\/<\/span> \/\/mm_struct\u7ed3\u6784\uff0c\u7b2c\u4e00\u4e2a\u6210\u5458\u5c31\u662f\u521d\u59cb\u5316\u7684mm_struct\u7ed3\u6784\uff0c<\/span> struct<\/span> list_head mmlist; \/* List of maybe swapped mm's. These are globally strung * together off init_mm.mmlist, and are protected * by mmlist_lock *\/<\/span> \/* Special counters, in some configurations protected by the * page_table_lock, in other configurations by being atomic. *\/<\/span> mm_counter_t _file_rss; mm_counter_t _anon_rss; mm_counter_t _swap_usage; \/\/\u8fdb\u7a0b\u62e5\u6709\u7684\u6700\u5927\u9875\u8868\u6570\u76ee<\/span> unsigned<\/span> long<\/span> hiwater_rss; \/* High-watermark of RSS usage *\/<\/span>\u3001 \/\/\u8fdb\u7a0b\u7ebf\u6027\u533a\u7684\u6700\u5927\u9875\u8868\u6570\u76ee<\/span> unsigned<\/span> long<\/span> hiwater_vm; \/* High-water virtual memory usage *\/<\/span> \/\/\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u7684\u5927\u5c0f\uff0c\u9501\u4f4f\u65e0\u6cd5\u6362\u9875\u7684\u4e2a\u6570\uff0c\u5171\u4eab\u6587\u4ef6\u5185\u5b58\u6620\u5c04\u7684\u9875\u6570\uff0c\u53ef\u6267\u884c\u5185\u5b58\u6620\u5c04\u4e2d\u7684\u9875\u6570<\/span> unsigned<\/span> long<\/span> total_vm, locked_vm, shared_vm, exec_vm; \/\/\u7528\u6237\u6001\u5806\u6808\u7684\u9875\u6570\uff0c<\/span> unsigned<\/span> long<\/span> stack_vm, reserved_vm, def_flags, nr_ptes; \/\/\u7ef4\u62a4\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5<\/span> unsigned<\/span> long<\/span> start_code, end_code, start_data, end_data; \/\/\u7ef4\u62a4\u5806\u548c\u6808<\/span> unsigned<\/span> long<\/span> start_brk, brk, start_stack; \/\/\u7ef4\u62a4\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u7684\u8d77\u59cb\u5730\u5740\u548c\u6700\u540e\u5730\u5740\uff0c\u4ee5\u53ca\u73af\u5883\u53d8\u91cf\u7684\u8d77\u59cb\u5730\u5740\u548c\u6700\u540e\u5730\u5740<\/span> unsigned<\/span> long<\/span> arg_start, arg_end, env_start, env_end; unsigned<\/span> long<\/span> saved_auxv[AT_VECTOR_SIZE]; \/* for \/proc\/PID\/auxv *\/<\/span> struct<\/span> linux_binfmt *binfmt; cpumask_t cpu_vm_mask; \/* Architecture-specific MM context *\/<\/span> mm_context_t context; \/* Swap token stuff *\/<\/span> \/* * Last value of global fault stamp as seen by this process. * In other words, this value gives an indication of how long * it has been since this task got the token. * Look at mm\/thrash.c *\/<\/span> unsigned<\/span> int<\/span> faultstamp; unsigned<\/span> int<\/span> token_priority; unsigned<\/span> int<\/span> last_interval; \/\/\u7ebf\u6027\u533a\u7684\u9ed8\u8ba4\u8bbf\u95ee\u6807\u5fd7<\/span> unsigned<\/span> long<\/span> flags; \/* Must use atomic bitops to access the bits *\/<\/span> struct<\/span> core_state *core_state; \/* coredumping support *\/<\/span> #ifdef CONFIG_AIO<\/span> spinlock_t ioctx_lock; struct<\/span> hlist_head ioctx_list; #endif<\/span> #ifdef CONFIG_MM_OWNER<\/span> \/* * \"owner\" points to a task that is regarded as the canonical * user\/owner of this mm. All of the following must be true in * order for it to be changed: * * current == mm->owner * current->mm != mm * new_owner->mm == mm * new_owner->alloc_lock is held *\/<\/span> struct<\/span> task_struct *owner; #endif<\/span> #ifdef CONFIG_PROC_FS<\/span> \/* store ref to file \/proc\/<pid>\/exe symlink points to *\/<\/span> struct<\/span> file *exe_file; unsigned<\/span> long<\/span> num_exe_file_vmas; #endif<\/span> #ifdef CONFIG_MMU_NOTIFIER<\/span> struct<\/span> mmu_notifier_mm *mmu_notifier_mm; #endif<\/span> #ifdef CONFIG_TRANSPARENT_HUGEPAGE<\/span> pgtable_t pmd_huge_pte; \/* protected by page_table_lock *\/<\/span> #endif<\/span> \/* reserved for Red Hat *\/<\/span> #ifdef __GENKSYMS__<\/span> unsigned<\/span> long<\/span> rh_reserved[2<\/span>]; #else<\/span> \/* How many tasks sharing this mm are OOM_DISABLE *\/<\/span> union<\/span> { unsigned<\/span> long<\/span> rh_reserved_aux; atomic_t oom_disable_count; }; \/* base of lib map area (ASCII armour) *\/<\/span> unsigned<\/span> long<\/span> shlib_base; #endif<\/span> }; <\/span><\/code><\/pre>\n

github\u6ce8\u91ca\u6e90\u7801\u94fe\u63a5\uff1ahttps:\/\/github.com\/wsy081414\/C_linux_practice\/blob\/master\/mm_struct.c<\/p>\n","protected":false},"excerpt":{"rendered":"\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b_linux\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u60c5\u51b5\u524d\u8a00\u4e0a\u4e00\u7bc7\u6211\u4eec\u8c08\u8bba\u4e86task_struct\u8fd9\u4e2a\u7ed3\u6784\u4f53\uff0c\u5b83\u88ab\u53eb\u505a\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff0c\u5185\u90e8\u6210\u5458\u5305\u542b\u4e86\u5f88...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5782"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5782"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5782\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}