For Kernel_Newbies By a Kernel_Newbie
You should also take care of the vm_operations_struct if you are defining
your own page_fault handlers.
struct vm_operations_struct your_ops = {
open: open,
close: close,
no_page:no_page,
};
Open and close are called on map and unmap time,or on a fork,when a child
tries to link itself against the inode address spaces mapping.
SLAB CACHE
A very important and an interesting function which you might want to look at
is copy_page_range,(memory.c) called from fork, which copies the page
tables(pte_entries) from the parent to the child across a fork. The function
also takes care of COW pages,if it manages to detect the COW pages.
(vm->vm_flags & (VM_SHARED | VM_MAYWRITE) ) == VM_MAYWRITE). If its a COW
page,it write protects the page both in the parent and the child
(pte_wrprotect),to ensure that a dirty,writable page would be faulted in when
either of them tries to do a write on the page,as was explained before. Try
looking at it,as that would help you to have control over page tables,if you
want to tweak the page tables. zap_page_range frees the pages mapped to the
pte_entries and zeroes out the pte_entries,in the page_tables, given a range of
addresses.do_munmap calls it,to free up the pages allocated to the tasks
page_tables for the area unmapped. clear_page_tables frees the page table
pointers. There are many other utility functions,which might be of help. You can
then take up the mprotect ,mlock codes,if you are through with the memory.c and
mmap.c stuff. A very important file that implements the slab_allocator for Linux
is slab.c.Its an implementation of a slab cache Let us discuss its actions in a
nutshell. A cache object is made up of several slabs,and each slab can contain
many instances of objects. The slab cache depends upon struct page, to extract
the slab and caches respectively from an object pointer. This way when an object
gets freed,the slab to which it belongs to is located,or the cache to which it
belongs to in case of kfree is located by either calling GET_PAGE_SLAB OR
GET_PAGE_CACHE. On system startup,the slab cache gets initialised by a call to
kmem_cache_init,kmem_cache_sizes_init. kmem_cache_init initialises the main
cache,cache_cache to which all the caches created are
linked.kmem_cache_sizes_init creates several caches(normal and dma) of various
sizes of powers of 2, starting from 32 through order 5, (PAGE_SIZE << 5)
- « first
- ‹ previous
- of 24
- next ›
- last »