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

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

问题描述

这两个术语在操作系统中有什么区别:swap和page?

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天全站免登陆