Backward Compatibility

The Linux memory management subsystem has changed dramatically since the 2.0 kernel came out. Happily, however, the changes to its programming interface have been much smaller and easier to deal with.

kmalloc and kfree have remained essentially constant between Linux 2.0 and 2.4. Access to high memory, and thus the __GFP_HIGHMEM flag, was added starting with kernel 2.3.23; sysdep.h fills the gaps and allows for 2.4 semantics to be used in 2.2 and 2.0.

The lookaside cache functions were introduced in Linux 2.1.23, and were simply not available in the 2.0 kernel. Code that must be portable back to Linux 2.0 should stick with kmalloc and kfree. Moreover, kmem_destroy_cache was introduced during 2.3 development and has only been backported to 2.2 as of 2.2.18. For this reason scullc refuses to compile with a 2.2 kernel older than that.

__get_free_pages in Linux 2.0 had a third, integer argument called dma; it served the same function that the __GFP_DMA flag serves in modern kernels but it was not merged in the flags argument. To address the problem, sysdep.h passes 0 as the third argument to the 2.0 function. If you want to request DMA pages and be backward compatible with 2.0, you need to call get_dma_pages instead of using __GFP_DMA.

vmalloc and vfree are unchanged across all 2.x kernels. However, the ioremap function was called vremap in the 2.0 days, and there was no iounmap. Instead, an I/O mapping obtained with vremap would be freed with vfree. Also, the header <linux/vmalloc.h> didn’t exist in 2.0; the functions were declared by <linux/mm.h> instead. As usual, sysdep.h makes 2.4 code work with earlier kernels; it also includes <linux/vmalloc.h> if <linux/mm.h> is included, thus hiding this difference as well.

Get Linux Device Drivers, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.