linux创建交换分区设置_如何在Linux上创建交换文件

linux创建交换分区设置

linux创建交换分区设置

The inside of a mechanical hard disk.
zentilia/Shutterstock.com zentilia / Shutterstock.com

Add swap space to a Linux computer, or increase the swap space that’s already present, without messing about with partitions. We show you the easy way to tailor your swap space.

将交换空间添加到Linux计算机,或增加已经存在的交换空间,而无需弄乱分区。 我们向您展示了定制交换空间的简便方法。

交换文件与交换分区 (Swap Files vs. Swap Partitions)

There are several scenarios where you might want to increase existing or add new swap space to your Linux computer.

在几种情况下,您可能希望增加现有空间或向Linux计算机添加新的交换空间。

  • Perhaps your swap space is frequently running at maximum or close to maximum.

    也许交换空间经常以最大或接近最大的速度运行。
  • It’s easy to click the wrong option during the installation process and to decline adding swap to your system inadvertently.

    很容易在安装过程中单击错误的选项,并拒绝在不经意间将交换添加到系统中。
  • Maybe you previously decided that you had so much random access memory (RAM) you didn’t need any swap, and you’ve changed your mind.

    也许您先前认为您有这么多的随机存取存储器 (RAM),不需要进行任何交换,但是您改变了主意。

  • Sometimes you inherit the administration of a system that has no swap, for reasons you’ll never be able to discover.

    有时,由于永远无法发现的原因,您继承了没有交换的系统的管理。

The simple solution to all of these is to add a swap file to your computer. This is a special file, pre-allocated and reserved for use as swap space. A swap file will work in tandem with any existing swap you may have, whether that is a swap file or a swap partition.

所有这些的简单解决方案是将交换文件添加到您的计算机 。 这是一个特殊文件,已预先分配并保留用作交换空间。 交换文件将与您可能拥有的任何现有交换(包括交换文件或交换分区)协同工作。

At one time, there was a performance hit for using a swap file compared to a swap partition. That’s no longer the case with improvements in the performance of mechanical (spinning) hard drives and more efficiency in the swap functions within the Linux operating system. In fact, some Linux distributions now default to creating swap files rather than swap partitions.

一次,与交换分区相比,使用交换文件的性能受到了影响。 机械(旋转)硬盘性能的提高和Linux操作系统中交换功能的更高效率不再是这种情况。 实际上,某些Linux发行版现在默认创建交换文件,而不是交换分区。

Swap isn’t just used as a means to free up RAM when you’re running low on memory. It’s an important part of a well functioning system. Without any swap, sane memory management becomes very difficult for the kernel to achieve. Let’s look at the easy way to add some swap space.

交换不仅仅用于在内存不足时释放RAM。 这是运作良好的系统的重要组成部分。 如果不进行任何交换,则对于内核而言,健全的内存管理将变得非常困难。 让我们看一下添加一些交换空间的简单方法。

在我们深入之前:Btrfs和SSD (Before We Dive In: Btrfs and SSDs)

There are two points we’d like to discuss quickly.

我们想快速讨论两点。

The Btrfs file system has certain caveats about swap files. At one time, there was a conflict between the copy-on-write nature of Btrfs, which wanted to operate in one way and swap files that needed to operate in another. Some functions that swap files depend on were not implemented, and some assumptions that were made about block numbering within the swap files did not hold true with Btrfs. So swap files were not supported.

Btrfs文件系统对交换文件有一些警告。 一次,Btrfs 的写时复制特性(想要以一种方式进行操作)与交换需要以另一种方式进行操作的文件之间存在冲突。 交换文件所依赖的某些功能尚未实现,并且有关交换文件中块编号的某些假设在Btrfs中不成立。 因此不支持交换文件。

Since kernel 5.0, you can have swap files in Btrfs file systems if they are set up with the following requirements:

从内核5.0开始,如果按以下要求设置了交换文件 ,则可以在Btrfs文件系统中拥有它们:

  • No copy-on-write (NOCOW) files.

    没有写时复制(NOCOW)文件。
  • They’re not compressed.

    他们没有被压缩。
  • They don’t straddle different hard drives.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值