With all this choice of APIs, how do we choose? Though we have already talked about this very case in this chapter as well as the previous one, we'll again summarize it as it's very important. Broadly speaking, there are two ways to look at it – the API to use depends upon the following:
- The amount of memory required
- The type of memory required
We will illustrate both cases in this section.
First, to decide which API to use by the type, amount, and contiguity of the memory to be allocated, scan through the following flowchart (starting at the upper right from the label Start here):
Figure 9.7 – Decision flowchart for which kernel memory allocation API(s) to use for a module/driver
Of course, it's not trivial; not only that, I'd like to remind you to recall the detailed discussions we covered earlier in this chapter, including the GFP flags to use (and the do not sleep in atomic...