mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Sam Vilain <sam@vilain.net>, "Serge E. Hallyn" <serue@us.ibm.com>,
	linux-kernel@vger.kernel.org, dev@sw.ru, herbert@13thfloor.at,
	devel@openvz.org, xemul@sw.ru, Dave Hansen <haveblue@us.ibm.com>,
	Andrew Morton <akpm@osdl.org>, Cedric Le Goater <clg@fr.ibm.com>
Subject: Re: [PATCH 1/9] namespaces: add nsproxy
Date: Mon, 22 May 2006 07:39:19 -0500	[thread overview]
Message-ID: <20060522123919.GC6025@sergelap.austin.ibm.com> (raw)
In-Reply-To: <m11wunne30.fsf@ebiederm.dsl.xmission.com>

Quoting Eric W. Biederman (ebiederm@xmission.com):
> Sam Vilain <sam@vilain.net> writes:
> 
> > Serge E. Hallyn wrote:
> >
> >>@@ -1585,7 +1591,15 @@ asmlinkage long sys_unshare(unsigned lon
> >> 
> >> 	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist) {
> >> 
> >>+		old_nsproxy = current->nsproxy;
> >>+		new_nsproxy = dup_namespaces(old_nsproxy);
> >>+		if (!new_nsproxy) {
> >>+			err = -ENOMEM;
> >>+			goto bad_unshare_cleanup_semundo;
> >>+		}
> >>+
> >> 		task_lock(current);
> >>  
> >>
> >
> > We'll get lots of duplicate nsproxy structures before we move all of the
> > pointers for those subsystems into it. Do we need to dup namespaces on
> > all of those conditions?
> 
> Ugh.  Good catch.  The new nsproxy needs to be just for the fs and the uts
> namespace.  
> 
> I guess that means that test should be moved up a few lines.

Oh.  Yeah.  It didn't look odd to me bc it's about the number of
namespaces we are *going* to have  :)

Fix follows:

Subject: [PATCH] uts: copy nsproxy only when needed.
From: Serge Hallyn <serue@us.ibm.com>

The nsproxy was being copied in unshare() when anything was being
unshared, even if it was something not referenced from nsproxy.
This should end up in some cases with far more memory usage than
necessary.

Signed-off-by: Serge Hallyn <serue@us.ibm.com>

---

 kernel/fork.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

74d1068458c62302ac8ed38e38a57b692580662f
diff --git a/kernel/fork.c b/kernel/fork.c
index cdc549e..9278a68 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1559,7 +1559,7 @@ asmlinkage long sys_unshare(unsigned lon
 	struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
 	struct files_struct *fd, *new_fd = NULL;
 	struct sem_undo_list *new_ulist = NULL;
-	struct nsproxy *new_nsproxy, *old_nsproxy;
+	struct nsproxy *new_nsproxy = NULL, *old_nsproxy = NULL;
 	struct uts_namespace *uts, *new_uts = NULL;
 
 	check_unshare_flags(&unshare_flags);
@@ -1587,18 +1587,24 @@ asmlinkage long sys_unshare(unsigned lon
 	if ((err = unshare_utsname(unshare_flags, &new_uts)))
 		goto bad_unshare_cleanup_semundo;
 
-	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist ||
-				new_uts) {
-
+	if (new_ns || new_uts) {
 		old_nsproxy = current->nsproxy;
 		new_nsproxy = dup_namespaces(old_nsproxy);
 		if (!new_nsproxy) {
 			err = -ENOMEM;
 			goto bad_unshare_cleanup_uts;
 		}
+	}
+
+	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist ||
+				new_uts) {
 
 		task_lock(current);
-		current->nsproxy = new_nsproxy;
+
+		if (new_nsproxy) {
+			current->nsproxy = new_nsproxy;
+			new_nsproxy = old_nsproxy;
+		}
 
 		if (new_fs) {
 			fs = current->fs;
@@ -1640,9 +1646,11 @@ asmlinkage long sys_unshare(unsigned lon
 		}
 
 		task_unlock(current);
-		put_nsproxy(old_nsproxy);
 	}
 
+	if (new_nsproxy)
+		put_nsproxy(new_nsproxy);
+
 bad_unshare_cleanup_uts:
 	if (new_uts)
 		put_uts_ns(new_uts);
-- 
1.1.6

  reply	other threads:[~2006-05-22 12:39 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-18 15:47 [PATCH 0/9] namespaces: Introduction Serge E. Hallyn
2006-05-18 15:48 ` [PATCH 1/9] namespaces: add nsproxy Serge E. Hallyn
2006-05-21 23:30   ` Sam Vilain
2006-05-21 23:38     ` Eric W. Biederman
2006-05-22 12:39       ` Serge E. Hallyn [this message]
2006-05-18 15:49 ` [PATCH 2/9] namespaces: incorporate fs namespace into nsproxy Serge E. Hallyn
2006-05-18 15:49 ` [PATCH 3/9] namespaces: utsname: introduce temporary helpers Serge E. Hallyn
2006-05-18 15:49 ` [PATCH 4/9] namespaces: utsname: switch to using uts namespaces Serge E. Hallyn
2006-05-19  0:02   ` Randy.Dunlap
2006-05-19  2:21     ` Serge E. Hallyn
2006-05-19  2:45       ` Randy.Dunlap
2006-05-19  3:12       ` Sam Vilain
2006-05-19  9:05     ` Eric W. Biederman
2006-05-19 17:39       ` Randy.Dunlap
2006-05-19 11:58     ` Eric W. Biederman
2006-05-22 19:43     ` Cedric Le Goater
2006-05-22 20:19       ` Randy.Dunlap
2006-05-22  0:19   ` Sam Vilain
2006-05-18 15:49 ` [PATCH 5/9] namespaces: utsname: use init_utsname when appropriate Serge E. Hallyn
2006-05-18 15:50 ` [PATCH 6/9] namespaces: utsname: implement utsname namespaces Serge E. Hallyn
2006-05-18 15:50 ` [PATCH 7/9] namespaces: utsname: sysctl hack Serge E. Hallyn
2006-05-18 15:50 ` [PATCH 8/9] namespaces: utsname: remove system_utsname Serge E. Hallyn
2006-05-18 23:03   ` Paul Mackerras
2006-05-18 23:04     ` Paul Mackerras
2006-05-18 15:51 ` [PATCH 9/9] namespaces: utsname: implement CLONE_NEWUTS flag Serge E. Hallyn
2006-05-18 17:34 ` [PATCH 0/9] namespaces: Introduction Andrew Morton
2006-05-18 19:23   ` John Kelly
2006-05-18 23:28   ` Sam Vilain
2006-05-18 23:43     ` Sam Vilain
2006-05-19  4:24     ` Paul Jackson
2006-05-19  9:23       ` Eric W. Biederman
2006-05-19 11:41   ` Eric W. Biederman
2006-05-19 17:52     ` Jeff Dike
2006-05-20  0:16     ` Sam Vilain
2006-05-19 12:42   ` Herbert Poetzl
2006-05-19 15:13     ` Andrew Morton
2006-05-19 16:27       ` Eric W. Biederman
2006-05-19 16:40         ` Andrew Morton
2006-05-19 17:15           ` Stephen Hemminger
2006-05-19 20:17           ` Dave Hansen
2006-05-19 20:52             ` Alexey Kuznetsov
2006-05-19 18:28         ` Hua Zhong
2006-05-19 19:38           ` Serge E. Hallyn
2006-05-19 19:45           ` John Kelly
2006-05-19 20:23             ` John Kelly
2006-05-19 20:04       ` Dave Hansen
2006-05-20  3:18         ` Eric W. Biederman
2006-05-21  0:48         ` Eric W. Biederman
2006-05-21 22:57       ` Pavel Machek
2006-05-21 23:18         ` Eric W. Biederman
2006-05-21 23:32           ` Herbert Poetzl
2006-05-22 16:54             ` Eric W. Biederman
2006-05-19 13:47   ` Andrey Savochkin
2006-05-19 15:25     ` Andrew Morton
2006-05-20 21:24       ` Herbert Poetzl
2006-05-22 17:23       ` Eric W. Biederman
2006-05-20  0:16     ` Sam Vilain
2006-05-19  8:50 ` Eric W. Biederman
2006-05-19 13:30   ` Serge E. Hallyn
2006-05-21 16:27   ` Serge E. Hallyn
2006-05-21 18:08     ` Eric W. Biederman
2006-05-22 12:10       ` Serge E. Hallyn
2006-05-22 16:44         ` Eric W. Biederman

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=20060522123919.GC6025@sergelap.austin.ibm.com \
    --to=serue@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=clg@fr.ibm.com \
    --cc=dev@sw.ru \
    --cc=devel@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=haveblue@us.ibm.com \
    --cc=herbert@13thfloor.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@vilain.net \
    --cc=xemul@sw.ru \
    /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®