Thursday, May 6, 2010

LDD3 notes: Memory

My notes while reading Linux Device Drivers 3rd edition.

Allocation Flags

- GFP_KERNEL - system call, i.e. behalf of a process running in kernel -> may sleep

- GFP_ATOMIC - won't sleep, but has limited memory available

Slab caches for quick allocation of constant size objects ( == object pool )

- a.k.a lookaside cache

- ctor/dtor can be called in atomic context, indicated by a flag


- a wrapper for slab cache which keeps some free memory ready

- try to avoid


  • contiguous region of virtual memory
  • non-hardware related work only, like loading modules
  • arbitrary size
  • GFP_KERNEL internally, cannot use in atomic context
  • limited address space available, avoid.


  • arbitrary size
  • contiguous region of physical memory
  • with 1:1 mapped virtual addresses

get_free_page[s]() & get_order()

  • power of 2 number of pages
  • more than 1 is failure prone
  • with 1:1 mapped virtual addresses


  • indirect access through struct page


  • good for counters: percpu_counter.h
  • how to iterate over all cpus?


  • i/o ports in separate i/o address space
  • inb() ... outsl()
  • or adapt them for memory mapped i/o using ioport_map()

request_mem_region() & ioremap()

  • memory mapped i/o
  • access through ioread8()/iowrite32_rep() ( == legacy readb() )

Chapter 8 recommends obsolete readb()? :"Rather, you should always use readb and the other I/O functions introduced in Chapter 9."

No comments:

Post a Comment