Skip to contentSkip to conversation

fault vs truncate/invalidate race fix

PATCH In review Nick Piggin 11 participants 99 messages Feb 21, 2007 – Mar 21, 2007

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

cover fault vs truncate/invalidate race fix

The following set of patches are based on current git.

These fix the fault vs invalidate and fault vs truncate_range race for filemap_nopage mappings, plus those and fault vs truncate race for nonlinear mappings.

These patches fix silent data corruption that we've had several people hitting in SUSE kernels. Our kernels have similar patches to lock the page over page fault, and no problem.

I've also got rid of the horrible populate API, and integrated nonlinear pages properly with the page fault path.

Downside is that this adds one more vector through which the buffered write deadlock can occur. However this is just a very tiny one (pte being unmapped for reclaim), compared to all the other ways that deadlock can occur (unmap, reclaim, truncate, invalidate). I doubt it will be noticable. At any rate, it is better than data corruption.

I hope these can get merged (at least into -mm) soon.

Thanks,
Nick

--
SuSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/6 mm: debug check for the fault vs invalidate race

Add a bugcheck for Andrea's pagefault vs invalidate race. This is triggerable for both linear and nonlinear pages with a userspace test harness (using direct IO and truncate, respectively).

 mm/filemap.c |    2 ++
 1 file changed, 2 insertions(+)
mm/filemap.c +2 -0
Index: linux-2.6/mm/filemap.c
===================================================================
@@ -120,6 +120,8 @@ void __remove_from_page_cache(struct pag
 	page->mapping = NULL;
 	mapping->nrpages--;
 	__dec_zone_page_state(page, NR_FILE_PAGES);
+
+	BUG_ON(page_mapped(page));
 }
 
 void remove_from_page_cache(struct page *page)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

PATCH 2/6 mm: simplify filemap_nopage

In reply to Nick Piggin

Identical block is duplicated twice: contrary to the comment, we have been re-reading the page *twice* in filemap_nopage rather than once.

If any retry logic or anything is needed, it belongs in lower levels anyway. Only retry once. Linus agrees.

 mm/filemap.c |   24 ------------------------
 1 file changed, 24 deletions(-)
mm/filemap.c +0 -24
Index: linux-2.6/mm/filemap.c
===================================================================
@@ -1448,30 +1448,6 @@ page_not_uptodate:
 		majmin = VM_FAULT_MAJOR;
 		count_vm_event(PGMAJFAULT);
 	}
-	lock_page(page);
-
-	/* Did it get unhashed while we waited for it? */
-	if (!page->mapping) {
-		unlock_page(page);
-		page_cache_release(page);
-		goto retry_all;
-	}
-
-	/* Did somebody else get it up-to-date? */
-	if (PageUptodate(page)) {
-		unlock_page(page);
-		goto success;
-	}
-
-	error = mapping->a_ops->readpage(file, page);
-	if (!error) {
-		wait_on_page_locked(page);
-		if (PageUptodate(page))
-			goto success;
-	} else if (error == AOP_TRUNCATED_PAGE) {
-		page_cache_release(page);
-		goto retry_find;
-	}
 
 	/*
 	 * Umm, take care of errors if the page isn't up-to-date.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

PATCH 3/6 mm: fix fault vs invalidate race for linear mappings

In reply to Nick Piggin

Fix the race between invalidate_inode_pages and do_no_page.

Andrea Arcangeli identified a subtle race between invalidation of pages from pagecache with userspace mappings, and do_no_page.

The issue is that invalidation has to shoot down all mappings to the page, before it can be discarded from the pagecache. Between shooting down ptes to a particular page, and actually dropping the struct page from the pagecache, do_no_page from any process might fault on that page and establish a new mapping to the page just before it gets discarded from the pagecache.

The most common case where such invalidation is used is in file truncation. This case was catered for by doing a sort of open-coded seqlock between the file's i_size, and its truncate_count.

Truncation will decrease i_size, then increment truncate_count before unmapping userspace pages; do_no_page will read truncate_count, then find the page if it is within i_size, and then check truncate_count under the page table lock and back out and retry if it had subsequently been changed (ptl will serialise against unmapping, and ensure a potentially updated truncate_count is actually visible).

Complexity and documentation issues aside, the locking protocol fails in the case where we would like to invalidate pagecache inside i_size. do_no_page can come in anytime and filemap_nopage is not aware of the invalidation in progress (as it is when it is outside i_size). The end result is that dangling (->mapping == NULL) pages that appear to be from a particular file may be mapped into userspace with nonsense data. Valid mappings to the same place will see a different page.

Andrea implemented two working fixes, one using a real seqlock, another using a page->flags bit. He also proposed using the page lock in do_no_page, but that was initially considered too heavyweight. However, it is not a global or per-file lock, and the page cacheline is modified in do_no_page to increment _count and _mapcount anyway, so a further modification should not be a large performance hit. Scalability is not an issue.

This patch implements this latter approach. ->nopage implementations return with the page locked if it is possible for their underlying file to be invalidated (in that case, they must set a special vm_flags bit to indicate so). do_no_page only unlocks the page after setting up the mapping completely. invalidation is excluded because it holds the page lock during invalidation of each page (and ensures that the page is not mapped while holding the lock).

This also allows significant simplifications in do_no_page, because we have the page locked in the right place in the pagecache from the start.

 fs/gfs2/ops_file.c          |    2 
 fs/ncpfs/mmap.c             |    1 
 fs/ocfs2/mmap.c             |    1 
 fs/xfs/linux-2.6/xfs_file.c |    1 
 include/linux/mm.h          |    6 +
 ipc/shm.c                   |    1 
 mm/filemap.c                |   53 ++++++----------
 mm/memory.c                 |  138 +++++++++++++++++++-------------------------
 mm/shmem.c                  |   11 ++-
 mm/truncate.c               |   10 +++
 10 files changed, 111 insertions(+), 113 deletions(-)
include/linux/mm.h +6 -0
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -170,6 +170,12 @@ extern unsigned int kobjsize(const void 
 #define VM_INSERTPAGE	0x02000000	/* The vma has had "vm_insert_page()" done on it */
 #define VM_ALWAYSDUMP	0x04000000	/* Always include in core dumps */
 
+#define VM_CAN_INVALIDATE 0x08000000	/* The mapping may be invalidated,
+					 * eg. truncate or invalidate_inode_*.
+					 * In this case, do_no_page must
+					 * return with the page locked.
+					 */
+
 #ifndef VM_STACK_DEFAULT_FLAGS		/* arch can override this */
 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
 #endif
mm/filemap.c +20 -33

105 lines not on this page · raw message

mm/memory.c +60 -78

223 lines not on this page · raw message

mm/shmem.c +9 -2
Index: linux-2.6/mm/shmem.c
===================================================================
@@ -82,6 +82,7 @@ enum sgp_type {
 	SGP_READ,	/* don't exceed i_size, don't allocate page */
 	SGP_CACHE,	/* don't exceed i_size, may allocate page */
 	SGP_WRITE,	/* may exceed i_size, may allocate page */
+	SGP_NOPAGE,	/* same as SGP_CACHE, return with page locked */
 };
 
 static int shmem_getpage(struct inode *inode, unsigned long idx,
@@ -1215,8 +1216,10 @@ repeat:
 	}
 done:
 	if (*pagep != filepage) {
-		unlock_page(filepage);
 		*pagep = filepage;
+		if (sgp != SGP_NOPAGE)
+			unlock_page(filepage);
+
 	}
 	return 0;
 
@@ -1235,13 +1238,15 @@ struct page *shmem_nopage(struct vm_area
 	unsigned long idx;
 	int error;
 
+	BUG_ON(!(vma->vm_flags & VM_CAN_INVALIDATE));
+
 	idx = (address - vma->vm_start) >> PAGE_SHIFT;
 	idx += vma->vm_pgoff;
 	idx >>= PAGE_CACHE_SHIFT - PAGE_SHIFT;
 	if (((loff_t) idx << PAGE_CACHE_SHIFT) >= i_size_read(inode))
 		return NOPAGE_SIGBUS;
 
-	error = shmem_getpage(inode, idx, &page, SGP_CACHE, type);
+	error = shmem_getpage(inode, idx, &page, SGP_NOPAGE, type);
 	if (error)
 		return (error == -ENOMEM)? NOPAGE_OOM: NOPAGE_SIGBUS;
 
@@ -1339,6 +1344,7 @@ int shmem_mmap(struct file *file, struct
 {
 	file_accessed(file);
 	vma->vm_ops = &shmem_vm_ops;
+	vma->vm_flags |= VM_CAN_INVALIDATE;
 	return 0;
 }
 
@@ -2532,5 +2538,6 @@ int shmem_zero_setup(struct vm_area_stru
 		fput(vma->vm_file);
 	vma->vm_file = file;
 	vma->vm_ops = &shmem_vm_ops;
+	vma->vm_flags |= VM_CAN_INVALIDATE;
 	return 0;
 }
fs/ncpfs/mmap.c +1 -0
Index: linux-2.6/fs/ncpfs/mmap.c
===================================================================
@@ -123,6 +123,7 @@ int ncp_mmap(struct file *file, struct v
 		return -EFBIG;
 
 	vma->vm_ops = &ncp_file_mmap;
+	vma->vm_flags |= VM_CAN_INVALIDATE;
 	file_accessed(file);
 	return 0;
 }
fs/ocfs2/mmap.c +1 -0
Index: linux-2.6/fs/ocfs2/mmap.c
===================================================================
@@ -104,6 +104,7 @@ int ocfs2_mmap(struct file *file, struct
 	ocfs2_meta_unlock(file->f_dentry->d_inode, lock_level);
 out:
 	vma->vm_ops = &ocfs2_file_vm_ops;
+	vma->vm_flags |= VM_CAN_INVALIDATE;
 	return 0;
 }
 
fs/xfs/linux-2.6/xfs_file.c +1 -0
Index: linux-2.6/fs/xfs/linux-2.6/xfs_file.c
===================================================================
@@ -343,6 +343,7 @@ xfs_file_mmap(
 	struct vm_area_struct *vma)
 {
 	vma->vm_ops = &xfs_file_vm_ops;
+	vma->vm_flags |= VM_CAN_INVALIDATE;
 
 #ifdef CONFIG_XFS_DMAPI
 	if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
ipc/shm.c +1 -0
Index: linux-2.6/ipc/shm.c
===================================================================
@@ -231,6 +231,7 @@ static int shm_mmap(struct file * file, 
 	ret = shmem_mmap(file, vma);
 	if (ret == 0) {
 		vma->vm_ops = &shm_vm_ops;
+		vma->vm_flags |= VM_CAN_INVALIDATE;
 		if (!(vma->vm_flags & VM_WRITE))
 			vma->vm_flags &= ~VM_MAYWRITE;
 		shm_inc(shm_file_ns(file), file->f_path.dentry->d_inode->i_ino);
mm/truncate.c +12 -1
Index: linux-2.6/mm/truncate.c
===================================================================
@@ -191,6 +191,11 @@ void truncate_inode_pages_range(struct a
 				unlock_page(page);
 				continue;
 			}
+			if (page_mapped(page)) {
+				unmap_mapping_range(mapping,
+				  (loff_t)page_index<<PAGE_CACHE_SHIFT,
+				  PAGE_CACHE_SIZE, 0);
+			}
 			truncate_complete_page(mapping, page);
 			unlock_page(page);
 		}
@@ -228,6 +233,11 @@ void truncate_inode_pages_range(struct a
 				break;
 			lock_page(page);
 			wait_on_page_writeback(page);
+			if (page_mapped(page)) {
+				unmap_mapping_range(mapping,
+				  (loff_t)page_index<<PAGE_CACHE_SHIFT,
+				  PAGE_CACHE_SIZE, 0);
+			}
 			if (page->index > next)
 				next = page->index;
 			next++;
@@ -396,7 +406,7 @@ int invalidate_inode_pages2_range(struct
 				break;
 			}
 			wait_on_page_writeback(page);
-			while (page_mapped(page)) {
+			if (page_mapped(page)) {
 				if (!did_range_unmap) {
 					/*
 					 * Zap the rest of the file in one hit.
@@ -416,6 +426,7 @@ int invalidate_inode_pages2_range(struct
 					  PAGE_CACHE_SIZE, 0);
 				}
 			}
+			BUG_ON(page_mapped(page));
 			ret = do_launder_page(mapping, page);
 			if (ret == 0 && !invalidate_complete_page2(mapping, page))
 				ret = -EIO;
fs/gfs2/ops_file.c +2 -0
Index: linux-2.6/fs/gfs2/ops_file.c
===================================================================
@@ -365,6 +365,8 @@ static int gfs2_mmap(struct file *file, 
 	else
 		vma->vm_ops = &gfs2_vm_ops_private;
 
+	vma->vm_flags |= VM_CAN_INVALIDATE;
+
 	gfs2_glock_dq_uninit(&i_gh);
 
 	return error;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#4 lore raw

Re: [patch 3/6] mm: fix fault vs invalidate race for linear mappings

Quoted 47 lines · On Wed, 21 Feb 2007 05:50:05 +0100 (CET) Nick Piggin <[email protected]> wrote:

Fix the race between invalidate_inode_pages and do_no_page.

Andrea Arcangeli identified a subtle race between invalidation of pages from pagecache with userspace mappings, and do_no_page.

The issue is that invalidation has to shoot down all mappings to the page, before it can be discarded from the pagecache. Between shooting down ptes to a particular page, and actually dropping the struct page from the pagecache, do_no_page from any process might fault on that page and establish a new mapping to the page just before it gets discarded from the pagecache.

The most common case where such invalidation is used is in file truncation. This case was catered for by doing a sort of open-coded seqlock between the file's i_size, and its truncate_count.

Truncation will decrease i_size, then increment truncate_count before unmapping userspace pages; do_no_page will read truncate_count, then find the page if it is within i_size, and then check truncate_count under the page table lock and back out and retry if it had subsequently been changed (ptl will serialise against unmapping, and ensure a potentially updated truncate_count is actually visible).

Complexity and documentation issues aside, the locking protocol fails in the case where we would like to invalidate pagecache inside i_size. do_no_page can come in anytime and filemap_nopage is not aware of the invalidation in progress (as it is when it is outside i_size). The end result is that dangling (->mapping == NULL) pages that appear to be from a particular file may be mapped into userspace with nonsense data. Valid mappings to the same place will see a different page.

Andrea implemented two working fixes, one using a real seqlock, another using a page->flags bit. He also proposed using the page lock in do_no_page, but that was initially considered too heavyweight. However, it is not a global or per-file lock, and the page cacheline is modified in do_no_page to increment _count and _mapcount anyway, so a further modification should not be a large performance hit. Scalability is not an issue.

This patch implements this latter approach. ->nopage implementations return with the page locked if it is possible for their underlying file to be invalidated (in that case, they must set a special vm_flags bit to indicate so). do_no_page only unlocks the page after setting up the mapping completely. invalidation is excluded because it holds the page lock during invalidation of each page (and ensures that the page is not mapped while holding the lock).

Quoted 4 lines

This also allows significant simplifications in do_no_page, because we have the page locked in the right place in the pagecache from the start.

Why was truncate_inode_pages_range() altered to unmap the page if it got mapped again?

Oh. Because the unmap_mapping_range() call got removed from vmtruncate(). Why? (Please send suitable updates to the changelog).

I guess truncate of a mmapped area isn't sufficiently common to worry about the inefficiency of this change.

Lots of memory barriers got removed in memory.c, unchangeloggedly.

Gratuitous renaming of locals in do_no_page() makes the change hard to review. Should have been a separate patch.

In fact, the patch would have been heaps clearer if that renaming had been a separate patch.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [patch 3/6] mm: fix fault vs invalidate race for linear mappings

Quoted 54 lines · Andrew Morton
Quoted 47 lines · On Wed, 21 Feb 2007 05:50:05 +0100 (CET) Nick Piggin <[email protected]> wrote:

Fix the race between invalidate_inode_pages and do_no_page.

Andrea Arcangeli identified a subtle race between invalidation of pages from pagecache with userspace mappings, and do_no_page.

The issue is that invalidation has to shoot down all mappings to the page, before it can be discarded from the pagecache. Between shooting down ptes to a particular page, and actually dropping the struct page from the pagecache, do_no_page from any process might fault on that page and establish a new mapping to the page just before it gets discarded from the pagecache.

The most common case where such invalidation is used is in file truncation. This case was catered for by doing a sort of open-coded seqlock between the file's i_size, and its truncate_count.

Truncation will decrease i_size, then increment truncate_count before unmapping userspace pages; do_no_page will read truncate_count, then find the page if it is within i_size, and then check truncate_count under the page table lock and back out and retry if it had subsequently been changed (ptl will serialise against unmapping, and ensure a potentially updated truncate_count is actually visible).

Complexity and documentation issues aside, the locking protocol fails in the case where we would like to invalidate pagecache inside i_size. do_no_page can come in anytime and filemap_nopage is not aware of the invalidation in progress (as it is when it is outside i_size). The end result is that dangling (->mapping == NULL) pages that appear to be from a particular file may be mapped into userspace with nonsense data. Valid mappings to the same place will see a different page.

Andrea implemented two working fixes, one using a real seqlock, another using a page->flags bit. He also proposed using the page lock in do_no_page, but that was initially considered too heavyweight. However, it is not a global or per-file lock, and the page cacheline is modified in do_no_page to increment _count and _mapcount anyway, so a further modification should not be a large performance hit. Scalability is not an issue.

This patch implements this latter approach. ->nopage implementations return with the page locked if it is possible for their underlying file to be invalidated (in that case, they must set a special vm_flags bit to indicate so). do_no_page only unlocks the page after setting up the mapping completely. invalidation is excluded because it holds the page lock during invalidation of each page (and ensures that the page is not mapped while holding the lock).

Quoted 4 lines

This also allows significant simplifications in do_no_page, because we have the page locked in the right place in the pagecache from the start.

Quoted 5 lines

Why was truncate_inode_pages_range() altered to unmap the page if it got mapped again?

Oh. Because the unmap_mapping_range() call got removed from vmtruncate(). Why? (Please send suitable updates to the changelog).

We have to ensure it is unmapped, and be prepared to unmap it while under the page lock.

Quoted 2 lines

I guess truncate of a mmapped area isn't sufficiently common to worry about the inefficiency of this change.

Yeah, and it should be more efficient for files that aren't mmapped, because we don't have to take i_mmap_lock for them.

Quoted 1 line

Lots of memory barriers got removed in memory.c, unchangeloggedly.

Yeah they were all for the lockless truncate_count checks. Now that we use the page lock, we don't need barriers.

Quoted 5 lines

Gratuitous renaming of locals in do_no_page() makes the change hard to review. Should have been a separate patch.

In fact, the patch would have been heaps clearer if that renaming had been a separate patch.

Shall I?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#6 lore raw

Re: [patch 3/6] mm: fix fault vs invalidate race for linear mappings

Quoted 9 lines · On Wed, 7 Mar 2007 07:57:27 +0100 Nick Piggin <[email protected]> wrote:
Quoted 6 lines

Why was truncate_inode_pages_range() altered to unmap the page if it got mapped again?

Oh. Because the unmap_mapping_range() call got removed from vmtruncate(). Why? (Please send suitable updates to the changelog).

We have to ensure it is unmapped, and be prepared to unmap it while under the page lock.

But vmtruncate() dropped i_size, so nobody will map this page into pagetables from then on.

Quoted 11 lines
Quoted 2 lines

I guess truncate of a mmapped area isn't sufficiently common to worry about the inefficiency of this change.

Yeah, and it should be more efficient for files that aren't mmapped, because we don't have to take i_mmap_lock for them.

Quoted 1 line

Lots of memory barriers got removed in memory.c, unchangeloggedly.

Yeah they were all for the lockless truncate_count checks. Now that we use the page lock, we don't need barriers.

Quoted 7 lines
Quoted 5 lines

Gratuitous renaming of locals in do_no_page() makes the change hard to review. Should have been a separate patch.

In fact, the patch would have been heaps clearer if that renaming had been a separate patch.

Shall I?

If you don't have anything better to do, yes please ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [patch 3/6] mm: fix fault vs invalidate race for linear mappings

Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Wed, 7 Mar 2007 07:57:27 +0100 Nick Piggin <[email protected]> wrote:
Quoted 4 lines

Why was truncate_inode_pages_range() altered to unmap the page if it got mapped again?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Oh. Because the unmap_mapping_range() call got removed from vmtruncate(). Why? (Please send suitable updates to the changelog).

We have to ensure it is unmapped, and be prepared to unmap it while under the page lock.

But vmtruncate() dropped i_size, so nobody will map this page into pagetables from then on.

But there could be a fault in progress... the only way to know is locking the page.

Quoted 14 lines
Quoted 14 lines
Quoted 2 lines

I guess truncate of a mmapped area isn't sufficiently common to worry about the inefficiency of this change.

Yeah, and it should be more efficient for files that aren't mmapped, because we don't have to take i_mmap_lock for them.

Quoted 1 line

Lots of memory barriers got removed in memory.c, unchangeloggedly.

Yeah they were all for the lockless truncate_count checks. Now that we use the page lock, we don't need barriers.

Quoted 3 lines

Gratuitous renaming of locals in do_no_page() makes the change hard to review. Should have been a separate patch.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

In fact, the patch would have been heaps clearer if that renaming had been a separate patch.

Shall I?

If you don't have anything better to do, yes please ;)

OK.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

PATCH 4/6 mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin

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

I can't see why the filesystem/pagecache code should need to know anything about it, except for the fact that the ->nopage handler didn't quite pass down enough information (ie. pgoff). But it is more logical to pass pgoff rather than have the ->nopage function calculate it itself anyway. And having the nopage handler install the pte itself is sort of nasty.

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.

 Documentation/feature-removal-schedule.txt |   27 ++++++
 Documentation/filesystems/Locking          |    2 
 fs/gfs2/ops_address.c                      |    2 
 fs/gfs2/ops_file.c                         |    2 
 fs/gfs2/ops_vm.c                           |   34 ++++---
 fs/ncpfs/mmap.c                            |   23 ++---
 fs/ocfs2/aops.c                            |    2 
 fs/ocfs2/mmap.c                            |   17 +--
 fs/xfs/linux-2.6/xfs_file.c                |   23 ++---
 include/linux/mm.h                         |   36 ++++++--
 ipc/shm.c                                  |    2 
 mm/filemap.c                               |   93 ++++++++++++--------
 mm/filemap_xip.c                           |   44 +++++----
 mm/fremap.c                                |  105 ++++++++++++++++-------
 mm/memory.c                                |  129 ++++++++++++++++++-----------
 mm/mmap.c                                  |    8 -
 mm/nommu.c                                 |    3 
 mm/shmem.c                                 |   80 ++++-------------
 mm/truncate.c                              |    2 
 19 files changed, 371 insertions(+), 263 deletions(-)
include/linux/mm.h +29 -7
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -175,6 +175,7 @@ extern unsigned int kobjsize(const void 
 					 * In this case, do_no_page must
 					 * return with the page locked.
 					 */
+#define VM_CAN_NONLINEAR 0x10000000	/* Has ->fault & does nonlinear pages */
 
 #ifndef VM_STACK_DEFAULT_FLAGS		/* arch can override this */
 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
@@ -198,6 +199,26 @@ extern unsigned int kobjsize(const void 
  */
 extern pgprot_t protection_map[16];
 
+#define FAULT_FLAG_WRITE	0x01
+#define FAULT_FLAG_NONLINEAR	0x02
+
+/*
+ * fault_data is filled in the the pagefault handler and passed to the
+ * vma's ->fault function. That function is responsible for filling in
+ * 'type', which is the type of fault if a page is returned, or the type
+ * of error if NULL is returned.
+ *
+ * pgoff should be used in favour of address, if possible. If pgoff is
+ * used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get
+ * nonlinear mapping support.
+ */
+struct fault_data {
+	unsigned long address;
+	pgoff_t pgoff;
+	unsigned int flags;
+
+	int type;
+};
 
 /*
  * These are the virtual MM functions - opening of an area, closing and
@@ -207,6 +228,7 @@ extern pgprot_t protection_map[16];
 struct vm_operations_struct {
 	void (*open)(struct vm_area_struct * area);
 	void (*close)(struct vm_area_struct * area);
+	struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
 	unsigned long (*nopfn)(struct vm_area_struct * area, unsigned long address);
 	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
@@ -636,7 +658,6 @@ static inline int page_mapped(struct pag
  */
 #define NOPAGE_SIGBUS	(NULL)
 #define NOPAGE_OOM	((struct page *) (-1))
-#define NOPAGE_REFAULT	((struct page *) (-2))	/* Return to userspace, rerun */
 
 /*
  * Error return values for the *_nopfn functions
@@ -666,14 +687,13 @@ static inline int page_mapped(struct pag
 extern void show_free_areas(void);
 
 #ifdef CONFIG_SHMEM
-struct page *shmem_nopage(struct vm_area_struct *vma,
-			unsigned long address, int *type);
+struct page *shmem_fault(struct vm_area_struct *vma, struct fault_data *fdata);
 int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *new);
 struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
 					unsigned long addr);
 int shmem_lock(struct file *file, int lock, struct user_struct *user);
 #else
-#define shmem_nopage filemap_nopage
+#define shmem_fault filemap_fault
 
 static inline int shmem_lock(struct file *file, int lock,
 			     struct user_struct *user)
@@ -1071,9 +1091,11 @@ extern void truncate_inode_pages_range(s
 				       loff_t lstart, loff_t lend);
 
 /* generic vm_area_ops exported for stackable file systems */
-extern struct page *filemap_nopage(struct vm_area_struct *, unsigned long, int *);
-extern int filemap_populate(struct vm_area_struct *, unsigned long,
-		unsigned long, pgprot_t, unsigned long, int);
+extern struct page *filemap_fault(struct vm_area_struct *, struct fault_data *);
+extern struct page * __deprecated_for_modules filemap_nopage(
+			struct vm_area_struct *, unsigned long, int *);
+extern int __deprecated_for_modules filemap_populate(struct vm_area_struct *,
+		unsigned long, unsigned long, pgprot_t, unsigned long, int);
 
 /* mm/page-writeback.c */
 int write_one_page(struct page *page, int wait);
mm/memory.c +84 -45

219 lines not on this page · raw message

mm/filemap.c +57 -36

199 lines not on this page · raw message

mm/fremap.c +73 -32

120 lines not on this page · raw message

fs/gfs2/ops_file.c +1 -1
Index: linux-2.6/fs/gfs2/ops_file.c
===================================================================
@@ -365,7 +365,7 @@ static int gfs2_mmap(struct file *file, 
 	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);
 
fs/gfs2/ops_vm.c +18 -16
Index: linux-2.6/fs/gfs2/ops_vm.c
===================================================================
@@ -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,21 +122,25 @@ static struct page *gfs2_sharewrite_nopa
 	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,
-					  PAGE_CACHE_SIZE, &alloc_required);
-	if (error)
+	error = gfs2_write_alloc_required(ip,
+					(u64)fdata->pgoff << PAGE_CACHE_SHIFT,
+					PAGE_CACHE_SIZE, &alloc_required);
+	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) {
 			page_cache_release(result);
+			fdata->type = VM_FAULT_OOM;
 			result = NULL;
 			goto out;
 		}
@@ -152,10 +154,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,
 };
 
fs/ocfs2/mmap.c +8 -9
Index: linux-2.6/fs/ocfs2/mmap.c
===================================================================
@@ -42,16 +42,14 @@
 #include "inode.h"
 #include "mmap.h"
 
-static struct page *ocfs2_nopage(struct vm_area_struct * area,
-				 unsigned long address,
-				 int *type)
+static struct page *ocfs2_fault(struct vm_area_struct *area,
+						struct fault_data *fdata)
 {
-	struct page *page = NOPAGE_SIGBUS;
+	struct page *page = NULL;
 	sigset_t blocked, oldset;
 	int ret;
 
-	mlog_entry("(area=%p, address=%lu, type=%p)\n", area, address,
-		   type);
+	mlog_entry("(area=%p, page offset=%lu)\n", area, fdata->pgoff);
 
 	/* The best way to deal with signals in this path is
 	 * to block them upfront, rather than allowing the
@@ -62,11 +60,12 @@ static struct page *ocfs2_nopage(struct 
 	 * from sigprocmask */
 	ret = sigprocmask(SIG_BLOCK, &blocked, &oldset);
 	if (ret < 0) {
+		fdata->type = VM_FAULT_SIGBUS;
 		mlog_errno(ret);
 		goto out;
 	}
 
-	page = filemap_nopage(area, address, type);
+	page = filemap_fault(area, fdata);
 
 	ret = sigprocmask(SIG_SETMASK, &oldset, NULL);
 	if (ret < 0)
@@ -77,7 +76,7 @@ out:
 }
 
 static struct vm_operations_struct ocfs2_file_vm_ops = {
-	.nopage = ocfs2_nopage,
+	.fault = ocfs2_fault,
 };
 
 int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
@@ -104,7 +103,7 @@ int ocfs2_mmap(struct file *file, struct
 	ocfs2_meta_unlock(file->f_dentry->d_inode, lock_level);
 out:
 	vma->vm_ops = &ocfs2_file_vm_ops;
-	vma->vm_flags |= VM_CAN_INVALIDATE;
+	vma->vm_flags |= VM_CAN_INVALIDATE | VM_CAN_NONLINEAR;
 	return 0;
 }
 
fs/xfs/linux-2.6/xfs_file.c +11 -12
Index: linux-2.6/fs/xfs/linux-2.6/xfs_file.c
===================================================================
@@ -246,18 +246,19 @@ xfs_file_fsync(
 
 #ifdef CONFIG_XFS_DMAPI
 STATIC struct page *
-xfs_vm_nopage(
-	struct vm_area_struct	*area,
-	unsigned long		address,
-	int			*type)
+xfs_vm_fault(
+	struct vm_area_struct	*vma,
+	struct fault_data	*fdata)
 {
-	struct inode	*inode = area->vm_file->f_path.dentry->d_inode;
+	struct inode	*inode = vma->vm_file->f_path.dentry->d_inode;
 	bhv_vnode_t	*vp = vn_from_inode(inode);
 
 	ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
-	if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), area, 0))
+	if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0)) {
+		fdata->type = VM_FAULT_SIGBUS;
 		return NULL;
-	return filemap_nopage(area, address, type);
+	}
+	return filemap_fault(vma, fdata);
 }
 #endif /* CONFIG_XFS_DMAPI */
 
@@ -343,7 +344,7 @@ xfs_file_mmap(
 	struct vm_area_struct *vma)
 {
 	vma->vm_ops = &xfs_file_vm_ops;
-	vma->vm_flags |= VM_CAN_INVALIDATE;
+	vma->vm_flags |= VM_CAN_INVALIDATE | VM_CAN_NONLINEAR;
 
 #ifdef CONFIG_XFS_DMAPI
 	if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
@@ -502,14 +503,12 @@ const struct file_operations xfs_dir_fil
 };
 
 static struct vm_operations_struct xfs_file_vm_ops = {
-	.nopage		= filemap_nopage,
-	.populate	= filemap_populate,
+	.fault		= filemap_fault,
 };
 
 #ifdef CONFIG_XFS_DMAPI
 static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
-	.nopage		= xfs_vm_nopage,
-	.populate	= filemap_populate,
+	.fault		= xfs_vm_fault,
 #ifdef HAVE_VMOP_MPROTECT
 	.mprotect	= xfs_vm_mprotect,
 #endif
mm/mmap.c +2 -6
Index: linux-2.6/mm/mmap.c
===================================================================
@@ -1147,12 +1147,8 @@ out:	
 		mm->locked_vm += len >> PAGE_SHIFT;
 		make_pages_present(addr, addr + len);
 	}
-	if (flags & MAP_POPULATE) {
-		up_write(&mm->mmap_sem);
-		sys_remap_file_pages(addr, len, 0,
-					pgoff, flags & MAP_NONBLOCK);
-		down_write(&mm->mmap_sem);
-	}
+	if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
+		make_pages_present(addr, addr + len);
 	return addr;
 
 unmap_and_free_vma:
ipc/shm.c +1 -1
Index: linux-2.6/ipc/shm.c
===================================================================
@@ -261,7 +261,7 @@ static const struct file_operations shm_
 static struct vm_operations_struct shm_vm_ops = {
 	.open	= shm_open,	/* callback for a new vm-area open */
 	.close	= shm_close,	/* callback for when the vm-area is released */
-	.nopage	= shmem_nopage,
+	.fault	= shmem_fault,
 #if defined(CONFIG_NUMA) && defined(CONFIG_SHMEM)
 	.set_policy = shmem_set_policy,
 	.get_policy = shmem_get_policy,
mm/filemap_xip.c +23 -21

91 lines not on this page · raw message

mm/nommu.c +1 -2
Index: linux-2.6/mm/nommu.c
===================================================================
@@ -1299,8 +1299,7 @@ int in_gate_area_no_task(unsigned long a
 	return 0;
 }
 
-struct page *filemap_nopage(struct vm_area_struct *area,
-			unsigned long address, int *type)
+struct page *filemap_fault(struct vm_area_struct *vma, struct fault_data *fdata)
 {
 	BUG();
 	return NULL;
mm/shmem.c +19 -61

129 lines not on this page · raw message

mm/truncate.c +1 -1
Index: linux-2.6/mm/truncate.c
===================================================================
@@ -81,7 +81,7 @@ EXPORT_SYMBOL(cancel_dirty_page);
 /*
  * If truncate cannot remove the fs-private metadata from the page, the page
  * becomes anonymous.  It will be left on the LRU and may even be mapped into
- * user pagetables if we're racing with filemap_nopage().
+ * user pagetables if we're racing with filemap_fault().
  *
  * We need to bale out if page->mapping is no longer equal to the original
  * mapping.  This happens a) when the VM reclaimed the page while we waited on
fs/gfs2/ops_address.c +1 -1
Index: linux-2.6/fs/gfs2/ops_address.c
===================================================================
@@ -239,7 +239,7 @@ static int gfs2_readpage(struct file *fi
 		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);
fs/ncpfs/mmap.c +12 -11
Index: linux-2.6/fs/ncpfs/mmap.c
===================================================================
@@ -25,8 +25,8 @@
 /*
  * Fill in the supplied page for mmap
  */
-static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area,
-				     unsigned long address, int *type)
+static struct page* ncp_file_mmap_fault(struct vm_area_struct *area,
+						struct fault_data *fdata)
 {
 	struct file *file = area->vm_file;
 	struct dentry *dentry = file->f_path.dentry;
@@ -40,15 +40,17 @@ static struct page* ncp_file_mmap_nopage
 
 	page = alloc_page(GFP_HIGHUSER); /* ncpfs has nothing against high pages
 	           as long as recvmsg and memset works on it */
-	if (!page)
-		return page;
+	if (!page) {
+		fdata->type = VM_FAULT_OOM;
+		return NULL;
+	}
 	pg_addr = kmap(page);
-	address &= PAGE_MASK;
-	pos = address - area->vm_start + (area->vm_pgoff << PAGE_SHIFT);
+	pos = fdata->pgoff << PAGE_SHIFT;
 
 	count = PAGE_SIZE;
-	if (address + PAGE_SIZE > area->vm_end) {
-		count = area->vm_end - address;
+	if (fdata->address + PAGE_SIZE > area->vm_end) {
+		WARN_ON(1); /* shouldn't happen? */
+		count = area->vm_end - fdata->address;
 	}
 	/* what we can read in one go */
 	bufsize = NCP_SERVER(inode)->buffer_size;
@@ -91,15 +93,14 @@ static struct page* ncp_file_mmap_nopage
 	 * fetches from the network, here the analogue of disk.
 	 * -- wli
 	 */
-	if (type)
-		*type = VM_FAULT_MAJOR;
+	fdata->type = VM_FAULT_MAJOR;
 	count_vm_event(PGMAJFAULT);
 	return page;
 }
 
 static struct vm_operations_struct ncp_file_mmap =
 {
-	.nopage	= ncp_file_mmap_nopage,
+	.fault = ncp_file_mmap_fault,
 };
 
 
fs/ocfs2/aops.c +1 -1
Index: linux-2.6/fs/ocfs2/aops.c
===================================================================
@@ -215,7 +215,7 @@ static int ocfs2_readpage(struct file *f
 	 * might now be discovering a truncate that hit on another node.
 	 * block_read_full_page->get_block freaks out if it is asked to read
 	 * beyond the end of a file, so we check here.  Callers
-	 * (generic_file_read, fault->nopage) are clever enough to check i_size
+	 * (generic_file_read, vm_ops->fault) are clever enough to check i_size
 	 * and notice that the page they just read isn't needed.
 	 *
 	 * XXX sys_readahead() seems to get that wrong?
Documentation/feature-removal-schedule.txt +27 -0
Index: linux-2.6/Documentation/feature-removal-schedule.txt
===================================================================
@@ -170,6 +170,33 @@ Who:	Greg Kroah-Hartman <[email protected]>
 
 ---------------------------
 
+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 <[email protected]>
+
+---------------------------
+
+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 <[email protected]>
+
+---------------------------
+
+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 <[email protected]>
+
+---------------------------
+
 What:	Interrupt only SA_* flags
 When:	Januar 2007
 Why:	The interrupt related SA_* flags are replaced by IRQF_* to move them
Documentation/filesystems/Locking +2 -0
Index: linux-2.6/Documentation/filesystems/Locking
===================================================================
@@ -508,12 +508,14 @@ More details about quota locking can be 
 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
 
 ================================================================================

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#9 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 15 lines · On Wed, 21 Feb 2007 05:50:17 +0100 (CET) Nick Piggin <[email protected]> wrote:

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

I can't see why the filesystem/pagecache code should need to know anything about it, except for the fact that the ->nopage handler didn't quite pass down enough information (ie. pgoff). But it is more logical to pass pgoff rather than have the ->nopage function calculate it itself anyway. And having the nopage handler install the pte itself is sort of nasty.

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.

Quoted 5 lines

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.

It's awkward to layer a largely do-nothing patch like this on top of a significant functional change. Makes it harder to isolate the source of regressions, harder to revert the do-something patch.

Quoted 2 lines

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

Does Ingo agree?

Quoted 2 lines

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

Did benh agree with that?

The patch unchangeloggedly adds a basic new structure to core mm (fault_data). Would be nice to document its fields, especially `flags'.

Please add less pointless blank lines.

How well has this been tested? The ocfs2 changes? gfs2? We should at least give those guys a heads-up.

Does anybody really pass a NULL `type' arg into filemap_nopage()?

This patch seems to churn things around an awful lot for minimal benefit.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 23 lines · Andrew Morton
Quoted 15 lines · On Wed, 21 Feb 2007 05:50:17 +0100 (CET) Nick Piggin <[email protected]> wrote:

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

I can't see why the filesystem/pagecache code should need to know anything about it, except for the fact that the ->nopage handler didn't quite pass down enough information (ie. pgoff). But it is more logical to pass pgoff rather than have the ->nopage function calculate it itself anyway. And having the nopage handler install the pte itself is sort of nasty.

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.

Quoted 5 lines

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.

Quoted 8 lines

It's awkward to layer a largely do-nothing patch like this on top of a significant functional change. Makes it harder to isolate the source of regressions, harder to revert the do-something patch.

Quoted 2 lines

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

Does Ingo agree?

I cc'ed him when first posting it. He didn't disagree.

Quoted 4 lines
Quoted 2 lines

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

Did benh agree with that?

Yes.

Quoted 2 lines

The patch unchangeloggedly adds a basic new structure to core mm (fault_data). Would be nice to document its fields, especially `flags'.

OK. This is actually something that I would like more people to review. Do we need any different fields? Should it be passed as arguments instead of a structure?

Quoted 5 lines

Please add less pointless blank lines.

How well has this been tested? The ocfs2 changes? gfs2? We should at least give those guys a heads-up.

Yes we should. Not all those filesystem changes have been tested.

Quoted 1 line

Does anybody really pass a NULL `type' arg into filemap_nopage()?

Dunno, it's exported. I remove that completely in a subsequent patch anyway.

Quoted 1 line

This patch seems to churn things around an awful lot for minimal benefit.

Well it fixes the whole design of the nonlinear fault path.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Nick Piggin
Quoted 1 line · Andrew Morton

This patch seems to churn things around an awful lot for minimal benefit.

Well it fixes the whole design of the nonlinear fault path.

If it doesn't look very impressive, it could be because it leaves all the old crud around for backwards compatibility (the worst offenders are removed in patch 6/6).

If you look at the patchset as a whole, it removes about 250 lines, mostly of (non trivial) duplicated code in filemap.c memory.c shmem.c fremap.c, that is nonlinear pages specific and doesn't get anywhere near the testing that the linear fault path does.

A minimal fix for nonlinear pages would have required changing all ->populate handlers, which I simply thought was not very productive considering the testing and coverage issues, and that I was going to rewrite the nonlinear path anyway.

If you like, you can consider patches 1,2,3 as the fix, and ignore nonlinear (hey, it doesn't even bother checking truncate_count today!).

Then 4,5,6 is the fault/nonlinear rewrite, take it or leave it. I thought you would have liked the patches...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 14 lines · Nick Piggin

If it doesn't look very impressive, it could be because it leaves all the old crud around for backwards compatibility (the worst offenders are removed in patch 6/6).

If you look at the patchset as a whole, it removes about 250 lines, mostly of (non trivial) duplicated code in filemap.c memory.c shmem.c fremap.c, that is nonlinear pages specific and doesn't get anywhere near the testing that the linear fault path does.

A minimal fix for nonlinear pages would have required changing all ->populate handlers, which I simply thought was not very productive considering the testing and coverage issues, and that I was going to rewrite the nonlinear path anyway.

Quoted 6 lines

If you like, you can consider patches 1,2,3 as the fix, and ignore nonlinear (hey, it doesn't even bother checking truncate_count today!).

Then 4,5,6 is the fault/nonlinear rewrite, take it or leave it. I thought you would have liked the patches...

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#13 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 21 lines · On Wed, 7 Mar 2007 09:27:55 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 18 lines · Nick Piggin

If it doesn't look very impressive, it could be because it leaves all the old crud around for backwards compatibility (the worst offenders are removed in patch 6/6).

If you look at the patchset as a whole, it removes about 250 lines, mostly of (non trivial) duplicated code in filemap.c memory.c shmem.c fremap.c, that is nonlinear pages specific and doesn't get anywhere near the testing that the linear fault path does.

A minimal fix for nonlinear pages would have required changing all ->populate handlers, which I simply thought was not very productive considering the testing and coverage issues, and that I was going to rewrite the nonlinear path anyway.

If you like, you can consider patches 1,2,3 as the fix, and ignore nonlinear (hey, it doesn't even bother checking truncate_count today!).

Quoted 9 lines
Quoted 2 lines

Then 4,5,6 is the fault/nonlinear rewrite, take it or leave it. I thought you would have liked the patches...

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

I'm rather regretting having merged it - I don't think it has been used for much.

Paolo's UML speedup patches might use nonlinear though.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 11 lines · Andrew Morton
Quoted 6 lines

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI - and remove all the nonlinear code. (This would split fremap areas into separate vmas)

I'm rather regretting having merged it - I don't think it has been used for much.

Paolo's UML speedup patches might use nonlinear though.

yes, i wrote the first, prototype version of that for UML, it needs an extended version of the syscall, sys_remap_file_pages_prot():

http://redhat.com/~mingo/remap-file-pages-patches/remap-file-pages-prot-2.6.4-rc1-mm1-A1

i also wrote an x86 hypervisor kind of thing for UML, called 'sys_vcpu()', which allows UML to execute guest user-mode in a box, which also relies on sys_remap_file_pages_prot():

http://redhat.com/~mingo/remap-file-pages-patches/vcpu-2.6.4-rc2-mm1-A2

which reduced the UML guest syscall overhead from 30 usecs to 4 usecs (with native syscalls taking 2 usecs, on the box i tested, years ago).

So it certainly looked useful to me - but wasnt really picked up widely.

We'll always have the option to get rid of it (and hence completely reverse the decision to merge it) without breaking the ABI, by emulating the API via mremap(). That eliminates the UML speedup though. So no need to feel sorry about having merged it, we can easily revisit that years-old 'do we want it' decision, without any ABI worries.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 29 lines · Ingo Molnar
Quoted 11 lines · Andrew Morton
Quoted 6 lines

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI - and remove all the nonlinear code. (This would split fremap areas into separate vmas)

I'm rather regretting having merged it - I don't think it has been used for much.

Paolo's UML speedup patches might use nonlinear though.

yes, i wrote the first, prototype version of that for UML, it needs an extended version of the syscall, sys_remap_file_pages_prot():

http://redhat.com/~mingo/remap-file-pages-patches/remap-file-pages-prot-2.6.4-rc1-mm1-A1

i also wrote an x86 hypervisor kind of thing for UML, called 'sys_vcpu()', which allows UML to execute guest user-mode in a box, which also relies on sys_remap_file_pages_prot():

http://redhat.com/~mingo/remap-file-pages-patches/vcpu-2.6.4-rc2-mm1-A2

which reduced the UML guest syscall overhead from 30 usecs to 4 usecs (with native syscalls taking 2 usecs, on the box i tested, years ago).

Quoted 7 lines

So it certainly looked useful to me - but wasnt really picked up widely.

We'll always have the option to get rid of it (and hence completely reverse the decision to merge it) without breaking the ABI, by emulating the API via mremap(). That eliminates the UML speedup though. So no need to feel sorry about having merged it, we can easily revisit that years-old 'do we want it' decision, without any ABI worries.

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.

For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 7 lines · Nick Piggin

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.
For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

Anonymous-only would make it a doorstop for Oracle, since its entire motive for using it is to window into objects larger than user virtual address spaces (this likely also applies to UML, though they should really chime in to confirm). Restrictions to tmpfs and/or ramfs would likely be liveable, though I suspect some things might want to do it to shm segments (I'll ask about that one). There's definitely no need for a persistent backing store for the object to be remapped in Oracle's case, in any event. It's largely the in-core destination and source of IO, not something saved on-disk itself.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 11 lines · Bill Irwin
Quoted 7 lines · Nick Piggin

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.
For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

Anonymous-only would make it a doorstop for Oracle, since its entire motive for using it is to window into objects larger than user virtual

Uh, duh yes I don't mean MAP_ANONYMOUS, I was just thinking of the shmem inode that sits behind MAP_ANONYMOUS|MAP_SHARED. Of course if you don't have a file descriptor to get a pgoff, then remap_file_pages is a doorstop for everyone ;)

Quoted 7 lines

address spaces (this likely also applies to UML, though they should really chime in to confirm). Restrictions to tmpfs and/or ramfs would likely be liveable, though I suspect some things might want to do it to shm segments (I'll ask about that one). There's definitely no need for a persistent backing store for the object to be remapped in Oracle's case, in any event. It's largely the in-core destination and source of IO, not something saved on-disk itself.

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 26 lines · Nick Piggin
Quoted 11 lines · Bill Irwin
Quoted 7 lines · Nick Piggin

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.
For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

Anonymous-only would make it a doorstop for Oracle, since its entire motive for using it is to window into objects larger than user virtual

Uh, duh yes I don't mean MAP_ANONYMOUS, I was just thinking of the shmem inode that sits behind MAP_ANONYMOUS|MAP_SHARED. Of course if you don't have a file descriptor to get a pgoff, then remap_file_pages is a doorstop for everyone ;)

Quoted 7 lines

address spaces (this likely also applies to UML, though they should really chime in to confirm). Restrictions to tmpfs and/or ramfs would likely be liveable, though I suspect some things might want to do it to shm segments (I'll ask about that one). There's definitely no need for a persistent backing store for the object to be remapped in Oracle's case, in any event. It's largely the in-core destination and source of IO, not something saved on-disk itself.

Quoted 2 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

But come to think of it, I still don't think nonlinear mappings are too bad as they are ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 27 lines · Nick Piggin
Quoted 26 lines · Nick Piggin
Quoted 11 lines · Bill Irwin
Quoted 7 lines · Nick Piggin

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.
For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

Anonymous-only would make it a doorstop for Oracle, since its entire motive for using it is to window into objects larger than user virtual

Uh, duh yes I don't mean MAP_ANONYMOUS, I was just thinking of the shmem inode that sits behind MAP_ANONYMOUS|MAP_SHARED. Of course if you don't have a file descriptor to get a pgoff, then remap_file_pages is a doorstop for everyone ;)

Quoted 7 lines

address spaces (this likely also applies to UML, though they should really chime in to confirm). Restrictions to tmpfs and/or ramfs would likely be liveable, though I suspect some things might want to do it to shm segments (I'll ask about that one). There's definitely no need for a persistent backing store for the object to be remapped in Oracle's case, in any event. It's largely the in-core destination and source of IO, not something saved on-disk itself.

Quoted 5 lines
Quoted 2 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

Well, we don't need truncate(), but MADV_REMOVE for memory hotunplug, which is way similar I guess.

About the restriction to tmpfs, I have just discovered
'[PATCH] mm: tracking shared dirty pages' (commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89), which already partially conflicts with remap_file_pages for file-based mmaps (and that's fully fine, for now).

Even if UML does not need it, till now if there is a VMA protection and a page hasn't been remapped with remap_file_pages, the VMA protection is used (just because it makes sense).

However, it is only used when the PTE is first created - we can never change protections on a VMA - so it vma_wants_writenotify() is true (on all file-based and on no shmfs based mapping, right?), and we write-protect the VMA, it will always be write-protected.

That's no problem for UML, but for any other user (I guess I'll have to prevent callers from trying such stuff - I started from a pretty generic patch).

Quoted 2 lines

But come to think of it, I still don't think nonlinear mappings are too bad as they are ;)

Btw, I really like removing ->populate and merging the common code together. filemap_populate and shmem_populate are so obnoxiously different that I already wanted to do that (after merging remap_file_pages() core).

Also, I'm curious. Since my patches are already changing remap_file_pages() code, should they be absolutely merged after yours?

Signature · 11 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 16 lines · Blaisorblade
Quoted 6 lines · Nick Piggin
Quoted 3 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

Well, we don't need truncate(), but MADV_REMOVE for memory hotunplug, which is way similar I guess.

About the restriction to tmpfs, I have just discovered
'[PATCH] mm: tracking shared dirty pages' (commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89), which already partially conflicts with remap_file_pages for file-based mmaps (and that's fully fine, for now).

Quoted 8 lines

Even if UML does not need it, till now if there is a VMA protection and a page hasn't been remapped with remap_file_pages, the VMA protection is used (just because it makes sense).

However, it is only used when the PTE is first created - we can never change protections on a VMA - so it vma_wants_writenotify() is true (on all file-based and on no shmfs based mapping, right?), and we write-protect the VMA, it will always be write-protected.

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

Quoted 10 lines

That's no problem for UML, but for any other user (I guess I'll have to prevent callers from trying such stuff - I started from a pretty generic patch).

Quoted 2 lines

But come to think of it, I still don't think nonlinear mappings are too bad as they are ;)

Btw, I really like removing ->populate and merging the common code together. filemap_populate and shmem_populate are so obnoxiously different that I already wanted to do that (after merging remap_file_pages() core).

Yeah they are also frustratingly similar to filemap_nopage and shmem_nopage, and duplicate a lot of the same code ;)

Quoted 2 lines

Also, I'm curious. Since my patches are already changing remap_file_pages() code, should they be absolutely merged after yours?

Is there a big clash? I don't think I did a great deal to fremap.c (mainly just removing stuff)...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 21 lines · Nick Piggin
Quoted 20 lines · Blaisorblade
Quoted 5 lines · Nick Piggin
Quoted 2 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

Well, we don't need truncate(), but MADV_REMOVE for memory hotunplug, which is way similar I guess.

About the restriction to tmpfs, I have just discovered '[PATCH] mm: tracking shared dirty pages' (commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89), which already partially conflicts with remap_file_pages for file-based mmaps (and that's fully fine, for now).

Even if UML does not need it, till now if there is a VMA protection and a page hasn't been remapped with remap_file_pages, the VMA protection is used (just because it makes sense).

Quoted 8 lines
Quoted 4 lines

However, it is only used when the PTE is first created - we can never change protections on a VMA - so it vma_wants_writenotify() is true (on all file-based and on no shmfs based mapping, right?), and we write-protect the VMA, it will always be write-protected.

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

I wouldn't be able to distinguish them, but am I going to get write faults for clean ptes when vma_wants_writenotify() is false (as seems to be for tmpfs)? I guess not.

For tmpfs pages, clean writable PTEs are mapped as writable so they won't give any problem, since vma_wants_writenotify() is false for tmpfs. Correct?

Quoted 5 lines
Quoted 2 lines

Also, I'm curious. Since my patches are already changing remap_file_pages() code, should they be absolutely merged after yours?

Is there a big clash? I don't think I did a great deal to fremap.c (mainly just removing stuff)...

Hopefully, we just both modify sys_remap_file_pages(), I'll see soon.

Signature · 11 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 30 lines · Blaisorblade
Quoted 21 lines · Nick Piggin
Quoted 20 lines · Blaisorblade
Quoted 5 lines · Nick Piggin
Quoted 2 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

Well, we don't need truncate(), but MADV_REMOVE for memory hotunplug, which is way similar I guess.

About the restriction to tmpfs, I have just discovered '[PATCH] mm: tracking shared dirty pages' (commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89), which already partially conflicts with remap_file_pages for file-based mmaps (and that's fully fine, for now).

Even if UML does not need it, till now if there is a VMA protection and a page hasn't been remapped with remap_file_pages, the VMA protection is used (just because it makes sense).

Quoted 8 lines
Quoted 4 lines

However, it is only used when the PTE is first created - we can never change protections on a VMA - so it vma_wants_writenotify() is true (on all file-based and on no shmfs based mapping, right?), and we write-protect the VMA, it will always be write-protected.

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

Quoted 6 lines

I wouldn't be able to distinguish them, but am I going to get write faults for clean ptes when vma_wants_writenotify() is false (as seems to be for tmpfs)? I guess not.

For tmpfs pages, clean writable PTEs are mapped as writable so they won't give any problem, since vma_wants_writenotify() is false for tmpfs. Correct?

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files? I guess that's OK if Oracle and UML both use tmpfs/shm?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 3 lines · Nick Piggin

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files? I guess that's OK if Oracle and UML both use tmpfs/shm?

It's OK for UML.

Jeff

Signature · 7 lines
Work email - jdike at linux dot intel dot com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#24 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin
Quoted 3 lines · Nick Piggin

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files? I guess that's OK if Oracle and UML both use tmpfs/shm?

Sometimes ramfs is also used in the Oracle case. I presume that's even simpler than tmpfs. (Hugetlb, while also used in for the same general buffer pool, is never used in conjunction with remap_file_pages() etc.)

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin
Quoted 36 lines · Nick Piggin
Quoted 35 lines · Blaisorblade
Quoted 21 lines · Nick Piggin
Quoted 20 lines · Blaisorblade
Quoted 5 lines · Nick Piggin
Quoted 2 lines

Yeah, tmpfs/shm segs are what I was thinking about. If UML can live with that as well, then I think it might be a good option.

Oh, hmm.... if you can truncate these things then you still need to force unmap so you still need i_mmap_nonlinear.

Well, we don't need truncate(), but MADV_REMOVE for memory hotunplug, which is way similar I guess.

About the restriction to tmpfs, I have just discovered '[PATCH] mm: tracking shared dirty pages' (commit d08b3851da41d0ee60851f2c75b118e1f7a5fc89), which already partially conflicts with remap_file_pages for file-based mmaps (and that's fully fine, for now).

Even if UML does not need it, till now if there is a VMA protection and a page hasn't been remapped with remap_file_pages, the VMA protection is used (just because it makes sense).

Quoted 8 lines
Quoted 4 lines

However, it is only used when the PTE is first created - we can never change protections on a VMA - so it vma_wants_writenotify() is true (on all file-based and on no shmfs based mapping, right?), and we write-protect the VMA, it will always be write-protected.

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

I wouldn't be able to distinguish them, but am I going to get write faults for clean ptes when vma_wants_writenotify() is false (as seems to be for tmpfs)? I guess not.

Quoted 6 lines
Quoted 3 lines

For tmpfs pages, clean writable PTEs are mapped as writable so they won't give any problem, since vma_wants_writenotify() is false for tmpfs. Correct?

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files?

They still work in most cases (including for UML), but if the initial mmap() specified PROT_WRITE, that is ignored, for pages which are not remapped via remap_file_pages(). UML uses PROT_NONE for the initial mmap, so that's no problem.

Quoted 2 lines

I guess that's OK if Oracle and UML both use
tmpfs/shm?

Signature · 11 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#26 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 14 lines · Blaisorblade
Quoted 13 lines · Nick Piggin
Quoted 12 lines
Quoted 4 lines

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

I wouldn't be able to distinguish them, but am I going to get write faults for clean ptes when vma_wants_writenotify() is false (as seems to be for tmpfs)? I guess not.

For tmpfs pages, clean writable PTEs are mapped as writable so they won't give any problem, since vma_wants_writenotify() is false for tmpfs. Correct?

Quoted 7 lines
Quoted 2 lines

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files?

They still work in most cases (including for UML), but if the initial mmap() specified PROT_WRITE, that is ignored, for pages which are not remapped via remap_file_pages(). UML uses PROT_NONE for the initial mmap, so that's no problem.

But how are you going to distinguish a write fault on a readonly pte for dirty page accounting vs a read-only nonlinear protection?

You can't store any more data in a present pte AFAIK, so you'd have to have some out of band data. At which point, you may as well just forget about vma_wants_writenotify vmas, considering that everybody is using shmem/ramfs.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 17 lines · Nick Piggin
Quoted 15 lines · Blaisorblade
Quoted 14 lines · Nick Piggin
Quoted 11 lines
Quoted 3 lines

Yes, I believe that is the case, however I wonder if that is going to be a problem for you to distinguish between write faults for clean writable ptes, and write faults for readonly ptes?

I wouldn't be able to distinguish them, but am I going to get write faults for clean ptes when vma_wants_writenotify() is false (as seems to be for tmpfs)? I guess not.

For tmpfs pages, clean writable PTEs are mapped as writable so they won't give any problem, since vma_wants_writenotify() is false for tmpfs. Correct?

Yes, that should be the case. So would this mean that nonlinear protections don't work on regular files?

Quoted 7 lines
Quoted 4 lines

They still work in most cases (including for UML), but if the initial mmap() specified PROT_WRITE, that is ignored, for pages which are not remapped via remap_file_pages(). UML uses PROT_NONE for the initial mmap, so that's no problem.

But how are you going to distinguish a write fault on a readonly pte for dirty page accounting vs a read-only nonlinear protection?

Hmm... I was only thinking to PTEs which hadn't been remapped via remap_file_pages, but just faulted in with initial mmap() protection.

For the other PTEs, however, I overlooked that the current code ignores vma_wants_writenotify(), i.e. breaks dirty page accounting for them, and I refused to even consider this opportunity, even without knowing the purposes of dirty pages accounting (I found the commits explaining this however).

Quoted 4 lines

You can't store any more data in a present pte AFAIK, so you'd have to have some out of band data. At which point, you may as well just forget about vma_wants_writenotify vmas, considering that everybody is using shmem/ramfs.

I was going to do that anyway. I'd guess that I should just disallow in remap_file_pages() the VM_MANYPROTS (i.e. MAP_CHGPROT in flags) && vma_wants_writenotify() combination, right? Ok, trivial (shouldn't even have pointed this out).

Signature · 11 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Bill Irwin
Quoted 9 lines · Bill Irwin
Quoted 7 lines · Nick Piggin

Depending on whether anyone wants it, and what features they want, we could emulate the old syscall, and make a new restricted one which is much less intrusive.
For example, if we can operate only on MAP_ANONYMOUS memory and specify that nonlinear mappings effectively mlock the pages, then we can get rid of all the objrmap and unmap_mapping_range handling, forget about the writeout and msync problems...

Quoted 4 lines

Anonymous-only would make it a doorstop for Oracle, since its entire motive for using it is to window into objects larger than user virtual address spaces (this likely also applies to UML, though they should really chime in to confirm).

We need it for shared file mappings (for tmpfs only).

Our scenario is:
RAM is implemented through a shared mapped file, kept on tmpfs (except by dumb users); various processes share an fd for this file (it's opened and immediately deleted).

We maintain page tables in x86 style, and TLB flush is implemented through mmap()/munmap()/mprotect().

Having a VMA per each 4K is not the intended VMA usage: for instance, the default /proc/sys/vm/max_map_count (64K) is saturated by a UML process with 64K * 4K = 256M of resident memory.

Quoted 11 lines

Restrictions to tmpfs and/or ramfs would
likely be liveable, though I suspect some things might want to do it to shm segments (I'll ask about that one).

There's definitely no need for a
persistent backing store for the object to be remapped in Oracle's case, in any event. It's largely the in-core destination and source of IO, not something saved on-disk itself.

-- wli

Signature · 11 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#29 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 5 lines · On Wed, 7 Mar 2007 09:27:55 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 5 lines

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

Quoted 3 lines · Andrew Morton

I'm rather regretting having merged it - I don't think it has been used for much.
Paolo's UML speedup patches might use nonlinear though.

Guess what major real-life application not only uses nonlinear daily but would even be very happy to see it extended with non-vma-creating protections and more? It's not terribly typical for things to be truncated while remap_file_pages() is doing its work, though it's been proposed as a method of dynamism. It won't stress remap_file_pages() vs. truncate() in any meaningful way, though, as userspace will be rather diligent about clearing in-use data out of the file offset range to be truncated away anyway, and all that via O_DIRECT.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#30 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 7 lines · On Wed, 7 Mar 2007 01:29:03 -0800 Bill Irwin <[email protected]> wrote:
Quoted 5 lines · On Wed, 7 Mar 2007 09:27:55 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 5 lines

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

Quoted 8 lines
Quoted 3 lines · Andrew Morton

I'm rather regretting having merged it - I don't think it has been used for much.
Paolo's UML speedup patches might use nonlinear though.

Guess what major real-life application not only uses nonlinear daily but would even be very happy to see it extended with non-vma-creating protections and more?

uh-oh. SQL server?

Quoted 6 lines

It's not terribly typical for things to be
truncated while remap_file_pages() is doing its work, though it's been proposed as a method of dynamism. It won't stress remap_file_pages() vs. truncate() in any meaningful way, though, as userspace will be rather diligent about clearing in-use data out of the file offset range to be truncated away anyway, and all that via O_DIRECT.

The problem here isn't related to truncate or direct-IO. It's just plain-old MAP_SHARED. nonlinear VMAs are now using the old-style dirty-memory management. msync() is basically a no-op and the code is wildly tricky and pretty much untested. The chances that we broke it are considerable.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#31 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 3 lines · On Wed, 7 Mar 2007 01:29:03 -0800 Bill Irwin <[email protected]> wrote:
Quoted 3 lines

Guess what major real-life application not only uses nonlinear daily but would even be very happy to see it extended with non-vma-creating protections and more?

Quoted 1 line · Andrew Morton

uh-oh. SQL server?

Close enough. ;)

Quoted 6 lines · On Wed, 7 Mar 2007 01:29:03 -0800 Bill Irwin <[email protected]> wrote:
Quoted 6 lines

It's not terribly typical for things to be
truncated while remap_file_pages() is doing its work, though it's been proposed as a method of dynamism. It won't stress remap_file_pages() vs. truncate() in any meaningful way, though, as userspace will be rather diligent about clearing in-use data out of the file offset range to be truncated away anyway, and all that via O_DIRECT.

Quoted 5 lines · Andrew Morton

The problem here isn't related to truncate or direct-IO. It's just plain-old MAP_SHARED. nonlinear VMAs are now using the old-style dirty-memory management. msync() is basically a no-op and the code is wildly tricky and pretty much untested. The chances that we broke it are considerable.

This would be of concern for swapping out tmpfs-backed nonlinearly- mapped files under extreme stress in Oracle's case, though it's rather typical for it all to be mlock()'d in-core and cases where that's necessary to be considered grossly underprovisioned. As far as I know, msync() is not used to manage the nonlinearly-mapped objects, which are most typically expected to be memory-backed, rendering writeback to disk of questionable value. Also quite happily, I'm not aware of any data integrity issues it would explain. Bug though it may be, it requires a usage model very rarely used by Oracle to trigger, so we've not run into it.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#32 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Ingo Molnar
Quoted 18 lines
Quoted 18 lines

If it doesn't look very impressive, it could be because it leaves all the old crud around for backwards compatibility (the worst offenders are removed in patch 6/6).

If you look at the patchset as a whole, it removes about 250 lines, mostly of (non trivial) duplicated code in filemap.c memory.c shmem.c fremap.c, that is nonlinear pages specific and doesn't get anywhere near the testing that the linear fault path does.

A minimal fix for nonlinear pages would have required changing all ->populate handlers, which I simply thought was not very productive considering the testing and coverage issues, and that I was going to rewrite the nonlinear path anyway.

If you like, you can consider patches 1,2,3 as the fix, and ignore nonlinear (hey, it doesn't even bother checking truncate_count today!).

Quoted 8 lines
Quoted 2 lines

Then 4,5,6 is the fault/nonlinear rewrite, take it or leave it. I thought you would have liked the patches...

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

That would make sense. Dirty page accounting doesn't work either on non-linear mappings, and I can't see how that could be fixed in any other way.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#33 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 2 lines · On Wed, 07 Mar 2007 09:38:34 +0100 Miklos Szeredi <[email protected]> wrote:

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#34 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#35 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 8 lines · On Wed, 07 Mar 2007 09:51:57 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty. That puts us back to the pre-2.6.17 algorithms and I guess it'll break the msync guarantees.

Peter, I thought we went through the nonlinear problem ages ago and decided it was OK?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#36 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 14 lines · Andrew Morton
Quoted 8 lines · On Wed, 07 Mar 2007 09:51:57 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

Quoted 6 lines

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty. That puts us back to the pre-2.6.17 algorithms and I guess it'll break the msync guarantees.

Peter, I thought we went through the nonlinear problem ages ago and decided it was OK?

msync breakage is bad, but otherwise I don't know that we care about dirty page writeout efficiency.

But I think we discovered that those msync changes are bogus anyway becuase there is a small race window where pte could be dirtied without page being set dirty?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#37 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 19 lines · On Wed, 7 Mar 2007 10:18:23 +0100 Nick Piggin <[email protected]> wrote:
Quoted 18 lines · Andrew Morton
Quoted 8 lines · On Wed, 07 Mar 2007 09:51:57 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty. That puts us back to the pre-2.6.17 algorithms and I guess it'll break the msync guarantees.

Quoted 5 lines
Quoted 2 lines

Peter, I thought we went through the nonlinear problem ages ago and decided it was OK?

msync breakage is bad, but otherwise I don't know that we care about dirty page writeout efficiency.

Well. We made so many changes to support the synchronous dirty-the-page-when-we-dirty-the-pte thing that I'm rather doubtful that the old-style approach still works. It might seem to, most of the time. But if it _is_ subtly broken, boy it's going to take a long time for us to find out.

Quoted 3 lines

But I think we discovered that those msync changes are bogus anyway becuase there is a small race window where pte could be dirtied without page being set dirty?

Dunno, I don't recall that. We dirty the page before the pte...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#38 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines
Quoted 3 lines

But I think we discovered that those msync changes are bogus anyway becuase there is a small race window where pte could be dirtied without page being set dirty?

Dunno, I don't recall that. We dirty the page before the pte...

That's the one I just submitted a fix for ;)

http://lkml.org/lkml/2007/3/6/308

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#39 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 11 lines · Andrew Morton
Quoted 3 lines · On Wed, 7 Mar 2007 10:18:23 +0100 Nick Piggin <[email protected]> wrote:

msync breakage is bad, but otherwise I don't know that we care about dirty page writeout efficiency.

Well. We made so many changes to support the synchronous dirty-the-page-when-we-dirty-the-pte thing that I'm rather doubtful that the old-style approach still works. It might seem to, most of the time. But if it _is_ subtly broken, boy it's going to take a long time for us to find out.

I can't think of anything that should have caused breakage (except for the msync thing). We're still careful about not dropping pte dirty bits.

Quoted 5 lines
Quoted 3 lines

But I think we discovered that those msync changes are bogus anyway becuase there is a small race window where pte could be dirtied without page being set dirty?

Dunno, I don't recall that. We dirty the page before the pte...

I don't think it isn't really that simple. There is a big comment in clear_page_dirty_for_io.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#40 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 9 lines
Quoted 3 lines

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty.

It won't even get that far, because it only looks at vmas on mapping->i_mmap, and not on i_mmap_nonlinear.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#41 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 14 lines · Andrew Morton
Quoted 8 lines · On Wed, 07 Mar 2007 09:51:57 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

Quoted 6 lines

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty. That puts us back to the pre-2.6.17 algorithms and I guess it'll break the msync guarantees.

Peter, I thought we went through the nonlinear problem ages ago and decided it was OK?

Can recollect as much, I modelled it after page_referenced() and can't find any VM_NONLINEAR specific code in there either.

Will have a hard look, but if its broken, then page_referenced if equally broken it seems, which would make page reclaim funny in the light of nonlinear mappings.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#42 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 22 lines · Peter Zijlstra
Quoted 14 lines · Andrew Morton
Quoted 8 lines · On Wed, 07 Mar 2007 09:51:57 +0100 Miklos Szeredi <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

Dirty page accounting doesn't work either on
non-linear mappings

It doesn't? Confused - these things don't have anything to do with each other do they?

Look in page_mkclean(). Where does it handle non-linear mappings?

OK, I'd forgotten about that. It won't break dirty memory accounting, but it'll potentially break dirty memory balancing.

Quoted 6 lines

If we have the wrong page (due to nonlinear), page_check_address() will fail and we'll leave the pte dirty. That puts us back to the pre-2.6.17 algorithms and I guess it'll break the msync guarantees.

Peter, I thought we went through the nonlinear problem ages ago and decided it was OK?

Quoted 6 lines

Can recollect as much, I modelled it after page_referenced() and can't find any VM_NONLINEAR specific code in there either.

Will have a hard look, but if its broken, then page_referenced if equally broken it seems, which would make page reclaim funny in the light of nonlinear mappings.

page_referenced is just an heuristic, and it ignores nonlinear mappings and the page which will get filtered down to try_to_unmap.

Page reclaim is already "funny" for nonlinear mappings, page_referenced is the least of its worries ;) It works, though.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#43 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 9 lines · Nick Piggin
Quoted 7 lines · Peter Zijlstra

Can recollect as much, I modelled it after page_referenced() and can't find any VM_NONLINEAR specific code in there either.

Will have a hard look, but if its broken, then page_referenced if equally broken it seems, which would make page reclaim funny in the light of nonlinear mappings.

Quoted 5 lines

page_referenced is just an heuristic, and it ignores nonlinear mappings and the page which will get filtered down to try_to_unmap.

Page reclaim is already "funny" for nonlinear mappings, page_referenced is the least of its worries ;) It works, though.

Or, to be more helpful, unmap_mapping_range is what it should be modelled on.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#44 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 10 lines · Nick Piggin
Quoted 9 lines · Nick Piggin
Quoted 7 lines · Peter Zijlstra

Can recollect as much, I modelled it after page_referenced() and can't find any VM_NONLINEAR specific code in there either.

Will have a hard look, but if its broken, then page_referenced if equally broken it seems, which would make page reclaim funny in the light of nonlinear mappings.

Quoted 8 lines
Quoted 5 lines

page_referenced is just an heuristic, and it ignores nonlinear mappings and the page which will get filtered down to try_to_unmap.

Page reclaim is already "funny" for nonlinear mappings, page_referenced is the least of its worries ;) It works, though.

Or, to be more helpful, unmap_mapping_range is what it should be modelled on.

*sigh* yes was looking at all that code, thats gonna be darn slow though, but I'll whip up a patch.

/me feels terribly bad about having missed this..

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#45 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 2 lines

*sigh* yes was looking at all that code, thats gonna be darn slow though, but I'll whip up a patch.

Well, if it's going to be darn slow, maybe it's better to go with mingo's plan on emulating nonlinear vmas with linear ones. That'll be darn slow as well, but at least it will be much less complicated.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#46 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Miklos Szeredi
Quoted 2 lines

*sigh* yes was looking at all that code, thats gonna be darn slow though, but I'll whip up a patch.

Well, if it's going to be darn slow, maybe it's better to go with mingo's plan on emulating nonlinear vmas with linear ones. That'll be

There are real users who want these fast, though.

Quoted 1 line

darn slow as well, but at least it will be much less complicated.

IMO, the best thing to do is just restore msync behaviour, and comment the fact that we ignore nonlinears. We need to restore msync behaviour to fix races in regular mappings anyway, at least for now.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#47 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 8 lines · Nick Piggin
Quoted 5 lines · Miklos Szeredi
Quoted 2 lines

*sigh* yes was looking at all that code, thats gonna be darn slow though, but I'll whip up a patch.

Well, if it's going to be darn slow, maybe it's better to go with mingo's plan on emulating nonlinear vmas with linear ones. That'll be

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

Quoted 5 lines
Quoted 1 line

darn slow as well, but at least it will be much less complicated.

IMO, the best thing to do is just restore msync behaviour, and comment the fact that we ignore nonlinears. We need to restore msync behaviour to fix races in regular mappings anyway, at least for now.

Seems to be the best quick solution indeed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#48 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Nick Piggin
Quoted 3 lines · Miklos Szeredi
Quoted 2 lines

*sigh* yes was looking at all that code, thats gonna be darn slow though, but I'll whip up a patch.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Well, if it's going to be darn slow, maybe it's better to go with mingo's plan on emulating nonlinear vmas with linear ones. That'll be

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

We could do something more efficient, but I thought that half the point was that they didn't carry any of this extra memory, and they could be really fast to set up at the expense of efficiency elsewhere.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

darn slow as well, but at least it will be much less complicated.

IMO, the best thing to do is just restore msync behaviour, and comment the fact that we ignore nonlinears. We need to restore msync behaviour to fix races in regular mappings anyway, at least for now.

Seems to be the best quick solution indeed.

If we fix the race in the linear mappings, then we can just do the full msync for nonlinear vmas, and the fast noop version for everyone else.

I don't see it being a big deal. I doubt anybody is writing out huge amounts of data via nonlinear mappings.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#49 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 9 lines · Nick Piggin
Quoted 5 lines
Quoted 1 line

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

We could do something more efficient, but I thought that half the point was that they didn't carry any of this extra memory, and they could be really fast to set up at the expense of efficiency elsewhere.

I'm failing to understand this :-(

That extra memory, and apparently they don't want the inefficiency either.

Quoted 2 lines

I don't see it being a big deal. I doubt anybody is writing out huge amounts of data via nonlinear mappings.

Well, now they don't, but it could be done or even exploited as a DoS.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#50 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Nick Piggin
Quoted 5 lines
Quoted 1 line

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

Quoted 8 lines
Quoted 3 lines

We could do something more efficient, but I thought that half the point was that they didn't carry any of this extra memory, and they could be really fast to set up at the expense of efficiency elsewhere.

I'm failing to understand this :-(

That extra memory, and apparently they don't want the inefficiency either.

Sorry, I didn't understand your misunderstandings ;)

Quoted 5 lines
Quoted 3 lines

I don't see it being a big deal. I doubt anybody is writing out huge amounts of data via nonlinear mappings.

Well, now they don't, but it could be done or even exploited as a DoS.

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#51 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 9 lines · Nick Piggin
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Nick Piggin
Quoted 5 lines
Quoted 1 line

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

We could do something more efficient, but I thought that half the point was that they didn't carry any of this extra memory, and they could be really fast to set up at the expense of efficiency elsewhere.

I'm failing to understand this :-(

That extra memory, and apparently they don't want the inefficiency

s/T/W/

Quoted 3 lines
Quoted 1 line

either.

Sorry, I didn't understand your misunderstandings ;)

Bah, my brain is thick and foggy today. Let us try again;

Nonlinear vmas exist because many vmas are expensive somehow, right? Nonlinear vmas keep the page mapping in the page tables and screw rmaps.

This 'extra memory' you mentioned would be the overhead of tracking the actual ranges?

And apparently now we want it to not suck on the rmap case :-(

Anyway, if used on a non writeback capable backing store (ramfs) page_mkclean will never be called. If also mlocked (I think oracle does this) then page reclaim will pass over too.

So we're only interested in the bdi_cap_accounting_dirty and VM_SHARED case, right?

Tracking these ranges on a per-vma basis would avoid taking the mm wide mmap_sem and so would be cheaper than regular vmas.

Would that still be too expensive?

Quoted 4 lines
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Can't we just 'fix' it?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#52 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 26 lines · Peter Zijlstra
Quoted 9 lines · Nick Piggin
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Nick Piggin
Quoted 5 lines
Quoted 1 line

There are real users who want these fast, though.

Yeah, why don't we have a tree per nonlinear vma to find these pages?

wli mentions shadow page tables..

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

We could do something more efficient, but I thought that half the point was that they didn't carry any of this extra memory, and they could be really fast to set up at the expense of efficiency elsewhere.

I'm failing to understand this :-(

That extra memory, and apparently they don't want the inefficiency

s/T/W/

Quoted 3 lines
Quoted 1 line

either.

Sorry, I didn't understand your misunderstandings ;)

Bah, my brain is thick and foggy today. Let us try again;

Quoted 7 lines

Nonlinear vmas exist because many vmas are expensive somehow, right? Nonlinear vmas keep the page mapping in the page tables and screw rmaps.

This 'extra memory' you mentioned would be the overhead of tracking the actual ranges?

And apparently now we want it to not suck on the rmap case :-(

Do we? I think just "work" is the way we've been handling them up until now. Making them suck less for rmap makes them suck more for what they're good at.

Quoted 11 lines

Anyway, if used on a non writeback capable backing store (ramfs) page_mkclean will never be called. If also mlocked (I think oracle does this) then page reclaim will pass over too.

So we're only interested in the bdi_cap_accounting_dirty and VM_SHARED case, right?

Tracking these ranges on a per-vma basis would avoid taking the mm wide mmap_sem and so would be cheaper than regular vmas.

Would that still be too expensive?

Well you can today remap N pages in a file, arbitrarily for sizeof(pte_t)*tiny bit for the upper page tables + small constant for the vma.

At best, you need an extra pointer to pte / vaddr, so you'd basically double memory overhead.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Can't we just 'fix' it?

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#53 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 11 lines · Nick Piggin
Quoted 4 lines

Tracking these ranges on a per-vma basis would avoid taking the mm wide mmap_sem and so would be cheaper than regular vmas.

Would that still be too expensive?

Well you can today remap N pages in a file, arbitrarily for sizeof(pte_t)*tiny bit for the upper page tables + small constant for the vma.

At best, you need an extra pointer to pte / vaddr, so you'd basically double memory overhead.

I was hoping some form of range compression would gain something, but if its a fully random mapping, then yes a shadow page table would be needed (still looking into what a pte_chain is)

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Can't we just 'fix' it?

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

What is the DoS scenario wrt reclaim? We really ought to fix that if real, those UML farms run on nothing but nonlinear reclaim I'd think.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#54 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 25 lines · Peter Zijlstra
Quoted 11 lines · Nick Piggin
Quoted 4 lines

Tracking these ranges on a per-vma basis would avoid taking the mm wide mmap_sem and so would be cheaper than regular vmas.

Would that still be too expensive?

Well you can today remap N pages in a file, arbitrarily for sizeof(pte_t)*tiny bit for the upper page tables + small constant for the vma.

At best, you need an extra pointer to pte / vaddr, so you'd basically double memory overhead.

I was hoping some form of range compression would gain something, but if its a fully random mapping, then yes a shadow page table would be needed (still looking into what a pte_chain is)

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Can't we just 'fix' it?

Quoted 7 lines
Quoted 4 lines

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

Not if we restricted it to root and mlocked tmpfs. But then why wouldn't you just do it with the much more efficient msync walk, so that if root does want to do writeout via these things, it does not blow up?

Quoted 2 lines

What is the DoS scenario wrt reclaim? We really ought to fix that if real, those UML farms run on nothing but nonlinear reclaim I'd think.

I guess you can just increase the computational complexity of reclaim quite easily.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#55 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Nick Piggin
Quoted 5 lines
Quoted 4 lines

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

Quoted 7 lines
Quoted 2 lines

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

Not if we restricted it to root and mlocked tmpfs. But then why wouldn't you just do it with the much more efficient msync walk, so that if root does want to do writeout via these things, it does not blow up?

This is all used on ram based filesystems right, they all have BDI_CAP_NO_WRITEBACK afaik, so page_mkclean will never get called anyway. Mlock doesn't avoid getting page_mkclean called.

Those who use this on a 'real' filesystem will get hit in the face by a linear scanning page_mkclean(), but AFAIK nobody does this anyway.

Restricting it to root for such filesystems is unwanted, that'd severely handicap both UML and Oracle as I understand it (are there other users of this feature around?)

msync() might never get called and then we're back with the old behaviour where we can surprise the VM with a ton of dirty pages.

Quoted 5 lines
Quoted 2 lines

What is the DoS scenario wrt reclaim? We really ought to fix that if real, those UML farms run on nothing but nonlinear reclaim I'd think.

I guess you can just increase the computational complexity of reclaim quite easily.

Right, on first glance it doesn't look to be too bad, but I should take a closer look.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#56 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 15 lines · Peter Zijlstra
Quoted 5 lines · Nick Piggin
Quoted 5 lines
Quoted 4 lines

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

Quoted 7 lines
Quoted 2 lines

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

Not if we restricted it to root and mlocked tmpfs. But then why wouldn't you just do it with the much more efficient msync walk, so that if root does want to do writeout via these things, it does not blow up?

Quoted 6 lines

This is all used on ram based filesystems right, they all have BDI_CAP_NO_WRITEBACK afaik, so page_mkclean will never get called anyway. Mlock doesn't avoid getting page_mkclean called.

Those who use this on a 'real' filesystem will get hit in the face by a linear scanning page_mkclean(), but AFAIK nobody does this anyway.

But somebody might do it. I just don't know why you'd want to make this _worse_ when the msync option would work?

Quoted 3 lines

Restricting it to root for such filesystems is unwanted, that'd severely handicap both UML and Oracle as I understand it (are there other users of this feature around?)

Why? I think they all use tmpfs backings, don't they?

Quoted 2 lines

msync() might never get called and then we're back with the old behaviour where we can surprise the VM with a ton of dirty pages.

But we're root. With your patch, root *can't* do nonlinear writeback well. Ever. With msync, at least you give them enough rope.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What is the DoS scenario wrt reclaim? We really ought to fix that if real, those UML farms run on nothing but nonlinear reclaim I'd think.

I guess you can just increase the computational complexity of reclaim quite easily.

Right, on first glance it doesn't look to be too bad, but I should take a closer look.

Well I don't think UML uses nonlinear yet anyway, does it? Can they make do with restricting nonlinear to mlocked vmas, I wonder? Probably not.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#57 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 23 lines · Nick Piggin
Quoted 15 lines · Peter Zijlstra
Quoted 5 lines · Nick Piggin
Quoted 5 lines
Quoted 4 lines

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

Quoted 7 lines
Quoted 2 lines

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

Not if we restricted it to root and mlocked tmpfs. But then why wouldn't you just do it with the much more efficient msync walk, so that if root does want to do writeout via these things, it does not blow up?

Quoted 6 lines

This is all used on ram based filesystems right, they all have BDI_CAP_NO_WRITEBACK afaik, so page_mkclean will never get called anyway. Mlock doesn't avoid getting page_mkclean called.

Those who use this on a 'real' filesystem will get hit in the face by a linear scanning page_mkclean(), but AFAIK nobody does this anyway.

Quoted 8 lines

But somebody might do it. I just don't know why you'd want to make this _worse_ when the msync option would work?

Quoted 3 lines

Restricting it to root for such filesystems is unwanted, that'd severely handicap both UML and Oracle as I understand it (are there other users of this feature around?)

Why? I think they all use tmpfs backings, don't they?

Ooh, you only want to restrict remap_file_pages on mappings from bdi's without BDI_CAP_NO_WRITEBACK. Sure, I can live with that, and I suspect others can as well.

Quoted 5 lines
Quoted 2 lines

msync() might never get called and then we're back with the old behaviour where we can surprise the VM with a ton of dirty pages.

But we're root. With your patch, root *can't* do nonlinear writeback well. Ever. With msync, at least you give them enough rope.

True. We could even guesstimate the nonlinear dirty pages by subtracting the result of page_mkclean() from page_mapcount() and force an msync(MS_ASYNC) on said mapping (or all (nonlinear) mappings of the related file) when some threshold gets exceeded.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

What is the DoS scenario wrt reclaim? We really ought to fix that if real, those UML farms run on nothing but nonlinear reclaim I'd think.

I guess you can just increase the computational complexity of reclaim quite easily.

Quoted 6 lines
Quoted 2 lines

Right, on first glance it doesn't look to be too bad, but I should take a closer look.

Well I don't think UML uses nonlinear yet anyway, does it? Can they make do with restricting nonlinear to mlocked vmas, I wonder? Probably not.

I think it does, but lets ask, Jeff?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#58 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines
Quoted 3 lines

Well I don't think UML uses nonlinear yet anyway, does it? Can they make do with restricting nonlinear to mlocked vmas, I wonder? Probably not.

I think it does, but lets ask, Jeff?

Looks like it doesn't:

$ grep -r remap_file_pages arch/um/
$

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#59 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Peter Zijlstra
Quoted 4 lines · Peter Zijlstra

True. We could even guesstimate the nonlinear dirty pages by subtracting the result of page_mkclean() from page_mapcount() and force an msync(MS_ASYNC) on said mapping (or all (nonlinear) mappings of the related file) when some threshold gets exceeded.

Almost, but not quite, we'd need to extract another value from the page_mkclean() run, the actual number of mappings encountered. The return value only sums the number of dirty mappings encountered.

s390 would already work I guess.

Certainly doable.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#60 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra

True. We could even guesstimate the nonlinear dirty pages by subtracting the result of page_mkclean() from page_mapcount() and force an msync(MS_ASYNC) on said mapping (or all (nonlinear) mappings of the related file) when some threshold gets exceeded.

Quoted 7 lines

Almost, but not quite, we'd need to extract another value from the page_mkclean() run, the actual number of mappings encountered. The return value only sums the number of dirty mappings encountered.

s390 would already work I guess.

Certainly doable.

But if we restrict it to root only, and have a note in the man page about it, then it really isn't worth cluttering up the kernel.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#61 lore raw

RFC PATCH 1/1 mm: fix page_mkclean() vs non-linear vmas

compile tested only so far

---

Partial revert of commit: 204ec841fbea3e5138168edbc3a76d46747cc987

Non-linear vmas aren't properly handled by page_mkclean() and fixing that would result in linear scans of all related non-linear vmas per page_mkclean() invocation.

This is deemed too costly, hence re-instate the msync scan for non-linear vmas.

However this can lead to double IO:

- pages get instanciated with RO mapping
- page takes write fault, and gets marked with PG_dirty
- page gets tagged for writeout and calls page_mkclean()
- page_mkclean() fails to find the dirty pte (and clean it)
- writeout happens and PG_dirty gets cleared.
- user calls msync, the dirty pte is found and the page marked with PG_dirty
- the page gets writen out _again_ even though its not re-dirtied.

To minimize this reset the protection when creating a nonlinear vma.

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

---
 mm/fremap.c |   21 ++++++++
 mm/msync.c  |  146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 5 deletions(-)
mm/msync.c +141 -5
Index: linux-2.6-git/mm/msync.c
===================================================================
@@ -7,12 +7,123 @@
 /*
  * The msync() system call.
  */
+#include <linux/slab.h>
+#include <linux/pagemap.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
+#include <linux/hugetlb.h>
+#include <linux/writeback.h>
 #include <linux/file.h>
 #include <linux/syscalls.h>
 
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+
+static unsigned long msync_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
+				unsigned long addr, unsigned long end)
+{
+	pte_t *pte;
+	spinlock_t *ptl;
+	int progress = 0;
+	unsigned long ret = 0;
+
+again:
+	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
+	do {
+		struct page *page;
+
+		if (progress >= 64) {
+			progress = 0;
+			if (need_resched() || need_lockbreak(ptl))
+				break;
+		}
+		progress++;
+		if (!pte_present(*pte))
+			continue;
+		if (!pte_maybe_dirty(*pte))
+			continue;
+		page = vm_normal_page(vma, addr, *pte);
+		if (!page)
+			continue;
+
+		/*
+		 * Only non-linear vmas reach here, resetting the RO state
+		 * has no use, since page_mkclean doesn't work for them anyway.
+		 * It might even cause extra IO.
+		 */
+		if (ptep_clear_flush_dirty(vma, addr, pte) ||
+				page_test_and_clear_dirty(page))
+			ret += set_page_dirty(page);
+		progress += 3;
+	} while (pte++, addr += PAGE_SIZE, addr != end);
+	pte_unmap_unlock(pte - 1, ptl);
+	cond_resched();
+	if (addr != end)
+		goto again;
+	return ret;
+}
+
+static inline unsigned long msync_pmd_range(struct vm_area_struct *vma,
+			pud_t *pud, unsigned long addr, unsigned long end)
+{
+	pmd_t *pmd;
+	unsigned long next;
+	unsigned long ret = 0;
+
+	pmd = pmd_offset(pud, addr);
+	do {
+		next = pmd_addr_end(addr, end);
+		if (pmd_none_or_clear_bad(pmd))
+			continue;
+		ret += msync_pte_range(vma, pmd, addr, next);
+	} while (pmd++, addr = next, addr != end);
+	return ret;
+}
+
+static inline unsigned long msync_pud_range(struct vm_area_struct *vma,
+			pgd_t *pgd, unsigned long addr, unsigned long end)
+{
+	pud_t *pud;
+	unsigned long next;
+	unsigned long ret = 0;
+
+	pud = pud_offset(pgd, addr);
+	do {
+		next = pud_addr_end(addr, end);
+		if (pud_none_or_clear_bad(pud))
+			continue;
+		ret += msync_pmd_range(vma, pud, addr, next);
+	} while (pud++, addr = next, addr != end);
+	return ret;
+}
+
+static unsigned long msync_page_range(struct vm_area_struct *vma,
+				unsigned long addr, unsigned long end)
+{
+	pgd_t *pgd;
+	unsigned long next;
+	unsigned long ret = 0;
+
+	/* For hugepages we can't go walking the page table normally,
+	 * but that's ok, hugetlbfs is memory based, so we don't need
+	 * to do anything more on an msync().
+	 */
+	if (vma->vm_flags & VM_HUGETLB)
+		return 0;
+
+	BUG_ON(addr >= end);
+	pgd = pgd_offset(vma->vm_mm, addr);
+	flush_cache_range(vma, addr, end);
+	do {
+		next = pgd_addr_end(addr, end);
+		if (pgd_none_or_clear_bad(pgd))
+			continue;
+		ret += msync_pud_range(vma, pgd, addr, next);
+	} while (pgd++, addr = next, addr != end);
+	return ret;
+}
+
 /*
  * MS_SYNC syncs the entire file - including mappings.
  *
@@ -27,6 +138,21 @@
  * So by _not_ starting I/O in MS_ASYNC we provide complete flexibility to
  * applications.
  */
+static int msync_interval(struct vm_area_struct *vma, unsigned long addr,
+			unsigned long end, int flags,
+			unsigned long *nr_pages_dirtied)
+{
+	struct file *file = vma->vm_file;
+
+	if ((flags & MS_INVALIDATE) && (vma->vm_flags & VM_LOCKED))
+		return -EBUSY;
+
+	if (file && (vma->vm_flags & VM_SHARED) &&
+			(vma->vm_flags & VM_NONLINEAR))
+		*nr_pages_dirtied = msync_page_range(vma, addr, end);
+	return 0;
+}
+
 asmlinkage long sys_msync(unsigned long start, size_t len, int flags)
 {
 	unsigned long end;
@@ -56,6 +182,7 @@ asmlinkage long sys_msync(unsigned long 
 	down_read(&mm->mmap_sem);
 	vma = find_vma(mm, start);
 	for (;;) {
+		unsigned long nr_pages_dirtied = 0;
 		struct file *file;
 
 		/* Still start < end. */
@@ -70,14 +197,23 @@ asmlinkage long sys_msync(unsigned long 
 			unmapped_error = -ENOMEM;
 		}
 		/* Here vma->vm_start <= start < vma->vm_end. */
-		if ((flags & MS_INVALIDATE) &&
-				(vma->vm_flags & VM_LOCKED)) {
-			error = -EBUSY;
+		error = msync_interval(vma, start, min(end, vma->vm_end),
+				flags, &nr_pages_dirtied);
+		if (error)
 			goto out_unlock;
-		}
 		file = vma->vm_file;
 		start = vma->vm_end;
-		if ((flags & MS_SYNC) && file &&
+		if ((flags & MS_ASYNC) && file && nr_pages_dirtied) {
+			get_file(file);
+			up_read(&mm->mmap_sem);
+			balance_dirty_pages_ratelimited_nr(file->f_mapping,
+					nr_pages_dirtied);
+			fput(file);
+			if (start >= end)
+				goto out;
+			down_read(&mm->mmap_sem);
+			vma = find_vma(mm, start);
+		} else if ((flags & MS_SYNC) && file &&
 				(vma->vm_flags & VM_SHARED)) {
 			get_file(file);
 			up_read(&mm->mmap_sem);
mm/fremap.c +21 -0
Index: linux-2.6-git/mm/fremap.c
===================================================================
@@ -15,6 +15,7 @@
 #include <linux/rmap.h>
 #include <linux/module.h>
 #include <linux/syscalls.h>
+#include <linux/capability.h>
 
 #include <asm/mmu_context.h>
 #include <asm/cacheflush.h>
@@ -178,6 +179,16 @@ asmlinkage long sys_remap_file_pages(uns
 	vma = find_vma(mm, start);
 
 	/*
+	 * Don't allow non root to create non-linear mappings on backing
+	 * devices capable of accounting dirty pages.
+	 */
+	if (!(vma->vm_flags & VM_NONLINEAR) && vma_wants_writenotify(vma) &&
+			!capable(CAP_SYS_ADMIN)) {
+		err = -EPERM;
+		goto out;
+	}
+
+	/*
 	 * Make sure the vma is shared, that it supports prefaulting,
 	 * and that the remapped range is valid and fully within
 	 * the single existing vma.  vm_private_data is used as a
@@ -201,6 +212,15 @@ asmlinkage long sys_remap_file_pages(uns
 			mapping = vma->vm_file->f_mapping;
 			spin_lock(&mapping->i_mmap_lock);
 			flush_dcache_mmap_lock(mapping);
+			/*
+			 * reset protection because non-linear maps don't
+			 * work with the fancy dirty page accounting code.
+			 */
+			if (vma_wants_writenotify(vma)) {
+				vma->vm_page_prot =
+					protection_map[vma->vm_flags &
+					(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
+			}
 			vma->vm_flags |= VM_NONLINEAR;
 			vma_prio_tree_remove(vma, &mapping->i_mmap);
 			vma_nonlinear_insert(vma, &mapping->i_mmap_nonlinear);
@@ -218,6 +238,7 @@ asmlinkage long sys_remap_file_pages(uns
 		 * downgrading the lock.  (Locks can't be upgraded).
 		 */
 	}
+out:
 	if (likely(!has_write_lock))
 		up_read(&mm->mmap_sem);
 	else

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#62 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 4 lines · Peter Zijlstra

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

I don't think that's a viable approach. Nonlinear mappings would normally be used by databases, and you don't want to limit databases to be run by root only.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#63 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Peter Zijlstra

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

I don't think that's a viable approach. Nonlinear mappings would normally be used by databases, and you don't want to limit databases to be run by root only.

It was claimed that they use it on tmpfs only, not on a 'real' filesystem.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#64 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Peter Zijlstra

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

Quoted 6 lines
Quoted 3 lines

I don't think that's a viable approach. Nonlinear mappings would normally be used by databases, and you don't want to limit databases to be run by root only.

It was claimed that they use it on tmpfs only, not on a 'real' filesystem.

More specifically, databases want to use direct IO (I know you hate it) and use the nonlinear vma as buffer area to feed this direct IO

Mapped IO is unsuited for databases in its current form due to the way IO errors are handled.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#65 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

In reply to Peter Zijlstra
Quoted 18 lines

Partial revert of commit: 204ec841fbea3e5138168edbc3a76d46747cc987

Non-linear vmas aren't properly handled by page_mkclean() and fixing that would result in linear scans of all related non-linear vmas per page_mkclean() invocation.

This is deemed too costly, hence re-instate the msync scan for non-linear vmas.

However this can lead to double IO:

- pages get instanciated with RO mapping
- page takes write fault, and gets marked with PG_dirty
- page gets tagged for writeout and calls page_mkclean()
- page_mkclean() fails to find the dirty pte (and clean it)
- writeout happens and PG_dirty gets cleared.
- user calls msync, the dirty pte is found and the page marked with PG_dirty
- the page gets writen out _again_ even though its not re-dirtied.

Quoted 5 lines

To minimize this reset the protection when creating a nonlinear vma.

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

Root only for !BDI_CAP_NO_WRITEBACK mappings doesn't make sense because:

- just encourages insecure applications

- there are no current users that want this and presumable no future uses either

- it's a maintenance burden: I'll have to layer the m/ctime update patch on top of this

- the only pro for this has been that Nick thinks it cool ;)

I think the proper way to deal with this is to

- allow BDI_CAP_NO_WRITEBACK (tmpfs/ramfs) uses, makes database people happy

- for !BDI_CAP_NO_WRITEBACK emulate using do_mmap_pgoff(), should be trivial, no userspace ABI breakage

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#66 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 24 lines · Miklos Szeredi
Quoted 18 lines

Partial revert of commit: 204ec841fbea3e5138168edbc3a76d46747cc987

Non-linear vmas aren't properly handled by page_mkclean() and fixing that would result in linear scans of all related non-linear vmas per page_mkclean() invocation.

This is deemed too costly, hence re-instate the msync scan for non-linear vmas.

However this can lead to double IO:

- pages get instanciated with RO mapping
- page takes write fault, and gets marked with PG_dirty
- page gets tagged for writeout and calls page_mkclean()
- page_mkclean() fails to find the dirty pte (and clean it)
- writeout happens and PG_dirty gets cleared.
- user calls msync, the dirty pte is found and the page marked with PG_dirty
- the page gets writen out _again_ even though its not re-dirtied.

Quoted 5 lines

To minimize this reset the protection when creating a nonlinear vma.

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

Quoted 7 lines

Root only for !BDI_CAP_NO_WRITEBACK mappings doesn't make sense because:

- just encourages insecure applications

- there are no current users that want this and presumable no future uses either

AFAIK no other OS does this against regular filesystems (hear-say)

Quoted 9 lines

- it's a maintenance burden: I'll have to layer the m/ctime update patch on top of this

- the only pro for this has been that Nick thinks it cool ;)

I think the proper way to deal with this is to

- allow BDI_CAP_NO_WRITEBACK (tmpfs/ramfs) uses, makes database people happy

And UML once the remap_file_pages_prot() stuff is merged.

Quoted 2 lines

- for !BDI_CAP_NO_WRITEBACK emulate using do_mmap_pgoff(), should be trivial, no userspace ABI breakage

I can live with that.

However this still leaves the non-linear reclaim (Nick pointed it out as a potential DoS and other people have corroborated this). I have no idea on that to do about that.

Oracle seems to mlock these things anyway, but UML surely would not.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#67 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 3 lines

However this still leaves the non-linear reclaim (Nick pointed it out as a potential DoS and other people have corroborated this). I have no idea on that to do about that.

OK, but that is a completely different problem, not affecting page_mkclean() or msync().

And it doesn't sound too hard to solve: when current algorithm doesn't seem to be making progress, then it will have to be done the hard way, searching for for all nonlinear ptes of a page to unmap.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#68 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 10 lines · Miklos Szeredi
Quoted 3 lines

However this still leaves the non-linear reclaim (Nick pointed it out as a potential DoS and other people have corroborated this). I have no idea on that to do about that.

OK, but that is a completely different problem, not affecting page_mkclean() or msync().

And it doesn't sound too hard to solve: when current algorithm doesn't seem to be making progress, then it will have to be done the hard way, searching for for all nonlinear ptes of a page to unmap.

Ah, you see, but that is when you've already lost.

The DoS is about the computational complexity of the reclaim, not if it will ever come out of it with free pages.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#69 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Miklos Szeredi
Quoted 3 lines

However this still leaves the non-linear reclaim (Nick pointed it out as a potential DoS and other people have corroborated this). I have no idea on that to do about that.

OK, but that is a completely different problem, not affecting page_mkclean() or msync().

Quoted 8 lines
Quoted 3 lines

And it doesn't sound too hard to solve: when current algorithm doesn't seem to be making progress, then it will have to be done the hard way, searching for for all nonlinear ptes of a page to unmap.

Ah, you see, but that is when you've already lost.

The DoS is about the computational complexity of the reclaim, not if it will ever come out of it with free pages.

If we really want to, we could limit it to mlock for !root. This is a reasonable way to solve the problem, and UML could fall back on vma emulated version if they didn't want to use mlock memory...

Or we could limit the size/number of nonlinear vmas that could be created.

But just quietly, I think there are probably a lot of other ways to perform a local DoS anyway ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#70 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 13 lines
Quoted 8 lines
Quoted 3 lines

And it doesn't sound too hard to solve: when current algorithm doesn't seem to be making progress, then it will have to be done the hard way, searching for for all nonlinear ptes of a page to unmap.

Ah, you see, but that is when you've already lost.

The DoS is about the computational complexity of the reclaim, not if it will ever come out of it with free pages.

If we really want to, we could limit it to mlock for !root. This is a reasonable way to solve the problem, and UML could fall back on vma emulated version if they didn't want to use mlock memory...

Quoted 5 lines

Or we could limit the size/number of nonlinear vmas that could be created.

But just quietly, I think there are probably a lot of other ways to perform a local DoS anyway ;)

I aggree, requiring apps to mlock would probably just make things slightly worse for about 100% of users, without any gain. There could be a

/proc/sys/vm/turn_off_nonlinear_for_paranoid_sysadmin

knob that would unconditionally emulate nonlinear vmas.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#71 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

In reply to Miklos Szeredi
Quoted 27 lines · Miklos Szeredi
Quoted 18 lines

Partial revert of commit: 204ec841fbea3e5138168edbc3a76d46747cc987

Non-linear vmas aren't properly handled by page_mkclean() and fixing that would result in linear scans of all related non-linear vmas per page_mkclean() invocation.

This is deemed too costly, hence re-instate the msync scan for non-linear vmas.

However this can lead to double IO:

- pages get instanciated with RO mapping
- page takes write fault, and gets marked with PG_dirty
- page gets tagged for writeout and calls page_mkclean()
- page_mkclean() fails to find the dirty pte (and clean it)
- writeout happens and PG_dirty gets cleared.
- user calls msync, the dirty pte is found and the page marked with PG_dirty
- the page gets writen out _again_ even though its not re-dirtied.

Quoted 5 lines

To minimize this reset the protection when creating a nonlinear vma.

I'm not at all happy with this, but plain disallowing remap_file_pages on bdis without BDI_CAP_NO_WRITEBACK seems to offend some people, hence restrict it to root only.

Root only for !BDI_CAP_NO_WRITEBACK mappings doesn't make sense because:

Quoted 7 lines

- just encourages insecure applications

- there are no current users that want this and presumable no future uses either

- it's a maintenance burden: I'll have to layer the m/ctime update patch on top of this

But you have to update m/ctime for BDI_CAP_NO_WRITEBACK mappings anyway don't you?

Quoted 2 lines

- the only pro for this has been that Nick thinks it cool ;)

Nonlinear in general, rather than this specifically.

Quoted 7 lines

I think the proper way to deal with this is to

- allow BDI_CAP_NO_WRITEBACK (tmpfs/ramfs) uses, makes database people happy

- for !BDI_CAP_NO_WRITEBACK emulate using do_mmap_pgoff(), should be trivial, no userspace ABI breakage

Yeah that sounds OK.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#72 lore raw

Re: [RFC][PATCH] mm: fix page_mkclean() vs non-linear vmas

Quoted 5 lines
Quoted 2 lines

- it's a maintenance burden: I'll have to layer the m/ctime update patch on top of this

But you have to update m/ctime for BDI_CAP_NO_WRITEBACK mappings anyway don't you?

Yes, but that's a different aspect of msync(), not about the data writeback issues that nonlinear mappings have.

So a solution that solves both these problems would probably be more complex.

Quoted 3 lines
Quoted 1 line

- the only pro for this has been that Nick thinks it cool ;)

Nonlinear in general, rather than this specifically.

Fair enough.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#73 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines

Well I don't think UML uses nonlinear yet anyway, does it? Can they make do with restricting nonlinear to mlocked vmas, I wonder? Probably not.

I think it does, but lets ask, Jeff?

Nope, UML needs to be able to change permissions as well as locations.

Would be nice, though, there are apparently nice UML speedups with it.

Jeff

Signature · 7 lines
Work email - jdike at linux dot intel dot com

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#74 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin
Quoted 30 lines · Peter Zijlstra
Quoted 15 lines · Nick Piggin
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The thing is, I don't think anybody who uses these things cares about any of the 'problems' you want to fix, do they? We are interested in dirty pages only for the correctness issue, rather than performance. Same as reclaim.

Quoted 7 lines
Quoted 2 lines

If so, we can just stick to the dead slow but correct 'scan the full vma' page_mkclean() and nobody would ever trigger it.

Not if we restricted it to root and mlocked tmpfs. But then why wouldn't you just do it with the much more efficient msync walk, so that if root does want to do writeout via these things, it does not blow up?

Quoted 6 lines

This is all used on ram based filesystems right, they all have BDI_CAP_NO_WRITEBACK afaik, so page_mkclean will never get called anyway. Mlock doesn't avoid getting page_mkclean called.

Those who use this on a 'real' filesystem will get hit in the face by a linear scanning page_mkclean(), but AFAIK nobody does this anyway.

But somebody might do it. I just don't know why you'd want to make this _worse_ when the msync option would work?

Quoted 3 lines

Restricting it to root for such filesystems is unwanted, that'd severely handicap both UML and Oracle as I understand it (are there other users of this feature around?)

Quoted 7 lines

Why? I think they all use tmpfs backings, don't they?

Quoted 2 lines

msync() might never get called and then we're back with the old behaviour where we can surprise the VM with a ton of dirty pages.

But we're root. With your patch, root *can't* do nonlinear writeback well. Ever. With msync, at least you give them enough rope.

Restricting to root doesn't buy you much, nobody wants to be root. Restricting to mlock is similarly pointless. UML _will_ want to get swapped out if there's no activity.

Restricting to tmpfs makes sense, but it's probably not what UML wants.

Conclusion: there's no good solution for UML in kernel-space.

Miklos

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#75 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 9 lines · Miklos Szeredi
Quoted 5 lines
Quoted 2 lines

msync() might never get called and then we're back with the old behaviour where we can surprise the VM with a ton of dirty pages.

But we're root. With your patch, root *can't* do nonlinear writeback well. Ever. With msync, at least you give them enough rope.

Restricting to root doesn't buy you much, nobody wants to be root. Restricting to mlock is similarly pointless. UML _will_ want to get swapped out if there's no activity.

They could always not use nonlinear, or we could add a ulimit to the size of nonlinear vaddr allowed.

Quoted 2 lines

Restricting to tmpfs makes sense, but it's probably not what UML wants.

I think it is OK. They might want some persistent storage to migrate or something, but that can always be done by copying from tmpfs to a block based filesystem.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#76 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin
Quoted 1 line · Peter Zijlstra
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

Quoted 2 lines · Nick Piggin

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Please not root. The users really don't want to be privileged. UML itself is at least partly for use as privilege isolation of the guest workload. Oracle has some of the same concerns itself, which is part of why it uses separate processes heavily, even: to isolate instances from each other.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#77 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 4 lines · Bill Irwin
Quoted 1 line · Peter Zijlstra
Quoted 1 line

Well, now they don't, but it could be done or even exploited as a DoS.

On Wed, Mar 07, 2007 at 12:00:36PM +0100, Nick Piggin wrote:

Quoted 8 lines
Quoted 2 lines

But so could nonlinear page reclaim. I think we need to restrict nonlinear mappings to root if we're worried about that.

Please not root. The users really don't want to be privileged. UML itself is at least partly for use as privilege isolation of the guest workload. Oracle has some of the same concerns itself, which is part of why it uses separate processes heavily, even: to isolate instances from each other.

Well non-root users could be allowed to work on mlocked regions on tmpfs/shm. That way they avoid the pathological nonlinear problems, and can work within the mlock ulimit.

That is, if we are worried about such a DoS.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#78 lore raw

[rfc][patch 7/6] mm: merge page_mkwrite

In reply to Miklos Szeredi

Now that I'm making some progress on merging the basic stuff, I'd like to get opinions about merging page_mkwrite functionality into ->fault().

I still don't see any callers in the tree, but I see no reason why this won't work (or why it isn't better).

--
Like everything else in life, page_mkwrite()ing is just a primitive, degenerate form of fault()ing.

Having FAULT_FLAG_WRITE in the fault operation allows us to just get rid of the page_mkwrite call in do_fault, because filesystems can check for that flag bit, and do the page_mkwrite thing before returning the page (this will improve efficiency for everyone).

Then, we introduce another fault flag to signal that the fault is an event notification for a page, rather than a request for a pgoff.

include/linux/mm.h +8 -6
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -176,6 +176,7 @@ extern unsigned int kobjsize(const void 
 					 * return with the page locked.
 					 */
 #define VM_CAN_NONLINEAR 0x10000000	/* Has ->fault & does nonlinear pages */
+#define VM_NOTIFY_MKWRITE 0x20000000	/* Has ->fault & wants page writable notification */
 
 #ifndef VM_STACK_DEFAULT_FLAGS		/* arch can override this */
 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
@@ -201,6 +202,7 @@ extern pgprot_t protection_map[16];
 
 #define FAULT_FLAG_WRITE	0x01
 #define FAULT_FLAG_NONLINEAR	0x02
+#define FAULT_FLAG_NOTIFY	0x04	/* fault_data.page contains page */
 
 /*
  * fault_data is filled in the the pagefault handler and passed to the
@@ -213,7 +215,10 @@ extern pgprot_t protection_map[16];
  * nonlinear mapping support.
  */
 struct fault_data {
-	unsigned long address;
+	union {
+		unsigned long address;
+		struct page *page;
+	};
 	pgoff_t pgoff;
 	unsigned int flags;
 
@@ -230,9 +235,6 @@ struct vm_operations_struct {
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
-	/* notification that a previously read-only page is about to become
-	 * writable, if an error is returned it will cause a SIGBUS */
-	int (*page_mkwrite)(struct vm_area_struct *vma, struct page *page);
 #ifdef CONFIG_NUMA
 	int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
 	struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
@@ -831,7 +833,7 @@ extern struct shrinker *set_shrinker(int
 extern void remove_shrinker(struct shrinker *shrinker);
 
 /*
- * Some shared mappigns will want the pages marked read-only
+ * Some shared mappings will want the pages marked read-only
  * to track write events. If so, we'll downgrade vm_page_prot
  * to the private version (using protection_map[] without the
  * VM_SHARED bit).
@@ -845,7 +847,7 @@ static inline int vma_wants_writenotify(
 		return 0;
 
 	/* The backer wishes to know when pages are first written to? */
-	if (vma->vm_ops && vma->vm_ops->page_mkwrite)
+	if (vma->vm_flags & VM_NOTIFY_MKWRITE)
 		return 1;
 
 	/* The open routine did something to the protections already? */
mm/memory.c +10 -19
Index: linux-2.6/mm/memory.c
===================================================================
@@ -1566,7 +1566,8 @@ static int do_wp_page(struct mm_struct *
 		 * read-only shared pages can get COWed by
 		 * get_user_pages(.write=1, .force=1).
 		 */
-		if (vma->vm_ops && vma->vm_ops->page_mkwrite) {
+		if (unlikely(vma->vm_flags & VM_NOTIFY_MKWRITE)) {
+			struct fault_data fdata;
 			/*
 			 * Notify the address space that the page is about to
 			 * become writable so that it can prohibit this or wait
@@ -1578,8 +1579,14 @@ static int do_wp_page(struct mm_struct *
 			page_cache_get(old_page);
 			pte_unmap_unlock(page_table, ptl);
 
-			if (vma->vm_ops->page_mkwrite(vma, old_page) < 0)
-				goto unwritable_page;
+			fdata.flags = FAULT_FLAG_NOTIFY|FAULT_FLAG_WRITE;
+			fdata.page = old_page;
+			fdata.type = -1;
+			old_page = vma->vm_ops->fault(vma, &fdata);
+			WARN_ON(fdata.type == -1);
+			ret = fdata.type;
+			if (!old_page)
+				return ret;
 
 			/*
 			 * Since we dropped the lock we need to revalidate
@@ -1677,10 +1684,6 @@ oom:
 	if (old_page)
 		page_cache_release(old_page);
 	return VM_FAULT_OOM;
-
-unwritable_page:
-	page_cache_release(old_page);
-	return VM_FAULT_SIGBUS;
 }
 
 /*
@@ -2254,18 +2257,6 @@ static int __do_fault(struct mm_struct *
 				goto out;
 			}
 			copy_user_highpage(page, faulted_page, address, vma);
-		} else {
-			/*
-			 * If the page will be shareable, see if the backing
-			 * address space wants to know that the page is about
-			 * to become writable
-			 */
-			if (vma->vm_ops->page_mkwrite &&
-			    vma->vm_ops->page_mkwrite(vma, page) < 0) {
-				fdata.type = VM_FAULT_SIGBUS;
-				anon = 1; /* no anon but release faulted_page */
-				goto out;
-			}
 		}
 
 	}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#79 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 2 lines · Nick Piggin

Then 4,5,6 is the fault/nonlinear rewrite, take it or leave it. I thought you would have liked the patches...

btw., if we decide that nonlinear isnt worth the continuing maintainance pain, we could internally implement/emulate sys_remap_file_pages() via a call to mremap() and essentially deprecate it, without breaking the ABI
- and remove all the nonlinear code. (This would split fremap areas into separate vmas)

Well I think it has a few possible uses outside the PAE database workloads. UML for one seem to be interested... as much as I don't use them, I think nonlinear mappings are kinda cool ;)

After these patches, I don't think there is too much burden. The main thing left really is just the objrmap stuff, but that is just handled with a minimal 'dumb' algorithm that doesn't cost much.

Then the core of it is just the file pte handling, which really doesn't seem to be much problem.

Apart from a handful of trivial if (pte_file()) cases throughout mm/, our maintainance burden basically now amounts to the following patch. Even the rmap.c change looks bigger than it is because I split out the nonlinear unmapping code from try_to_unmap_file. Not too bad, eh? :)

--

 include/asm-powerpc/pgtable.h |   12 ++++
 mm/Kconfig                    |    6 ++
 mm/Makefile                   |    6 +-
 mm/rmap.c                     |  101 +++++++++++++++++++++++++-----------------
 4 files changed, 83 insertions(+), 42 deletions(-)
include/asm-powerpc/pgtable.h +12 -0
Index: linux-2.6/include/asm-powerpc/pgtable.h
===================================================================
@@ -243,7 +243,12 @@ static inline int pte_write(pte_t pte) {
 static inline int pte_exec(pte_t pte)  { return pte_val(pte) & _PAGE_EXEC;}
 static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;}
 static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;}
+
+#ifdef CONFIG_NONLINEAR
 static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;}
+#else
+static inline int pte_file(pte_t pte) { return 0; }
+#endif
 
 static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
 static inline void pte_cache(pte_t pte)   { pte_val(pte) &= ~_PAGE_NO_CACHE; }
@@ -483,9 +488,16 @@ extern void update_mmu_cache(struct vm_a
 #define __swp_entry(type, offset) ((swp_entry_t){((type)<< 1)|((offset)<<8)})
 #define __pte_to_swp_entry(pte)	((swp_entry_t){pte_val(pte) >> PTE_RPN_SHIFT})
 #define __swp_entry_to_pte(x)	((pte_t) { (x).val << PTE_RPN_SHIFT })
+
+#ifdef CONFIG_NONLINEAR
 #define pte_to_pgoff(pte)	(pte_val(pte) >> PTE_RPN_SHIFT)
 #define pgoff_to_pte(off)	((pte_t) {((off) << PTE_RPN_SHIFT)|_PAGE_FILE})
 #define PTE_FILE_MAX_BITS	(BITS_PER_LONG - PTE_RPN_SHIFT)
+#else
+#define pte_to_pgoff(pte)	({BUG(); -1;})
+#define pgoff_to_pte(off)	({BUG(); (pte_t){-1};})
+#define PTE_FILE_MAX_BITS	0
+#endif
 
 /*
  * kern_addr_valid is intended to indicate whether an address is a valid
mm/Kconfig +6 -0
Index: linux-2.6/mm/Kconfig
===================================================================
@@ -142,6 +142,12 @@ config SPLIT_PTLOCK_CPUS
 #
 # support for page migration
 #
+config NONLINEAR
+	bool "Non linear mappings"
+	def_bool y
+	help
+	  Provides support for the remap_file_pages syscall.
+
 config MIGRATION
 	bool "Page migration"
 	def_bool y
mm/Makefile +3 -3
Index: linux-2.6/mm/Makefile
===================================================================
@@ -3,9 +3,8 @@
 #
 
 mmu-y			:= nommu.o
-mmu-$(CONFIG_MMU)	:= fremap.o highmem.o madvise.o memory.o mincore.o \
-			   mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \
-			   vmalloc.o
+mmu-$(CONFIG_MMU)	:= highmem.o madvise.o memory.o mincore.o mlock.o \
+			   mmap.o mprotect.o mremap.o msync.o rmap.o vmalloc.o
 
 obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
 			   page_alloc.o page-writeback.o pdflush.o \
@@ -27,5 +26,6 @@ obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_SLAB) += slab.o
 obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o
 obj-$(CONFIG_FS_XIP) += filemap_xip.o
+obj-$(CONFIG_NONLINEAR) += fremap.o
 obj-$(CONFIG_MIGRATION) += migrate.o
 obj-$(CONFIG_SMP) += allocpercpu.o
mm/rmap.c +62 -39

127 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#80 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 4 lines · Nick Piggin

Apart from a handful of trivial if (pte_file()) cases throughout mm/, our maintainance burden basically now amounts to the following patch. Even the rmap.c change looks bigger than it is because I split out the nonlinear unmapping code from try_to_unmap_file. Not too bad, eh? :)

Oh, there is a bit more nonlinear mmap list manipulation I'd forgotten about too... makes things a little bit worse, but not too much.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#81 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Nick Piggin
Quoted 3 lines · Nick Piggin

After these patches, I don't think there is too much burden. The main thing left really is just the objrmap stuff, but that is just handled with a minimal 'dumb' algorithm that doesn't cost much.

ok. What do you think about the sys_remap_file_pages_prot() thing that Paolo has done in a nicely split up form - does that complicate things in any fundamental way? That is what is useful to UML.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#82 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 3 lines · Nick Piggin
Quoted 3 lines

After these patches, I don't think there is too much burden. The main thing left really is just the objrmap stuff, but that is just handled with a minimal 'dumb' algorithm that doesn't cost much.

Quoted 3 lines · Ingo Molnar

ok. What do you think about the sys_remap_file_pages_prot() thing that Paolo has done in a nicely split up form - does that complicate things in any fundamental way? That is what is useful to UML.

Oracle would love it. You don't want to know how far back I've been asked to backport that.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#83 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Bill Irwin
Quoted 3 lines · Nick Piggin
Quoted 3 lines

After these patches, I don't think there is too much burden. The main thing left really is just the objrmap stuff, but that is just handled with a minimal 'dumb' algorithm that doesn't cost much.

Quoted 7 lines
Quoted 3 lines · Ingo Molnar

ok. What do you think about the sys_remap_file_pages_prot() thing that Paolo has done in a nicely split up form - does that complicate things in any fundamental way? That is what is useful to UML.

Oracle would love it. You don't want to know how far back I've been asked to backport that.

ok, cool! Then the first step would be for you to talk to Paolo and to pick up the patches, review them, nurse it in -mm, etc. Suffering in silence is just a pointless act of masochism, not an efficient upstream-merge tactic ;-)

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#84 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 3 lines · Ingo Molnar
Quoted 3 lines
Quoted 3 lines

ok. What do you think about the sys_remap_file_pages_prot() thing that Paolo has done in a nicely split up form - does that complicate things in any fundamental way? That is what is useful to UML.

Quoted 2 lines · Bill Irwin
Quoted 2 lines

Oracle would love it. You don't want to know how far back I've been asked to backport that.

Quoted 4 lines · Ingo Molnar

ok, cool! Then the first step would be for you to talk to Paolo and to pick up the patches, review them, nurse it in -mm, etc. Suffering in silence is just a pointless act of masochism, not an efficient upstream-merge tactic ;-)

It was intended for use in a debugging mode for the database, so given the general mood where fighting backouts was an issue, I was relatively loath to bring it up. With UML behind it I don't feel that's as much of a concern.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#85 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 3 lines · Nick Piggin

After these patches, I don't think there is too much burden. The main thing left really is just the objrmap stuff, but that is just handled with a minimal 'dumb' algorithm that doesn't cost much.

ok. What do you think about the sys_remap_file_pages_prot() thing that Paolo has done in a nicely split up form - does that complicate things in any fundamental way? That is what is useful to UML.

Last time I looked (a while ago), the only issue I had was that he was doing a weird special case rather than using another !present pte bit for his "nonlinear protection" ptes.

I think he fixed that now and so it should be quite good now.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#86 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 1 line · Andrew Morton

Does anybody really pass a NULL `type' arg into filemap_nopage()?

The major vs. minor fault accounting patch that introduced the argument didn't make non-NULL type arguments a requirement. It's essentially an optional second return value and the NULL pointer represents the caller choosing to ignore it. I'm not sure I actually liked that aspect of it, but that's how it ended up going in. I think it had something to do with driver churn clashing with the sweep at the time of the merge. I'd rather the argument be mandatory and defaulted to VM_FAULT_MINOR.

It's something of a non-answer, though, since it only discusses a convention as opposed to reviewing specific callers of filemap_nopage(). NULL type arguments to ->nopage() are rare at most, and could be easily eliminated, at least for in-tree drivers.

egrep -nr 'nopage.*NULL' . 2>/dev/null | grep -v '^Bin' on a current git tree yields zero matches.

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#87 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

In reply to Andrew Morton
Quoted 4 lines
Quoted 2 lines

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

Did benh agree with that?

I won't use NOPAGE_REFAULT, I use NOPFN_REFAULT and that has hit mainline. I will switch to ->fault when I have time to adapt the code, in the meantime, NOPFN_REFAULT should stay.

Note that one thing we really want with the new ->fault (though I haven't looked at the patches lately to see if it's available) is to be able to differenciate faults coming from userspace from faults coming from the kernel. The major difference is that the former can be re-executed to handle signals, the later can't. Thus waiting in the fault handler can be made interruptible in the former case, not in the later case.

Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#88 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines
Quoted 3 lines

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

Did benh agree with that?

I won't use NOPAGE_REFAULT, I use NOPFN_REFAULT and that has hit mainline. I will switch to ->fault when I have time to adapt the code, in the meantime, NOPFN_REFAULT should stay.

I think I removed not only NOFPN_REFAULT, but also nopfn itself, *and* adapted the code for you ;) it is in patch 5/6, sent a while ago.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#89 lore raw

Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)

Quoted 5 lines · Nick Piggin
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 4 lines
Quoted 3 lines

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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Did benh agree with that?

I won't use NOPAGE_REFAULT, I use NOPFN_REFAULT and that has hit mainline. I will switch to ->fault when I have time to adapt the code, in the meantime, NOPFN_REFAULT should stay.

I think I removed not only NOFPN_REFAULT, but also nopfn itself, *and* adapted the code for you ;) it is in patch 5/6, sent a while ago.

Ok, I need to look. I've been travelling, having meeting etc... for the last couple of weeks and I'm taking a week off next week :-)

Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#90 lore raw

PATCH 5/6 mm: merge nopfn into fault

In reply to Nick Piggin

Remove ->nopfn and reimplement the existing handlers with ->fault

 arch/powerpc/platforms/cell/spufs/file.c |   90 ++++++++++++++++---------------
 drivers/char/mspec.c                     |   29 ++++++---
 include/linux/mm.h                       |    8 --
 mm/memory.c                              |   58 +------------------
 4 files changed, 71 insertions(+), 114 deletions(-)
drivers/char/mspec.c +19 -10
Index: linux-2.6/drivers/char/mspec.c
===================================================================
@@ -182,24 +182,25 @@ mspec_close(struct vm_area_struct *vma)
 
 
 /*
- * mspec_nopfn
+ * mspec_fault
  *
  * Creates a mspec page and maps it to user space.
  */
-static unsigned long
-mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
+static struct page *
+mspec_fault(struct fault_data *fdata)
 {
 	unsigned long paddr, maddr;
 	unsigned long pfn;
-	int index;
-	struct vma_data *vdata = vma->vm_private_data;
+	int index = fdata->pgoff;
+	struct vma_data *vdata = fdata->vma->vm_private_data;
 
-	index = (address - vma->vm_start) >> PAGE_SHIFT;
 	maddr = (volatile unsigned long) vdata->maddr[index];
 	if (maddr == 0) {
 		maddr = uncached_alloc_page(numa_node_id());
-		if (maddr == 0)
-			return NOPFN_OOM;
+		if (maddr == 0) {
+			fdata->type = VM_FAULT_OOM;
+			return NULL;
+		}
 
 		spin_lock(&vdata->lock);
 		if (vdata->maddr[index] == 0) {
@@ -219,13 +220,21 @@ mspec_nopfn(struct vm_area_struct *vma, 
 
 	pfn = paddr >> PAGE_SHIFT;
 
-	return pfn;
+	fdata->type = VM_FAULT_MINOR;
+	/*
+	 * vm_insert_pfn can fail with -EBUSY, but in that case it will
+	 * be because another thread has installed the pte first, so it
+	 * is no problem.
+	 */
+	vm_insert_pfn(fdata->vma, fdata->address, pfn);
+
+	return NULL;
 }
 
 static struct vm_operations_struct mspec_vm_ops = {
 	.open = mspec_open,
 	.close = mspec_close,
-	.nopfn = mspec_nopfn
+	.fault = mspec_fault,
 };
 
 /*
include/linux/mm.h +0 -8
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -230,7 +230,6 @@ struct vm_operations_struct {
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
-	unsigned long (*nopfn)(struct vm_area_struct * area, unsigned long address);
 	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
 
 	/* notification that a previously read-only page is about to become
@@ -660,13 +659,6 @@ static inline int page_mapped(struct pag
 #define NOPAGE_OOM	((struct page *) (-1))
 
 /*
- * Error return values for the *_nopfn functions
- */
-#define NOPFN_SIGBUS	((unsigned long) -1)
-#define NOPFN_OOM	((unsigned long) -2)
-#define NOPFN_REFAULT	((unsigned long) -3)
-
-/*
  * Different kinds of faults, as returned by handle_mm_fault().
  * Used to decide whether a process gets delivered SIGBUS or
  * just gets major/minor fault counters bumped up.
mm/memory.c +5 -53

76 lines not on this page · raw message

arch/powerpc/platforms/cell/spufs/file.c +47 -43

205 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#91 lore raw

Re: [patch 5/6] mm: merge nopfn into fault

Quoted 3 lines · Nick Piggin

Remove ->nopfn and reimplement the existing handlers with ->fault

Dang, forgot to quilt refresh after fixing spufs compile. --

Remove ->nopfn and reimplement the existing handlers with ->fault

 arch/powerpc/platforms/cell/spufs/file.c |   90 ++++++++++++++++---------------
 drivers/char/mspec.c                     |   29 ++++++---
 include/linux/mm.h                       |    8 --
 mm/memory.c                              |   58 +------------------
 4 files changed, 71 insertions(+), 114 deletions(-)
drivers/char/mspec.c +19 -10
Index: linux-2.6/drivers/char/mspec.c
===================================================================
@@ -182,24 +182,25 @@ mspec_close(struct vm_area_struct *vma)
 
 
 /*
- * mspec_nopfn
+ * mspec_fault
  *
  * Creates a mspec page and maps it to user space.
  */
-static unsigned long
-mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
+static struct page *
+mspec_fault(struct fault_data *fdata)
 {
 	unsigned long paddr, maddr;
 	unsigned long pfn;
-	int index;
-	struct vma_data *vdata = vma->vm_private_data;
+	int index = fdata->pgoff;
+	struct vma_data *vdata = fdata->vma->vm_private_data;
 
-	index = (address - vma->vm_start) >> PAGE_SHIFT;
 	maddr = (volatile unsigned long) vdata->maddr[index];
 	if (maddr == 0) {
 		maddr = uncached_alloc_page(numa_node_id());
-		if (maddr == 0)
-			return NOPFN_OOM;
+		if (maddr == 0) {
+			fdata->type = VM_FAULT_OOM;
+			return NULL;
+		}
 
 		spin_lock(&vdata->lock);
 		if (vdata->maddr[index] == 0) {
@@ -219,13 +220,21 @@ mspec_nopfn(struct vm_area_struct *vma, 
 
 	pfn = paddr >> PAGE_SHIFT;
 
-	return pfn;
+	fdata->type = VM_FAULT_MINOR;
+	/*
+	 * vm_insert_pfn can fail with -EBUSY, but in that case it will
+	 * be because another thread has installed the pte first, so it
+	 * is no problem.
+	 */
+	vm_insert_pfn(fdata->vma, fdata->address, pfn);
+
+	return NULL;
 }
 
 static struct vm_operations_struct mspec_vm_ops = {
 	.open = mspec_open,
 	.close = mspec_close,
-	.nopfn = mspec_nopfn
+	.fault = mspec_fault,
 };
 
 /*
include/linux/mm.h +0 -8
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -230,7 +230,6 @@ struct vm_operations_struct {
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
-	unsigned long (*nopfn)(struct vm_area_struct * area, unsigned long address);
 	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
 
 	/* notification that a previously read-only page is about to become
@@ -660,13 +659,6 @@ static inline int page_mapped(struct pag
 #define NOPAGE_OOM	((struct page *) (-1))
 
 /*
- * Error return values for the *_nopfn functions
- */
-#define NOPFN_SIGBUS	((unsigned long) -1)
-#define NOPFN_OOM	((unsigned long) -2)
-#define NOPFN_REFAULT	((unsigned long) -3)
-
-/*
  * Different kinds of faults, as returned by handle_mm_fault().
  * Used to decide whether a process gets delivered SIGBUS or
  * just gets major/minor fault counters bumped up.
mm/memory.c +5 -53

76 lines not on this page · raw message

arch/powerpc/platforms/cell/spufs/file.c +49 -45

211 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#92 lore raw

PATCH 6/6 mm: remove legacy cruft

In reply to Nick Piggin

Remove legacy filemap_nopage and all of the .populate API cruft.

This patch can be skipped if it will cause clashes in your tree, or you disagree with removing these guys right now.

 Documentation/feature-removal-schedule.txt |   18 --
 include/linux/mm.h                         |    8 -
 mm/filemap.c                               |  195 -----------------------------
 mm/fremap.c                                |   71 +---------
 mm/memory.c                                |   36 +----
 5 files changed, 19 insertions(+), 309 deletions(-)
include/linux/mm.h +0 -8
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -230,8 +230,6 @@ struct vm_operations_struct {
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*fault)(struct vm_area_struct *vma, struct fault_data * fdata);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
-	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
-
 	/* notification that a previously read-only page is about to become
 	 * writable, if an error is returned it will cause a SIGBUS */
 	int (*page_mkwrite)(struct vm_area_struct *vma, struct page *page);
@@ -767,8 +765,6 @@ static inline void unmap_shared_mapping_
 
 extern int vmtruncate(struct inode * inode, loff_t offset);
 extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
-extern int install_page(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, struct page *page, pgprot_t prot);
-extern int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long pgoff, pgprot_t prot);
 
 #ifdef CONFIG_MMU
 extern int __handle_mm_fault(struct mm_struct *mm,struct vm_area_struct *vma,
@@ -1084,10 +1080,6 @@ extern void truncate_inode_pages_range(s
 
 /* generic vm_area_ops exported for stackable file systems */
 extern struct page *filemap_fault(struct vm_area_struct *, struct fault_data *);
-extern struct page * __deprecated_for_modules filemap_nopage(
-			struct vm_area_struct *, unsigned long, int *);
-extern int __deprecated_for_modules filemap_populate(struct vm_area_struct *,
-		unsigned long, unsigned long, pgprot_t, unsigned long, int);
 
 /* mm/page-writeback.c */
 int write_one_page(struct page *page, int wait);
mm/filemap.c +0 -195

201 lines not on this page · raw message

mm/fremap.c +9 -62

93 lines not on this page · raw message

mm/memory.c +10 -26
Index: linux-2.6/mm/memory.c
===================================================================
@@ -2334,18 +2334,10 @@ static int do_linear_fault(struct mm_str
 			- vma->vm_start) >> PAGE_CACHE_SHIFT) + vma->vm_pgoff;
 	unsigned int flags = (write_access ? FAULT_FLAG_WRITE : 0);
 
-	return __do_fault(mm, vma, address, page_table, pmd, pgoff, flags, orig_pte);
+	return __do_fault(mm, vma, address, page_table, pmd, pgoff,
+							flags, orig_pte);
 }
 
-static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
-		unsigned long address, pte_t *page_table, pmd_t *pmd,
-		int write_access, pgoff_t pgoff, pte_t orig_pte)
-{
-	unsigned int flags = FAULT_FLAG_NONLINEAR |
-				(write_access ? FAULT_FLAG_WRITE : 0);
-
-	return __do_fault(mm, vma, address, page_table, pmd, pgoff, flags, orig_pte);
-}
 
 /*
  * Fault of a previously existing named mapping. Repopulate the pte
@@ -2356,17 +2348,19 @@ static int do_nonlinear_fault(struct mm_
  * but allow concurrent faults), and pte mapped but not yet locked.
  * We return with mmap_sem still held, but pte unmapped and unlocked.
  */
-static int do_file_page(struct mm_struct *mm, struct vm_area_struct *vma,
+static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 		unsigned long address, pte_t *page_table, pmd_t *pmd,
 		int write_access, pte_t orig_pte)
 {
+	unsigned int flags = FAULT_FLAG_NONLINEAR |
+				(write_access ? FAULT_FLAG_WRITE : 0);
 	pgoff_t pgoff;
-	int err;
 
 	if (!pte_unmap_same(mm, pmd, page_table, orig_pte))
 		return VM_FAULT_MINOR;
 
-	if (unlikely(!(vma->vm_flags & VM_NONLINEAR))) {
+	if (unlikely(!(vma->vm_flags & VM_NONLINEAR) ||
+			!(vma->vm_flags & VM_CAN_NONLINEAR))) {
 		/*
 		 * Page table corrupted: show pte and kill process.
 		 */
@@ -2376,18 +2370,8 @@ static int do_file_page(struct mm_struct
 
 	pgoff = pte_to_pgoff(orig_pte);
 
-	if (vma->vm_ops && vma->vm_ops->fault)
-		return do_nonlinear_fault(mm, vma, address, page_table, pmd,
-					write_access, pgoff, orig_pte);
-
-	/* We can then assume vm->vm_ops && vma->vm_ops->populate */
-	err = vma->vm_ops->populate(vma, address & PAGE_MASK, PAGE_SIZE,
-					vma->vm_page_prot, pgoff, 0);
-	if (err == -ENOMEM)
-		return VM_FAULT_OOM;
-	if (err)
-		return VM_FAULT_SIGBUS;
-	return VM_FAULT_MAJOR;
+	return __do_fault(mm, vma, address, page_table, pmd, pgoff,
+							flags, orig_pte);
 }
 
 /*
@@ -2423,7 +2407,7 @@ static inline int handle_pte_fault(struc
 						 pte, pmd, write_access);
 		}
 		if (pte_file(entry))
-			return do_file_page(mm, vma, address,
+			return do_nonlinear_fault(mm, vma, address,
 					pte, pmd, write_access, entry);
 		return do_swap_page(mm, vma, address,
 					pte, pmd, write_access, entry);
Documentation/feature-removal-schedule.txt +0 -18
Index: linux-2.6/Documentation/feature-removal-schedule.txt
===================================================================
@@ -170,24 +170,6 @@ Who:	Greg Kroah-Hartman <[email protected]>
 
 ---------------------------
 
-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 <[email protected]>
-
----------------------------
-
-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 <[email protected]>
-
----------------------------
-
 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#93 lore raw
In reply to Nick Piggin
Quoted 11 lines

I've also got rid of the horrible populate API, and integrated nonlinear pages properly with the page fault path.

Downside is that this adds one more vector through which the buffered write deadlock can occur. However this is just a very tiny one (pte being unmapped for reclaim), compared to all the other ways that deadlock can occur (unmap, reclaim, truncate, invalidate). I doubt it will be noticable. At any rate, it is better than data corruption.

I hope these can get merged (at least into -mm) soon.

Have these been put into mm? can I expect them in the next -mm so I can start merging up the drm memory manager code to my -mm tree..

Dave.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#94 lore raw
Quoted 11 lines · On Tue, 27 Feb 2007 15:36:03 +1100 "Dave Airlie" <[email protected]> wrote:
Quoted 10 lines

I've also got rid of the horrible populate API, and integrated nonlinear pages properly with the page fault path.

Downside is that this adds one more vector through which the buffered write deadlock can occur. However this is just a very tiny one (pte being unmapped for reclaim), compared to all the other ways that deadlock can occur (unmap, reclaim, truncate, invalidate). I doubt it will be noticable. At any rate, it is better than data corruption.

Quoted 3 lines
Quoted 1 line

I hope these can get merged (at least into -mm) soon.

Have these been put into mm?

Not yet - I need to get back on the correct continent, review the code, stuff like that. It still hurts that this work makes the write() deadlock harder to hit, and we haven't worked out how to fix that.

Quoted 2 lines

can I expect them in the next -mm so I
can start merging up the drm memory manager code to my -mm tree..

What is the linkage between these patches and DRM?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#95 lore raw
Quoted 15 lines · Andrew Morton
Quoted 11 lines · On Tue, 27 Feb 2007 15:36:03 +1100 "Dave Airlie" <[email protected]> wrote:
Quoted 10 lines

I've also got rid of the horrible populate API, and integrated nonlinear pages properly with the page fault path.

Downside is that this adds one more vector through which the buffered write deadlock can occur. However this is just a very tiny one (pte being unmapped for reclaim), compared to all the other ways that deadlock can occur (unmap, reclaim, truncate, invalidate). I doubt it will be noticable. At any rate, it is better than data corruption.

Quoted 3 lines
Quoted 1 line

I hope these can get merged (at least into -mm) soon.

Have these been put into mm?

Quoted 9 lines

Not yet - I need to get back on the correct continent, review the code, stuff like that. It still hurts that this work makes the write() deadlock harder to hit, and we haven't worked out how to fix that.

Quoted 2 lines

can I expect them in the next -mm so I
can start merging up the drm memory manager code to my -mm tree..

What is the linkage between these patches and DRM?

the new fault hander made the memory manager code a lot cleaner and very less hacky in a lot of cases. so I'd rather merge the clean code than have to fight with the current code...

Dave.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#96 lore raw
Quoted 3 lines

the new fault hander made the memory manager code a lot cleaner and very less hacky in a lot of cases. so I'd rather merge the clean code than have to fight with the current code...

Note that you can probably get away with NOPFN_REFAULT etc... like I did for the SPEs in the meantime.

Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#97 lore raw
Quoted 6 lines
Quoted 3 lines

the new fault hander made the memory manager code a lot cleaner and very less hacky in a lot of cases. so I'd rather merge the clean code than have to fight with the current code...

Note that you can probably get away with NOPFN_REFAULT etc... like I did for the SPEs in the meantime.

Indeed, Thomas has done this work and I'm just lining up a TTM tree to start the merge process..

Dave.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#98 lore raw
In reply to Andrew Morton
Quoted 11 lines · Andrew Morton
Quoted 11 lines · On Tue, 27 Feb 2007 15:36:03 +1100 "Dave Airlie" <[email protected]> wrote:
Quoted 10 lines

I've also got rid of the horrible populate API, and integrated nonlinear pages properly with the page fault path.

Downside is that this adds one more vector through which the buffered write deadlock can occur. However this is just a very tiny one (pte being unmapped for reclaim), compared to all the other ways that deadlock can occur (unmap, reclaim, truncate, invalidate). I doubt it will be noticable. At any rate, it is better than data corruption.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I hope these can get merged (at least into -mm) soon.

Have these been put into mm?

Not yet - I need to get back on the correct continent, review the code, stuff like that. It still hurts that this work makes the write() deadlock harder to hit,

s/harder/easier of course...

I think there is good reason to assume the buffered write page lock deadlocks would not occur in "normal" programs (or very very few), because it would require writing from the same page you are writing to, or 2 processes writing from the page the other is writing to. If any innocent users do hit this, at least it is not data corrupting, and is relatively easy to trace back to the kernel.

In the case of local DoS exploits, the deadlocks already present in the buffered write path are already trivial to exploit... locking the page in the fault path doesn't make the deadlock exploit any more possible.

So the downside to merging is that we _may_ get some additional deadlocks.

What is being fixed is silent data corruption that has been reported by several different users of the SLES kernel (because we have assertions there to catch it), and can be triggered by DIO or NFS, or anything using vmtruncate_range or invalidate_inode_pages2 on regular files. Or even a regular truncate with nonlinear pages. These are known problems on production workloads.

That's my argument for merging these. I think it's reasonable, but I'm open to debate.

I did get some page fault performance numbers at one stage. Nothing really exciting seemed to happen IIRC, but I can do another set of tests if you want?

Quoted 1 line

and we haven't worked out how to fix that.

To be fair, I have 2 ways to fix it. Unfortunately one is slow and the other requires cooperation from filesystem developers. perform_write() is still on track, but it is going to take a reasonable amount of time and effort to convert filesystems. I just can't see any gain in holding these patches back until that all happens.

Thanks,
Nick

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>