> ## Documentation Index
> Fetch the complete documentation index at: https://docs.windsurf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Linux 上出现 'No Space Left on Device' 导致 Language Server 启动失败

> 解决由于 inotify 监视/实例数量限制（ENOSPC）耗尽而导致的 Linux language server 启动失败问题。内容包括症状表现、诊断命令以及通过 sysctl 进行修复的方法。

在 Linux 上，即使系统还有大量可用磁盘空间，Windsurf language server 也可能在启动时失败，并出现包含 **"no space left on device"** 的错误。这是由于 Linux 内核的 **inotify watch** 或 **inotify instance** 数量限制被耗尽所致，而不是因为磁盘空间真的用完了。

language server 使用 **inotify** 监视工作区中的文件更改。当触及内核限制时，系统会返回 `ENOSPC` 错误——通常会表现为 "no space left on device"。

***

<div id="symptoms">
  ## **现象**
</div>

你可能会在 Windsurf 的输出日志中看到如下内容：

```
Language server failed - no space left on device: no space left on device
```

通常会伴随引用如下组件的堆栈跟踪（stack trace）：

* `file_watcher`
* `AddTrackedWorkspace`
* `AddDirectoriesRecursive`

通常会出现以下现象：

* Windsurf 能正常打开
* 语言服务器在启动后立即退出
* 依赖语言服务器的功能（例如 Cascade、Autocomplete）无法使用

***

<div id="diagnosis">
  ## **诊断**
</div>

<div id="1-check-your-current-inotify-limits">
  ### **1. 检查你当前的 inotify 限制值**
</div>

运行以下命令：

```shell theme={null}
# Check the maximum number of inotify watches per user
cat /proc/sys/fs/inotify/max_user_watches

# 检查每个用户的 inotify instances 最大数量
cat /proc/sys/fs/inotify/max_user_instances
```

常见的默认值是 **8192** 个 watch 和 **128** 个实例。对于在大型工作区（尤其是 monorepo）中的 IDE 使用来说，这些值通常过低，并且可用配额还可能被其他消耗 inotify 资源的进程进一步压缩（容器、同步工具、其他编辑器、后台服务）。

<div id="2-check-how-many-inotify-instances-are-currently-in-use">
  ### **2. 检查当前有多少 inotify 实例正在使用**
</div>

```shell theme={null}
find /proc/*/fd -lname anon_inode:inotify 2>/dev/null | wc -l
```

如果该计数接近（或超过）你的 `max_user_instances`，新的 inotify 用户（例如语言服务器）可能会初始化失败。

***

<div id="solution">
  ## **解决方案**
</div>

提升 inotify 限制值。你可以选择临时（重启前有效）或永久性地应用这些更改。

<div id="temporary-fix-until-reboot">
  ### **临时解决方案（在重启前有效）**
</div>

```shell theme={null}
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs.inotify.max_user_instances=1024
```

<div id="permanent-fix-survives-reboot">
  ### **永久解决方案（重启后仍然生效）**
</div>

```shell theme={null}
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
echo "fs.inotify.max_user_instances=1024" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
```

在采用任一修复措施后，**重启 Windsurf**。语言服务器应能正常启动。

这是 Linux 上众所周知的一个限制，会影响其他依赖文件监视器的 IDE 和开发者工具。如果你们组织采用集中方式管理系统配置，请联系 IT / 基础设施团队应用这些 sysctl 设置。

***

<div id="when-to-use-which-value">
  ## **何时使用哪个数值**
</div>

* **`fs.inotify.max_user_watches=524288`**\
  推荐用于大型代码仓库或 monorepo。每个被监控的文件/目录都会消耗内核内存（在 64 位系统上通常每个监控项约占用 \~1 KB），因此 **524288 个监控项** 大约会使用 **\~512 MB** 的内核内存。
* **`fs.inotify.max_user_instances=1024`**\
  推荐在运行多个会创建 inotify 实例的应用程序时使用（多个 IDE 窗口、容器、文件同步工具等）。默认值 **128** 在开发环境中很容易被耗尽。
