Skip to content

cs-pub-ro/os-lecture-03-data-part-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Data (part 1)

running software needs memory

  • CPU interacts with memory: read / featch, write
  • instructions / code and actual data

who uses memory:

  • kernel (in kernel mode)
  • processes / applications (in user mode)

memory relevance:

  • functionality: software requires memory to run
  • correctness: improper use leads to crashes, bugs, exploits
  • security: memory can be exploited: information leaks, control flow hijack
  • performance: proper placement of data in memory and proper operations increases performance
  • efficiency: memory use can be wasteful; a clever design reduces memory use

1. Memory vs. Storage

CPU communicates with memory

data and code are loaded from storage into memory

data is flushed from storage to disk

memory is faster than disk

diagram: memory and storage

storage may be absent - load from network

storage is used for persistence

the buffer cache stores recent storage data in memory

2. Memory Operations

allocate: a new chuck or increase an existing chunk

deallocate: a chunk or decrease an existing chunk

diagram: allocation and deallocation

use: address and access: point to address + read from / write to address

diagram: addressing and accessing

demo: memory operations: allocation/ and memory-access/

3. When Do We Allocate Memory

at load time

at runtime

at load time: allocate + populate (from executable)

  • static allocation

at runtime: allocate

  • eventually populate with program generated information
  • dynamic allocation

diagram: memory allocation: static (load time) and dynamic (runtime)

demo: program: dynamic allocation and static allocation snippets

4. The Process (Virtual) Address Space / Memory Map

memory areas:

  • different permissions
  • different types: static, dynamic
  • different sources of input

demo: run pmap on static and dynamic executable

diagram: the process virtual address space

table: different memory areas with different properties

5. Memory and Loading

from executable to memory

diagram: from executable sections to process areas

see executable sections: size, protections

static non-PIE binary

demo: GDB: info proc mappings

bss region doesn't consume space in the executable

demo: dynamic binary

6. Runtime Allocation

no connection to the executable

stack + dynamic allocation - malloc()

diagram: heap, stack, mapped memory regions

demo: increase stack

malloc() uses an allocator

  • provided by libc
  • heap: issues: large size, fragmentation, concurrency

demo: malloc() vs different calls: brk() vs mmap()

Conclusion and Takeaways

  • Memory is essentials for running software.
  • Memory stores instructions and data used by the CPU.
  • Memory is allocated and used.
  • Memory allocation is static (happens at load-time) or dynamic (happens at runtime).
  • The application / process uses a process address space: a list of memory areas.
  • Dynamic allocation may be backed by heap or memory mapping.

About

The first lecture from the "Data" chapter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •