Specifications

This is the Title of the Book, eMatter Edition
Copyright © 2005 O’Reilly & Associates, Inc. All rights reserved.
Memory Management in Linux
|
421
VMAs are as follows (note the similarity between these fields and the /proc output we
just saw):
unsigned long vm_start;
unsigned long vm_end;
The virtual address range covered by this VMA. These fields are the first two
fields shown in /proc/*/maps.
struct file *vm_file;
A pointer to the struct file structure associated with this area (if any).
unsigned long vm_pgoff;
The offset of the area in the file, in pages. When a file or device is mapped, this is
the file position of the first page mapped in this area.
unsigned long vm_flags;
A set of flags describing this area. The flags of the most interest to device driver
writers are
VM_IO and VM_RESERVED. VM_IO marks a VMA as being a memory-
mapped I/O region. Among other things, the
VM_IO flag prevents the region from
being included in process core dumps.
VM_RESERVED tells the memory manage-
ment system not to attempt to swap out this VMA; it should be set in most
device mappings.
struct vm_operations_struct *vm_ops;
A set of functions that the kernel may invoke to operate on this memory area. Its
presence indicates that the memory area is a kernel “object,” like the
struct file
we have been using throughout the book.
void *vm_private_data;
A field that may be used by the driver to store its own information.
Like
struct vm_area_struct, the vm_operations_struct is defined in <linux/mm.h>;it
includes the operations listed below. These operations are the only ones needed to
handle the process’s memory needs, and they are listed in the order they are
declared. Later in this chapter, some of these functions are implemented.
void (*open)(struct vm_area_struct *vma);
The open method is called by the kernel to allow the subsystem implementing
the VMA to initialize the area. This method is invoked any time a new reference
to the VMA is made (when a process forks, for example). The one exception
happens when the VMA is first created by mmap; in this case, the driver’s mmap
method is called instead.
void (*close)(struct vm_area_struct *vma);
When an area is destroyed, the kernel calls its close operation. Note that there’s
no usage count associated with VMAs; the area is opened and closed exactly
once by each process that uses it.
,ch15.13676 Page 421 Friday, January 21, 2005 11:04 AM