{"id":208387,"date":"2025-08-28T10:07:50","date_gmt":"2025-08-28T02:07:50","guid":{"rendered":"https:\/\/www.server.hk\/blog\/?p=208387"},"modified":"2025-08-28T10:07:50","modified_gmt":"2025-08-28T02:07:50","slug":"%e6%b7%b1%e5%85%a5%e5%89%96%e6%9e%90-linux-%e8%99%9a%e6%8b%9f%e6%96%87%e4%bb%b6%e7%b3%bb%e7%bb%9f%ef%bc%9a%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c%e5%85%a8%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208387\/","title":{"rendered":"\u6df1\u5165\u5256\u6790 Linux \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff1a\u6587\u4ef6\u64cd\u4f5c\u5168\u89e3\u6790"},"content":{"rendered":"<p dir=\"auto\">Linux \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff08Virtual File System, VFS\uff09\u662f Linux \u5185\u6838\u7684\u6838\u5fc3\u7ec4\u4ef6\uff0c\u4f5c\u4e3a\u7528\u6237\u8fdb\u7a0b\u4e0e\u5404\u79cd\u6587\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u7684\u62bd\u8c61\u5c42\uff0c\u5b9e\u73b0\u4e86\u5bf9\u672c\u5730\u78c1\u76d8\u3001\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u4ee5\u53ca I\/O \u8bbe\u5907\u7684\u7edf\u4e00\u64cd\u4f5c\u63a5\u53e3\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8 VFS \u7684\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u3001\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u8fc7\u7a0b\u4ee5\u53ca\u6587\u4ef6\u64cd\u4f5c\uff08\u5982\u6253\u5f00\u3001\u8bfb\u5199\uff09\u7684\u8be6\u7ec6\u673a\u5236\u3002\u672c\u6587\u4ee5 IT \u4e13\u4e1a\u4eba\u58eb\u4e3a\u76ee\u6807\u53d7\u4f17\uff0c\u529b\u6c42\u63d0\u4f9b\u8be6\u5c3d\u3001\u51c6\u786e\u4e14\u5b9e\u7528\u7684\u6280\u672f\u4fe1\u606f\u3002<\/p>\n<h2 dir=\"auto\">\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u7b80\u4ecb<\/h2>\n<p dir=\"auto\">Linux \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff08VFS\uff09\u662f\u7528\u6237\u8fdb\u7a0b\u4e0e\u5e95\u5c42\u6587\u4ef6\u7cfb\u7edf\u4ea4\u4e92\u7684\u6865\u6881\uff0c\u80fd\u591f\u65e0\u7f1d\u652f\u6301\u591a\u79cd\u5b58\u50a8\u7cfb\u7edf\uff0c\u5305\u62ec\u672c\u5730\u78c1\u76d8\u3001\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u548c I\/O \u8bbe\u5907\u3002VFS \u901a\u8fc7\u62bd\u8c61\u5316\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\uff0c\u4e3a\u7528\u6237\u8fdb\u7a0b\u63d0\u4f9b\u7edf\u4e00\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u65e0\u8bba\u5e95\u5c42\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\u5982\u4f55\uff0c\u8fdb\u7a0b\u90fd\u80fd\u8f7b\u677e\u6267\u884c\u6253\u5f00\u3001\u8bfb\u5199\u7b49\u64cd\u4f5c\u3002<\/p>\n<p dir=\"auto\">VFS \u67b6\u6784\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u4e09\u4e2a\u4e3b\u8981\u5c42\u6b21\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u6587\u4ef6\u7cfb\u7edf\u5c42<\/strong>\uff1a\u5305\u542b VFS \u4ee5\u53ca\u5177\u4f53\u6587\u4ef6\u7cfb\u7edf\u5b9e\u73b0\uff08\u5982 ext4\uff09\uff0c\u4e3a\u4e0a\u5c42\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u6807\u51c6\u6587\u4ef6\u8bbf\u95ee\u63a5\u53e3\u3002<\/li>\n<li><strong>\u5757\u8bbe\u5907\u5c42<\/strong>\uff1a\u8d1f\u8d23\u7ba1\u7406 I\/O \u961f\u5217\u548c\u8c03\u5ea6\uff0c\u4f18\u5316\u6587\u4ef6\u7cfb\u7edf\u7684 I\/O \u8bf7\u6c42\u540e\u53d1\u9001\u81f3\u8bbe\u5907\u5c42\u3002<\/li>\n<li><strong>\u8bbe\u5907\u5c42<\/strong>\uff1a\u5904\u7406\u7269\u7406\u5b58\u50a8\u8bbe\u5907\u53ca\u5176\u9a71\u52a8\u7a0b\u5e8f\uff0c\u6267\u884c\u6700\u7ec8\u7684 I\/O \u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd VFS \u7684\u6838\u5fc3\u7ec4\u4ef6\u3001\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u6d41\u7a0b\u4ee5\u53ca\u6587\u4ef6\u64cd\u4f5c\u7684\u5b9e\u73b0\u673a\u5236\u3002<\/p>\n<h2 dir=\"auto\">VFS \u7684\u6838\u5fc3\u6570\u636e\u7ed3\u6784<\/h2>\n<p dir=\"auto\">VFS \u4f9d\u8d56\u4e24\u4e2a\u4e3b\u8981\u6570\u636e\u7ed3\u6784\u6765\u7ba1\u7406\u6587\u4ef6\u64cd\u4f5c\uff1a<strong>dentry<\/strong>\uff08\u76ee\u5f55\u9879\uff09\u548c <strong>inode<\/strong>\uff08\u7d22\u5f15\u8282\u70b9\uff09\u3002\u8fd9\u4e9b\u7ed3\u6784\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u62bd\u8c61\u4e86\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u7cfb\u7edf\u7ed3\u6784\u3002<\/p>\n<h3 dir=\"auto\">\u7d22\u5f15\u8282\u70b9\uff08Inode\uff09<\/h3>\n<p dir=\"auto\"><strong>\u7d22\u5f15\u8282\u70b9\uff08inode\uff09<\/strong> \u7528\u4e8e\u5b58\u50a8\u6587\u4ef6\u7684\u5143\u6570\u636e\uff0c\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u7d22\u5f15\u8282\u70b9\u7f16\u53f7<\/li>\n<li>\u6587\u4ef6\u5927\u5c0f<\/li>\n<li>\u8bbf\u95ee\u6743\u9650<\/li>\n<li>\u4fee\u6539\u65f6\u95f4\u6233<\/li>\n<li>\u6570\u636e\u5757\u4f4d\u7f6e<\/li>\n<\/ul>\n<p dir=\"auto\">\u6bcf\u4e2a\u6587\u4ef6\u5bf9\u5e94\u4e00\u4e2a inode\uff0cinode \u4e0e\u6587\u4ef6\u6570\u636e\u4e00\u6837\u88ab\u6301\u4e45\u5316\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u56e0\u6b64\u4f1a\u5360\u7528\u78c1\u76d8\u7a7a\u95f4\u3002<\/p>\n<h3 dir=\"auto\">\u76ee\u5f55\u9879\uff08Dentry\uff09<\/h3>\n<p dir=\"auto\"><strong>\u76ee\u5f55\u9879\uff08dentry\uff09<\/strong> \u8868\u793a VFS \u4e2d\u7684\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u5305\u542b\u4ee5\u4e0b\u5173\u952e\u4fe1\u606f\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u6587\u4ef6\u540d<\/li>\n<li>\u6307\u5411\u5173\u8054 inode \u7684\u6307\u9488<\/li>\n<li>\u4e0e\u7236\u76ee\u5f55\u7684\u5173\u7cfb\uff08\u901a\u8fc7 d_parent\uff09<\/li>\n<li>\u6587\u4ef6\u7cfb\u7edf\u7279\u5b9a\u7684\u64cd\u4f5c\uff08\u901a\u8fc7 d_op\uff09<\/li>\n<li>\u6307\u5411\u8d85\u7ea7\u5757\u7684\u6307\u9488\uff08\u901a\u8fc7 d_sb\uff09<\/li>\n<\/ul>\n<p dir=\"auto\">\u4e0e inode \u4e0d\u540c\uff0cdentry \u662f\u5185\u5b58\u4e2d\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4f5c\u4e3a\u76ee\u5f55\u9879\u7f13\u5b58\uff08dcache\uff09\u5b58\u50a8\uff0c\u7528\u4e8e\u52a0\u901f\u6587\u4ef6\u67e5\u627e\u3002VFS \u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u7f13\u5b58\u673a\u5236\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u54c8\u5e0c\u8868\uff08dentry_hashtable\uff09<\/strong>\uff1a\u901a\u8fc7 d_hash \u6307\u9488\u5c06\u6240\u6709 dentry \u7ec4\u7ec7\u4e3a\u54c8\u5e0c\u94fe\u8868\uff0c\u4ee5\u4fbf\u5feb\u901f\u67e5\u627e\u3002<\/li>\n<li><strong>LRU \u5217\u8868\uff08s_dentry_lru\uff09<\/strong>\uff1a\u7ba1\u7406\u672a\u4f7f\u7528\u7684 dentry\uff0c\u5141\u8bb8\u6839\u636e\u5f15\u7528\u8ba1\u6570\u8fdb\u884c\u91cd\u7528\u6216\u56de\u6536\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">dentry \u7684\u751f\u547d\u5468\u671f\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u5f15\u7528\u8ba1\u6570\u4e3a\u96f6\u65f6\uff0c\u79fb\u81f3 LRU \u5217\u8868\u3002<\/li>\n<li>\u518d\u6b21\u88ab\u5f15\u7528\u65f6\uff0c\u4ece LRU \u5217\u8868\u79fb\u9664\u3002<\/li>\n<li>\u5728\u54c8\u5e0c\u8868\u4e2d\u672a\u627e\u5230\u65f6\uff0c\u4ece SLUB \u5206\u914d\u5668\u5206\u914d\u65b0\u7684 dentry\u3002<\/li>\n<li>\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u56de\u6536 LRU \u5217\u8868\u4e2d\u6700\u4e45\u672a\u4f7f\u7528\u7684 dentry\u3002<\/li>\n<li>\u6587\u4ef6\u5220\u9664\u65f6\uff0c\u91ca\u653e\u5bf9\u5e94\u7684 dentry\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d<\/h2>\n<p dir=\"auto\">\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u662f\u5c06 VFS \u4e0e\u5b9e\u9645\u6587\u4ef6\u7cfb\u7edf\uff08\u5982 ext4\uff09\u5efa\u7acb\u8054\u7cfb\u7684\u8fc7\u7a0b\uff0c\u4f7f\u6587\u4ef6\u7cfb\u7edf\u878d\u5165 VFS \u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u4ece\u800c\u53ef\u4f9b\u8bbf\u95ee\u3002<\/p>\n<h3 dir=\"auto\">\u6587\u4ef6\u7cfb\u7edf\u6ce8\u518c<\/h3>\n<p dir=\"auto\">\u6302\u8f7d\u6587\u4ef6\u7cfb\u7edf\u524d\uff0c\u9700\u901a\u8fc7 register_filesystem() \u51fd\u6570\u5411\u5185\u6838\u6ce8\u518c\u3002\u4ee5 ext4 \u4e3a\u4f8b\uff0c\u6ce8\u518c\u65f6\u4f7f\u7528 ext4_fs_type \u7ed3\u6784\uff1a<\/p>\n<div dir=\"auto\">\n<div>\n<div>c<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div><code><\/code><\/p>\n<div>\n<div>\n<div>static struct file_system_type ext4_fs_type = {<\/div>\n<div>.owner = THIS_MODULE,<\/div>\n<div>.name = &#8220;ext4&#8221;,<\/div>\n<div>.mount = ext4_mount,<\/div>\n<div>.kill_sb = kill_block_super,<\/div>\n<div>.fs_flags = FS_REQUIRES_DEV,<\/div>\n<div>};<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">mount \u7cfb\u7edf\u8c03\u7528\u542f\u52a8\u6302\u8f7d\u6d41\u7a0b\uff0c\u8c03\u7528\u94fe\u4e3a\uff1ado_mount() \u2192 do_new_mount() \u2192 do_new_mount_fc()\u3002<\/p>\n<h3 dir=\"auto\">\u6302\u8f7d\u6d41\u7a0b<\/h3>\n<p dir=\"auto\">do_new_mount_fc() \u51fd\u6570\u521b\u5efa struct mount \u8868\u793a\u6302\u8f7d\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5e76\u901a\u8fc7\u4ee5\u4e0b\u7ed3\u6784\u4e0e VFS \u5173\u8054\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>fs_context<\/strong>\uff1a\u5b58\u50a8\u6587\u4ef6\u7cfb\u7edf\u7684\u6839\u76ee\u5f55\u9879\u548c\u8d85\u7ea7\u5757\u3002<\/li>\n<li><strong>vfsmount<\/strong>\uff1a\u5305\u542b\u6302\u8f7d\u6587\u4ef6\u7cfb\u7edf\u7684\u6839\u76ee\u5f55\u9879\uff08mnt_root\uff09\u548c\u8d85\u7ea7\u5757\u6307\u9488\uff08mnt_sb\uff09\u3002<\/li>\n<li><strong>mount<\/strong>\uff1a\u8bb0\u5f55\u7236\u6587\u4ef6\u7cfb\u7edf\uff08mnt_parent\uff09\u548c\u6302\u8f7d\u70b9\uff08mnt_mountpoint\uff09\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u4f8b\u5982\uff0c\u5c06\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u5230 \/home \u4f1a\u521b\u5efa\u4e00\u4e2a mount \u7ed3\u6784\uff0c\u4e0e\u6839\u6587\u4ef6\u7cfb\u7edf\u7684 mount \u5173\u8054\uff0c\u5e76\u751f\u6210\u5bf9\u5e94\u7684 \/home \u76ee\u5f55\u9879\u3002\u8fd9\u79cd\u5c42\u7ea7\u7ed3\u6784\u652f\u6301\u8de8\u6587\u4ef6\u7cfb\u7edf\u7684\u65e0\u7f1d\u5bfc\u822a\u3002<\/p>\n<h2 dir=\"auto\">\u6587\u4ef6\u64cd\u4f5c\uff1a\u6253\u5f00\u6587\u4ef6<\/h2>\n<p dir=\"auto\">\u6253\u5f00\u6587\u4ef6\u662f\u5c06\u7528\u6237\u6001\u8bf7\u6c42\u8f6c\u6362\u4e3a\u5185\u6838\u64cd\u4f5c\u7684\u8fc7\u7a0b\uff0c\u7531 VFS \u534f\u8c03\u3002\u4ee5\u4e0b\u4ee5 open() \u7cfb\u7edf\u8c03\u7528\u4e3a\u4f8b\uff0c\u89e3\u6790\u5176\u5b9e\u73b0\uff1a<\/p>\n<ol dir=\"auto\">\n<li><strong>\u7cfb\u7edf\u8c03\u7528\u5904\u7406<\/strong>\uff1aopen() \u8c03\u7528\u89e6\u53d1 do_sys_open()\uff0c\u5176\u6b65\u9aa4\u5305\u62ec\uff1a\n<ul dir=\"auto\">\n<li>\u4f7f\u7528 build_open_flags() \u89e3\u6790\u4f20\u5165\u7684\u6807\u5fd7\u3002<\/li>\n<li>\u901a\u8fc7 get_unused_fd_flags() \u5206\u914d\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08fd\uff09\u3002<\/li>\n<li>\u8c03\u7528 do_filp_open() \u521b\u5efa struct file\u3002<\/li>\n<li>\u901a\u8fc7 fd_install() \u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0e struct file \u5173\u8054\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6587\u4ef6\u63cf\u8ff0\u7b26\u5206\u914d<\/strong>\uff1aget_unused_fd_flags() \u4ece\u8fdb\u7a0b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\uff08files_struct\uff0c\u4f4d\u4e8e task_struct \u4e2d\uff09\u5206\u914d\u53ef\u7528\u63cf\u8ff0\u7b26\uff0c\u6620\u5c04\u5230 struct file \u6307\u9488\u3002<\/li>\n<li><strong>\u8def\u5f84\u89e3\u6790<\/strong>\uff1ado_filp_open() \u521d\u59cb\u5316 nameidata \u7ed3\u6784\u89e3\u6790\u6587\u4ef6\u8def\u5f84\uff0c\u968f\u540e\u8c03\u7528 path_openat()\uff1a\n<ul dir=\"auto\">\n<li>\u4f7f\u7528 alloc_empty_file() \u5206\u914d struct file\u3002<\/li>\n<li>\u901a\u8fc7 path_init() \u521d\u59cb\u5316\u8def\u5f84\u89e3\u6790\u3002<\/li>\n<li>\u4f7f\u7528 link_path_walk() \u9010\u5c42\u89e3\u6790\u8def\u5f84\uff08\u4f8b\u5982\uff0c\/root\/hello\/world\uff09\u3002<\/li>\n<li>\u901a\u8fc7 do_last() \u83b7\u53d6 inode \u5e76\u521d\u59cb\u5316 struct file\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u76ee\u5f55\u9879\u67e5\u627e<\/strong>\uff1alookup_fast() \u5728\u76ee\u5f55\u9879\u7f13\u5b58\u4e2d\u67e5\u627e\u6587\u4ef6\u7684 dentry\uff0c\u4f7f\u7528 hlist_bl_for_each_entry_rcu\u3002\u82e5\u672a\u627e\u5230\uff0clookup_open() \u521b\u5efa\u65b0 dentry\uff0c\u8c03\u7528\u6587\u4ef6\u7cfb\u7edf\u7684 lookup \u64cd\u4f5c\uff08\u5982 ext4 \u7684 ext4_lookup\uff09\u3002<\/li>\n<li><strong>\u6587\u4ef6\u6253\u5f00<\/strong>\uff1avfs_open() \u8c03\u7528\u6587\u4ef6\u7cfb\u7edf\u7684 open \u64cd\u4f5c\uff08\u5982 ext4_file_open\uff09\uff0c\u5b8c\u6210 struct file \u7684\u521d\u59cb\u5316\uff0c\u8bbe\u7f6e inode\u3001\u8def\u5f84\u548c\u6587\u4ef6\u64cd\u4f5c\u6307\u9488\u3002<\/li>\n<\/ol>\n<p dir=\"auto\">VFS \u56e0\u6b64\u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c4f\u853d\u4e86\u6587\u4ef6\u7cfb\u7edf\u7ec6\u8282\uff0c\u63d0\u4f9b\u7edf\u4e00\u7684\u8bbf\u95ee\u63a5\u53e3\u3002<\/p>\n<h2 dir=\"auto\">\u6587\u4ef6\u64cd\u4f5c\uff1a\u8bfb\u5199\u6587\u4ef6<\/h2>\n<p dir=\"auto\">\u6587\u4ef6\u7684\u8bfb\u5199\u64cd\u4f5c\u901a\u8fc7 VFS \u4e0e\u5e95\u5c42\u6587\u4ef6\u7cfb\u7edf\u4ea4\u4e92\uff0c\u652f\u6301\u7f13\u51b2 I\/O \u548c\u76f4\u63a5 I\/O\u3002<\/p>\n<h3 dir=\"auto\">\u8bfb\u64cd\u4f5c<\/h3>\n<p dir=\"auto\">read() \u7cfb\u7edf\u8c03\u7528\u89e6\u53d1 vfs_read() \u2192 __vfs_read()\uff0c\u4f7f\u7528\u6587\u4ef6\u7684 file_operations\uff08f_op\uff09\u6267\u884c\u8bfb\u53d6\u3002\u5bf9\u4e8e ext4\uff0c\u8c03\u7528 ext4_file_read_iter() \u2192 generic_file_read_iter()\uff0c\u652f\u6301\u4ee5\u4e0b\u6a21\u5f0f\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u7f13\u51b2 I\/O<\/strong>\uff1a\u68c0\u67e5\u9875\u9762\u7f13\u5b58\u662f\u5426\u5305\u542b\u6570\u636e\u3002\u82e5\u65e0\uff0c\u8bfb\u53d6\u78c1\u76d8\u5e76\u7f13\u5b58\u3002\u4f7f\u7528 page_cache_sync_readahead() \u6216 page_cache_async_readahead() \u8fdb\u884c\u9884\u8bfb\u4f18\u5316\u3002<\/li>\n<li><strong>\u76f4\u63a5 I\/O<\/strong>\uff1a\u901a\u8fc7 ext4_direct_IO \u76f4\u63a5\u8bbf\u95ee\u78c1\u76d8\uff0c\u7ed5\u8fc7\u7f13\u5b58\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u6570\u636e\u901a\u8fc7 copy_page_to_iter() \u62f7\u8d1d\u81f3\u7528\u6237\u7a7a\u95f4\u3002<\/p>\n<h3 dir=\"auto\">\u5199\u64cd\u4f5c<\/h3>\n<p dir=\"auto\">write() \u7cfb\u7edf\u8c03\u7528\u89e6\u53d1 vfs_write() \u2192 __vfs_write()\uff0c\u8c03\u7528 ext4_file_write_iter() \u2192 __generic_file_write_iter()\uff0c\u652f\u6301\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u7f13\u51b2 I\/O<\/strong>\uff1a\u5c06\u6570\u636e\u5199\u5165\u9875\u9762\u7f13\u5b58\u5e76\u6807\u8bb0\u4e3a\u810f\u9875\uff0c\u6d41\u7a0b\u5305\u62ec\uff1a\n<ol dir=\"auto\">\n<li>\u4f7f\u7528 ext4_write_begin() \u51c6\u5907\u7f13\u5b58\u9875\u9762\u3002<\/li>\n<li>\u901a\u8fc7 iov_iter_copy_from_user_atomic() \u5c06\u7528\u6237\u6001\u6570\u636e\u62f7\u8d1d\u81f3\u5185\u6838\u9875\u9762\u3002<\/li>\n<li>\u8c03\u7528 ext4_write_end() \u5b8c\u6210\u5199\u5165\uff0c\u6807\u8bb0\u810f\u9875\u3002<\/li>\n<li>\u4f7f\u7528 balance_dirty_pages_ratelimited() \u7ba1\u7406\u810f\u9875\uff0c\u5fc5\u8981\u65f6\u89e6\u53d1\u56de\u5199\u3002<\/li>\n<\/ol>\n<\/li>\n<li><strong>\u76f4\u63a5 I\/O<\/strong>\uff1a\u901a\u8fc7 ext4_direct_IO \u76f4\u63a5\u5199\u5165\u78c1\u76d8\uff0c\u7ed5\u8fc7\u7f13\u5b58\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">Ext4 \u5199\u6a21\u5f0f<\/h3>\n<p dir=\"auto\">Ext4 \u63d0\u4f9b\u4e09\u79cd\u5199\u6a21\u5f0f\u4ee5\u5e73\u8861\u6570\u636e\u5b8c\u6574\u6027\u548c\u6027\u80fd\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u65e5\u5fd7\u6a21\u5f0f<\/strong>\uff1a\u5728\u5199\u5165\u524d\u8bb0\u5f55\u5143\u6570\u636e\u548c\u6570\u636e\u7684\u65e5\u5fd7\uff0c\u5b89\u5168\u6027\u6700\u9ad8\u4f46\u6027\u80fd\u8f83\u4f4e\u3002<\/li>\n<li><strong>\u6709\u5e8f\u6a21\u5f0f<\/strong>\uff1a\u4ec5\u8bb0\u5f55\u5143\u6570\u636e\u65e5\u5fd7\uff0c\u786e\u4fdd\u6570\u636e\u5148\u4e8e\u5143\u6570\u636e\u5199\u5165\u78c1\u76d8\uff08\u9ed8\u8ba4\u6a21\u5f0f\uff09\u3002<\/li>\n<li><strong>\u56de\u5199\u6a21\u5f0f<\/strong>\uff1a\u4ec5\u8bb0\u5f55\u5143\u6570\u636e\u65e5\u5fd7\uff0c\u4e0d\u4fdd\u8bc1\u6570\u636e\u5199\u5165\u987a\u5e8f\uff0c\u6027\u80fd\u6700\u4f73\u4f46\u5b89\u5168\u6027\u6700\u4f4e\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">\u9875\u9762\u7f13\u5b58\u4e0e\u56de\u5199<\/h3>\n<p dir=\"auto\">\u9875\u9762\u7f13\u5b58\u7531 struct address_space \u7ba1\u7406\uff0c\u4f7f\u7528\u57fa\u6570\u6811\uff08radix tree\uff09\u8ddf\u8e2a\u7f13\u5b58\u9875\u9762\u3002\u56de\u5199\u89e6\u53d1\u6761\u4ef6\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u810f\u9875\u6570\u91cf\u8d85\u9650\uff0c\u7531 balance_dirty_pages_ratelimited() \u5904\u7406\u3002<\/li>\n<li>\u663e\u5f0f\u8c03\u7528 sync\uff0c\u901a\u8fc7 wakeup_flusher_threads \u540c\u6b65\u810f\u9875\u3002<\/li>\n<li>\u5185\u5b58\u538b\u529b\u5927\u65f6\uff0c\u8c03\u7528 free_more_memory \u91ca\u653e\u810f\u9875\u3002<\/li>\n<li>\u5b9a\u65f6\u540c\u6b65\uff0c\u786e\u4fdd\u5185\u5b58\u4e0e\u78c1\u76d8\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u603b\u7ed3<\/h2>\n<p dir=\"auto\">Linux \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u662f\u5185\u6838\u6587\u4ef6\u5904\u7406\u7684\u6838\u5fc3\uff0c\u901a\u8fc7\u62bd\u8c61\u4e0d\u540c\u6587\u4ef6\u7cfb\u7edf\uff0c\u63d0\u4f9b\u7edf\u4e00\u7684\u8bbf\u95ee\u63a5\u53e3\u3002VFS \u7ba1\u7406\u76ee\u5f55\u9879\u548c\u7d22\u5f15\u8282\u70b9\u3001\u534f\u8c03\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u3001\u5e76\u4f18\u5316\u6587\u4ef6\u64cd\u4f5c\u6d41\u7a0b\u3002\u7406\u89e3\u5176\u673a\u5236\u2014\u2014\u5982\u76ee\u5f55\u9879\u7f13\u5b58\u3001\u8def\u5f84\u89e3\u6790\u3001\u7f13\u51b2\u4e0e\u76f4\u63a5 I\/O\u2014\u2014\u6709\u52a9\u4e8e IT \u4e13\u4e1a\u4eba\u58eb\u4f18\u5316\u7cfb\u7edf\u6027\u80fd\u5e76\u6709\u6548\u6392\u67e5\u6587\u4ef6\u76f8\u5173\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff08Vir&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-208387","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208387"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208387\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}