TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  •  Paging in Operating System

    Socho tumhare paas ek badi kitaab (Book) hai, jisme 100 pages hain. Tumhare bookshelf me jagah nahi ki pura book ek jagah rakho. Toh tum us kitab ke pages ko alag-alag shelf ke khaali jagah me rakh dete ho.

     But yeh yaad rakhte ho ki kaunsa page kis shelf me rakha hai, taaki baad me easily dhoond sako.

    Yahi kaam Operating System karta hai memory me!
    Isse hi kehte hain Paging.

     Definition – Paging Kya Hai?

    Paging ek technique hai jisme Operating System:

    -> Process ki memory ko todta hai chhoti-chhoti pages me
    -> Physical memory (RAM) ko todta hai chhoti-chhoti frames me
    -> Fir har page ko kisi bhi available frame me store karta hai (sequence me nahi)

    Aur ek Page Table banta hai jo batata hai:

    “Page 0 kaha gaya, Page 1 kaha gaya, Page 2 kaha gaya…”

     Basic Concepts – 5 Important Terms

    TermMeaning (Easy)
    PageLogical memory ka ek fixed-size tukda
    FramePhysical RAM ka ek fixed-size tukda
    Page TableEk table jo batata hai har page kis frame me hai
    Logical AddressCPU dwara banaya gaya address (virtual)
    Physical AddressActual address in RAM (jaha data store hai)

     Paging Kyu Zaroori Hai?

    Bina Paging:

    • Process ko ek badi continuous memory chahiye hoti hai

    • Memory me chhoti-chhoti khaali jagah hoti hai (external fragmentation)

    • Process memory me fit nahi ho pati 

    Paging ke Saath:

    • Process ke pages RAM ke kisi bhi frame me ja sakte hain

    • Memory ka achha use hota hai

    • No external fragmentation 

     Paging Kaise Kaam Karta Hai? (Step-by-Step)

     Step 1: Memory ko Todna

    • Suppose process = 4 KB

    • Page size = 1 KB
      → Process will have 4 pages

    • RAM me bhi frames = 1 KB size ke hote hain

     Step 2: Page Table Banana

    Page Table ek table hoti hai jisme likha hota hai:

    Page NoFrame No
    03
    16
    21
    34

    Matlab:

    • Page 0 → Frame 3 me gaya

    • Page 1 → Frame 6 me gaya
      …and so on

     Step 3: Address Translation

    Jab CPU data mangta hai, woh logical address bhejta hai (Page No + Offset)

    • Page No = Page Table se check karte hain → Frame No milta hai

    • Offset = Page ke andar ki position

    Fir banta hai Physical Address = Frame Start Address + Offset

     Example 

    • Page/Frame size = 1 KB (1024 bytes)

    • Logical Address = 2049

    Page Number = 2049 / 1024 = 2
    Offset = 2049 % 1024 = 1

    Page 2 → Frame 5 me hai (Page Table se mila)
    Frame 5 ka address = 5 × 1024 = 5120
    → Physical Address = 5120 + 1 = 5121

     Logical 2049 → Physical 5121 

     Flow 

    Logical Address (Page No + Offset)
          ↓
    Page Table → Frame No
          ↓
    Physical Address = Frame No + Offset
     

     Real Life Analogy

     Student (Process) = Many books
     Books = Pages
     Shelves (RAM) = Frames
     Index Card (Page Table) = Bata raha hai ki kaunsa book kaunsa shelf me hai


     Advantages

    -> No External Fragmentation
    -> Process memory kahin bhi RAM me store ho sakti hai
    -> Swapping (Disk ↔ RAM) easy ho jata hai
    -> Same-size blocks = Simple memory allocation


     Disadvantages

    -> Internal Fragmentation – Last page frame me thoda space waste ho sakta hai
    -> Page Table Overhead – Large processes = badi page table
    -> Slow Access – Har bar address translate karna padta hai


     TLB – Speed Booster

    TLB (Translation Lookaside Buffer) ek chhoti fast memory hoti hai CPU ke paas

    • Page Table me baar-baar dekhne se bachata hai

    • Recent page-frame mappings ko yaad rakhta hai

    Agar CPU ko address TLB me mil gaya → Super Fast
    Nahi mila → Page Table me jaake dhoondo

     

    Scroll to Top