linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rajesh Venkatasubramanian <vrajesh@umich.edu>
To: Andrea Arcangeli <andrea@suse.de>
Cc: akpm@osdl.org, hugh@veritas.com, riel@redhat.com, mingo@elte.hu,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC][PATCH 1/3] radix priority search tree - objrmap complexity fix
Date: Sat, 27 Mar 2004 14:51:45 -0500 (EST)	[thread overview]
Message-ID: <Pine.GSO.4.58.0403271448120.28539@sapphire.engin.umich.edu> (raw)
In-Reply-To: <20040326175842.GC9604@dualathlon.random>


This patch adds a list_head i_mmap_nonlinear to the address_space
structure. The list is used for storing all nonlinear vmas. This
is helpful in try_to_unmap_inode to find all nonlinear mappings of
a file.

This patch does not change invalidate_mmap_range_list. Already
the behavior of truncate on nonlinear mappings is undefined. We
understand that nonlinear mappings do not guarantee SIGBUS on
truncate. After this patch, we do not touch nonlinear maps on
the truncate path. So it is assured that the nonlinear maps will
not be destroyed by a truncate.

I am not happy with the truncate behavior on nonlinear maps. I
think we can guarantee SIGBUS on nonlinear maps by reusing Andrea's
try_to_unmap_nonlinear code. But, I have to study more to do that.
So I am leaving that for future.

This patch is against 2.6.5-rc2-aa4. The patch was tested in a
SMP m/c. It boots and compiles a kernel without any problem.

Please review and apply.

Thanks,
Rajesh


 fs/inode.c         |    1 +
 fs/locks.c         |    6 ++++--
 include/linux/fs.h |    1 +
 mm/filemap.c       |    3 ++-
 mm/fremap.c        |   14 +++++++++++++-
 mm/mmap.c          |   25 +++++++++++++++++++------
 mm/mremap.c        |    6 ++++--
 mm/objrmap.c       |   10 +++++++++-
 mm/shmem.c         |    3 ++-
 mm/swap_state.c    |    1 +
 mm/vmscan.c        |    2 ++
 11 files changed, 58 insertions(+), 14 deletions(-)

diff -puN include/linux/fs.h~010_nonlinear include/linux/fs.h
--- mmlinux-2.6/include/linux/fs.h~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/include/linux/fs.h	2004-03-27 14:25:07.000000000 -0500
@@ -328,6 +328,7 @@ struct address_space {
 	struct address_space_operations *a_ops;	/* methods */
 	struct prio_tree_root	i_mmap;		/* tree of private mappings */
 	struct prio_tree_root	i_mmap_shared;	/* tree of shared mappings */
+	struct list_head	i_mmap_nonlinear;/*list of nonlinear mappings */
 	struct semaphore	i_shared_sem;	/* protect both above lists */
 	atomic_t		truncate_count;	/* Cover race condition with truncate */
 	unsigned long		dirtied_when;	/* jiffies of first page dirtying */
diff -puN fs/inode.c~010_nonlinear fs/inode.c
--- mmlinux-2.6/fs/inode.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/fs/inode.c	2004-03-27 14:25:07.000000000 -0500
@@ -187,6 +187,7 @@ void inode_init_once(struct inode *inode
 	spin_lock_init(&inode->i_data.private_lock);
 	INIT_PRIO_TREE_ROOT(&inode->i_data.i_mmap);
 	INIT_PRIO_TREE_ROOT(&inode->i_data.i_mmap_shared);
+	INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear);
 	spin_lock_init(&inode->i_lock);
 	i_size_ordered_init(inode);
 }
diff -puN fs/locks.c~010_nonlinear fs/locks.c
--- mmlinux-2.6/fs/locks.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/fs/locks.c	2004-03-27 14:25:07.000000000 -0500
@@ -1455,7 +1455,8 @@ int fcntl_setlk(struct file *filp, unsig
 	if (IS_MANDLOCK(inode) &&
 	    (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) {
 		struct address_space *mapping = filp->f_mapping;
-		if (!prio_tree_empty(&mapping->i_mmap_shared)) {
+		if (!prio_tree_empty(&mapping->i_mmap_shared) ||
+			!list_empty(&mapping->i_mmap_nonlinear)) {
 			error = -EAGAIN;
 			goto out;
 		}
@@ -1592,7 +1593,8 @@ int fcntl_setlk64(struct file *filp, uns
 	if (IS_MANDLOCK(inode) &&
 	    (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) {
 		struct address_space *mapping = filp->f_mapping;
-		if (!prio_tree_empty(&mapping->i_mmap_shared)) {
+		if (!prio_tree_empty(&mapping->i_mmap_shared) ||
+			!list_empty(&mapping->i_mmap_nonlinear)) {
 			error = -EAGAIN;
 			goto out;
 		}
diff -puN mm/filemap.c~010_nonlinear mm/filemap.c
--- mmlinux-2.6/mm/filemap.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/filemap.c	2004-03-27 14:25:07.000000000 -0500
@@ -650,7 +650,8 @@ page_ok:
 		 * virtual addresses, take care about potential aliasing
 		 * before reading the page on the kernel side.
 		 */
-		if (!prio_tree_empty(&mapping->i_mmap_shared))
+		if (!prio_tree_empty(&mapping->i_mmap_shared) ||
+			!list_empty(&mapping->i_mmap_nonlinear))
 			flush_dcache_page(page);

 		/*
diff -puN mm/shmem.c~010_nonlinear mm/shmem.c
--- mmlinux-2.6/mm/shmem.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/shmem.c	2004-03-27 14:25:07.000000000 -0500
@@ -1328,7 +1328,8 @@ static void do_shmem_file_read(struct fi
 			 * virtual addresses, take care about potential aliasing
 			 * before reading the page on the kernel side.
 			 */
-			if (!prio_tree_empty(&mapping->i_mmap_shared))
+			if (!prio_tree_empty(&mapping->i_mmap_shared) ||
+				!list_empty(&mapping->i_mmap_nonlinear))
 				flush_dcache_page(page);
 			/*
 			 * Mark the page accessed if we read the beginning.
diff -puN mm/swap_state.c~010_nonlinear mm/swap_state.c
--- mmlinux-2.6/mm/swap_state.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/swap_state.c	2004-03-27 14:25:07.000000000 -0500
@@ -30,6 +30,7 @@ struct address_space swapper_space = {
 	.backing_dev_info = &swap_backing_dev_info,
 	.i_mmap		= PRIO_TREE_ROOT_INIT,
 	.i_mmap_shared	= PRIO_TREE_ROOT_INIT,
+	.i_mmap_nonlinear = LIST_HEAD_INIT(swapper_space.i_mmap_nonlinear),
 	.i_shared_sem	= __MUTEX_INITIALIZER(swapper_space.i_shared_sem),
 	.truncate_count  = ATOMIC_INIT(0),
 	.private_lock	= SPIN_LOCK_UNLOCKED,
diff -puN mm/vmscan.c~010_nonlinear mm/vmscan.c
--- mmlinux-2.6/mm/vmscan.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/vmscan.c	2004-03-27 14:25:07.000000000 -0500
@@ -195,6 +195,8 @@ static inline int page_mapping_inuse(str
 		return 1;
 	if (!prio_tree_empty(&mapping->i_mmap_shared))
 		return 1;
+	if (!list_empty(&mapping->i_mmap_nonlinear))
+		return 1;

 	return 0;
 }
diff -puN mm/fremap.c~010_nonlinear mm/fremap.c
--- mmlinux-2.6/mm/fremap.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/fremap.c	2004-03-27 14:25:07.000000000 -0500
@@ -151,6 +151,8 @@ asmlinkage long sys_remap_file_pages(uns
 	unsigned long __prot, unsigned long pgoff, unsigned long flags)
 {
 	struct mm_struct *mm = current->mm;
+	struct address_space *mapping;
+	unsigned long linear_pgoff;
 	unsigned long end = start + size;
 	struct vm_area_struct *vma;
 	int err = -EINVAL;
@@ -187,9 +189,19 @@ asmlinkage long sys_remap_file_pages(uns
 			end > start && start >= vma->vm_start &&
 				end <= vma->vm_end) {

+		linear_pgoff = vma->vm_pgoff;
+		linear_pgoff +=  ((start - vma->vm_start) >> PAGE_SHIFT);
 		/* Must set VM_NONLINEAR before any pages are populated. */
-		if (pgoff != ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff)
+		if (pgoff != linear_pgoff && !(vma->vm_flags & VM_NONLINEAR)) {
+			mapping = vma->vm_file->f_mapping;
+			down(&mapping->i_shared_sem);
 			vma->vm_flags |= VM_NONLINEAR;
+			__vma_prio_tree_remove(&mapping->i_mmap_shared, vma);
+			INIT_VMA_SHARED_LIST(vma);
+			list_add_tail(&vma->shared.vm_set.list,
+					&mapping->i_mmap_nonlinear);
+			up(&mapping->i_shared_sem);
+		}

 		/* ->populate can take a long time, so downgrade the lock. */
 		downgrade_write(&mm->mmap_sem);
diff -puN mm/mmap.c~010_nonlinear mm/mmap.c
--- mmlinux-2.6/mm/mmap.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/mmap.c	2004-03-27 14:25:07.000000000 -0500
@@ -81,7 +81,11 @@ __remove_shared_vm_struct(struct vm_area
 	if (inode) {
 		if (vma->vm_flags & VM_DENYWRITE)
 			atomic_inc(&inode->i_writecount);
-		if (vma->vm_flags & VM_SHARED)
+		if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
+			list_del_init(&vma->shared.vm_set.list);
+			INIT_VMA_SHARED(vma);
+		}
+		else if (vma->vm_flags & VM_SHARED)
 			__vma_prio_tree_remove(&mapping->i_mmap_shared, vma);
 		else
 			__vma_prio_tree_remove(&mapping->i_mmap, vma);
@@ -273,7 +277,12 @@ static inline void __vma_link_file(struc
 		if (vma->vm_flags & VM_DENYWRITE)
 			atomic_dec(&file->f_dentry->d_inode->i_writecount);

-		if (vma->vm_flags & VM_SHARED)
+		if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
+			INIT_VMA_SHARED_LIST(vma);
+			list_add_tail(&vma->shared.vm_set.list,
+					&mapping->i_mmap_nonlinear);
+		}
+		else if (vma->vm_flags & VM_SHARED)
 			__vma_prio_tree_insert(&mapping->i_mmap_shared, vma);
 		else
 			__vma_prio_tree_insert(&mapping->i_mmap, vma);
@@ -430,8 +439,10 @@ static int vma_merge(struct mm_struct *m
 	i_shared_sem = file ? &file->f_mapping->i_shared_sem : NULL;

 	if (mapping) {
-		if (vm_flags & VM_SHARED)
-			root = &mapping->i_mmap_shared;
+		if (vm_flags & VM_SHARED) {
+			if (likely(!(vm_flags & VM_NONLINEAR)))
+				root = &mapping->i_mmap_shared;
+		}
 		else
 			root = &mapping->i_mmap;
 	}
@@ -1271,8 +1282,10 @@ int split_vma(struct mm_struct * mm, str
 	if (vma->vm_file) {
 		 mapping = vma->vm_file->f_mapping;

-		 if (vma->vm_flags & VM_SHARED)
-			 root = &mapping->i_mmap_shared;
+		 if (vma->vm_flags & VM_SHARED) {
+			 if (likely(!(vma->vm_flags & VM_NONLINEAR)))
+			 	root = &mapping->i_mmap_shared;
+		 }
 		 else
 			 root = &mapping->i_mmap;
 	}
diff -puN mm/mremap.c~010_nonlinear mm/mremap.c
--- mmlinux-2.6/mm/mremap.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/mremap.c	2004-03-27 14:25:07.000000000 -0500
@@ -413,8 +413,10 @@ unsigned long do_mremap(unsigned long ad

 			if (vma->vm_file) {
 				mapping = vma->vm_file->f_mapping;
-				if (vma->vm_flags & VM_SHARED)
-					root = &mapping->i_mmap_shared;
+				if (vma->vm_flags & VM_SHARED) {
+					if (likely(!(vma->vm_flags & VM_NONLINEAR)))
+						root = &mapping->i_mmap_shared;
+				}
 				else
 					root = &mapping->i_mmap;
 				down(&mapping->i_shared_sem);
diff -puN mm/objrmap.c~010_nonlinear mm/objrmap.c
--- mmlinux-2.6/mm/objrmap.c~010_nonlinear	2004-03-27 14:25:07.000000000 -0500
+++ mmlinux-2.6-jaya/mm/objrmap.c	2004-03-27 14:25:07.000000000 -0500
@@ -133,8 +133,10 @@ page_referenced_one(struct vm_area_struc
 	 * Tracking the referenced info is too expensive
 	 * for nonlinear mappings.
 	 */
-	if (vma->vm_flags & VM_NONLINEAR)
+	if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
+		BUG();
 		goto out;
+	}

 	if (unlikely(!spin_trylock(&mm->page_table_lock)))
 		goto out;
@@ -630,6 +632,12 @@ try_to_unmap_inode(struct page *page)
 				loffset, loffset);
 	}

+	list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.vm_set.list) {
+		ret = try_to_unmap_one(vma, page, &young);
+		if (ret == SWAP_FAIL || !page->mapcount)
+			goto out;
+	}
+
 out:
 	up(&mapping->i_shared_sem);
 	return ret;

_

  reply	other threads:[~2004-03-27 19:59 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.44.0403150527400.28579-100000@localhost.localdomain>
2004-03-21 22:10 ` [RFC][PATCH 1/3] radix priority search tree - objrmap complexity fix Rajesh Venkatasubramanian
2004-03-21 22:12   ` [RFC][PATCH 2/3] Dave & Hugh's objrmap patch Rajesh Venkatasubramanian
2004-03-21 22:13   ` [RFC][PATCH 3/3] Covert objrmap to use prio_tree Rajesh Venkatasubramanian
2004-03-21 22:26   ` URL typo Rajesh Venkatasubramanian
2004-03-22  0:46   ` [RFC][PATCH 1/3] radix priority search tree - objrmap complexity fix Andrea Arcangeli
2004-03-22  2:32     ` Rik van Riel
2004-03-22  3:49     ` Rajesh Venkatasubramanian
2004-03-22  4:02       ` Rik van Riel
2004-03-22  4:21         ` put_super for proc Abhishek Rai
2004-03-22 12:04           ` Maneesh Soni
2004-03-25 22:59   ` [RFC][PATCH 1/3] radix priority search tree - objrmap complexity fix Andrea Arcangeli
2004-03-26  4:06     ` Rajesh Venkatasubramanian
2004-03-26  7:53       ` Andrea Arcangeli
2004-03-26 15:43         ` Rajesh Venkatasubramanian
2004-03-26 17:58           ` Andrea Arcangeli
2004-03-27 19:51             ` Rajesh Venkatasubramanian [this message]
2004-03-29 17:22               ` Andrea Arcangeli
2004-03-29 17:50                 ` Rajesh Venkatasubramanian
2004-03-29 18:01                   ` Andrea Arcangeli
2004-03-29 20:40                     ` Andrew Morton
2004-03-29 22:24                       ` Hugh Dickins
2004-03-29 22:54                         ` Andrea Arcangeli
2004-03-29 23:08                         ` William Lee Irwin III
2004-03-29 22:39                       ` Andrea Arcangeli
2004-03-29 22:42                         ` Andrew Morton
2004-03-31 15:07                           ` Andrea Arcangeli
2004-03-31 15:26                             ` Andrea Arcangeli
2004-03-31 16:45                             ` Hugh Dickins
2004-03-31 17:28                               ` Andrea Arcangeli
2004-04-01  0:45                                 ` Andrea Arcangeli
2004-04-01  1:22                                   ` Andrew Morton
2004-04-01  1:26                                     ` Andrea Arcangeli
2004-04-01  1:51                                       ` Andrew Morton
2004-04-01  2:01                                         ` Andrea Arcangeli
2004-04-01  5:05                                           ` Hugh Dickins
2004-04-01 13:35                                             ` Andrea Arcangeli
2004-04-01 15:09                                               ` Andrea Arcangeli
2004-04-01 15:15                                                 ` Andrea Arcangeli
2004-04-02  0:15                                                   ` Andrea Arcangeli
2004-04-02  0:52                                                     ` Andrew Morton
2004-04-02  1:06                                                       ` Andrea Arcangeli
2004-04-02  1:03                                                     ` Hugh Dickins
2004-04-02  1:16                                                       ` Andrea Arcangeli
2004-04-02  1:36                                                         ` Andrew Morton
2004-04-02  2:00                                                           ` Andrea Arcangeli
2004-04-02  2:08                                                             ` Andrew Morton
2004-04-02  2:22                                                               ` Andrea Arcangeli
2004-04-02  6:05                                                                 ` Christoph Hellwig
2004-04-02  7:07                                                                   ` Paul Mackerras
2004-04-02  7:11                                                                     ` Christoph Hellwig
2004-04-02 15:28                                                                     ` Andrea Arcangeli
2004-04-02 15:22                                                                   ` Andrea Arcangeli
2004-04-02 15:27                                                                     ` Christoph Hellwig
2004-04-02 15:38                                                                       ` Andrea Arcangeli
2004-04-02 15:45                                                                         ` Andrea Arcangeli
2004-04-02  9:43                                                             ` Christoph Hellwig
2004-04-02 10:21                                                               ` Marc-Christian Petersen
2004-04-02 10:55                                                                 ` Hugh Dickins
2004-04-02 16:46                                                               ` Andrea Arcangeli
2004-04-02 18:59                                                                 ` Christoph Hellwig
2004-04-02 19:29                                                                   ` Andrea Arcangeli
2004-04-02 19:54                                                                     ` Christoph Hellwig
2004-04-02 20:35                                                                       ` Andrea Arcangeli
2004-04-03  8:40                                                                         ` Christoph Hellwig
2004-04-03 15:20                                                                           ` Andrea Arcangeli
2004-04-03 15:59                                                                             ` Andrea Arcangeli
2004-04-03 17:02                                                                               ` Andrea Arcangeli
2004-04-05  9:59                                                                                 ` Christoph Hellwig
2004-04-05 12:11                                                                                   ` Christoph Hellwig
2004-04-05 16:08                                                                                     ` Andrea Arcangeli
2004-04-06  4:22                                                                                     ` Andrea Arcangeli
2004-04-06  4:43                                                                                       ` Andrew Morton
2004-04-06  5:14                                                                                         ` Christoph Hellwig
2004-04-06 21:54                                                                                         ` Andrea Arcangeli
2004-04-07  1:39                                                                                           ` Nathan Scott
2004-04-06  5:16                                                                                       ` Christoph Hellwig
2004-04-06 16:01                                                                                         ` Andrea Arcangeli
2004-04-07  1:33                                                                                           ` Nathan Scott
2004-04-03 17:40                                                                 ` Andrea Arcangeli
2004-04-03 20:02                                                                   ` Andrew Morton
2004-04-03 23:27                                                                     ` Andrea Arcangeli
2004-04-03 23:46                                                                       ` Andrew Morton
2004-04-04  0:40                                                                         ` Andrea Arcangeli
2004-04-08 19:10                                                                   ` Bill Davidsen
2004-04-20 22:29                                                                     ` Pavel Machek
2004-04-02 20:13                                           ` Pavel Machek
2004-04-02 21:42                                             ` Andrea Arcangeli
2004-04-02 21:45                                               ` Pavel Machek
2004-04-02 21:49                                                 ` Andrea Arcangeli
2004-03-29 18:12                 ` Hugh Dickins
2004-03-29 18:20                   ` Andrea Arcangeli
2004-03-29 18:38                     ` Christoph Hellwig
2004-03-29 21:30                   ` 2.6.5-rc2-aa5 Rajesh Venkatasubramanian
2004-03-29 22:50                     ` 2.6.5-rc2-aa5 Andrea Arcangeli
2004-04-05  3:14       ` [RFC][PATCH 1/3] radix priority search tree - objrmap complexity fix Rajesh Venkatasubramanian
2004-04-05  4:42         ` Andrea Arcangeli
2004-03-26 12:26     ` William Lee Irwin III
2004-03-26 19:18       ` Andrea Arcangeli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.58.0403271448120.28539@sapphire.engin.umich.edu \
    --to=vrajesh@umich.edu \
    --cc=akpm@osdl.org \
    --cc=andrea@suse.de \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).