ITPub博客

首页 > Linux操作系统 > Linux操作系统 > latch 获取失败时为什么要spin(转)

latch 获取失败时为什么要spin(转)

原创 Linux操作系统 作者:lsq_008 时间:2009-10-22 14:33:49 0 删除 编辑

3.3.1.1 Why spin?

The idea of spinning is that another process executing on another CPU may release the latch, thereby allowing the spinning process to proceed. Of course, it makes no sense to spin on a machine with just one CPU, and so Oracle does not. The alternative to spinning is to relinquish the CPU and allow another process to use it. At first glance, this may seem like a good idea. However, for a CPU to stop executing one process and begin executing another, it must perform. a context switch . That is, it must save the context of the first process, determine which process to schedule next, and then resume the context of the next process. The context of a process is essentially a set of CPU register values that describes the exact state of the process.

The implementation of context switches is highly machine dependent. In fact, it is typically written in assembly language. System vendors make  every effort to minimize the size of the context data and optimize context switching by using tricks such as remapping memory addresses rather than copying data. Nevertheless, context switching remains an expensive operation because various kernel data structures have to be searched and updated. Access to these structures is protected by spinlocks, which are the equivalent of latches for the operating system. On a large and busy system, context switching normally consumes between 1% and 3% of CPU time. So if a context switch can be avoided

by spinning briefly, then some CPU time can be saved, and the waiting time to obtain the latch can be minimized. For this reason, spinning briefly is normally preferable to relinquishing the CPU immediately.

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10972173/viewspace-617154/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 何为buffer sort?
请登录后发表评论 登录
全部评论
十余年大型金融及电信系统数据库管理经验,曾服务于中国建设银行、中国移动。对oracle,mysql数据库有深入了解。 擅长python开发,独立开发了开源数据库自动化监控运维平台Power Monitor。

注册时间:2008-02-29

  • 博文量
    335
  • 访问量
    1369124