]> asedeno.scripts.mit.edu Git - linux.git/blob - Documentation/core-api/memory-hotplug-notifier.rst
docs/vm: split memory hotplug notifier description to Documentation/core-api
[linux.git] / Documentation / core-api / memory-hotplug-notifier.rst
1 .. _memory_hotplug_notifier:
2
3 =============================
4 Memory hotplug event notifier
5 =============================
6
7 Hotplugging events are sent to a notification queue.
8
9 There are six types of notification defined in ``include/linux/memory.h``:
10
11 MEM_GOING_ONLINE
12   Generated before new memory becomes available in order to be able to
13   prepare subsystems to handle memory. The page allocator is still unable
14   to allocate from the new memory.
15
16 MEM_CANCEL_ONLINE
17   Generated if MEM_GOING_ONLINE fails.
18
19 MEM_ONLINE
20   Generated when memory has successfully brought online. The callback may
21   allocate pages from the new memory.
22
23 MEM_GOING_OFFLINE
24   Generated to begin the process of offlining memory. Allocations are no
25   longer possible from the memory but some of the memory to be offlined
26   is still in use. The callback can be used to free memory known to a
27   subsystem from the indicated memory block.
28
29 MEM_CANCEL_OFFLINE
30   Generated if MEM_GOING_OFFLINE fails. Memory is available again from
31   the memory block that we attempted to offline.
32
33 MEM_OFFLINE
34   Generated after offlining memory is complete.
35
36 A callback routine can be registered by calling::
37
38   hotplug_memory_notifier(callback_func, priority)
39
40 Callback functions with higher values of priority are called before callback
41 functions with lower values.
42
43 A callback function must have the following prototype::
44
45   int callback_func(
46     struct notifier_block *self, unsigned long action, void *arg);
47
48 The first argument of the callback function (self) is a pointer to the block
49 of the notifier chain that points to the callback function itself.
50 The second argument (action) is one of the event types described above.
51 The third argument (arg) passes a pointer of struct memory_notify::
52
53         struct memory_notify {
54                 unsigned long start_pfn;
55                 unsigned long nr_pages;
56                 int status_change_nid_normal;
57                 int status_change_nid_high;
58                 int status_change_nid;
59         }
60
61 - start_pfn is start_pfn of online/offline memory.
62 - nr_pages is # of pages of online/offline memory.
63 - status_change_nid_normal is set node id when N_NORMAL_MEMORY of nodemask
64   is (will be) set/clear, if this is -1, then nodemask status is not changed.
65 - status_change_nid_high is set node id when N_HIGH_MEMORY of nodemask
66   is (will be) set/clear, if this is -1, then nodemask status is not changed.
67 - status_change_nid is set node id when N_MEMORY of nodemask is (will be)
68   set/clear. It means a new(memoryless) node gets new memory by online and a
69   node loses all memory. If this is -1, then nodemask status is not changed.
70
71   If status_changed_nid* >= 0, callback should create/discard structures for the
72   node if necessary.
73
74 The callback routine shall return one of the values
75 NOTIFY_DONE, NOTIFY_OK, NOTIFY_BAD, NOTIFY_STOP
76 defined in ``include/linux/notifier.h``
77
78 NOTIFY_DONE and NOTIFY_OK have no effect on the further processing.
79
80 NOTIFY_BAD is used as response to the MEM_GOING_ONLINE, MEM_GOING_OFFLINE,
81 MEM_ONLINE, or MEM_OFFLINE action to cancel hotplugging. It stops
82 further processing of the notification queue.
83
84 NOTIFY_STOP stops further processing of the notification queue.