首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >伪造vs作为swapfile?

伪造vs作为swapfile?
EN

Ask Ubuntu用户
提问于 2018-03-19 13:37:40
回答 1查看 13.3K关注 0票数 36

我想知道创建一个swapfile与

代码语言:javascript
复制
fallocate -l 1G /swapfile

代码语言:javascript
复制
dd if=/dev/zero of=/swapfile bs=1024 count=1024

两者似乎都很好,但一个比另一个有优势吗?

我在网上唯一能找到的就是fallocate并不能在所有的文件系统上工作。

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2018-03-19 13:48:35

来自这个mkswap命令页

代码语言:javascript
复制
Note  that  a  swap  file  must  not contain any holes.  Using cp(1) to
create the file is not acceptable.  Neither is use of  fallocate(1)  on
file  systems  that support preallocated files, such as XFS or ext4, or
on copy-on-write filesystems like btrfs.   It  is  recommended  to  use
dd(1)  and  /dev/zero in these cases.  Please read notes from swapon(8)
before adding a swap file to copy-on-write filesystems.

来自这个swapon命令页

代码语言:javascript
复制
You should not use swapon on a file with holes.  This can  be  seen  in
the system log as

      swapon: swapfile has holes.

The  swap file implementation in the kernel expects to be able to write
to the file directly, without the assistance of the  filesystem.   This
is  a problem on preallocated files (e.g.  fallocate(1)) on filesystems
like XFS or ext4, and on copy-on-write filesystems like btrfs.

因此,虽然fallocate可能比dd更快,但它不适合创建交换文件,也不受交换相关工具的支持。

票数 38
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1017309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档