mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@mellanox.co.il>
To: Gleb Natapov <gleb@minantech.com>
Cc: Hugh Dickins <hugh@veritas.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Petr Vandrovec <vandrove@vc.cvut.cz>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	Badari Pulavarty <pbadari@us.ibm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Nick's core remove PageReserved broke vmware...
Date: Mon, 14 Nov 2005 22:23:49 +0200	[thread overview]
Message-ID: <20051114202349.GA3603@mellanox.co.il> (raw)
In-Reply-To: <20051114150022.GG5492@minantech.com>

Quoting Gleb Natapov <gleb@minantech.com>:
> It seams now you broke MADV_NORMAL.

Right. How's this?

---

Add madvise options to control whether memory range is inherited across fork.
Useful e.g. for when hardware is doing DMA from/into these pages.

Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>

Index: linux-2.6.14-dontcopy/kernel/fork.c
===================================================================
--- linux-2.6.14-dontcopy.orig/kernel/fork.c	2005-11-08 23:41:30.000000000 +0200
+++ linux-2.6.14-dontcopy/kernel/fork.c	2005-11-14 16:59:05.000000000 +0200
@@ -209,7 +209,7 @@ static inline int dup_mmap(struct mm_str
 	for (mpnt = current->mm->mmap ; mpnt ; mpnt = mpnt->vm_next) {
 		struct file *file;
 
-		if (mpnt->vm_flags & VM_DONTCOPY) {
+		if (mpnt->vm_flags & (VM_DONTCOPY | VM_DONTFORK)) {
 			long pages = vma_pages(mpnt);
 			mm->total_vm -= pages;
 			__vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
Index: linux-2.6.14-dontcopy/mm/mmap.c
===================================================================
--- linux-2.6.14-dontcopy.orig/mm/mmap.c	2005-11-08 23:42:01.000000000 +0200
+++ linux-2.6.14-dontcopy/mm/mmap.c	2005-11-14 17:02:37.000000000 +0200
@@ -840,7 +840,7 @@ void __vm_stat_account(struct mm_struct 
 
 #ifdef CONFIG_HUGETLB
 	if (flags & VM_HUGETLB) {
-		if (!(flags & VM_DONTCOPY))
+		if (!(flags & (VM_DONTCOPY|VM_DONTFORK)))
 			mm->shared_vm += pages;
 		return;
 	}
Index: linux-2.6.14-dontcopy/mm/madvise.c
===================================================================
--- linux-2.6.14-dontcopy.orig/mm/madvise.c	2005-10-28 02:02:08.000000000 +0200
+++ linux-2.6.14-dontcopy/mm/madvise.c	2005-11-14 22:40:43.000000000 +0200
@@ -22,16 +22,23 @@ static long madvise_behavior(struct vm_a
 	struct mm_struct * mm = vma->vm_mm;
 	int error = 0;
 	pgoff_t pgoff;
-	int new_flags = vma->vm_flags & ~VM_READHINTMASK;
+	int new_flags = vma->vm_flags;
 
 	switch (behavior) {
+	case MADV_NORMAL:
+		new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
+		break;
 	case MADV_SEQUENTIAL:
-		new_flags |= VM_SEQ_READ;
+		new_flags = (new_flags & ~VM_RAND_READ) | VM_SEQ_READ;
 		break;
 	case MADV_RANDOM:
-		new_flags |= VM_RAND_READ;
+		new_flags = (new_flags & ~VM_SEQ_READ) | VM_RAND_READ;
 		break;
-	default:
+	case MADV_DONTFORK:
+		new_flags |= VM_DONTFORK;
+		break;
+	case MADV_DOFORK:
+		new_flags &= ~VM_DONTFORK;
 		break;
 	}
 
@@ -150,6 +157,8 @@ madvise_vma(struct vm_area_struct *vma, 
 	case MADV_NORMAL:
 	case MADV_SEQUENTIAL:
 	case MADV_RANDOM:
+	case MADV_DONTFORK:
+	case MADV_DOFORK:
 		error = madvise_behavior(vma, prev, start, end, behavior);
 		break;
 
Index: linux-2.6.14-dontcopy/include/linux/mm.h
===================================================================
--- linux-2.6.14-dontcopy.orig/include/linux/mm.h	2005-11-08 23:24:58.000000000 +0200
+++ linux-2.6.14-dontcopy/include/linux/mm.h	2005-11-14 16:58:51.000000000 +0200
@@ -162,6 +162,7 @@ extern unsigned int kobjsize(const void 
 #define VM_HUGETLB	0x00400000	/* Huge TLB Page VM */
 #define VM_NONLINEAR	0x00800000	/* Is non-linear (remap_file_pages) */
 #define VM_MAPPED_COPY	0x01000000	/* T if mapped copy of data (nommu mmap) */
+#define VM_DONTFORK	0x02000000      /* App wants to set VM_DONTCOPY */
 
 #ifndef VM_STACK_DEFAULT_FLAGS		/* arch can override this */
 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
Index: linux-2.6.14-dontcopy/include/asm-x86_64/mman.h
===================================================================
--- linux-2.6.14-dontcopy.orig/include/asm-x86_64/mman.h	2005-11-08 23:19:35.000000000 +0200
+++ linux-2.6.14-dontcopy/include/asm-x86_64/mman.h	2005-11-14 16:57:29.000000000 +0200
@@ -36,6 +36,8 @@
 #define MADV_SEQUENTIAL	0x2		/* read-ahead aggressively */
 #define MADV_WILLNEED	0x3		/* pre-fault pages */
 #define MADV_DONTNEED	0x4		/* discard these pages */
+#define MADV_DONTFORK	0x30		/* dont inherit across fork */
+#define MADV_DOFORK	0x31		/* do inherit across fork */
 
 /* compatibility flags */
 #define MAP_ANON	MAP_ANONYMOUS
-- 
MST

  reply	other threads:[~2005-11-14 20:22 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-01 19:30 Petr Vandrovec
2005-11-02  0:34 ` Nick Piggin
2005-11-02  1:17   ` Petr Vandrovec
2005-11-02  2:09     ` Nick Piggin
2005-11-02 12:26     ` Hugh Dickins
2005-11-02 18:06       ` Petr Vandrovec
2005-11-02 21:04       ` Benjamin Herrenschmidt
2005-11-02 21:41         ` Hugh Dickins
2005-11-02 21:45           ` Benjamin Herrenschmidt
2005-11-02 22:02             ` Hugh Dickins
2005-11-02 22:22               ` Benjamin Herrenschmidt
2005-11-03  8:03                 ` Gleb Natapov
2005-11-03 13:32                   ` Hugh Dickins
2005-11-03 13:55                     ` Gleb Natapov
2005-11-03 21:21                       ` Benjamin Herrenschmidt
2005-11-02 22:39               ` Petr Vandrovec
2005-11-03  8:12               ` Gleb Natapov
2005-11-03 14:11                 ` Hugh Dickins
2005-11-03 14:22                   ` Gleb Natapov
2005-11-03 14:37                   ` Michael S. Tsirkin
2005-11-03 14:59                     ` Hugh Dickins
2005-11-03 15:09                       ` Gleb Natapov
2005-11-03 15:14                       ` Michael S. Tsirkin
2005-11-03 15:37                         ` Hugh Dickins
2005-11-03 15:53                           ` Gleb Natapov
2005-11-03 15:56                           ` Michael S. Tsirkin
2005-11-08 21:34                   ` Michael S. Tsirkin
2005-11-10 12:35                     ` Gleb Natapov
2005-11-10 12:48                       ` Michael S. Tsirkin
2005-11-10 12:49                         ` Gleb Natapov
2005-11-10 13:16                           ` Michael S. Tsirkin
2005-11-10 13:16                             ` Gleb Natapov
2005-11-10 13:21                             ` Hugh Dickins
2005-11-10 13:26                               ` Gleb Natapov
2005-11-10 13:15                         ` Hugh Dickins
2005-11-10 13:10                     ` Hugh Dickins
2005-11-10 13:37                       ` Michael S. Tsirkin
2005-11-10 13:55                         ` Hugh Dickins
2005-11-10 14:12                           ` Michael S. Tsirkin
2005-11-14 12:25                       ` Michael S. Tsirkin
2005-11-14 12:27                         ` Gleb Natapov
2005-11-14 12:34                           ` Michael S. Tsirkin
2005-11-14 12:40                             ` Hugh Dickins
2005-11-14 14:57                               ` Michael S. Tsirkin
2005-11-14 15:07                                 ` Gleb Natapov
2005-11-14 12:41                             ` Gleb Natapov
2005-11-14 14:52                       ` Michael S. Tsirkin
2005-11-14 15:00                         ` Gleb Natapov
2005-11-14 20:23                           ` Michael S. Tsirkin [this message]
2005-11-15  9:26                             ` Gleb Natapov
2005-11-14 15:58                         ` Hugh Dickins
2005-11-14 21:17                           ` Michael S. Tsirkin

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=20051114202349.GA3603@mellanox.co.il \
    --to=mst@mellanox.co.il \
    --cc=benh@kernel.crashing.org \
    --cc=gleb@minantech.com \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    --cc=pbadari@us.ibm.com \
    --cc=vandrove@vc.cvut.cz \
    /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

all inboxes | Powered by JetHome®