Using the slab APIs for memory allocation in kernel space is highly recommended. For one, it guarantees both physically contiguous as well as cacheline-aligned memory. This is very good for performance; in addition, let's check out a few quick tips that can yield big returns.
CPU caching can provide tremendous performance gains. Thus, especially for time-critical code, take care to design your data structures for best performance:
- Keep the most important (frequently accessed, "hot") members together and at the top of the structure. To see why, imagine there are five important members (of a total size of say, 56 bytes) in your data structure; keep them all together and at the top of the structure. Say the CPU cacheline size is 64 bytes. Now, when your code accesses any one of these five important members (for anything, read/write), all five members will be fetched into the...