LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 9374 - clang makes a lot of system calls for output files
Summary: clang makes a lot of system calls for output files
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: unspecified
Hardware: All All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords: slow-compile
Depends on:
Blocks:
 
Reported: 2011-03-02 14:20 PST by Dan Gohman
Modified: 2011-07-27 19:48 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Gohman 2011-03-02 14:20:12 PST
Running clang -c testcase.c gets the following in a system call trace (which I've manually filtered):

[pid 17523] stat("testcase.o", {st_mode=S_IFREG|0600, st_size=1120, ...}) = 0
[pid 17523] stat("testcase.o", {st_mode=S_IFREG|0600, st_size=1120, ...}) = 0
[pid 17523] access("testcase.o", W_OK)  = 0
[pid 17523] stat("testcase.o", {st_mode=S_IFREG|0600, st_size=1120, ...}) = 0
[pid 17523] open("testcase.o-rM0aoW", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
[pid 17523] close(3)                    = 0
[pid 17523] open("testcase.o-rM0aoW", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 17523] close(3)                    = 0
[pid 17523] open("testcase.o-rM0aoW", O_WRONLY|O_CREAT|O_TRUNC, 0664) = 3
[pid 17523] fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
[pid 17523] close(3)                    = 0
[pid 17523] rename("testcase.o-rM0aoW", "testcase.o") = 0

This is pretty excessive. A fair amount of it appears to have come from r114187, which was apparently intended for AST/PCH files, but was implemented to apply to all output files.
Comment 1 Dan Gohman 2011-03-02 14:29:58 PST
As an aside, some of this is coming from the only use of canWrite() in the tree.
Comment 2 Ted Kremenek 2011-03-03 15:31:55 PST
cloned to <rdar://problem/9082880>
Comment 3 Dan Gohman 2011-03-03 15:34:33 PST
For reference, some background for r114187 is here, though the proposed solution is not what was ultimately implemented:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-September/011002.html
Comment 4 Chris Lattner 2011-05-22 00:54:32 PDT
Bob, can someone take a look at this?
Comment 5 Bob Wilson 2011-05-22 17:44:28 PDT
I pointed Eli at this earlier but we weren't sure what to do about it.  I think the next step is to talk with Argyrios to better understand the issues.  We'll do that this week.
Comment 6 Argyrios Kyrtzidis 2011-05-24 17:18:47 PDT
Would it be ok if we managed to reduce the number of system calls to the absolute minimum necessary to 

1) create the temporary file
2) rename the temporary over the output file

?
Comment 7 Dan Gohman 2011-05-24 17:28:45 PDT
One option would be to put the responsibility for doing the temporary file plus rename in the client which needs this.  For example, in place of having the client doing the equivalent of "clang ... -o out.o", the client could wrap this in some simple logic which does the equivalent of "clang ... -o out.o.blahblah && mv out.o.blahblah out.o".  That way, the client would be in control of its own safety, and all other clients would be spared the overhead.
Comment 8 Argyrios Kyrtzidis 2011-05-24 17:43:15 PDT
How about temp file + rename only when writing PCH files ?
Comment 9 Argyrios Kyrtzidis 2011-07-27 19:48:26 PDT
After changes to trunk, for writing PCH:
 10    119                       open:entry clang test.pch-0fa1da06
 12    121                      close:entry clang test.pch-0fa1da06
 12    365                     rename:entry clang test.pch-0fa1da06 test.pch

for other output files:
  4    119                       open:entry clang test.o
  4    121                      close:entry clang test.o

llvm r136310 +
clang r136315.