Direct Memory Access (DMA)

 

1. Direct Memory Access (DMA)

🔷 The Problem with Programmed I/O (PIO)

In Programmed I/O (PIO):

  • The CPU transfers data between memory and device

  • Data is copied word by word

❌ Issues:

  • CPU spends too much time on simple data movement

  • Reduces time available for executing processes

  • Becomes a bottleneck for large data transfers


💡 The Solution: DMA

🔷 What is DMA?

Direct Memory Access (DMA) is a technique where a special hardware unit (DMA controller) transfers data:

  • Directly between memory and device

  • Without continuous CPU involvement

👉 Key idea:

  • Offload data movement from CPU → DMA controller


2. How DMA Works (Step-by-Step)

1. OS Programs the DMA Controller

The OS provides:

  • 📍 Memory location of data

  • 📦 Size of data

  • 🎯 Target device


2. DMA Takes Over

  • DMA controller handles the entire data transfer

  • CPU is not involved in copying


3. CPU Continues Other Work

  • OS schedules another process (e.g., Process 2)

  • CPU utilization improves


4. DMA Completion

  • DMA controller sends an interrupt

  • OS is notified that transfer is done


3. Execution Comparison

🔴 With PIO

CPU: Process1 → Copying → Copying → Process2 Disk: Idle → Working
  • CPU stuck copying data (c c c)

  • Inefficient





🟢 With DMA

CPU: Process1 → Process2 → Process2 → Process1 DMA: Copying data Disk: Working
  • DMA handles copying

  • CPU runs other processes





 4. Advantages of DMA

✅ 1. Better CPU Utilization

  • CPU is free during data transfer


✅ 2. Faster Data Movement

  • Dedicated hardware is more efficient


✅ 3. Overlap of Work

  • CPU + DMA + Device operate in parallel


✅ 4. Ideal for Large Transfers

  • Especially useful for:

    • Disk I/O

    • Network transfers


5. Key Insight

👉 DMA + Interrupts work together:

  • DMA handles data transfer

  • Interrupt notifies completion


6. Simple Analogy

  • PIO → Teacher copies notes to board line by line

  • DMA → Assign a helper (DMA) to copy notes while teacher continues teaching


7. Key Takeaways 

  • DMA removes CPU involvement in data transfer

  • OS only initiates transfer

  • DMA controller performs copying

  • Completion is signaled via interrupt

  • Improves performance and efficiency

Comments

Popular posts from this blog

Operating Systems OS PCCST403 Semester 4 BTech KTU CS 2024 Scheme

Introduction to Operating System -Virtualization, Concurrency, and Persistence

Operating Systems PCCST403 Scheme and Syllabus