]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] get_unmapped_area for hugetlbfs
authorAndrew Morton <akpm@digeo.com>
Thu, 6 Feb 2003 00:58:06 +0000 (16:58 -0800)
committerLinus Torvalds <torvalds@home.transmeta.com>
Thu, 6 Feb 2003 00:58:06 +0000 (16:58 -0800)
Having to specify the mapping address is a pain.  Give hugetlbfs files a
file_operations.get_unmapped_area().

The implementation is in hugetlbfs rather than in arch code because it's
probably common to several architectures.  If the architecture has special
needs it can define HAVE_ARCH_HUGETLB_UNMAPPED_AREA and go it alone.  Just
like HAVE_ARCH_UNMAPPED_AREA.

fs/hugetlbfs/inode.c

index 1022c9ce54bd6359edd927002dbe2a56a44a5f4e..65d32c207254a4034363505e65a6a6dabc405f7c 100644 (file)
@@ -73,6 +73,47 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
        return ret;
 }
 
+/*
+ * Called under down_write(mmap_sem), page_table_lock is not held
+ */
+
+#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
+unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
+               unsigned long len, unsigned long pgoff, unsigned long flags);
+#else
+static unsigned long
+hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
+               unsigned long len, unsigned long pgoff, unsigned long flags)
+{
+       struct mm_struct *mm = current->mm;
+       struct vm_area_struct *vma;
+
+       if (len & ~HPAGE_MASK)
+               return -EINVAL;
+       if (len > TASK_SIZE)
+               return -ENOMEM;
+
+       if (addr) {
+               addr = ALIGN(addr, HPAGE_SIZE);
+               vma = find_vma(mm, addr);
+               if (TASK_SIZE - len >= addr &&
+                   (!vma || addr + len <= vma->vm_start))
+                       return addr;
+       }
+
+       addr = ALIGN(mm->free_area_cache, HPAGE_SIZE);
+
+       for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
+               /* At this point:  (!vma || addr < vma->vm_end). */
+               if (TASK_SIZE - len < addr)
+                       return -ENOMEM;
+               if (!vma || addr + len <= vma->vm_start)
+                       return addr;
+               addr = ALIGN(vma->vm_end, HPAGE_SIZE);
+       }
+}
+#endif
+
 /*
  * Read a page. Again trivial. If it didn't already exist
  * in the page cache, it is zero-filled.
@@ -466,8 +507,9 @@ static struct address_space_operations hugetlbfs_aops = {
 };
 
 struct file_operations hugetlbfs_file_operations = {
-       .mmap           = hugetlbfs_file_mmap,
-       .fsync          = simple_sync_file,
+       .mmap                   = hugetlbfs_file_mmap,
+       .fsync                  = simple_sync_file,
+       .get_unmapped_area      = hugetlb_get_unmapped_area,
 };
 
 static struct inode_operations hugetlbfs_dir_inode_operations = {