Reserving Memory with vmalloc

struct vm_struct void unsigned long unsigned long struct page unsigned int unsigned long

size;

flags;

**pages nr_pages; phys_addr;

There is an instance of the structure in kernel memory for each area allocated with vmalloc. The meanings of the structure elements are as follows:

□ addr defines the start address of the allocated area in virtual address space; size indicates the size of the area. A complete allocation plan of the vmalloc area can be drawn up on the basis of this information.

□ flags stores the — almost inevitable — flag set associated with the memory section. It is used only to specify the memory area type and currently accepts one of the three values below.

□ vm_alloc specifies that the area was created by vmalloc.

□ vm_map is set to indicate that an existing collection of pages was mapped into the contiguous virtual address space.

□ vm_ioremap indicates that an (almost) random physical memory area was mapped into the vmalloc area; this is an architecture-specific operation.

Section 3.5.7 shows how the latter two values are employed.

□ pages is a pointer to an array of page pointers. Each element represents the page instance of a physical page mapped into virtual address space.

nr_pages specifies the number of entries in pages and therefore the number of memory pages involved.

□ phys_addr is required only if physical memory areas described by a physical address are mapped with ioremap. This information is held in phys_addr.

□ next enables the kernel to hold all sections in the vmalloc area on a singly linked list.

Figure 3-38 shows an example of how the structure is used. Three physical pages whose (fictitious) positions in RAM are 1,023, 725 and 7,311 are mapped one after the other. In the virtual vmalloc area, the kernel sees them as a contiguous memory area starting at the vmalloc_start + 100.

1023 725 7311

1023 725 7311

725 1023 7311

Figure 3-38: Mapping physical pages into the vmalloc area.

725 1023 7311

Figure 3-38: Mapping physical pages into the vmalloc area.

Continue reading here: Creating a vmarea

Was this article helpful?

0 0