Commit e9ec735
authored
feat: 内存管理、mmap支持与设备驱动的综合改进 (#1455)
* refactor(mm): 重构页缓存读写以解决死锁问题并改进错误处理
- 将页缓存读写拆分为两阶段以避免用户缺页时持有锁
- 改进文件系统缺页处理,返回SIGBUS而非panic
- 优化sys_read/sys_write的用户缓冲区访问检查
- 修复mprotect参数对齐检查
Signed-off-by: longjin <[email protected]>
* feat(devfs): 添加随机设备支持
- 新增随机设备模块random_dev,提供随机字节生成能力
- 在DevFS中注册/dev/random设备,确保系统能够访问随机数据
- 更新相关文件以支持新设备的集成
Signed-off-by: longjin <[email protected]>
* feat(filesystem): 添加mmap支持到多个文件系统节点
- 为LockedZeroInode、LockedExt4Inode、LockedFATInode和LockedRamFSInode实现mmap方法,允许内存映射操作。
- 更新相关文件以支持mmap功能,确保与用户空间的交互更加灵活。
Signed-off-by: longjin <[email protected]>
* fix(mm): Improve mmap error handling and validation
- Enhanced error handling in mmap implementation to return appropriate errors for unsupported operations.
- Added checks for MAP_PRIVATE and MAP_SHARED flags to ensure only one is set.
- Implemented page alignment validation for MAP_FIXED.
- Updated tests to reflect changes in mmap behavior.
Signed-off-by: longjin <[email protected]>
* fix(mm): Enhance memory protection handling and validation
- Updated the `init_xd_rsvd` function to ensure NX support is enabled and correctly handle hardware limitations.
- Improved alignment checks in `sys_mprotect` to prevent overflow and ensure proper memory area verification.
- Removed outdated tests from `mmap_test` to streamline the test suite.
Signed-off-by: longjin <[email protected]>
* feat(procfs): Add support for /proc/[pid]/statm file
- Introduced the ProcStatm file type to the ProcFileType enum.
- Implemented the open_statm function to return a placeholder response for the statm file.
- Updated the ProcFS inode creation to include the statm file for each process.
- Enhanced the IndexNode implementation to handle the new ProcStatm file type.
Signed-off-by: longjin <[email protected]>
* fix(mmap): 增强mmap系统调用的偏移量检查和内存分配逻辑
* fix(procfs): 优化statm文件打开逻辑,增加虚拟内存页数计算
* fix(syscall): 处理len为0的情况,确保read和write系统调用遵循POSIX标准
* refactor(mm): Optimize page reclamation process to prevent deadlocks
- Separated the page reclamation into two phases to avoid holding the reclaimer lock for extended periods, reducing the risk of lock order inversion with page_manager/page_cache.
- Updated the `shrink_list` method to handle victim page eviction without holding the reclaimer lock, ensuring safer memory management.
- Improved the `drain_lru` method to efficiently retrieve victim pages for reclamation.
Signed-off-by: longjin <[email protected]>
---------
Signed-off-by: longjin <[email protected]>1 parent 92c81de commit e9ec735
File tree
26 files changed
+882
-189
lines changed- kernel/src
- arch/x86_64/mm
- filesystem
- devfs
- ext4
- fat
- procfs
- ramfs
- vfs
- syscall
- mm
- syscall
- user/apps/tests/syscall/gvisor
26 files changed
+882
-189
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 2 | + | |
6 | 3 | | |
7 | 4 | | |
8 | 5 | | |
| |||
391 | 388 | | |
392 | 389 | | |
393 | 390 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
399 | 396 | | |
400 | 397 | | |
401 | 398 | | |
| |||
422 | 419 | | |
423 | 420 | | |
424 | 421 | | |
425 | | - | |
426 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
427 | 455 | | |
| 456 | + | |
| 457 | + | |
428 | 458 | | |
429 | 459 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
527 | | - | |
528 | | - | |
| 527 | + | |
| 528 | + | |
529 | 529 | | |
530 | | - | |
531 | | - | |
532 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
533 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
534 | 538 | | |
535 | 539 | | |
536 | 540 | | |
537 | 541 | | |
538 | 542 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
544 | 546 | | |
545 | 547 | | |
546 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
42 | 61 | | |
43 | 62 | | |
44 | 63 | | |
| |||
62 | 81 | | |
63 | 82 | | |
64 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
65 | 103 | | |
66 | 104 | | |
67 | 105 | | |
| |||
109 | 147 | | |
110 | 148 | | |
111 | 149 | | |
| 150 | + | |
112 | 151 | | |
113 | 152 | | |
114 | 153 | | |
| |||
117 | 156 | | |
118 | 157 | | |
119 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
120 | 162 | | |
121 | 163 | | |
122 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
120 | | - | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
161 | | - | |
| 165 | + | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| |||
0 commit comments