没有硬件支持的虚拟内存 [英] Virtual memory without hardware support

查看:152
本文介绍了没有硬件支持的虚拟内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读此问题及其答案时,我忍不住想了为什么硬件必须支持虚拟内存?

While reading this question and its answer I couldn't help but think why is it obligatory for the hardware to support virtual memory?

例如,我不能仅使用软件来模拟这种行为吗(例如,将所有内存表示为某个表,拦截所有与内存相关的动作以及执行映射本身的操作系统)?

For example can't I simulate this behavior with software only (e.g the o.s with represent all the memory as some table, intercept all memory related actions and and do the mapping itself)?

有没有实现这种技术的操作系统?

Is there any OS that implements such techniques?

推荐答案

据我所知,.

intercept all memory related actions?看起来并非不可能,但我必须非常非常慢.

intercept all memory related actions? It doesn't look impossible, but I must be very very slow.

例如,假设此代码:

int f(int *a1, int *b1, int *c1, int *d1)
{
    const int n=100000;

    for(int j=0;j<n;j++){
        a1[j] += b1[j];
        c1[j] += d1[j];
    }
}

(从这里> o<)

此简单循环由gcc 4.8.3的gcc -std=c99 -O3编译为以下内容:

This simple loop is compiled into following by gcc -std=c99 -O3 with gcc 4.8.3:

push   %edi                     ; 1
xor    %eax,%eax
push   %esi                     ; 2
push   %ebx                     ; 3
mov    0x10(%esp),%ecx          ; 4
mov    0x14(%esp),%esi          ; 5
mov    0x18(%esp),%edx          ; 6
mov    0x1c(%esp),%ebx          ; 7
mov    (%esi,%eax,4),%edi       ; 8
add    %edi,(%ecx,%eax,4)       ; 9
mov    (%ebx,%eax,4),%edi       ; 10
add    %edi,(%edx,%eax,4)       ; 11
add    $0x1,%eax
cmp    $0x186a0,%eax
jne    15 <_f+0x15>             ; 12
pop    %ebx                     ; 13
pop    %esi                     ; 14
pop    %edi                     ; 15
ret                             ; 16

即使这个非常简单的功能也具有用于访问内存的 16 机器码.操作系统的模拟代码可能包含数百个机器代码,那么我们可以猜测这种内存访问代码的速度至少会降低数百倍.

Even this really really simple function has 16 machine codes that access memory. Probably OS's simulate code has hundreds of machine codes, Then we can guess this memory-accessing codes' speed will slows down hundreds times at least.

此外,这是您只能观看 内存访问代码的时候.可能您的处理器没有此功能,您应该使用逐步调试(例如x86的陷阱标志),并每次检查每一个命令.

Moreover, It's when you can watch only memory-accessing codes. Probably your processor doesn't have this feature, you should use step-by-step debugging, like x86's Trap Flag, and check every command every time.

情况变得更糟-仅检查代码是不够的.您可能还希望IP(指令指针)也遵循操作系统的虚拟内存规则,因此在运行每个代码后,您必须检查IP是否超出页面边界.您还必须非常小心处理可能更改IP的代码,例如jmp, call, ret, ...

Things goes worse - It's not enough to check codes. You may want IP (Instruction Pointer) to follow your OS's virtual memory rule as well, so you must check whether IP is over page's boundary after each codes was run. You also must very carefully deal with codes which can change IP, such as jmp, call, ret, ...

我认为它无法有效实施. 无法有效实施.速度是操作系统最重要的部分之一.如果操作系统变慢,则所有系统都会受到影响.在这种情况下,这不是一点-您的计算机变得很慢很多.而且,如上所述,实现此目标非常困难-我宁愿写一个具有硬件支持的虚拟内存的处理器的仿真器,也不愿做这个疯狂的工作!

I don't think it can be implemented efficiently. It cannot be implemented efficiently. Speed is one of the most important part of operating system. If OS become a bit slow, all system is affected. In this case, it's not a bit - your computer gets slow lots and lots. Moreover, implementing this is very difficult as I say above - I'd rather write an emulator of a processor which has hardware-suppported virtual memory than do this crazy job!

这篇关于没有硬件支持的虚拟内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆