OS PyramidTechnion 234123 · Operating Systemsbasics → exam
Stage 9: Virtual Memory
2017B_Spring_AQuestion 3core25 pts
Full original question text (raw OCR)

שאלה 3 - זיכרון וירטואלי (25 נקודות)

  1. א· diagram· 4 ptsVirtual Memory

    (4 נק') שרטטי את תהליך המהלך על טבלת הדפים (page table walk) בעת תרגום כתובת וירטואלית לכתובת פיזית בארכיטקטורת x86-64, מתחילתו ועד סופו. נא לציין את תחילת, סיום, וגודל כל שדה ביטים (bit-field) בכתובת הוירטואלית, שנכלל בשירטוטך. לדוגמא, בשירטוט הבא רואים שדה בגודל 4 ביטים שמתחיל בביט #6 ונגמר בביט #9. (נא לא לכלול את ה- TLB בשרטוטך.) 4 9 6 0 63

    Virtual-to-physical address translation
  2. ב· short_answer· 4 ptsVirtual Memory

    (4 נק') בהתייחס לארכיטקטורת x86-64: מה גודל כל דף בהיררכיה (בבתים)? כמה ביטים מכיל שדה ההיסט בתוך הדף (page offset) כמה רמות יש בהיררכיית טבלאות הדפים? מה גודל כל PTE (בבתים)? כמה PTES יש בכל טבלת דפים? רגיסטר CR3 מכיל כתובת ווירטואלית / פיזית (הקיפי את התשובה הנכונה)

    Linux VMA vm_flags interpretationCopy-on-write fork memory protectionPage fault error code classification
  3. ג· short_answer· 8 ptsVirtual Memory

    (8 נק') באיזה גדלים של סופר-דפים (super-pages) ארכיטקטורת x86-64 תומכת? מדוע דווקא גדלים אלה? (יש להסביר ולפרט את אופן החישוב.)

    Linux VMA vm_flags interpretationCopy-on-write fork memory protectionPage fault error code classification
  4. ד· short_answer· 1 ptsVirtual Memory

    (1 נק') למה משמש TLB?.

    Virtual-to-physical address translation
  5. ה· short_answer· 8 ptsVirtual Memory

    (8 נק') מה היתרונות והחסרונות של שימוש בדפים גדולים. יתרונות: חסרונות:

    Linux VMA vm_flags interpretationCopy-on-write fork memory protectionPage fault error code classification

The exam question — original PDF

pages 7, 8

Exactly as it appears on the exam paper.

loading page 7
loading page 8

Built from these components

Ordered basic → advanced. Master the earlier ones first.

L3Virtual-to-physical address translationL3Linux VMA vm_flags interpretationL3Copy-on-write fork memory protectionL4Page fault error code classificationL4do_page_fault handler reasoning

Review the material

Read these before you answer — each verified slide teaches a component this question tests, and nothing from an unrelated topic is included. Tutorial slides show the actual slide image.

Lecture 9slide 32On-demand paging & readahead

On-demand paging & readahead • On-demand paging rpt – OS maps / reads page from disk into DRAM only if/when the process attempts to access it for the first time (and, hence, a page fault occurs) – That is, OS pages-in data only via page faults (+ prefetching; see below) – Thus, a process begins execution with most pages “unmapped”, possibly not residing in physical memory (executable code included), and page faults occur until its pages are placed in in DRAM & mapped – Also called “ lazy” loading – What’s the benefit? Reading/mapping is costly, & with demand-paging we only read what we need • Notice: on-demand allocation also works rpt – For anonymously mmap-ed / (s)brk-ed memory • Readahead prefetching (anticipatory paging) – read() does prefetching when identifying sequential access – The page fault handler does the same when doing on-demand paging • Complements demand-paging in an attempt to minimize page faults OS (234123) - virtual memory 33

Lecture slide — text above is the material (no raster available).
Lecture 13slide 23Reminder: x86 paging

Reminder: x86 paging Need to translate from: virtual addresses to: physical addresses Translation is cached on-chip TLB (Translation Lookaside Buffer) Page table is read & modified by HW (Access/dirty bit) Each process has its own virtual address space Page table pointed to by CR3 register During context switch the OS updates the value of CR3. Page table is a hierarchical structure OS – virtualization 23

Lecture slide — text above is the material (no raster available).
Tutorial 10slide 19טבלת הדפים (page table)לכל תהליך יש טבלת דפים משלו – מבנה נתונים אשר ממפה בין דפים למסגרות

טבלת הדפים (page table)לכל תהליך יש טבלת דפים משלו – מבנה נתונים אשר ממפה בין דפים למסגרות.ניתן לממש טבלת דפים באמצעות מבני נתונים שונים: מערך פשוט, עצים, טבלאות גיבוב (hash tables), ...עבור כל דף במרחב הזיכרון הווירטואלי של התהליך, יש כניסה בטבלת הדפים אשר מציינת:האם הדף נמצא בזיכרון ובאיזו מסגרת?האם הדף נמצא בדיסק ובאיזה מיקום?האם הדף מעולם לא הוקצה? (כלומר איננו בזיכרון ואיננו בדיסק)טבלת הדפים אחראית לתפקידים נוספים כמו הגנת גישה.למשל: טבלת הדפים מסמנת דפים לקריאה בלבד ומונעת גישות כתיבה.19מערכות הפעלה - תרגול 10

Tutorial 10slide 39סיכום: תהליך התרגום במעבדי אינטל39the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysi...

סיכום: תהליך התרגום במעבדי אינטל39the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysical addressvirtual addressthe OS serves the page faultמערכות הפעלה - תרגול 10

Tutorial 11slide 2סיכום השיעור שעבר2the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysical addressvirtu...

סיכום השיעור שעבר2the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysical addressvirtual addressthe OS serves the page faultמערכות הפעלה - תרגול 10

Tutorial 11slide 3מה נלמד היום?3the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysical addressvirtual a...

מה נלמד היום?3the CPU searches the TLBhitmissthe CPU walks the page tablecompletedpage faultphysical addressvirtual addresskill the process or the entire systemfix the page table and retrythe OS serves the page faultinvalidvalidמערכות הפעלה - תרגול 10

Tutorial 11slide 17הרשאות של אזור זיכרוןהדגלים המציינים את הרשאות האזור נשמרים בשדה vm_flags והם מאפשרים לגרעין לסווג גישות חוקיות ולא ח...

הרשאות של אזור זיכרוןהדגלים המציינים את הרשאות האזור נשמרים בשדה vm_flags והם מאפשרים לגרעין לסווג גישות חוקיות ולא חוקיות לדפים באזור.VM_READ, VM_WRITE, VM_EXEC – האם מותר לקרוא/לכתוב/לבצע נתונים בדפים באזור.VM_MAYREAD, VM_MAYWRITE, VM_MAYEXEC – "הרשאת הרשאה" לכל אחת מההרשאות הנ"ל.לדוגמה VM_MAYWRITE קובע האם מותר להדליק את VM_WRITE.הדגלים האלה קשורים לקריאת המערכת mprotect() – מעבר לחומר הקורס.VM_SHARED – האם צריך לשתף דפים באזור זה עם תהליכי בן.VM_LOCKED – אסור לפנות את הדפים באזור מהזיכרון לדיסק.17מערכות הפעלה - תרגול 10

Tutorial 11slide 23מרחבי זיכרון וקריאות מערכתחוטים הנוצרים ע"י קריאת המערכתclone() משתפים את מרחב הזיכרון ע"י הצבעה לאותו מתאר מרחב הזיכ...

מרחבי זיכרון וקריאות מערכתחוטים הנוצרים ע"י קריאת המערכתclone() משתפים את מרחב הזיכרון ע"י הצבעה לאותו מתאר מרחב הזיכרון של תהליך האב.יש להגדיל את מונה השיתוף (mm_users) של מתאר מרחב הזיכרון של תהליך האב.קריאת המערכת execv() ודומותיה טוענות תהליך חדש ולכן הן משחררות את מרחב הזיכרון ומקצות אחד חדש.קריאת המערכתfork() מקצה לתהליך הבן מרחב זיכרון משלו.במקרה שכזה צריך להעתיק את מרחב הזיכרון של האב לזה של הבן.בפועל, בדרך-כלל אין באמת העתקה בזכות מנגנון copy-on-write.23מערכות הפעלה - תרגול 10

Tutorial 11slide 27הפתרון: copy-on-write (COW)הרעיון של מנגנון copy-on-write (COW) הוא:דפים הניתנים לכתיבה שאינם יכולים להיות משותפים (ל...

הפתרון: copy-on-write (COW)הרעיון של מנגנון copy-on-write (COW) הוא:דפים הניתנים לכתיבה שאינם יכולים להיות משותפים (לדוגמה, המחסנית), מוגדרים בתחילה כמשותפים אבל מועתקים לעותק פרטי כאשר אחד התהליכים השותפים (האב או הבן) מנסה לכתוב אליהם לראשונה.שאר הדפים (כדוגמת דפי קוד או דפי נתונים לקריאה בלבד) הופכים למשותפים בין מרחבי הזיכרון של האב והבן.מנגנון COW פותר את שתי הבעיות שהוצגו קודם:COW מקטין את זמן הביצוע של fork() כי הוא "פורס לתשלומים" את ההעתקה של כל מרחב הזיכרון להרבה העתקות קטנות בגודל דף שיתבצעו בעתיד---בכל כתיבה ראשונה לדף שאינו משותף.במידה ותהליך הבן יבצע מיד execv(), מרחב הזיכרון שלו יימחק וכך תיחסך רוב פעולת ההעתקה.27מערכות הפעלה - תרגול 10

Tutorial 11slide 28father processpage tablememory regionsדוגמה: לפני קריאת מערכת fork()28…PTE #11r/w = 1…frame #250count == 1מערכות הפעל...

father processpage tablememory regionsדוגמה: לפני קריאת מערכת fork()28…PTE #11r/w = 1…frame #250count == 1מערכות הפעלה - תרגול 10region #1VM_MAYWRITE=1VM_WRITE=1region #2

Tutorial 11slide 30father processpage tablememory regionsדוגמה: אחרי קריאת מערכת fork()30…PTE #11r/w = 0…son processpage tablememory reg...

father processpage tablememory regionsדוגמה: אחרי קריאת מערכת fork()30…PTE #11r/w = 0…son processpage tablememory regions…PTE #11r/w = 0…מערכות הפעלה - תרגול 10frame #250count == 2region #1VM_MAYWRITE=1VM_WRITE=1region #2region #1VM_MAYWRITE=1VM_WRITE=1region #2

Tutorial 11slide 37COW: טיפול ב-page faultתרחיש הטיפול: האב או הבן מנסים לכתוב לדף מוגן ע"י COW

COW: טיפול ב-page faultתרחיש הטיפול: האב או הבן מנסים לכתוב לדף מוגן ע"י COW.המעבד ניגש לסיביות הבקרה ב-PTE של הדף, ומגלה כי r/w כבוי.המעבד יוצר חריגת דף (page fault).הגרעין מטפל בחריגה, ובודק שהדף שייך לאחד מאזורי הזיכרון ושהגישה בכלל חוקית (דגל VM_WRITE דלוק במתאר האזור).הגרעין בודק את ערך המונה השיתוף של המסגרת:אם count > 1, מקצים מסגרת חדשה, מעתיקים אליה את המסגרת המקורית, ומצביעים את הדף למסגרת החדשה.במסגרת הישנה מבוצע count-- .במסגרת החדשה מוצב count = 1 .בעותק החדש מאופשרת הכתיבה.אחרת (count == 1), הגרעין פשוט מאפשר כתיבה בדף ע"י הדלקת הדגל r/w.37מערכות הפעלה - תרגול 10

Tutorial 11slide 43חריגת דף (page fault)החומרה מתריעה באמצעות חריגת דף על:גישה לדף שאינו נמצא בזיכרון, כלומר הביט present==0 בכניסה המתא...

חריגת דף (page fault)החומרה מתריעה באמצעות חריגת דף על:גישה לדף שאינו נמצא בזיכרון, כלומר הביט present==0 בכניסה המתאימה בטבלת הדפים.גישה לא חוקית (שלא לפי ההרשאות בטבלת הדפים) לדף שנמצא בזיכרון, למשל ניסיון כתיבה לדף שמותר לקריאה בלבד.חריגת דף מפעילה את שגרת הטיפול הממומשת בפונקציית הגרעין do_page_fault().בסיום הטיפול בחריגה מבוצעת מחדש ההוראה שגרמה לה.אלא אם כן, כמובן, הטיפול בחריגה הורג את התהליך.43מערכות הפעלה - תרגול 10

Ask Gemini
2017B_Spring_A · Q3 — question + its material already loaded
Pick a shortcut above or ask anything about this question.
The exam text, the skills it tests, and the exact slides are already in context.