zoukankan      html  css  js  c++  java
  • CPU Affinity

    Reference:

    [1] http://www.linuxjournal.com/article/6799

    Soft vs. Hard CPU Affinity

    There are two types of CPU affinity. The first, soft affinity, also called natural affinity, is the tendency of a scheduler to try to keep processes on the same CPU as long as possible. It is merely an attempt; if it is ever infeasible, the processes certainly will migrate to another processor. The new O(1) scheduler in 2.5 exhibits excellent natural affinity. On the opposite end, however, is the 2.4 scheduler, which has poor CPU affinity. This behavior results in the ping-pong effect. The scheduler bounces processes between multiple processors each time they are scheduled and rescheduled. Table 1 is an example of poor natural affinity; Table 2 shows what good natural affinity looks like.

    Why One Needs CPU Affinity

    1. The first benefit of CPU affinity is optimizing cache performance. I said the O(1) scheduler tries hard to keep tasks on the same processor, and it does. But in some performance-critical situations—perhaps a large database or a highly threaded Java server—it makes sense to enforce the affinity as a hard requirement. Multiprocessing computers go through a lot of trouble to keep the processor caches valid. Data can be kept in only one processor's cache at a time. Otherwise, the processor's cache may grow out of sync, leading to the question, who has the data that is the most up-to-date copy of the main memory? Consequently, whenever a processor adds a line of data to its local cache, all the other processors in the system also caching it must invalidate that data. This invalidation is costly and unpleasant. But the real problem comes into play when processes bounce between processors: they constantly cause cache invalidations, and the data they want is never in the cache when they need it. Thus, cache miss rates grow very large. CPU affinity protects against this and improves cache performance.

    2. A second benefit of CPU affinity is a corollary to the first. If multiple threads are accessing the same data, it might make sense to bind them all to the same processor. Doing so guarantees that the threads do not contend over data and cause cache misses. This does diminish the performance gained from multithreading on SMP. If the threads are inherently serialized, however, the improved cache hit rate may be worth it.

    3. The third and final benefit is found in real-time or otherwise time-sensitive applications. In this approach, all the system processes are bound to a subset of the processors on the system. The specialized application then is bound to the remaining processors. Commonly, in a dual-processor system, the specialized application is bound to one processor, and all other processes are bound to the other. This ensures that the specialized application receives the full attention of the processor.

  • 相关阅读:
    HDU 1394 Minimum Inversion Number
    HDU 4931 Happy Three Friends
    BZOJ 1089 严格n元树 (递推+高精度)
    BZOJ 1088 扫雷Mine (递推)
    BZOJ 3038 上帝造题的七分钟2 (并查集+树状数组)
    BZOJ 3211 花神游历各国 (树状数组+并查集)
    BZOJ 1087 互不侵犯King (位运算)
    BZOJ 1002 轮状病毒 (基尔霍夫矩阵)
    BZOJ 1005 明明的烦恼 (组合数学)
    BZOJ 1058 报表统计 (STL)
  • 原文地址:https://www.cnblogs.com/codingforum/p/6652845.html
Copyright © 2011-2022 走看看