You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Linux内核的semaphore down()函数被标记为废弃?

Why is the Linux kernel's down() semaphore function deprecated?

Great question! Let's break down why down() was marked deprecated, and why the recommended alternatives (down_interruptible() or down_killable()) are far better choices for kernel code.

The core issue with down()

When you call down() to grab a semaphore, if the semaphore isn't available, the calling process drops into an uninterruptible sleep state (TASK_UNINTERRUPTIBLE). Here's why that's such a problem:

  • Once in this state, the process won't wake up for any signal—even a fatal SIGKILL that would normally terminate a stuck process cold.
  • If the process holding the semaphore crashes, deadlocks, or gets stuck indefinitely, the process waiting via down() will hang forever. This can lead to unresponsive system components, or even force a full system reboot to fix.

Why the alternatives are safer

The recommended functions fix this critical flaw by letting waiting processes respond to signals:

  • down_interruptible(): Puts the process into an interruptible sleep state (TASK_INTERRUPTIBLE). If a signal (like SIGINT from Ctrl+C) hits while waiting, the process wakes up and returns the -EINTR error code. This lets developers handle interruptions gracefully, and gives users a way to terminate stuck processes without rebooting.
  • down_killable(): A middle-ground option that only responds to fatal signals (like SIGKILL). This is perfect for code paths that shouldn't be interrupted by regular signals, but still need to let the system terminate the process if absolutely necessary.

The kernel community's mindset

Deprecating down() ties directly to the Linux kernel's core values of system robustness and responsiveness. Uninterruptible sleep creates unnecessary risk of system lockups, so the community pushes developers to use signal-aware alternatives that let the system recover from unexpected issues far more easily.

内容的提问来源于stack exchange,提问作者luobuda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:10:39