public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nigel Cunningham <ncunningham@crca.org.au>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: No more bits in vm_area_struct's vm_flags.
Date: Mon, 28 Sep 2009 14:37:48 +1000	[thread overview]
Message-ID: <4AC03D9C.3020907@crca.org.au> (raw)
In-Reply-To: <20090928125705.6656e8c5.kamezawa.hiroyu@jp.fujitsu.com>

Hi.

KAMEZAWA Hiroyuki wrote:
> Then, Nigel, you have 2 choices I think.
> 
> (1) don't merge if vm_hints is set  or (2) pass vm_hints to all
> __merge() functions.
> 
> One of above will be accesptable for stakeholders... I personally
> like (1) but just trying (2) may be accepted.
> 
> What I dislike is making vm_flags to be long long ;)

Okay. I've gone for option 1 for now. Here's what I
currently have (compile testing as I write)...



vm_flags in struct vm_area_struct is full. Move some of the less commonly
used flags to a new variable so that other flags that need to be in vm_flags
(because, for example, they need to be in variables that are passed around)
can be added.

Signed-off-by: Nigel Cunningham <nigel@tuxonice.net>
---
 include/linux/mm.h       |   16 ++++++++--------
 include/linux/mm_types.h |    1 +
 mm/madvise.c             |   28 ++++++++++++++++++----------
 mm/mmap.c                |    2 ++
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 24c3956..040d0ce 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -85,10 +85,6 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_LOCKED	0x00002000
 #define VM_IO           0x00004000	/* Memory mapped I/O or similar */
 
-					/* Used by sys_madvise() */
-#define VM_SEQ_READ	0x00008000	/* App will access data sequentially */
-#define VM_RAND_READ	0x00010000	/* App will not benefit from clustered reads */
-
 #define VM_DONTCOPY	0x00020000      /* Do not copy this vma on fork */
 #define VM_DONTEXPAND	0x00040000	/* Cannot expand with mremap() */
 #define VM_RESERVED	0x00080000	/* Count as reserved_vm like IO */
@@ -116,11 +112,15 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_STACK_FLAGS	(VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
 #endif
 
+					/* Used by sys_madvise() */
+#define VM_SEQ_READ	0x00000001	/* App will access data sequentially */
+#define VM_RAND_READ	0x00000002	/* App will not benefit from clustered reads */
+
 #define VM_READHINTMASK			(VM_SEQ_READ | VM_RAND_READ)
-#define VM_ClearReadHint(v)		(v)->vm_flags &= ~VM_READHINTMASK
-#define VM_NormalReadHint(v)		(!((v)->vm_flags & VM_READHINTMASK))
-#define VM_SequentialReadHint(v)	((v)->vm_flags & VM_SEQ_READ)
-#define VM_RandomReadHint(v)		((v)->vm_flags & VM_RAND_READ)
+#define VM_ClearReadHint(v)		(v)->vm_hints &= ~VM_READHINTMASK
+#define VM_NormalReadHint(v)		(!((v)->vm_hints & VM_READHINTMASK))
+#define VM_SequentialReadHint(v)	((v)->vm_hints & VM_SEQ_READ)
+#define VM_RandomReadHint(v)		((v)->vm_hints & VM_RAND_READ)
 
 /*
  * special vmas that are non-mergable, non-mlock()able
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 84a524a..5c66e3a 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -178,6 +178,7 @@ struct vm_area_struct {
 					   units, *not* PAGE_CACHE_SIZE */
 	struct file * vm_file;		/* File we map to (can be NULL). */
 	void * vm_private_data;		/* was vm_pte (shared mem) */
+	unsigned long vm_hints;		/* Hints, see mm.h. */
 	unsigned long vm_truncate_count;/* truncate_count or restart_addr */
 
 #ifndef CONFIG_MMU
diff --git a/mm/madvise.c b/mm/madvise.c
index 35b1479..59a93d3 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -40,19 +40,22 @@ static long madvise_behavior(struct vm_area_struct * vma,
 		     unsigned long start, unsigned long end, int behavior)
 {
 	struct mm_struct * mm = vma->vm_mm;
-	int error = 0;
+	int error = 0, skip_merge = 0;
 	pgoff_t pgoff;
-	unsigned long new_flags = vma->vm_flags;
+	unsigned long new_flags = vma->vm_flags, new_hints = vma->vm_hints;
 
 	switch (behavior) {
 	case MADV_NORMAL:
-		new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
+		new_hints = new_hints & ~VM_RAND_READ & ~VM_SEQ_READ;
+		skip_merge = 1;
 		break;
 	case MADV_SEQUENTIAL:
-		new_flags = (new_flags & ~VM_RAND_READ) | VM_SEQ_READ;
+		new_hints = (new_hints & ~VM_RAND_READ) | VM_SEQ_READ;
+		skip_merge = 1;
 		break;
 	case MADV_RANDOM:
-		new_flags = (new_flags & ~VM_SEQ_READ) | VM_RAND_READ;
+		new_hints = (new_hints & ~VM_SEQ_READ) | VM_RAND_READ;
+		skip_merge = 1;
 		break;
 	case MADV_DONTFORK:
 		new_flags |= VM_DONTCOPY;
@@ -78,11 +81,15 @@ static long madvise_behavior(struct vm_area_struct * vma,
 	}
 
 	pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
-	*prev = vma_merge(mm, *prev, start, end, new_flags, vma->anon_vma,
-				vma->vm_file, pgoff, vma_policy(vma));
-	if (*prev) {
-		vma = *prev;
-		goto success;
+
+	if (!skip_merge) {
+		*prev = vma_merge(mm, *prev, start, end, new_flags,
+				vma->anon_vma, vma->vm_file, pgoff,
+				vma_policy(vma));
+		if (*prev) {
+			vma = *prev;
+			goto success;
+		}
 	}
 
 	*prev = vma;
@@ -104,6 +111,7 @@ success:
 	 * vm_flags is protected by the mmap_sem held in write mode.
 	 */
 	vma->vm_flags = new_flags;
+	vma->vm_hints = new_hints;
 
 out:
 	if (error == -ENOMEM)
diff --git a/mm/mmap.c b/mm/mmap.c
index 73f5e4b..fb4bf98 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -670,6 +670,8 @@ static inline int is_mergeable_vma(struct vm_area_struct *vma,
 		return 0;
 	if (vma->vm_ops && vma->vm_ops->close)
 		return 0;
+	if (vma->vm_hints)
+		return 0;
 	return 1;
 }
 
-- 
1.6.3.3


  reply	other threads:[~2009-09-28  4:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-23  4:15 No more bits in vm_area_struct's vm_flags Nigel Cunningham
2009-09-23 20:23 ` Hugh Dickins
2009-09-25  8:30   ` Nigel Cunningham
2009-09-25 11:36     ` Hugh Dickins
2009-09-25 11:47       ` Nigel Cunningham
2009-09-30 12:02     ` Pavel Machek
2009-09-30 13:08       ` swsusp on nommu, was 'Re: No more bits in vm_area_struct's vm_flags.' Johannes Weiner
2009-09-30 16:06         ` Mike Frysinger
2009-09-24  1:05 ` No more bits in vm_area_struct's vm_flags KAMEZAWA Hiroyuki
2009-09-25  8:34   ` Nigel Cunningham
2009-09-25  8:40     ` KAMEZAWA Hiroyuki
2009-09-25  8:48       ` Nigel Cunningham
2009-09-25 21:09         ` Joerg Roedel
2009-09-28  2:45       ` Nigel Cunningham
2009-09-28  3:04         ` KAMEZAWA Hiroyuki
2009-09-28  3:36           ` Wu Fengguang
2009-09-28  3:57             ` KAMEZAWA Hiroyuki
2009-09-28  4:37               ` Nigel Cunningham [this message]
2009-09-28  4:51                 ` Wu Fengguang
2009-09-28  4:53                 ` KAMEZAWA Hiroyuki
2009-09-28  5:22                   ` Nigel Cunningham
2009-09-28  5:32                     ` KAMEZAWA Hiroyuki
2009-09-28 21:21                 ` Hugh Dickins
2009-09-28 21:33                   ` Nigel Cunningham
2009-09-28 15:38               ` Hugh Dickins
2009-09-28 16:14                 ` KAMEZAWA Hiroyuki
2009-09-28 21:00                   ` Hugh Dickins
2009-09-28 21:22                     ` Nigel Cunningham
2009-09-29  1:57                     ` KAMEZAWA Hiroyuki
2009-09-29 14:22                       ` Christoph Lameter
2009-10-01 10:54                         ` Hugh Dickins
2009-10-01 13:47                           ` Christoph Lameter
2009-10-01 11:38                       ` Hugh Dickins
2009-10-02  0:42                         ` KAMEZAWA Hiroyuki
2009-10-02  1:37                           ` KAMEZAWA Hiroyuki
2009-10-02  2:39                             ` KAMEZAWA Hiroyuki

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=4AC03D9C.3020907@crca.org.au \
    --to=ncunningham@crca.org.au \
    --cc=fengguang.wu@intel.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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