Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54cb8821 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds
Browse files

mm: merge populate and nopage into fault (fixes nonlinear)



Nonlinear mappings are (AFAIKS) simply a virtual memory concept that encodes
the virtual address -> file offset differently from linear mappings.

->populate is a layering violation because the filesystem/pagecache code
should need to know anything about the virtual memory mapping.  The hitch here
is that the ->nopage handler didn't pass down enough information (ie.  pgoff).
 But it is more logical to pass pgoff rather than have the ->nopage function
calculate it itself anyway (because that's a similar layering violation).

Having the populate handler install the pte itself is likewise a nasty thing
to be doing.

This patch introduces a new fault handler that replaces ->nopage and
->populate and (later) ->nopfn.  Most of the old mechanism is still in place
so there is a lot of duplication and nice cleanups that can be removed if
everyone switches over.

The rationale for doing this in the first place is that nonlinear mappings are
subject to the pagefault vs invalidate/truncate race too, and it seemed stupid
to duplicate the synchronisation logic rather than just consolidate the two.

After this patch, MAP_NONBLOCK no longer sets up ptes for pages present in
pagecache.  Seems like a fringe functionality anyway.

NOPAGE_REFAULT is removed.  This should be implemented with ->fault, and no
users have hit mainline yet.

[akpm@linux-foundation.org: cleanup]
[randy.dunlap@oracle.com: doc. fixes for readahead]
[akpm@linux-foundation.org: build fix]
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Signed-off-by: default avatarRandy Dunlap <randy.dunlap@oracle.com>
Cc: Mark Fasheh <mark.fasheh@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d00806b1
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -135,6 +135,33 @@ Who: Greg Kroah-Hartman <gregkh@suse.de>

---------------------------

What:	filemap_nopage, filemap_populate
When:	April 2007
Why:	These legacy interfaces no longer have any callers in the kernel and
	any functionality provided can be provided with filemap_fault. The
	removal schedule is short because they are a big maintainence burden
	and have some bugs.
Who:	Nick Piggin <npiggin@suse.de>

---------------------------

What:	vm_ops.populate, install_page
When:	April 2007
Why:	These legacy interfaces no longer have any callers in the kernel and
	any functionality provided can be provided with vm_ops.fault.
Who:	Nick Piggin <npiggin@suse.de>

---------------------------

What:	vm_ops.nopage
When:	February 2008, provided in-kernel callers have been converted
Why:	This interface is replaced by vm_ops.fault, but it has been around
	forever, is used by a lot of drivers, and doesn't cost much to
	maintain.
Who:	Nick Piggin <npiggin@suse.de>

---------------------------

What:	Interrupt only SA_* flags
When:	September 2007
Why:	The interrupt related SA_* flags are replaced by IRQF_* to move them
+2 −0
Original line number Diff line number Diff line
@@ -510,12 +510,14 @@ More details about quota locking can be found in fs/dquot.c.
prototypes:
	void (*open)(struct vm_area_struct*);
	void (*close)(struct vm_area_struct*);
	struct page *(*fault)(struct vm_area_struct*, struct fault_data *);
	struct page *(*nopage)(struct vm_area_struct*, unsigned long, int *);

locking rules:
		BKL	mmap_sem
open:		no	yes
close:		no	yes
fault:		no	yes
nopage:		no	yes

================================================================================
+1 −1
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ static int gfs2_readpage(struct file *file, struct page *page)
		if (file) {
			gf = file->private_data;
			if (test_bit(GFF_EXLOCK, &gf->f_flags))
				/* gfs2_sharewrite_nopage has grabbed the ip->i_gl already */
				/* gfs2_sharewrite_fault has grabbed the ip->i_gl already */
				goto skip_lock;
		}
		gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
+1 −1
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
	else
		vma->vm_ops = &gfs2_vm_ops_private;

	vma->vm_flags |= VM_CAN_INVALIDATE;
	vma->vm_flags |= VM_CAN_INVALIDATE|VM_CAN_NONLINEAR;

	gfs2_glock_dq_uninit(&i_gh);

+19 −17
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@
#include "trans.h"
#include "util.h"

static struct page *gfs2_private_nopage(struct vm_area_struct *area,
					unsigned long address, int *type)
static struct page *gfs2_private_fault(struct vm_area_struct *vma,
					struct fault_data *fdata)
{
	struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host);
	struct gfs2_inode *ip = GFS2_I(vma->vm_file->f_mapping->host);

	set_bit(GIF_PAGED, &ip->i_flags);
	return filemap_nopage(area, address, type);
	return filemap_fault(vma, fdata);
}

static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
@@ -104,16 +104,14 @@ out:
	return error;
}

static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area,
					   unsigned long address, int *type)
static struct page *gfs2_sharewrite_fault(struct vm_area_struct *vma,
						struct fault_data *fdata)
{
	struct file *file = area->vm_file;
	struct file *file = vma->vm_file;
	struct gfs2_file *gf = file->private_data;
	struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
	struct gfs2_holder i_gh;
	struct page *result = NULL;
	unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) +
			      area->vm_pgoff;
	int alloc_required;
	int error;

@@ -124,23 +122,27 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area,
	set_bit(GIF_PAGED, &ip->i_flags);
	set_bit(GIF_SW_PAGED, &ip->i_flags);

	error = gfs2_write_alloc_required(ip, (u64)index << PAGE_CACHE_SHIFT,
	error = gfs2_write_alloc_required(ip,
					(u64)fdata->pgoff << PAGE_CACHE_SHIFT,
					PAGE_CACHE_SIZE, &alloc_required);
	if (error)
	if (error) {
		fdata->type = VM_FAULT_OOM; /* XXX: are these right? */
		goto out;
	}

	set_bit(GFF_EXLOCK, &gf->f_flags);
	result = filemap_nopage(area, address, type);
	result = filemap_fault(vma, fdata);
	clear_bit(GFF_EXLOCK, &gf->f_flags);
	if (!result || result == NOPAGE_OOM)
	if (!result)
		goto out;

	if (alloc_required) {
		error = alloc_page_backing(ip, result);
		if (error) {
			if (area->vm_flags & VM_CAN_INVALIDATE)
			if (vma->vm_flags & VM_CAN_INVALIDATE)
				unlock_page(result);
			page_cache_release(result);
			fdata->type = VM_FAULT_OOM;
			result = NULL;
			goto out;
		}
@@ -154,10 +156,10 @@ out:
}

struct vm_operations_struct gfs2_vm_ops_private = {
	.nopage = gfs2_private_nopage,
	.fault = gfs2_private_fault,
};

struct vm_operations_struct gfs2_vm_ops_sharewrite = {
	.nopage = gfs2_sharewrite_nopage,
	.fault = gfs2_sharewrite_fault,
};
Loading