Posted on 2007-10-15 09:09
dennis 閱讀(676)
評論(0) 編輯 收藏 所屬分類:
涂鴉 、
linux & C
hack有水平高低之分,最近看到一個blog,牛人的hack水平讓你不得不服。情況是這樣的,牛人在使用
mongrel_light_cluster的過程中,發現這個cluster違反了copy-on-write的語義,導致占用了太多的內存。根本原因在于Ruby的GC機制是
marks all memory pages as dirty。為了減少內存的占用,讓集群跑更多mongrel,牛人走上了hack之路,給c ruby打補丁,他也真的
做到了。c ruby的GC使用的是mark and sweep(標記并清除)的垃圾收集算法,他發現在mark過程中使用了
st_table,這個數據結構占用了很大的內存,那么就改用
Google’s sparse_hash。然后他又寫了一個memory pool,以應對marking和sweep使用過程中對malloc和free調用帶來的內存損失,因為在x86 GNU/linux gcc上,malloc函數如果申請的內存小于76KB,那么當free的時候這些內存不會被返還給操作系統。他的hack之路還沒結束,有興趣的關注他的blog:
http://izumi.plan99.net/blog/index.php/