linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fork: dup_mm: init vm stat counters under mmap_sem
@ 2014-06-18 13:33 Vladimir Davydov
  2014-06-18 15:22 ` Oleg Nesterov
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Davydov @ 2014-06-18 13:33 UTC (permalink / raw)
  To: akpm; +Cc: oleg, rientjes, cl, linux-mm, linux-kernel

If a forking process has a thread calling (un)mmap (silly but still),
the child process may have some of its mm's vm stats (total_vm and
friends) screwed up, because currently they are copied from oldmm w/o
holding any locks (see dup_mm).

This patch moves the stats initialization to dup_mmap to be called under
oldmm->mmap_sem, which eliminates any possibility of race.

Also, mm->pinned_vm is not reset on fork. Let's fix it.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
---
 kernel/fork.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/fork.c b/kernel/fork.c
index d2799d1fc952..eaacc75da4f7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -365,7 +365,12 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	 */
 	down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING);
 
+	mm->total_vm = oldmm->total_vm;
 	mm->locked_vm = 0;
+	mm->pinned_vm = 0;
+	mm->shared_vm = oldmm->shared_vm;
+	mm->exec_vm = oldmm->exec_vm;
+	mm->stack_vm = oldmm->stack_vm;
 	mm->mmap = NULL;
 	mm->vmacache_seqnum = 0;
 	mm->map_count = 0;
-- 
1.7.10.4

--
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] 3+ messages in thread

* Re: [PATCH] fork: dup_mm: init vm stat counters under mmap_sem
  2014-06-18 13:33 [PATCH] fork: dup_mm: init vm stat counters under mmap_sem Vladimir Davydov
@ 2014-06-18 15:22 ` Oleg Nesterov
  2014-06-19  7:14   ` Vladimir Davydov
  0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2014-06-18 15:22 UTC (permalink / raw)
  To: Vladimir Davydov; +Cc: akpm, rientjes, cl, linux-mm, linux-kernel

On 06/18, Vladimir Davydov wrote:
>
> @@ -365,7 +365,12 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>  	 */
>  	down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING);
>  
> +	mm->total_vm = oldmm->total_vm;
>  	mm->locked_vm = 0;
> +	mm->pinned_vm = 0;
> +	mm->shared_vm = oldmm->shared_vm;
> +	mm->exec_vm = oldmm->exec_vm;
> +	mm->stack_vm = oldmm->stack_vm;
>  	mm->mmap = NULL;
>  	mm->vmacache_seqnum = 0;
>  	mm->map_count = 0;

I think the patch is fine.


But perhaps this deserves more cleanups, with or without this patch
the initialization does not look consistent. dup_mmap() nullifies
locked_vm/pinned_vm/mmap/map_count while mm_init() clears core_state/
nr_ptes/rss_stat.

Oleg.

--
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] 3+ messages in thread

* Re: [PATCH] fork: dup_mm: init vm stat counters under mmap_sem
  2014-06-18 15:22 ` Oleg Nesterov
@ 2014-06-19  7:14   ` Vladimir Davydov
  0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Davydov @ 2014-06-19  7:14 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: akpm, rientjes, cl, linux-mm, linux-kernel

On Wed, Jun 18, 2014 at 05:22:09PM +0200, Oleg Nesterov wrote:
> But perhaps this deserves more cleanups, with or without this patch
> the initialization does not look consistent. dup_mmap() nullifies
> locked_vm/pinned_vm/mmap/map_count while mm_init() clears core_state/
> nr_ptes/rss_stat.

Agree. Will try to clean this up.

Thanks.

--
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] 3+ messages in thread

end of thread, other threads:[~2014-06-19  7:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-18 13:33 [PATCH] fork: dup_mm: init vm stat counters under mmap_sem Vladimir Davydov
2014-06-18 15:22 ` Oleg Nesterov
2014-06-19  7:14   ` Vladimir Davydov

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