# 是否应该将我的交换文件从 2GB 增加？

**URL:** <https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808>\
**Category:** Self-hosting\
**Created:** [2025年十二月20日 16:34 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808 "2025-12-20T16:34:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)\
**Post date:** [2025年十二月20日 16:34 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/1 "2025-12-20T16:34:07Z")

</div>

我最近在 Hetzner 服务器上重新安装了 Discourse。现在我有 4GB 内存和 40GB 空间。默认情况下，它创建了 2GB 的交换文件

![image](https://global.discourse-cdn.com/meta/original/4X/3/e/2/3e2147761e7a35efe92149f0818940f6f311f076.png)

这足够了吗？

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2025年十二月20日 16:52 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/2 "2025-12-20T16:52:22Z")

</div>

在构建过程中使用 htop 观看。可能足够了。

---

<div class="post-metadata">

**Author:** ![Rubi](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@Rubi](https://meta.discourse.org/u/Rubi)\
**Post date:** [2025年十二月21日 04:42 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/3 "2025-12-21T04:42:31Z")

</div>

您在服务器上安装时使用了哪个 Linux 发行版？

我本来会建议使用交换文件而不是交换分区。

交换文件是目前大多数发行版的默认设置，在调整交换性（swappiness）方面更加灵活。

---

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2025年十二月21日 05:27 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/4 "2025-12-21T05:27:19Z")

</div>

我没有看到提到交换分区？

> [@alltiagocom](#):
>
> 它创建了 2GB 的交换文件

我认为 2GB 交换分区 + 4GB 内存是足够的。除非你还在服务器上运行其他东西，否则我认为你不需要更多的交换空间。

---

<div class="post-metadata">

**Author:** ![Rubi](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@Rubi](https://meta.discourse.org/u/Rubi)\
**Post date:** [2025年十二月21日 05:41 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/5 "2025-12-21T05:41:05Z")

</div>

抱歉，你说得对。

应该在回复前多喝点咖啡 😉

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2025年十二月21日 07:00 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/6 "2025-12-21T07:00:08Z")

</div>

这取决于正在使用的插件、人工智能等有多少。对我来说，4+2是不够的。

---

<div class="post-metadata">

**Author:** ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)\
**Post date:** [2025年十二月21日 09:22 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/7 "2025-12-21T09:22:52Z")

</div>

我不是专家，所以我只拍了一些过程中的截图：

![SCR-20251221-ilhi](https://global.discourse-cdn.com/meta/original/4X/4/1/d/41dc4978adae41a861ea1b7ea8a248da2d940d8d.png)

![SCR-20251221-imkv](https://global.discourse-cdn.com/meta/original/4X/e/4/2/e42a6b79c1b007c424802d03a166eacb8f6028d9.png)

完成后立即是这样：

![SCR-20251221-imvf](https://global.discourse-cdn.com/meta/original/4X/0/a/e/0aef60f58eb9d72bfde1e21da0c1aa0bda39f620.png)

然后，我让它再运行了一会儿，因为我看到 `0` 和 `1` 条（我假设是核心？）都达到了大约 80%，我想看看这是否只是暂时的：

![SCR-20251221-ince](https://global.discourse-cdn.com/meta/original/4X/a/5/a/a5a37b1cad170d2b04933e9a870345988f65e6af.png)

![SCR-20251221-infh](https://global.discourse-cdn.com/meta/original/4X/6/3/6/63688348c787a0f6ec0ef077feefdf3c9bb33663.png)

![SCR-20251221-inoo](https://global.discourse-cdn.com/meta/original/4X/c/5/6/c565cd701ba23233806f5378668d7616e4c3dcaa.png)

![SCR-20251221-inzv](https://global.discourse-cdn.com/meta/original/4X/c/5/1/c51055d0c14d102a2d487973ad633bec9bc06f95.png)

这有帮助吗？

大部分时间里，`Mem` 平均不超过 500M。重建期间，最高值大约是 1GB 左右，但时间很短。只有在重建停止后，它才达到了 1.6GB 左右的数值。

即使现在，在它停止了几分钟后，我仍然看到这个，所以我想知道这是否正常？

![image](https://global.discourse-cdn.com/meta/original/4X/0/9/e/09e729cc12226860536e1bda4560e6a765b047ba.png)

---

<div class="post-metadata">

**Author:** ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)\
**Post date:** [2025年十二月21日 09:25 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/8 "2025-12-21T09:25:30Z")

</div>

@NateDhaliwal 和 @Rubi 我没有自己做任何操作，它是自动创建的，所以我猜是交换文件（swapfile）？我只是按照官方说明安装的，让它自行运行。希望这能说明白？

@Jagster 我没有安装太多东西。没有人工智能（AI），至少不是我自己安装的，除了原生的插件外，我只安装了 3 个，还有组件（Components），可能 20 个或更少，但我认为那些不太相关？

---

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2025年十二月21日 09:59 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/9 "2025-12-21T09:59:46Z")

</div>

是的，这是一个交换文件。 ~~我记得今年早些时候做了一个更改，如果内存低于 5GB（我记得以前是 1GB？），则创建一个交换文件。~~

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2025年十二月21日 10:49 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/10 "2025-12-21T10:49:46Z")

</div>

很明显，有足够的备用容量，你可以开始了 👍

---

<div class="post-metadata">

**Author:** ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)\
**Post date:** [2025年十二月21日 10:59 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/11 "2025-12-21T10:59:44Z")

</div>

> [@merefield](#):
>
> 在构建过程中使用 `htop` 观察。

我下次可能会自己试一下。你是只打开一个单独的终端窗口并输入 `htop` 吗？有什么推荐的选项吗？我会自己上网搜索更多关于它的通用信息。

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2025年十二月21日 11:20 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/12 "2025-12-21T11:20:35Z")

</div>

是的。但请注意，这不是一个精细的工具。很明显，这里 2GB 已经足够了，但如果你想更准确地了解交换空间（swap）的使用峰值，你可以研究一下 `sysstat` 和日志记录。我把这项研究留给你。

---

<div class="post-metadata">

**Author:** ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)\
**Post date:** [2025年十二月21日 11:48 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/13 "2025-12-21T11:48:51Z")

</div>

太棒了！感谢您的反馈和 `htop` 命令，我之前不知道这个命令。已将其保存在我的笔记中。

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2025年十二月21日 17:55 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/14 "2025-12-21T17:55:07Z")

</div>

对我个人而言，我不会使用 htop，而是使用 `vmstat 5`，因为它会留下一个清晰的文本日志记录它所看到的情况（每 5 秒一次）。这很方便，因为你可以向上滚动，或者搜索最糟糕的时刻。最糟糕的时刻才是真正重要的，特别是如果它导致了故障。平均情况（在重建期间）没有参考价值。使用像 htop 这样的工具，你很容易错过峰值，一旦过去就无法回顾。

我以前也发过关于 vmstat 的帖子，并解释了如何解释输出。

---

<div class="post-metadata">

**Author:** ![alltiagocom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alltiagocom/32/492709_2.png) [@alltiagocom](https://meta.discourse.org/u/alltiagocom)\
**Post date:** [2025年十二月27日 20:30 UTC](https://meta.discourse.org/t/should-i-increase-the-swap-file-from-2gb/391808/15 "2025-12-27T20:30:38Z")

</div>

谢谢。我对这一切非常陌生，所以我总是添加这些“要点”并保存到我的笔记中。非常感谢！
