Kernel janitorial possibilities

From Crashcourse Wiki

Jump to: navigation, search

[edit] Overview

Just some observations about things that could be removed, updated or simplified.

[edit] VM_RESERVED, VM_IO and remap_pfn_range

A number of source files set those first two flags, like this in drivers/uio/uio.c:

        vma->vm_flags |= VM_IO | VM_RESERVED;

        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

        return remap_pfn_range(vma,
                               idev->info->mem[mi].addr >> PAGE_SHIFT,
                               vma->vm_end - vma->vm_start,

even though the subsequent call to remap_pfn_range will handle that:

int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
                    unsigned long pfn, unsigned long size, pgprot_t prot)
        pgd_t *pgd;
        unsigned long next;
        unsigned long end = addr + PAGE_ALIGN(size);
        struct mm_struct *mm = vma->vm_mm;
        int err;

         * Physically remapped pages are special. Tell the
         * rest of the world about it:
         *   VM_IO tells people not to look at these pages
         *      (accesses can have side effects).
         *   VM_RESERVED is specified all over the place, because
         *      in 2.4 it kept swapout's vma scan off this vma; but
         *      in 2.6 the LRU scan won't even find its pages, so this
         *      flag means no more than count its pages in reserved_vm,
         *      and omit it from core dump, even when VM_IO turned off.
         *   VM_PFNMAP tells the core MM that the base pages are just
         *      raw PFN mappings, and do not have a "struct page" associated
         *      with them.
         * There's a horrible special case to handle copy-on-write
         * behaviour that some programs depend on. We mark the "original"
         * un-COW'ed pages by matching them up with "vma->vm_pgoff".
        if (addr == vma->vm_start && end == vma->vm_end) {
                vma->vm_pgoff = pfn;
                vma->vm_flags |= VM_PFN_AT_MMAP;
        } else if (is_cow_mapping(vma->vm_flags))
                return -EINVAL;

        vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP;

Personal tools