Application to manage its own Virtual Memory

浪子不回头ぞ 提交于 2019-12-08 06:38:16

问题


I have a slight doubt regarding virtual memory.

Normally, it is up to the OS to provide virtual memory to using disk space to expand the amount of memory which appears to be available for applications.

The OS will clear physical memory by copying the data to disk and restoring when needed.

However, it is possible for an application to manage its own “virtual memory” rather than the OS, for example by writing objects to a file then destroying them?

If so, is allowing application to manage its own virtual memory for advantageous or allowing the OS to provide?


回答1:


Most applications would not be able to even know that they are being managed using virtual memory because the operating system would perform address translation on every memory request made by your application.

This is a task definitely best left to the operating system unless you are working in a very low-level environment (in which case you are probably writing your own operating system anyway).

Aside from the fact that this requires kernel privileges to accomplish, you would need to take care not to corrupt other process' memory.

The operating system is the best place for this kind of logic.




回答2:


It is not just not advantageous for the application to manage its own virtual memory, it is not possible with standard operating systems (Windows, Unix, Linux, Mac OS X, etc.).

Translation from virtual address to physical address is done by the Memory Management Unit of the system, which is typically firmware, not strictly part of the operating system software.

The only part of the process done by the operating system software is handling of page faults (swapping units of virtual memory to and from backing store), when the address translation finds a reference to a virtual address that is not currently mapped in physical memory.

What could be advantageous is for an application to minimize its use of virtual memory by writing out its own data to disk rather than allocating larger amounts of virtual memory. However, this will only yield a benefit if the application's disk i/o is more efficient than the operating system page handler's disk i/o - an unlikely scenario these days.



来源:https://stackoverflow.com/questions/9050852/application-to-manage-its-own-virtual-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!