tailieunhanh - Linux Device Drivers-Chapter 7 : Getting Hold of Memory

Tham khảo tài liệu 'linux device drivers-chapter 7 : getting hold of memory', công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 7 Getting Hold of Memory Thus far we have used kmalloc and kfree for the allocation and freeing of memory. The Linux kernel offers a richer set of memory allocation primitives however. In this chapter we look at other ways of making use of memory in device drivers and at how to make the best use of your system s memory resources. We will not get into how the different architectures actually administer memory. Modules are not involved in issues of segmentation paging and so on since the kernel offers a unified memory management interface to the drivers. In addition we won t describe the internal details of memory management in this chapter but will defer it to Memory Management in Linux in Chapter 13 mmap and DMA . The Real Story of kmalloc The kmalloc allocation engine is a powerful tool and easily learned because of its similarity to malloc. The function is fast -- unless it blocks -- and it doesn t clear the memory it obtains the allocated region still holds its previous content. The allocated region is also contiguous in physical memory. In the next few sections we talk in detail about kmalloc so you can compare it with the memory allocation techniques that we discuss later. The Flags Argument The first argument to kmalloc is the size of the block to be allocated. The second argument the allocation flags is much more interesting because it controls the behavior of kmalloc in a number of ways. The most-used flag GFP_KERNEL means that the allocation internally performed by calling eventually getfree pages which is the source of the GFP_ prefix is performed on behalf of a process running in kernel space. In other words this means that the calling function is executing a system call on behalf of a process. Using GFP_KERNEL means that kmalloccan put the current process to sleep waiting for a page when called in low-memory situations. A function that allocates memory using GFP_KERNEL must therefore be reentrant. While the current process sleeps the kernel .

TỪ KHÓA LIÊN QUAN