You will notice that the first parameter to all the previous allocator APIs (or macros) is gfp_t gfp_mask. What does this mean? Essentially, these are GFP flags. These are flags (there are several of them) used by the kernel's internal memory management code layers. For all practical purposes, for the typical kernel module (or device driver) developer, just two GFP flags are crucial (as mentioned before, the rest are for internal usage). They are as follows:
- GFP_KERNEL
- GFP_ATOMIC
Deciding which of these to use when performing memory allocation via the page allocator APIs is important; a key rule to always remember is the following:
If in process context and it is safe to sleep, use the GFP_KERNEL flag. If it is unsafe to sleep (typically, when in any type of atomic or interrupt context), you must use the GFP_ATOMIC flag.
Following the preceding rule is critical...