操作系统“交换"有什么区别?和“页面"? [英] What's the difference between operating system "swap" and "page"?

查看:16
本文介绍了操作系统“交换"有什么区别?和“页面"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统中这两个术语有什么区别:交换和页面?

What is the difference between these 2 terms in Operating System: swap and page?

推荐答案

尽管这两个术语在历史上互换了,但它们表示不同的东西.它们都是管理将内存中的数据移动到另一个存储设备(称为后备存储(通常是硬盘))的方法,但它们使用不同的方法.

In spite of the historical interchanging of these two terms, they indicate different things. They are both methods for managing moving data in memory to another storage device, called a backing store (often a hard drive), but they use different methods of doing so.

交换涉及将内存中进程的整个集合数据移动到后备存储上的一系列空间,通常是交换文件或交换分区.该过程从内存中完全换出;中间没有.显然,这个过程需要完全空闲,交换才有价值.这样做的好处是比较容易掌握并且程序的内存总是连续分配的,缺点是当系统最终处于不断交换的状态时,机器上的性能可能会变得非常糟糕.该算法还涉及重复交换在可预见的未来不会使用的数据.

Swapping involves the moving of a process's entire collection data in memory to a range of space on the backing store, often to a swapfile or swap partition. The process goes from being in memory to swapped out entirely; there is no in-between. Obviously the process will need to be entirely idle for swapping to be at all worthwhile. The advantage of this is that it is relatively simple to grasp and memory for a program is always allocated contiguously, the downside is that performance on a machine can become absolutely abysmal when the system ends up in a state where things are constantly swapping. The algorithm also involves the repeated swapping in and out of data that will not be used in the foreseeable future.

分页试图解决这些问题,方法是占用物理内存,并将其分割成一些固定大小的称为帧"的东西.它还占用每个正在运行的进程的内存空间,并将其划分为页面(与帧大小相同);这称为物理地址空间,因为需要使用物理地址来访问每个内存块.

Paging attempts to solve these problem, by taking physical memory, and carving it up into things called "frames" of some fixed size. It also takes the memory space of each running process, and carves it up into pages (which are the same size as frames); this is called the physical address space, due to the need to use physical addresses to access each block of memory.

每个程序都由操作系统提供一个环境,并得到现代硬件的支持,这使得程序的内存占用看起来像一个非常大的内存块的单个连续块;这称为逻辑地址空间.

Each program is presented an environment by the OS, and supported by modern hardware, which makes the programs memory footprint look like a single contiguous block of a very large amount of memory; this is called a logical address space.

但是,这个连续块的每一页都可能在内存中,也可能在后备存储中.操作系统通过查阅称为页表"的东西来确定每个页面的位置.如果它发现程序请求的页面在内存中的某个地方,它将简单地转到该内存页面并获取请求的数据.

However, each page of this contiguous block may be in memory, or it may be on the backing store. The operating system determines where each page is by consulting something called a "page table". If it finds the page the program has asked for is in memory somewhere, it will simply go to that page of memory and grab the data requested.

如果发现页面不在内存中;这会导致页面错误".操作系统将在从后备存储加载请求的页面时暂停该进程,并且可能会根据某些替换算法将另一个页面从内存移动到后备存储以腾出空间.后备存储可能被称为页面文件,也可能仍被称为交换文件或交换分区,从而导致混淆正在使用哪个系统.是单独的分区,还是只是一个文件,取决于操作系统.

If it finds the page is not in memory; this causes a "page fault". The OS will suspend the process while it loads the requested page in from the backing store, and may in turn move another page from memory to the backing store to make room, based on some replacement algorithm. The backing store may be called a pagefile, or may still be called a swapfile or swap partition, leading to confusion about which system is being used. Whether it is a separate partition, or just a file, depends on the operating system.

内存的某些部分不会被分页.其中之一是分页代码本身,以及处理页面错误等事情的内核部分.某些操作系统(如 MacOS)将此内存称为有线".

There are certain parts of memory that aren't subject to being paged out. One of these is the paging code itself, and the parts of the kernel that handle things like page faults. Some operating systems, like MacOS, refer to this memory as "wired".

现代硬件有多种设备可以让操作系统更有效地支持分页.其中最常见的是翻译后备缓冲区或 TLB.这存储了一种硬件页表缓存,因此每当程序需要进行逻辑地址到物理地址的转换时,它不必每次都去询问操作系统.

Modern day hardware has several devices that allow an operating system to support paging far more effectively. The most common of these is a Translation Lookaside Buffer, or TLB. This stores a sort of hardware page table cache, so that whenever a program needs to do a logical address to physical address translation, it doesn't have to go ask the operating system every time.

现代操作系统还通过延迟加载它们正在运行的部分进程来利用分页.例如,如果您启动 Microsoft Word,而不是将整个程序加载到内存中,操作系统只会将它需要的程序部分加载到内存中,并且只会在需要时获取程序的其他部分.这也需要在内存占用、启动速度以及程序中在需要加载新部件时出现延迟的频率之间进行权衡.

Modern operating systems also take advantage of paging by lazily-loading parts of the processes they are running. For instance, if you startup Microsoft Word, instead of loading the entire program into memory, the operating system will instead load only those parts of the program it needs into memory, and will grab the other parts of the program only as it needs them. This has trade-offs as well between memory footprint, boot speed, and how often delays occur within the program as new parts need to be loaded.

无论如何,也许比你想要的更多,但希望很有趣.

Anyway, maybe more than you are looking for, but hopefully interesting.

这篇关于操作系统“交换"有什么区别?和“页面"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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