论文标题
当malloc()永远不会返回零时 - 可靠性作为幻觉
When malloc() Never Returns NULL -- Reliability as an Illusion
论文作者
论文摘要
几十年来,提供的软件工程师的指导一直是检查内存分配结果。为了避免崩溃,必须进行此验证步骤。但是,在用户模式下,在现代操作系统(OS)中,例如Android,FreeBSD,iOS和MACOS,呼叫者没有机会处理内存分配失败。这种行为特征是由称为“内存(OOM)杀手”的系统组件的动作引起的。我们确定默认情况下,唯一的主流操作系统是Microsoft Windows,它可以检测到内存分配故障。关于应用程序可以处理OOM错误的错误期望会对其设计产生负面影响。错误处理代码的存在产生了可靠性的幻想,并且在代码和代码大小的行中浪费了。我们描述了在低内存条件下流行OSS样本的当前行为,并为未来的工程实践提供了建议。
For decades, the guidance given to software engineers has been to check the memory allocation results. This validation step is necessary to avoid crashes. However, in user mode, in modern operating systems (OS), such as Android, FreeBSD, iOS, and macOS, the caller does not have an opportunity to handle the memory allocation failures. This behavioral trait results from the actions of a system component called an out-of-memory (OOM) killer. We identify that the only mainstream OS that, by default, lets applications detect memory allocation failures is Microsoft Windows. The false expectation that an application can handle OOM errors can negatively impact its design. The presence of error-handling code creates an illusion of reliability and is wasteful in terms of lines of code and code size. We describe the current behavior of a sample of popular OSs during low-memory conditions and provide recommendations for engineering practices going forward.