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
Test your architecture with Archunit
thirion
2
2.4k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Crafting Experiences
bethany
1
370
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
HDC tutorial
michielstock
2
950
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
260
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
How to Talk to Developers About Accessibility
jct
2
560
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