Successfully reported this slideshow.
Your SlideShare is downloading. ×

Ruby gvl-improvement at ruby 1.9.3

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
JavaSE 7
JavaSE 7
Loading in …3
×

Check these out next

1 of 37 Ad
Advertisement

More Related Content

Similar to Ruby gvl-improvement at ruby 1.9.3 (20)

Recently uploaded (20)

Advertisement

Ruby gvl-improvement at ruby 1.9.3

  1. 1. Ruby 1.9.3 GVL Fujitsu Sunday, July 17, 2011
  2. 2. Who am I? Sunday, July 17, 2011
  3. 3. • • IO OS • usa Sunday, July 17, 2011
  4. 4. at Linux Kernel Summit 2010 Sunday, 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. GVL Sunday, July 17, 2011
  9. 9. What’s GVL • Global(or Giant) VM Lock • • multi thread issue Ruby script • CPU • Python Sunday, July 17, 2011
  10. 10. What’s GVL (cont.) • GVL • GVL • OS Sunday, July 17, 2011
  11. 11. f = false Thread.new { ....; f = true } Thread.pass until f Sunday, 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 core Sunday, July 17, 2011
  18. 18. if (th->interrupt_flag) { gvl_release(); sched_yield(); gvl_acquire(); } •gvl_release() gvl_acquire() sched_yield() • sched_yield() yield Sunday, 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 core Sunday, July 17, 2011
  21. 21. (ry CPU Thread core Thread Thread Thread core Thread Thread core Thread Sunday, July 17, 2011
  22. 22. Yield! Ruby Thread core Thread Thread core Ruby Thread Sunday, July 17, 2011
  23. 23. thread list head Thread core Ruby Thread Thread core Ruby Thread Sunday, July 17, 2011
  24. 24. Ruby Thread core Thread Thread core Ruby Thread POSIX Sunday, July 17, 2011
  25. 25. CFS yield • Linux RHEL5 RHEL6 • RHEL6 (CFS) sched_yield (RHEL5 knob • Java • Linux upstream knob CPU Sunday, July 17, 2011
  26. 26. • fairness Sunday, 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 pipe Sunday, July 17, 2011
  33. 33. • 1.9.2 • • • Sunday, July 17, 2011
  34. 34. vm_thread_mutex3 Sunday, July 17, 2011
  35. 35. Sunday, July 17, 2011
  36. 36. • CPU • GVL CPU • Ruby Sunday, July 17, 2011
  37. 37. Question? Sunday, July 17, 2011

Editor's Notes

  • \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

×