Ruby 1.9.3                        GVL                                           FujitsuSunday, July 17, 2011
Who am I?Sunday, July 17, 2011
•                    •       IO   OS                    • usaSunday, July 17, 2011
at Linux Kernel                         Summit 2010Sunday, July 17, 2011
Shyouhei commiter ranking                                                me!Sunday, July 17, 2011
Sunday, July 17, 2011
Sunday, July 17, 2011
GVLSunday, July 17, 2011
What’s GVL                    • Global(or Giant) VM Lock                    •                    •             multi threa...
What’s GVL (cont.)                    • GVL                    •        GVL                    • OSSunday, July 17, 2011
f = false                        Thread.new {                            ....;                            f = true        ...
GVL design                    • Lock                            wait                             (e.g. write)             ...
GVL design (cont.)                    •                    •Sunday, July 17, 2011
GVL design (cont.)                •       ON            if (th->interrupt_flag) {                                          ...
•              OSS            while (true) {                               (         )          lock();                   ...
Why?Sunday, July 17, 2011
CPU                          cpu1        cpu2        memory          core core   core core   memory          1            ...
if (th->interrupt_flag) {                                      gvl_release();                                      sched_yi...
sched_yield                    • Unix                               API                             http://pubs.opengroup....
Thread                core                                 Thread   Thread   Thread                        Thread         ...
(ry                                          CPU                        Thread                core             Thread     ...
Yield!                           Ruby                          Thread                core               Thread            ...
thread list                                          head                        Thread                core              R...
Ruby                        Thread                core             Thread                        Thread                  c...
CFS yield                    • Linux    RHEL5   RHEL6                    • RHEL6               (CFS)   sched_yield        ...
•   fairnessSunday, July 17, 2011
•          fairness                    •                     GVL         gvl_acquire                            gvl_releas...
vm_thread_pipe  lmax = 100_000  r, w = IO.pipe  [Thread.new{    lmax.times{      w.write(a)    }    p "w:exit"  }, Thread....
(´   ω   )Sunday, July 17, 2011
• fairness                    •         unfairness                    • Linux                    •Sunday, July 17, 2011
1.9.3                    • 1.9.3      IO   GVL release                        GVL release                    • IO         ...
1.9.2          1.9.3              2         1.5              1         0.5              0                  create_join mut...
•   1.9.2                    •                    •                    •Sunday, July 17, 2011
vm_thread_mutex3Sunday, July 17, 2011
Sunday, July 17, 2011
•            CPU           • GVL              CPU           •                   RubySunday, July 17, 2011
Question?Sunday, July 17, 2011
Upcoming SlideShare
Loading in …5
×

Ruby gvl-improvement at ruby 1.9.3

12,018 views

Published on

ruby 1.9.3 でのGVLの改善について解説します

Published in: Technology
0 Comments
14 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
12,018
On SlideShare
0
From Embeds
0
Number of Embeds
4,504
Actions
Shares
0
Downloads
42
Comments
0
Likes
14
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Ruby gvl-improvement at ruby 1.9.3

    1. 1. Ruby 1.9.3 GVL FujitsuSunday, July 17, 2011
    2. 2. Who am I?Sunday, July 17, 2011
    3. 3. • • IO OS • usaSunday, July 17, 2011
    4. 4. at Linux Kernel Summit 2010Sunday, July 17, 2011
    5. 5. Shyouhei commiter ranking me!Sunday, July 17, 2011
    6. 6. Sunday, July 17, 2011
    7. 7. Sunday, July 17, 2011
    8. 8. GVLSunday, July 17, 2011
    9. 9. What’s GVL • Global(or Giant) VM Lock • • multi thread issue Ruby script • CPU • PythonSunday, July 17, 2011
    10. 10. What’s GVL (cont.) • GVL • GVL • OSSunday, July 17, 2011
    11. 11. f = false Thread.new { ....; f = true } Thread.pass until fSunday, July 17, 2011
    12. 12. GVL design • Lock wait (e.g. write) • lock, unlock Python, QEMU, Linux • GVL acquire/release pthread_mutex_{lock,unlock}Sunday, July 17, 2011
    13. 13. GVL design (cont.) • •Sunday, July 17, 2011
    14. 14. GVL design (cont.) • ON if (th->interrupt_flag) { gvl_release(); sched_yield(); gvl_acquire(); }Sunday, July 17, 2011
    15. 15. • OSS while (true) { ( ) lock(); if (hoge) { unlock(); break; • } unlock(); • thread lock rep_nop(); } hoge=1 lock(); hoge = 1; unlock();Sunday, July 17, 2011
    16. 16. Why?Sunday, July 17, 2011
    17. 17. CPU cpu1 cpu2 memory core core core core memory 1 2 core core core coreSunday, July 17, 2011
    18. 18. if (th->interrupt_flag) { gvl_release(); sched_yield(); gvl_acquire(); } •gvl_release() gvl_acquire() sched_yield() • sched_yield() yieldSunday, July 17, 2011
    19. 19. sched_yield • Unix API http://pubs.opengroup.org/onlinepubs/009695399/ functions/sched_yield.html int sched_yield(void); • The sched_yield() function shall force the running thread to relinquish the processor until it again becomes the head of its thread list. •Sunday, July 17, 2011
    20. 20. Thread core Thread Thread Thread Thread core Thread coreSunday, July 17, 2011
    21. 21. (ry CPU Thread core Thread Thread Thread core Thread Thread core ThreadSunday, July 17, 2011
    22. 22. Yield! Ruby Thread core Thread Thread core Ruby ThreadSunday, July 17, 2011
    23. 23. thread list head Thread core Ruby Thread Thread core Ruby ThreadSunday, July 17, 2011
    24. 24. Ruby Thread core Thread Thread core Ruby Thread POSIXSunday, July 17, 2011
    25. 25. CFS yield • Linux RHEL5 RHEL6 • RHEL6 (CFS) sched_yield (RHEL5 knob • Java • Linux upstream knob CPUSunday, July 17, 2011
    26. 26. • fairnessSunday, July 17, 2011
    27. 27. • fairness • GVL gvl_acquire gvl_release mutex_lock(&lock->lock) mutex_lock(&lock->lock) cond_wait(&lock->wait) lock->acquired = 0; lock->acquired = 1; cond_signal(&lock->wait_cond) // // cond_signal(&lock->switch_cond) cond_wait(&lock->switch_cond) mutex_unlock(&lock->lock) mutex_unlock(&lock->lock)Sunday, July 17, 2011
    28. 28. vm_thread_pipe lmax = 100_000 r, w = IO.pipe [Thread.new{ lmax.times{ w.write(a) } p "w:exit" }, Thread.new{ lmax.times{ r.read(1) } p "r:exit" }].each{|t| t.join}Sunday, July 17, 2011
    29. 29. (´ ω )Sunday, July 17, 2011
    30. 30. • fairness • unfairness • Linux •Sunday, July 17, 2011
    31. 31. 1.9.3 • 1.9.3 IO GVL release GVL release • IO GVL 1.9.2 IO GVL switch • GVL release switch GVL •Sunday, July 17, 2011
    32. 32. 1.9.2 1.9.3 2 1.5 1 0.5 0 create_join mutex1 mutex2 mutex3 pass_flood pipeSunday, July 17, 2011
    33. 33. • 1.9.2 • • •Sunday, July 17, 2011
    34. 34. vm_thread_mutex3Sunday, July 17, 2011
    35. 35. Sunday, July 17, 2011
    36. 36. • CPU • GVL CPU • RubySunday, July 17, 2011
    37. 37. Question?Sunday, July 17, 2011

    ×