False Sharing 회피

False sharing 은 멀티 프로세서 환경에서 서로 다른 쓰레드가 공유 캐시 라인의 서로 다른 위치에 쓰려고 할 때 발생한다고 합니다. 이로 인해 심각한 성능 하락이 생길 수 있다고 합니다.

다음은 False sharing 이 발생하는 예입니다. 그림에서 보는 바와 같이 Thread 0 과 Thread 1 이 각각 Core 0, Core 1 에서 동작하고 있습니다. 그리고 각각 개인 캐시(Private Cache) 인 L1 캐시를 가지고, 공유 캐시인 L2 캐시를 가지고 동작할 때, Core 0, 1 이 각각 공유 캐시의 같은 라인을 사용하는 개인 캐시 라인에 쓰려고 할 경우 발생합니다.

false_sharing

False sharing 을 피하는 방법들

  • 쓰레드 간에 공유하지 않는 데이터를 서로 다른 캐시 라인에 할당하도록 합니다.
  • 전역 변수를 함수의 지역 변수로 복사하고, 처리한 후 함수에서 나가기 전에 지역 변수를 전역 변수에 복사해 줍니다.
  • 쓰레드를 하나의 코어에서 수행하도록 합니다.

Reference

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 Korea License.
This entry was posted in Development and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Notify me of followup comments via e-mail. You can also subscribe without commenting.