Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
プロセスへのメモリ割り当て2-Pythonのようなナウい言語ではどうやってメモリ獲得するのか
Search
Satoru Takeuchi
PRO
July 10, 2024
210
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
プロセスへのメモリ割り当て2-Pythonのようなナウい言語ではどうやってメモリ獲得するのか
以下動画のテキストです。
https://youtu.be/aI7ancLZUTQ
Satoru Takeuchi
PRO
July 10, 2024
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
76
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
100
あなたの知らないバージョン命名規則
sat
PRO
3
920
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
70
Machine Check Exception
sat
PRO
2
68
バイナリダンプの模様を読む
sat
PRO
0
110
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
100
114-ファイルのshallow_copy.pdf
sat
PRO
2
59
113-Btrfsのスナップショット.pdf
sat
PRO
0
43
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Product Roadmaps are Hard
iamctodd
55
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
How to Ace a Technical Interview
jacobian
280
24k
Designing for Timeless Needs
cassininazir
1
520
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
620
Paper Plane
katiecoart
PRO
4
54k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
920
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Transcript
プロセスへのメモリ割り当て(2) Pythonのようなナウい言語では どうやってメモリ獲得するのか Jul. 10th, 2024 Satoru Takeuchi X: satoru_takeuchi
1
はじめに • 前回の動画で学んだこと ◦ プロセスへのメモリ割り当てには mmapというシステムコールを使う • 疑問 ◦ Pythonのようなナウい言語はメモリやらアドレスを直接意識せずに変数を操作できる
◦ ナウい言語で変数を動的に作成すると何が起こる ? • 備考 ◦ 📝 Pythonでも抽象化された形で mmapを呼ぶことはできます 2
答え • 言語処理系が頑張って、変数を作るときに裏でmmapを呼んでいます • 雑に書くと以下のようになっている ◦ プログラム作成時に変数を格納するためのメモリ領域を一定量獲得しておく ◦ 変数が獲得されるたびに確保済みのメモリ領域を一部ずつ切り出す ◦
確保済みの領域が足りなくなれば mmapを発行して領域の数を増やす 3
Pythonの場合は? • Pythonの公式実装(CPython)はCプログラム • 処理系のメモリ獲得の方法 ◦ mmapを呼ぶ ◦ C標準のメモリ獲得関数 mallocを呼ぶ
▪ その裏側ではC標準ライブラリ(glibc)がmmapを呼んでいる 4
実機確認 • Pythonで大きなメモリ領域を獲得した際にmmapが発行されることを確認 • mem.pyプログラム ◦ メモリ獲得前であることを示すメッセージを表示する ◦ メモリ獲得後であることを示すメッセージを表示する •
mem.pyをstrace経由で動かしたとき、2つのメッセージが表示される間にmmapが 発行されるかを確認。 5
まとめ PythonスクリプトもC言語の処理系を通してmmapによってメモリを獲得 6