git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Should we discuss Windows-related changes on git@vger.kernel.org?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 12, 2008, 01:07 UTC
Message-ID
<alpine.LFD.1.10.0807111750200.2875@woody.linux-foundation.org>
In-Reply-To
<alpine.LFD.1.10.0807111653500.2875@woody.linux-foundation.org>
On Fri, 11 Jul 2008, Linus Torvalds wrote:
> 
> If it's something that should be merged, and if it concerns code that I'm 
> interested in, I want to know about it. It's that simple.

Btw, an example of where I think we need to look at both windows and unix behavior and not try to make them two different camps is in that "start_command()" thing.

It was changed to have a totally separate __MINGW32__ part, but the thing is, the unix side could really be improved - and actually made more like the MINGW32 code at the same time!

For example, on many systems it is rather noticeably faster to use "vfork+execve" than it is to do "fork+execve", because you avoid a whole "duplicate and tear down page tables" sequence. So the UNIX code would actually be better off using "vfork()" instead of "fork()" there.

But it can't right now - because if "cmd->env" changes the environment, it would change it both in the caller and in the result.

It turns out that Windows has the exact same issue (because it uses a spawn thing), and already does a "copy_env() + change-in-copy + free" model for that reason.

If that was shared, the UNIX side could just use vfork, I believe. In fact, the following trivial - but horribly ugly - patch passes all the tests, by doing the vfork() in all cases except when the environment changes. But I don't know what coverage that has, though (maybe env is effectively always set?).

And I suspect there are other cases where we'd actually be better off trying to share things than having all the differences hidden away in compat layers.

			Linus
---
 builtin-grep.c |    2 +-
 run-command.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index ef29910..5d3053a 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -168,7 +168,7 @@ static int exec_grep(int argc, const char **argv)
 	int status;
 
 	argv[argc] = NULL;
-	pid = fork();
+	pid = vfork();
 	if (pid < 0)
 		return pid;
 	if (!pid) {
diff --git a/run-command.c b/run-command.c
index 6e29fdf..200ba7b 100644
--- a/run-command.c
+++ b/run-command.c
@@ -68,7 +68,7 @@ int start_command(struct child_process *cmd)
 	trace_argv_printf(cmd->argv, "trace: run_command:");
 
 #ifndef __MINGW32__
-	cmd->pid = fork();
+	cmd->pid = cmd->env ? fork() : vfork();
 	if (!cmd->pid) {
 		if (cmd->no_stdin)
 			dup_devnull(0);
Previous: Johannes SchindelinNext: Steffen Prohaska
Message 20 of 21 in “Should we discuss Windows-related changes on git@vger.kernel.org?”
  1. Steffen ProhaskaJul 11, 2008
  2. Johannes SchindelinJul 11, 2008
  3. Steffen ProhaskaJul 11, 2008
  4. Johannes SchindelinJul 11, 2008
  5. Steffen ProhaskaJul 11, 2008
  6. Johannes SchindelinJul 11, 2008
  7. Linus TorvaldsJul 11, 2008
  8. Johannes SchindelinJul 11, 2008
  9. Steffen ProhaskaJul 11, 2008
  10. Johannes SchindelinJul 11, 2008
  11. Junio C HamanoJul 11, 2008
  12. Johannes SchindelinJul 11, 2008
  13. Steffen ProhaskaJul 12, 2008
  14. Junio C HamanoJul 11, 2008
  15. Johannes SchindelinJul 11, 2008
  16. Linus TorvaldsJul 11, 2008
  17. Johannes SchindelinJul 11, 2008
  18. Linus TorvaldsJul 11, 2008
  19. Johannes SchindelinJul 12, 2008
  20. Linus TorvaldsJul 12, 2008
  21. Steffen ProhaskaJul 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.