Commit | Line | Data |
---|---|---|
a48d07af CL |
1 | Page migration |
2 | -------------- | |
3 | ||
4 | Page migration allows the moving of the physical location of pages between | |
5 | nodes in a numa system while the process is running. This means that the | |
6 | virtual addresses that the process sees do not change. However, the | |
7 | system rearranges the physical location of those pages. | |
8 | ||
9 | The main intend of page migration is to reduce the latency of memory access | |
10 | by moving pages near to the processor where the process accessing that memory | |
11 | is running. | |
12 | ||
13 | Page migration allows a process to manually relocate the node on which its | |
14 | pages are located through the MF_MOVE and MF_MOVE_ALL options while setting | |
15 | a new memory policy. The pages of process can also be relocated | |
16 | from another process using the sys_migrate_pages() function call. The | |
17 | migrate_pages function call takes two sets of nodes and moves pages of a | |
18 | process that are located on the from nodes to the destination nodes. | |
19 | ||
20 | Manual migration is very useful if for example the scheduler has relocated | |
21 | a process to a processor on a distant node. A batch scheduler or an | |
22 | administrator may detect the situation and move the pages of the process | |
23 | nearer to the new processor. At some point in the future we may have | |
24 | some mechanism in the scheduler that will automatically move the pages. | |
25 | ||
26 | Larger installations usually partition the system using cpusets into | |
27 | sections of nodes. Paul Jackson has equipped cpusets with the ability to | |
28 | move pages when a task is moved to another cpuset. This allows automatic | |
29 | control over locality of a process. If a task is moved to a new cpuset | |
30 | then also all its pages are moved with it so that the performance of the | |
31 | process does not sink dramatically (as is the case today). | |
32 | ||
33 | Page migration allows the preservation of the relative location of pages | |
34 | within a group of nodes for all migration techniques which will preserve a | |
35 | particular memory allocation pattern generated even after migrating a | |
36 | process. This is necessary in order to preserve the memory latencies. | |
37 | Processes will run with similar performance after migration. | |
38 | ||
39 | Page migration occurs in several steps. First a high level | |
40 | description for those trying to use migrate_pages() and then | |
41 | a low level description of how the low level details work. | |
42 | ||
43 | A. Use of migrate_pages() | |
44 | ------------------------- | |
45 | ||
46 | 1. Remove pages from the LRU. | |
47 | ||
48 | Lists of pages to be migrated are generated by scanning over | |
49 | pages and moving them into lists. This is done by | |
50 | calling isolate_lru_page() or __isolate_lru_page(). | |
51 | Calling isolate_lru_page increases the references to the page | |
52 | so that it cannot vanish under us. | |
53 | ||
54 | 2. Generate a list of newly allocates page to move the contents | |
55 | of the first list to. | |
56 | ||
57 | 3. The migrate_pages() function is called which attempts | |
58 | to do the migration. It returns the moved pages in the | |
59 | list specified as the third parameter and the failed | |
60 | migrations in the fourth parameter. The first parameter | |
61 | will contain the pages that could still be retried. | |
62 | ||
63 | 4. The leftover pages of various types are returned | |
64 | to the LRU using putback_to_lru_pages() or otherwise | |
65 | disposed of. The pages will still have the refcount as | |
66 | increased by isolate_lru_pages()! | |
67 | ||
68 | B. Operation of migrate_pages() | |
69 | -------------------------------- | |
70 | ||
71 | migrate_pages does several passes over its list of pages. A page is moved | |
72 | if all references to a page are removable at the time. | |
73 | ||
74 | Steps: | |
75 | ||
76 | 1. Lock the page to be migrated | |
77 | ||
78 | 2. Insure that writeback is complete. | |
79 | ||
80 | 3. Make sure that the page has assigned swap cache entry if | |
81 | it is an anonyous page. The swap cache reference is necessary | |
82 | to preserve the information contain in the page table maps. | |
83 | ||
84 | 4. Prep the new page that we want to move to. It is locked | |
85 | and set to not being uptodate so that all accesses to the new | |
86 | page immediately lock while we are moving references. | |
87 | ||
88 | 5. All the page table references to the page are either dropped (file backed) | |
89 | or converted to swap references (anonymous pages). This should decrease the | |
90 | reference count. | |
91 | ||
92 | 6. The radix tree lock is taken | |
93 | ||
94 | 7. The refcount of the page is examined and we back out if references remain | |
95 | otherwise we know that we are the only one referencing this page. | |
96 | ||
97 | 8. The radix tree is checked and if it does not contain the pointer to this | |
98 | page then we back out. | |
99 | ||
100 | 9. The mapping is checked. If the mapping is gone then a truncate action may | |
101 | be in progress and we back out. | |
102 | ||
103 | 10. The new page is prepped with some settings from the old page so that accesses | |
104 | to the new page will be discovered to have the correct settings. | |
105 | ||
106 | 11. The radix tree is changed to point to the new page. | |
107 | ||
108 | 12. The reference count of the old page is dropped because the reference has now | |
109 | been removed. | |
110 | ||
111 | 13. The radix tree lock is dropped. | |
112 | ||
113 | 14. The page contents are copied to the new page. | |
114 | ||
115 | 15. The remaining page flags are copied to the new page. | |
116 | ||
117 | 16. The old page flags are cleared to indicate that the page does | |
118 | not use any information anymore. | |
119 | ||
120 | 17. Queued up writeback on the new page is triggered. | |
121 | ||
122 | 18. If swap pte's were generated for the page then remove them again. | |
123 | ||
124 | 19. The locks are dropped from the old and new page. | |
125 | ||
126 | 20. The new page is moved to the LRU. | |
127 | ||
128 | Christoph Lameter, December 19, 2005. | |
129 |