linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] add MAP_UNLOCKED mmap flag
@ 2009-10-06  9:51 Gleb Natapov
  2009-10-06 10:09 ` Frederik Deweerdt
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06  9:51 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel, linux-api

If application does mlockall(MCL_FUTURE) it is no longer possible to
mmap file bigger than main memory or allocate big area of anonymous
memory. Sometimes it is desirable to lock everything related to program
execution into memory, but still be able to mmap big file or allocate
huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
allows to do that.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/include/asm-generic/mman.h b/include/asm-generic/mman.h
index 32c8bd6..0ab4c74 100644
--- a/include/asm-generic/mman.h
+++ b/include/asm-generic/mman.h
@@ -12,6 +12,7 @@
 #define MAP_NONBLOCK	0x10000		/* do not block on IO */
 #define MAP_STACK	0x20000		/* give out an address that is best suited for process/thread stacks */
 #define MAP_HUGETLB	0x40000		/* create a huge page mapping */
+#define MAP_UNLOKED	0x80000         /* pages are unlocked */
 
 #define MCL_CURRENT	1		/* lock all current mappings */
 #define MCL_FUTURE	2		/* lock all future mappings */
diff --git a/mm/mmap.c b/mm/mmap.c
index 73f5e4b..7c2abdb 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -985,6 +985,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 		if (!can_do_mlock())
 			return -EPERM;
 
+        if (flags & MAP_UNLOKED)
+                vm_flags &= ~VM_LOCKED;
+
 	/* mlock MCL_FUTURE? */
 	if (vm_flags & VM_LOCKED) {
 		unsigned long locked, lock_limit;
--
			Gleb.

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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06  9:51 [PATCH][RFC] add MAP_UNLOCKED mmap flag Gleb Natapov
@ 2009-10-06 10:09 ` Frederik Deweerdt
  2009-10-06 10:11 ` KOSAKI Motohiro
  2009-10-06 10:49 ` Arnd Bergmann
  2 siblings, 0 replies; 16+ messages in thread
From: Frederik Deweerdt @ 2009-10-06 10:09 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: linux-mm, linux-kernel, linux-api

Hello Gleb,

On Tue, Oct 06, 2009 at 11:51:11AM +0200, Gleb Natapov wrote:
> If application does mlockall(MCL_FUTURE) it is no longer possible to
> mmap file bigger than main memory or allocate big area of anonymous
> memory. Sometimes it is desirable to lock everything related to program
> execution into memory, but still be able to mmap big file or allocate
> huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> allows to do that.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> diff --git a/include/asm-generic/mman.h b/include/asm-generic/mman.h
> index 32c8bd6..0ab4c74 100644
> --- a/include/asm-generic/mman.h
> +++ b/include/asm-generic/mman.h
> @@ -12,6 +12,7 @@
>  #define MAP_NONBLOCK	0x10000		/* do not block on IO */
>  #define MAP_STACK	0x20000		/* give out an address that is best suited for process/thread stacks */
>  #define MAP_HUGETLB	0x40000		/* create a huge page mapping */
> +#define MAP_UNLOKED	0x80000         /* pages are unlocked */
                 ^^^
You're missing a 'C' here and below. Also '/* force page unlocking */'
seems a better comment?

Regards,
Frederik
>  
>  #define MCL_CURRENT	1		/* lock all current mappings */
>  #define MCL_FUTURE	2		/* lock all future mappings */
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 73f5e4b..7c2abdb 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -985,6 +985,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  		if (!can_do_mlock())
>  			return -EPERM;
>  
> +        if (flags & MAP_UNLOKED)
> +                vm_flags &= ~VM_LOCKED;
> +
>  	/* mlock MCL_FUTURE? */
>  	if (vm_flags & VM_LOCKED) {
>  		unsigned long locked, lock_limit;
> --
> 			Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06  9:51 [PATCH][RFC] add MAP_UNLOCKED mmap flag Gleb Natapov
  2009-10-06 10:09 ` Frederik Deweerdt
@ 2009-10-06 10:11 ` KOSAKI Motohiro
  2009-10-06 10:21   ` Gleb Natapov
  2009-10-06 10:49 ` Arnd Bergmann
  2 siblings, 1 reply; 16+ messages in thread
From: KOSAKI Motohiro @ 2009-10-06 10:11 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kosaki.motohiro, linux-mm, linux-kernel, linux-api

Hi

> If application does mlockall(MCL_FUTURE) it is no longer possible to
> mmap file bigger than main memory or allocate big area of anonymous
> memory. Sometimes it is desirable to lock everything related to program
> execution into memory, but still be able to mmap big file or allocate
> huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> allows to do that.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>

Why don't you use explicit munlock()?
Plus, Can you please elabrate which workload nedd this feature?



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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 10:11 ` KOSAKI Motohiro
@ 2009-10-06 10:21   ` Gleb Natapov
  2009-10-06 10:27     ` KOSAKI Motohiro
  0 siblings, 1 reply; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06 10:21 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 07:11:06PM +0900, KOSAKI Motohiro wrote:
> Hi
> 
> > If application does mlockall(MCL_FUTURE) it is no longer possible to
> > mmap file bigger than main memory or allocate big area of anonymous
> > memory. Sometimes it is desirable to lock everything related to program
> > execution into memory, but still be able to mmap big file or allocate
> > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> > allows to do that.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> 
> Why don't you use explicit munlock()?
Because mmap will fail before I'll have a chance to run munlock on it.
Actually when I run my process inside memory limited container host dies
(I suppose trashing, but haven't checked).

> Plus, Can you please elabrate which workload nedd this feature?
> 
I wanted to run kvm with qemu process locked in memory, but guest memory
unlocked. And guest memory is bigger then host memory in the case I am
testing. I found out that it is impossible currently.

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 10:21   ` Gleb Natapov
@ 2009-10-06 10:27     ` KOSAKI Motohiro
  2009-10-06 10:33       ` Gleb Natapov
  0 siblings, 1 reply; 16+ messages in thread
From: KOSAKI Motohiro @ 2009-10-06 10:27 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kosaki.motohiro, linux-mm, linux-kernel, linux-api

> On Tue, Oct 06, 2009 at 07:11:06PM +0900, KOSAKI Motohiro wrote:
> > Hi
> > 
> > > If application does mlockall(MCL_FUTURE) it is no longer possible to
> > > mmap file bigger than main memory or allocate big area of anonymous
> > > memory. Sometimes it is desirable to lock everything related to program
> > > execution into memory, but still be able to mmap big file or allocate
> > > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> > > allows to do that.
> > > 
> > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > 
> > Why don't you use explicit munlock()?
> Because mmap will fail before I'll have a chance to run munlock on it.
> Actually when I run my process inside memory limited container host dies
> (I suppose trashing, but haven't checked).
> 
> > Plus, Can you please elabrate which workload nedd this feature?
> > 
> I wanted to run kvm with qemu process locked in memory, but guest memory
> unlocked. And guest memory is bigger then host memory in the case I am
> testing. I found out that it is impossible currently.

1. process creation (qemu)
2. load all library
3. mlockall(MCL_CURRENT)
4. load guest OS

is impossible? why?




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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 10:27     ` KOSAKI Motohiro
@ 2009-10-06 10:33       ` Gleb Natapov
  2009-10-06 12:10         ` KOSAKI Motohiro
  0 siblings, 1 reply; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06 10:33 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 07:27:56PM +0900, KOSAKI Motohiro wrote:
> > On Tue, Oct 06, 2009 at 07:11:06PM +0900, KOSAKI Motohiro wrote:
> > > Hi
> > > 
> > > > If application does mlockall(MCL_FUTURE) it is no longer possible to
> > > > mmap file bigger than main memory or allocate big area of anonymous
> > > > memory. Sometimes it is desirable to lock everything related to program
> > > > execution into memory, but still be able to mmap big file or allocate
> > > > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> > > > allows to do that.
> > > > 
> > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > 
> > > Why don't you use explicit munlock()?
> > Because mmap will fail before I'll have a chance to run munlock on it.
> > Actually when I run my process inside memory limited container host dies
> > (I suppose trashing, but haven't checked).
> > 
> > > Plus, Can you please elabrate which workload nedd this feature?
> > > 
> > I wanted to run kvm with qemu process locked in memory, but guest memory
> > unlocked. And guest memory is bigger then host memory in the case I am
> > testing. I found out that it is impossible currently.
> 
> 1. process creation (qemu)
> 2. load all library
Can't control this if program has plugging. Not qemu case
though.

> 3. mlockall(MCL_CURRENT)
> 4. load guest OS
And what about all other allocations qemu does during its life time? Not
all of them will be small enough to be from brk area.

> 
> is impossible? why?
> 
Because what you are proposing is not the same as mlockall(MCL_CURRENT|MCL_FUTURE);
You essentially say that MCL_FUTURE is not needed.

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06  9:51 [PATCH][RFC] add MAP_UNLOCKED mmap flag Gleb Natapov
  2009-10-06 10:09 ` Frederik Deweerdt
  2009-10-06 10:11 ` KOSAKI Motohiro
@ 2009-10-06 10:49 ` Arnd Bergmann
  2009-10-06 11:00   ` Gleb Natapov
  2 siblings, 1 reply; 16+ messages in thread
From: Arnd Bergmann @ 2009-10-06 10:49 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: linux-mm, linux-kernel, linux-api

On Tuesday 06 October 2009, Gleb Natapov wrote:
> If application does mlockall(MCL_FUTURE) it is no longer possible to
> mmap file bigger than main memory or allocate big area of anonymous
> memory. Sometimes it is desirable to lock everything related to program
> execution into memory, but still be able to mmap big file or allocate
> huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> allows to do that.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> diff --git a/include/asm-generic/mman.h b/include/asm-generic/mman.h
> index 32c8bd6..0ab4c74 100644
> --- a/include/asm-generic/mman.h
> +++ b/include/asm-generic/mman.h
> @@ -12,6 +12,7 @@
>  #define MAP_NONBLOCK   0x10000         /* do not block on IO */
>  #define MAP_STACK      0x20000         /* give out an address that is best suited for process/thread stacks */
>  #define MAP_HUGETLB    0x40000         /* create a huge page mapping */
> +#define MAP_UNLOKED    0x80000         /* pages are unlocked */
>  
>  #define MCL_CURRENT    1               /* lock all current mappings */
>  #define MCL_FUTURE     2               /* lock all future mappings */

Not all architectures use asm-generic/mman.h, so you have to change
the other architectures separately if you add a flag.

	Arnd <><

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 10:49 ` Arnd Bergmann
@ 2009-10-06 11:00   ` Gleb Natapov
  0 siblings, 0 replies; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06 11:00 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 12:49:52PM +0200, Arnd Bergmann wrote:
> On Tuesday 06 October 2009, Gleb Natapov wrote:
> > If application does mlockall(MCL_FUTURE) it is no longer possible to
> > mmap file bigger than main memory or allocate big area of anonymous
> > memory. Sometimes it is desirable to lock everything related to program
> > execution into memory, but still be able to mmap big file or allocate
> > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> > allows to do that.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > diff --git a/include/asm-generic/mman.h b/include/asm-generic/mman.h
> > index 32c8bd6..0ab4c74 100644
> > --- a/include/asm-generic/mman.h
> > +++ b/include/asm-generic/mman.h
> > @@ -12,6 +12,7 @@
> >  #define MAP_NONBLOCK   0x10000         /* do not block on IO */
> >  #define MAP_STACK      0x20000         /* give out an address that is best suited for process/thread stacks */
> >  #define MAP_HUGETLB    0x40000         /* create a huge page mapping */
> > +#define MAP_UNLOKED    0x80000         /* pages are unlocked */
> >  
> >  #define MCL_CURRENT    1               /* lock all current mappings */
> >  #define MCL_FUTURE     2               /* lock all future mappings */
> 
> Not all architectures use asm-generic/mman.h, so you have to change
> the other architectures separately if you add a flag.
> 
Ah, good to know. Thanks.

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 10:33       ` Gleb Natapov
@ 2009-10-06 12:10         ` KOSAKI Motohiro
  2009-10-06 12:16           ` Gleb Natapov
  0 siblings, 1 reply; 16+ messages in thread
From: KOSAKI Motohiro @ 2009-10-06 12:10 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: linux-mm, linux-kernel, linux-api

2009/10/6 Gleb Natapov <gleb@redhat.com>:
> On Tue, Oct 06, 2009 at 07:27:56PM +0900, KOSAKI Motohiro wrote:
>> > On Tue, Oct 06, 2009 at 07:11:06PM +0900, KOSAKI Motohiro wrote:
>> > > Hi
>> > >
>> > > > If application does mlockall(MCL_FUTURE) it is no longer possible to
>> > > > mmap file bigger than main memory or allocate big area of anonymous
>> > > > memory. Sometimes it is desirable to lock everything related to program
>> > > > execution into memory, but still be able to mmap big file or allocate
>> > > > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
>> > > > allows to do that.
>> > > >
>> > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
>> > >
>> > > Why don't you use explicit munlock()?
>> > Because mmap will fail before I'll have a chance to run munlock on it.
>> > Actually when I run my process inside memory limited container host dies
>> > (I suppose trashing, but haven't checked).
>> >
>> > > Plus, Can you please elabrate which workload nedd this feature?
>> > >
>> > I wanted to run kvm with qemu process locked in memory, but guest memory
>> > unlocked. And guest memory is bigger then host memory in the case I am
>> > testing. I found out that it is impossible currently.
>>
>> 1. process creation (qemu)
>> 2. load all library
> Can't control this if program has plugging. Not qemu case
> though.
>
>> 3. mlockall(MCL_CURRENT)
>> 4. load guest OS
> And what about all other allocations qemu does during its life time? Not
> all of them will be small enough to be from brk area.
>
>> is impossible? why?
>>
> Because what you are proposing is not the same as mlockall(MCL_CURRENT|MCL_FUTURE);
>
> You essentially say that MCL_FUTURE is not needed.

No, I only think your case doesn't fit MC_FUTURE.
I haven't find any real benefit in this patch.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 12:10         ` KOSAKI Motohiro
@ 2009-10-06 12:16           ` Gleb Natapov
  2009-10-06 13:50             ` Peter Zijlstra
  2009-10-07 18:50             ` Olivier Galibert
  0 siblings, 2 replies; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06 12:16 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 09:10:35PM +0900, KOSAKI Motohiro wrote:
> 2009/10/6 Gleb Natapov <gleb@redhat.com>:
> > On Tue, Oct 06, 2009 at 07:27:56PM +0900, KOSAKI Motohiro wrote:
> >> > On Tue, Oct 06, 2009 at 07:11:06PM +0900, KOSAKI Motohiro wrote:
> >> > > Hi
> >> > >
> >> > > > If application does mlockall(MCL_FUTURE) it is no longer possible to
> >> > > > mmap file bigger than main memory or allocate big area of anonymous
> >> > > > memory. Sometimes it is desirable to lock everything related to program
> >> > > > execution into memory, but still be able to mmap big file or allocate
> >> > > > huge amount of memory and allow OS to swap them on demand. MAP_UNLOCKED
> >> > > > allows to do that.
> >> > > >
> >> > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> >> > >
> >> > > Why don't you use explicit munlock()?
> >> > Because mmap will fail before I'll have a chance to run munlock on it.
> >> > Actually when I run my process inside memory limited container host dies
> >> > (I suppose trashing, but haven't checked).
> >> >
> >> > > Plus, Can you please elabrate which workload nedd this feature?
> >> > >
> >> > I wanted to run kvm with qemu process locked in memory, but guest memory
> >> > unlocked. And guest memory is bigger then host memory in the case I am
> >> > testing. I found out that it is impossible currently.
> >>
> >> 1. process creation (qemu)
> >> 2. load all library
> > Can't control this if program has plugging. Not qemu case
> > though.
> >
> >> 3. mlockall(MCL_CURRENT)
> >> 4. load guest OS
> > And what about all other allocations qemu does during its life time? Not
> > all of them will be small enough to be from brk area.
> >
> >> is impossible? why?
> >>
> > Because what you are proposing is not the same as mlockall(MCL_CURRENT|MCL_FUTURE);
> >
> > You essentially say that MCL_FUTURE is not needed.
> 
> No, I only think your case doesn't fit MC_FUTURE.
> I haven't find any real benefit in this patch.
I did. It allows me to achieve something I can't now. Steps you provide
just don't fit my needs. I need all memory areas (current and feature) to be
locked except one. Very big one. You propose to lock memory at some
arbitrary point and from that point on all newly mapped memory areas will
be unlocked. Don't you see it is different?

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 12:16           ` Gleb Natapov
@ 2009-10-06 13:50             ` Peter Zijlstra
  2009-10-06 14:06               ` Gleb Natapov
  2009-10-07 18:50             ` Olivier Galibert
  1 sibling, 1 reply; 16+ messages in thread
From: Peter Zijlstra @ 2009-10-06 13:50 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: KOSAKI Motohiro, linux-mm, linux-kernel, linux-api

On Tue, 2009-10-06 at 14:16 +0200, Gleb Natapov wrote:
> > No, I only think your case doesn't fit MC_FUTURE.
> > I haven't find any real benefit in this patch.

> I did. It allows me to achieve something I can't now. Steps you provide
> just don't fit my needs. I need all memory areas (current and feature) to be
> locked except one. Very big one. You propose to lock memory at some
> arbitrary point and from that point on all newly mapped memory areas will
> be unlocked. Don't you see it is different?

While true, it does demonstrates very sloppy programming. The proper fix
is to rework qemu to mlock what is needed.

I'm not sure encouraging mlockall() usage is a good thing. When using
resource locks one had better know what he's doing. mlockall() doesn't
promote caution.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 13:50             ` Peter Zijlstra
@ 2009-10-06 14:06               ` Gleb Natapov
  0 siblings, 0 replies; 16+ messages in thread
From: Gleb Natapov @ 2009-10-06 14:06 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: KOSAKI Motohiro, linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 03:50:03PM +0200, Peter Zijlstra wrote:
> On Tue, 2009-10-06 at 14:16 +0200, Gleb Natapov wrote:
> > > No, I only think your case doesn't fit MC_FUTURE.
> > > I haven't find any real benefit in this patch.
> 
> > I did. It allows me to achieve something I can't now. Steps you provide
> > just don't fit my needs. I need all memory areas (current and feature) to be
> > locked except one. Very big one. You propose to lock memory at some
> > arbitrary point and from that point on all newly mapped memory areas will
> > be unlocked. Don't you see it is different?
> 
> While true, it does demonstrates very sloppy programming. The proper fix
> is to rework qemu to mlock what is needed.
> 
So you are saying for application (any application forget about qemu) to lock
everything except one memory region it needs to provide its own memory allocation
routings and its own dynamic linker? BTW the interface is not symmetric currently.
Application may mmap single memory area locked (MAP_LOCKED), but can't do reverse
if mlockall(MC_FUTURE) was called.

> I'm not sure encouraging mlockall() usage is a good thing. When using
This is up to application programmer to decide whether he wants to use
mlockall() or not. May be he has a good reason do so. As it stands the
existing interface doesn't allow to do what I need without rewriting
libc memory allocator and dynamic linking loader.

> resource locks one had better know what he's doing. mlockall() doesn't
> promote caution.
No need to patronize userspace developers. Lets provide them with
flexible interface and if they'll use it inappropriately we will not use
their software.

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-06 12:16           ` Gleb Natapov
  2009-10-06 13:50             ` Peter Zijlstra
@ 2009-10-07 18:50             ` Olivier Galibert
  2009-10-07 18:59               ` Gleb Natapov
  1 sibling, 1 reply; 16+ messages in thread
From: Olivier Galibert @ 2009-10-07 18:50 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: KOSAKI Motohiro, linux-mm, linux-kernel, linux-api

On Tue, Oct 06, 2009 at 02:16:03PM +0200, Gleb Natapov wrote:
> I did. It allows me to achieve something I can't now. Steps you provide
> just don't fit my needs. I need all memory areas (current and feature) to be
> locked except one. Very big one. You propose to lock memory at some
> arbitrary point and from that point on all newly mapped memory areas will
> be unlocked. Don't you see it is different?

What about mlockall(MCL_CURRENT); mmap(...); mlockall(MCL_FUTURE);?
Or toggle MCL_FUTURE if a mlockall call can stop it?

  OG.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-07 18:50             ` Olivier Galibert
@ 2009-10-07 18:59               ` Gleb Natapov
  2009-10-07 20:10                 ` Olivier Galibert
  0 siblings, 1 reply; 16+ messages in thread
From: Gleb Natapov @ 2009-10-07 18:59 UTC (permalink / raw)
  To: Olivier Galibert, KOSAKI Motohiro, linux-mm, linux-kernel,
	linux-api

On Wed, Oct 07, 2009 at 08:50:54PM +0200, Olivier Galibert wrote:
> On Tue, Oct 06, 2009 at 02:16:03PM +0200, Gleb Natapov wrote:
> > I did. It allows me to achieve something I can't now. Steps you provide
> > just don't fit my needs. I need all memory areas (current and feature) to be
> > locked except one. Very big one. You propose to lock memory at some
> > arbitrary point and from that point on all newly mapped memory areas will
> > be unlocked. Don't you see it is different?
> 
> What about mlockall(MCL_CURRENT); mmap(...); mlockall(MCL_FUTURE);?
> Or toggle MCL_FUTURE if a mlockall call can stop it?
> 
This may work. And MCL_FUTURE can be toggled, but this is not thread
safe.
 
--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-07 18:59               ` Gleb Natapov
@ 2009-10-07 20:10                 ` Olivier Galibert
  2009-10-07 20:47                   ` Gleb Natapov
  0 siblings, 1 reply; 16+ messages in thread
From: Olivier Galibert @ 2009-10-07 20:10 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: KOSAKI Motohiro, linux-mm, linux-kernel, linux-api

On Wed, Oct 07, 2009 at 08:59:52PM +0200, Gleb Natapov wrote:
> On Wed, Oct 07, 2009 at 08:50:54PM +0200, Olivier Galibert wrote:
> > On Tue, Oct 06, 2009 at 02:16:03PM +0200, Gleb Natapov wrote:
> > > I did. It allows me to achieve something I can't now. Steps you provide
> > > just don't fit my needs. I need all memory areas (current and feature) to be
> > > locked except one. Very big one. You propose to lock memory at some
> > > arbitrary point and from that point on all newly mapped memory areas will
> > > be unlocked. Don't you see it is different?
> > 
> > What about mlockall(MCL_CURRENT); mmap(...); mlockall(MCL_FUTURE);?
> > Or toggle MCL_FUTURE if a mlockall call can stop it?
> > 
> This may work. And MCL_FUTURE can be toggled, but this is not thread
> safe.

Just ensure that your one special mmap is done with the other threads
not currently allocating stuff.  It's probably a synchronization point
for the whole process anyway.

  OG.


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH][RFC] add MAP_UNLOCKED mmap flag
  2009-10-07 20:10                 ` Olivier Galibert
@ 2009-10-07 20:47                   ` Gleb Natapov
  0 siblings, 0 replies; 16+ messages in thread
From: Gleb Natapov @ 2009-10-07 20:47 UTC (permalink / raw)
  To: Olivier Galibert, KOSAKI Motohiro, linux-mm, linux-kernel,
	linux-api

On Wed, Oct 07, 2009 at 10:10:17PM +0200, Olivier Galibert wrote:
> On Wed, Oct 07, 2009 at 08:59:52PM +0200, Gleb Natapov wrote:
> > On Wed, Oct 07, 2009 at 08:50:54PM +0200, Olivier Galibert wrote:
> > > On Tue, Oct 06, 2009 at 02:16:03PM +0200, Gleb Natapov wrote:
> > > > I did. It allows me to achieve something I can't now. Steps you provide
> > > > just don't fit my needs. I need all memory areas (current and feature) to be
> > > > locked except one. Very big one. You propose to lock memory at some
> > > > arbitrary point and from that point on all newly mapped memory areas will
> > > > be unlocked. Don't you see it is different?
> > > 
> > > What about mlockall(MCL_CURRENT); mmap(...); mlockall(MCL_FUTURE);?
> > > Or toggle MCL_FUTURE if a mlockall call can stop it?
> > > 
> > This may work. And MCL_FUTURE can be toggled, but this is not thread
> > safe.
> 
> Just ensure that your one special mmap is done with the other threads
> not currently allocating stuff.  It's probably a synchronization point
> for the whole process anyway.
> 
How can you stop other threads and libraries from calling malloc()? And if
it is two special allocations? Or many mmap(big file)/munmap(big file)?
This is the same issue as opening file CLOEXEC atomically. Why not
prevent other thread from calling fork() instead of adding flags to
bunch of system calls.

--
			Gleb.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-10-07 20:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-06  9:51 [PATCH][RFC] add MAP_UNLOCKED mmap flag Gleb Natapov
2009-10-06 10:09 ` Frederik Deweerdt
2009-10-06 10:11 ` KOSAKI Motohiro
2009-10-06 10:21   ` Gleb Natapov
2009-10-06 10:27     ` KOSAKI Motohiro
2009-10-06 10:33       ` Gleb Natapov
2009-10-06 12:10         ` KOSAKI Motohiro
2009-10-06 12:16           ` Gleb Natapov
2009-10-06 13:50             ` Peter Zijlstra
2009-10-06 14:06               ` Gleb Natapov
2009-10-07 18:50             ` Olivier Galibert
2009-10-07 18:59               ` Gleb Natapov
2009-10-07 20:10                 ` Olivier Galibert
2009-10-07 20:47                   ` Gleb Natapov
2009-10-06 10:49 ` Arnd Bergmann
2009-10-06 11:00   ` Gleb Natapov

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).