Upgrade to Pro — share decks privately, control downloads, hide ads and more …

slub: alloc and free

slub: alloc and free

Masami Ichikawa

January 17, 2015
Tweet

More Decks by Masami Ichikawa

Other Decks in Programming

Transcript

  1. *OUFSGBDFT w ֎෦ʹެ։͍ͯ͠Δओͳ*' w LNFN@DBDIF@BMMPD  w LNFN@DBDIF@BMMPD@OPEF  w

    $0/'*(@/6."Z w LNFN@DBDIF@GSFF  w 4MVC಺෦ͷ*' w TMBC@BMMPD@OPEF  w TMBC@GSFF
  2. TMBC@BMMPD@OPEF w BMMPDBUFର৅ͷTMBCΛ؅ཧ͢ΔΦϒδΣΫτ w ('1ϑϥά w /6."ϊʔυ w LNFN@DBDIF@BMMPD ͔Βݺ͹Εͨ৔߹͸/6."@/0@/0%&͕࢖ΘΕΔ

    w ݺͼग़͠ݩͷΞυϨε w σόοά༻ w @3&5@*1@ϚΫϩʢ@@CVJMUJO@SFUVSO@BEESFTT  ʣΛ౉͢ TUBUJD@@BMXBZT@JOMJOFWPJE TMBC@BMMPD@OPEF TUSVDULNFN@DBDIF T    HGQ@UHGQqBHT JOUOPEF VOTJHOFEMPOHBEES
  3. TMBC@GSFF w GSFFର৅ͷTMBCΛ؅ཧ͢ΔΦϒδΣΫτ w GSFFର৅ͷPCKFDUΛؚΉQBHF w GSFFର৅ͷTMBCΩϟογϡ w ݺͼग़͠ݩͷΞυϨε w

    TMBC@BMMPD@OPEF ͱಉ༷ʹσόοά༻ TUBUJD@@BMXBZT@JOMJOFWPJETMBC@GSFF TUSVDULNFN@DBDIF T     TUSVDUQBHF QBHF WPJE Y VOTJHOFEMPOHBEES
  4. "MMPDBUJPOqPX LNFN@DBDIF@BMMPD  TMBC@BMMPD@OPEF  DVSSFOUDQVʹTMBCΩϟογϡ͕͋Δʁ DGSFFMJTU/6--   ͋Ε͹ɺ࣍ճBMMPD࣌ͷฦ٫༻ΦϒδΣΫτΛΩϟογϡʹࡌͤɺGSFFMJTUΛฦ͢

     ͳ͚Ε͹@@TMBC@BMMPD ͰQBSUJBMMJTUΛ୳͢ @@TMBC@BMMPD  /6."ϊʔυΛݟ͍ͯͬͯ࢖͑ͦ͏ͳTMBCΩϟογϡ͕͋Δʁ  ࢖͑Δ΋ͷ͕͋Ε͹ͦΕΛฦ͢  ݟ͔ͭΒͳ͚Ε͹OFX@TMBC@PCKFDUT Ͱߋʹݕࡧ  @@TMBC@BMMPD Ҏ߱Ͱฦ͖ͬͯͨΦϒδΣΫτΛGSFFMJTUͱͯ͠ઃఆ OFX@TMBC  QBSUJBMMJTUͷݕࡧͱɺඞཁͳΒTMBCDBDIFͷ৽ن࡞੒  QBSUJBMMJTUΛḷͬͯ࢖͑Δ΋ͷ͕͋Ε͹ͦΕΛฦ٫  ͳ͚Ε͹OFX@TMBC Ͱ৽ن࡞੒ OFX@TMBC  BMMPDBUF@TMBC ͰQBHFΛ֬อ  ֬อͨ͠QBHFʹରͯ͠TMBCPCKFDUΛઃఆ
  5. TMBC@BMMPD@OPEF w ԼهͷॲཧͰTMBCΛ৽نʹ࡞Δ͔νΣοΫ w VOMJLFMZͷ৚݅ʹೖΒͳ͍৔߹ GBTUQBUI  w ࣍ճͷBMMPDʹඋ͑ΔॲཧΛ࣮ߦ͠ɺPCKFDUΛฦ͢ w

    VOMJLFMZͳ৚݅ʹ֘౰ͨ͠৔߹ TMPXQBUI  w ۭ͖TMBCͷ୳ࡧͱඞཁͳΒ৽ن࡞੒ w @@TMBC@BMMPD Λݺͼग़͠ PCKFDUDGSFFMJTU  QBHFDQBHF  JG VOMJLFMZ PCKFDUccOPEF@NBUDI QBHF OPEF \ OPEF͕/6."@/0@/0%&ͳ৔߹͸͕̍ฦΔɻ LNFN@DBDIF@BMMPD ͷ৔߹ɺOPEF͸ /6."@/0@/0%&͕࢖ΘΕΔɻ
  6. TMBC@BMMPD@OPEF w GBTUQBUIͰ͸࣍ճͷBMMPDʹ޲͚ͯઌಡΈΛ࣮ߦ WPJE OFYU@PCKFDUHFU@GSFFQPJOUFS@TBGF T PCKFDU  JG VOMJLFMZ

    UIJT@DQV@DNQYDIH@EPVCMF      TDQV@TMBCGSFFMJTU TDQV@TMBCUJE      PCKFDU UJE      OFYU@PCKFDU OFYU@UJE UJE \    OPUF@DNQYDIH@GBJMVSF TMBC@BMMPD T UJE     HPUPSFEP ^ QSFGFUDI@GSFFQPJOUFS T OFYU@PCKFDU  TDQV@TMBCGSFFMJTUPCKFDEU TDQV@TMBCUJEUJE ͳΒOFYU@PCKFDU OFYU@UJE UJE ͕৽͍͠GSFFMJTU UJEʹͳΔ ࣍ճͷLNFN@DBDIF@BMMPD Ͱฦ͢PCKFDU ΛDQVͷΩϟογϡʹࡌͤΔ ࣍ͷۭ͖PCKFDUऔಘ
  7. @@TMBC@BMMPD w ࢖͑ΔTMBCΩϟογϡPS৽ن࡞੒͠ɺGSFFMJTUΛઃఆ w DQBHF͕/6--ͳΒTMBCΩϟογϡͷ৽ن࡞੒ w OPEFࢦఆ͕͋Δ৔߹ w QBHFͱQBHF͕͋ΔOPEF͕Ұக͠ͳ͍৔߹͸৽ن࡞੒ w

    QBHFͱLNFN@DBDIF@BMMPD Ͱ࢖༻ͨ͠('1ϑϥά͕ҧ͏৔߹΋৽ ن࡞੒ w QBHFGSFFMJTU͕/6--ʢۭ͖ΦϒδΣΫτແ͠ʣͷ৔߹΋৽ن࡞੒ w GSFFMJTUʹTMBCPCKFDU͕͋Ε͹MPBE@GSFFMJTUϥϕϧͷॲཧ΁
  8. @@TMBC@BMMPD w GSFFMJTUͷઃఆ w ࠓճฦ٫෼͸͢Ͱʹ͋ΔͷͰMPBE@GSFFMJTUͰ࣍ճ ෼Λઃఆ MPBE@GSFFMJTU  DGSFFMJTUHFU@GSFFQPJOUFS T

    GSFFMJTU   DUJEOFYU@UJE DUJE   MPDBM@JSR@SFTUPSF qBHT   SFUVSOGSFFMJTU ࣍ճͷBMMPDͰฦ͢PCKFDUɺUJEΛઃఆ
  9. @@TMBC@BMMPD w TMBCDBDIFͷ৽ن࡞੒ OFX@TMBC  JG DQBSUJBM \  

    QBHFDQBHFDQBSUJBM   DQBSUJBMQBHFOFYU   TUBU T $16@1"35*"-@"--0$    DGSFFMJTU/6--   HPUPSFEP  ^  GSFFMJTUOFX@TMBC@PCKFDUT T HGQqBHT OPEF D   JG VOMJLFMZ GSFFMJTU \   TMBC@PVU@PG@NFNPSZ T HGQqBHT OPEF    MPDBM@JSR@SFTUPSF qBHT    SFUVSO/6--  ^  QBHFDQBHF  JG MJLFMZ LNFN@DBDIF@EFCVH T QGNFNBMMPD@NBUDI QBHF HGQqBHT    HPUPMPBE@GSFFMJTU ৽ن࡞੒લʹDQVʹؔ࿈͢ΔQBSUJBMMJTU͔Β࢖͑Δ ΩϟογϡΛ୳͢ ʢ/6."ϊʔυͱͷൺֱ෦෼͔Β࠶࣮ߦʣ ࢖͑ͦ͏ͳ΋ͷ͕ͳ͔ͬͨͷͰ৽ن࡞੒ ໰୊ͳ͚Ε͹MPBE@GSFFMJTUϥϕϧʹඈΜͰGSFFMJTUΛઃఆ
  10. OFX@TMBC@PCKFDUT w ࠷ॳʹHFU@QBSUJBM ͰQBSUJBMMJTUΑΓ࢖͑ΔTMBC Λ୳͢ TUBUJDWPJE HFU@QBSUJBM TUSVDULNFN@DBDIF T HGQ@UqBHT

    JOUOPEF    TUSVDULNFN@DBDIF@DQV D  \  WPJE PCKFDU  JOUTFBSDIOPEFOPEF  JG OPEF/6."@/0@/0%&    TFBSDIOPEFOVNB@NFN@JE   FMTFJG OPEF@QSFTFOU@QBHFT OPEF    TFBSDIOPEFOPEF@UP@NFN@OPEF OPEF   PCKFDUHFU@QBSUJBM@OPEF T HFU@OPEF T TFBSDIOPEF D qBHT   JG PCKFDUccOPEF/6."@/0@/0%&    SFUVSOPCKFDU  SFUVSOHFU@BOZ@QBSUJBM T qBHT D  ^ ݕࡧର৅ͷOPEFΛܾΊͯݕࡧΛ࣮ߦ શ/6."κʔϯ͔Β࢖͑ΔTMBCDBDIF͕͋ Δ͔୳͢
  11. OFX@TMBC@PCKFDUT w ࢖͑ΔTMBCDBDIF͕ͳ͚Ε͹OFX@TMBC Ͱ৽ن ࡞੒ JG QBHF \  

    DSBX@DQV@QUS TDQV@TMBC    JG DQBHF     qVTI@TMBC T D    GSFFMJTUQBHFGSFFMJTU   QBHFGSFFMJTU/6--   TUBU T "--0$@4-"#    DQBHFQBHF   QDD  ^ طଘͷΩϟογϡ͕͋ͬͨΒTMBCΛ D͔Β֎͢
  12. HFU@QBSUJBM@OPEF  MJTU@GPS@FBDI@FOUSZ@TBGF QBHF QBHF OQBSUJBM MSV \  

    WPJE U   JG QGNFNBMMPD@NBUDI QBHF qBHT     DPOUJOVF   UBDRVJSF@TMBC T O QBHF PCKFDU/6-- PCKFDUT    JG U     CSFBL   BWBJMBCMF PCKFDUT   JG PCKFDU \    DQBHFQBHF    TUBU T "--0$@'30.@1"35*"-     PCKFDUU   ^FMTF\    QVU@DQV@QBSUJBM T QBHF      TUBU T $16@1"35*"-@/0%&    ^   JG LNFN@DBDIF@IBT@DQV@QBSUJBM T     ccBWBJMBCMFTDQV@QBSUJBM     CSFBL  ^ ̽Ͱࢦఆ͞ΕͨOPEFͷQBSUJBMMJTUΛḷΔ TMBCͷ͋ΔQBHFΛطଘͷQBHFͱೖΕସ͑
  13. BDRVJSF@TMBC GSFFMJTUQBHFGSFFMJTU  DPVOUFSTQBHFDPVOUFST  OFXDPVOUFSTDPVOUFST  PCKFDUTOFXPCKFDUTOFXJOVTF  JG

    NPEF \   OFXJOVTFQBHFPCKFDUT   OFXGSFFMJTU/6--  ^FMTF\   OFXGSFFMJTUGSFFMJTU  ^  7.@#6(@0/ OFXGSP[FO   OFXGSP[FO  JG @@DNQYDIH@EPVCMF@TMBC T QBHF     GSFFMJTU DPVOUFST     OFXGSFFMJTU OFXDPVOUFST     BDRVJSF@TMBC    SFUVSO/6-- QBHFGSFFMJTUOFXGSFFMJTU QBHFDPVOUFSTOFXDPVOUFST
  14. OFX@TMBC w BMMPDBUF@TMBC ͰGSFFMJTU༻ͷQBHFΛ֬อ w TMBCPCKFDUΛॳظԽ GPS@FBDI@PCKFDU@JEY Q JEY T

    TUBSU QBHFPCKFDUT \   TFUVQ@PCKFDU T QBHF Q    JG MJLFMZ JEYQBHFPCKFDUT     TFU@GSFFQPJOUFS T Q Q TTJ[F    FMTF    TFU@GSFFQPJOUFS T Q /6--  ^ GPS@FBDI@PCKFDU@JEYϚΫϩͷऴྃ৚݅͸JEYQBHFPCKFDUT
  15. TFU@GSFFQPJOUFS w PCKFDU TP⒎TFUͷͱ͜Ζʹ࣍ͷPCKFDUͷΞυϨε Λઃఆ TUBUJDJOMJOFWPJETFU@GSFFQPJOUFS TUSVDULNFN@DBDIF T WPJE PCKFDU

    WPJE GQ  \  WPJE PCKFDU TP⒎TFU GQ ^ GPS@FBDI@PCKFDU@JEY Q JEY T TUBSU QBHFPCKFDUT \   TFUVQ@PCKFDU T QBHF Q    JG MJLFMZ JEYQBHFPCKFDUT     TFU@GSFFQPJOUFS T Q Q TTJ[F    FMTF    TFU@GSFFQPJOUFS T Q /6--  ^
  16. TMBC@GSFF  JG MJLFMZ QBHFDQBHF \   TFU@GSFFQPJOUFS T

    PCKFDU DGSFFMJTU    JG VOMJLFMZ UIJT@DQV@DNQYDIH@EPVCMF      TDQV@TMBCGSFFMJTU TDQV@TMBCUJE      DGSFFMJTU UJE      PCKFDU OFYU@UJE UJE \    OPUF@DNQYDIH@GBJMVSF TMBC@GSFF T UJE     HPUPSFEP   ^   TUBU T '3&&@'"451"5)   ^FMTF   @@TMBC@GSFF T QBHF Y BEES  ࣍ͷۭ͖PCKFDUΛDGSFFMJTUʹ ࠓGSFFͨ͠PCKFDUΛ࣍ճฦ͢Α͏ʹ TMPXQBUI ղ์͢ΔPCKFDU͕DQBHFʹ͋Δʁ
  17. @@TMBC@GSFF QSJPSQBHFGSFFMJTU DPVOUFSTQBHFDPVOUFST TFU@GSFFQPJOUFS T PCKFDU QSJPS  OFXDPVOUFSTDPVOUFST XBT@GSP[FOOF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  JG QSJPS

    \   SFNPWF@QBSUJBM O QBHF   ^FMTF\   SFNPWF@GVMM T O QBHF   ^  TQJO@VOMPDL@JSRSFTUPSF OMJTU@MPDL qBHT   EJTDBSE@TMBC T QBHF  GSFFʹΑͬͯ࢖༻தPCKFDU͕TMBC͔Βͳ ͘ͳͬͨ৔߹͸Ϧετ͔ΒQBHFΛ֎ͯ͠ EJTDBSE@TMBC ͰTMBCΛഁغ͢Δ
  20. @@TMBC@GSFF JG LNFN@DBDIF@IBT@DQV@QBSUJBM T VOMJLFMZ QSJPS \ JG LNFN@DBDIF@EFCVH T

     SFNPWF@GVMM T O QBHF  BEE@QBSUJBM O QBHF %&"$5*7"5&@50@5"*-  TUBU T '3&&@"%%@1"35*"-  ^ ۭ͖PCKFDUແ͠ͷঢ়ଶ͔ΒGSFFʹΑۭ͖ͬͯ PCKFDU͕Ͱ͖ͨ৔߹͸QBHFΛGVMMMJTU͔Β QBSUJBMMJTU΁Ҡಈ
  21. EFBDUJWBUF@TMBC w TDQV@TMBC͔ΒTMBCΛ֎͢ w TMBC@BMMPD ΍OFX@TMBC@PCKFDUT Ͱ࢖༻ w ॲཧ͸ஈ֊ w

    TMBCͷঢ়ଶʹΑΓ࠷ऴతʹԼهͷॲཧ͕ߦΘΕΔ w QBSUJBMMJTU΁௥ՃPS࡟আ w GVMMMJTU΁ͷ௥ՃPS࡟আ w TMBCͷഁغ EJTDBSE@TMBC $0/'*(@4-6#@%&#6(Z
  22. EFBDUJWBUF@TMBC  XIJMF GSFFMJTU OFYUGSFFHFU@GSFFQPJOUFS T GSFFMJTU \  

    WPJE QSJPS   VOTJHOFEMPOHDPVOUFST   EP\    QSJPSQBHFGSFFMJTU    DPVOUFSTQBHFDPVOUFST    TFU@GSFFQPJOUFS T GSFFMJTU QSJPS     OFXDPVOUFSTDPVOUFST    OFXJOVTF    7.@#6(@0/ OFXGSP[FO    ^XIJMF @@DNQYDIH@EPVCMF@TMBC T QBHF     QSJPS DPVOUFST     GSFFMJ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