[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
18/118: Print a warning when loading a large path into memory
From: |
Ludovic Courtès |
Subject: |
18/118: Print a warning when loading a large path into memory |
Date: |
Tue, 19 May 2015 14:45:18 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 829af22759b8a99c3b44697365390a945f3acc04
Author: Eelco Dolstra <address@hidden>
Date: Tue Jun 10 13:30:09 2014 +0200
Print a warning when loading a large path into memory
I.e. if you have a derivation with
src = ./huge-directory;
you'll get a warning that this is not a good idea.
---
src/libstore/remote-store.cc | 3 +++
src/libutil/serialise.cc | 27 +++++++++++++++++++++++++++
src/libutil/serialise.hh | 7 +++----
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 4619206..177b8e7 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -402,7 +402,10 @@ Path RemoteStore::addToStore(const Path & _srcPath,
writeInt((hashAlgo == htSHA256 && recursive) ? 0 : 1, to);
writeInt(recursive ? 1 : 0, to);
writeString(printHashType(hashAlgo), to);
+ to.written = 0;
+ to.warn = true;
dumpPath(srcPath, to, filter);
+ to.warn = false;
processStderr();
return readStorePath(from);
}
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 6b71f52..9241750 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -54,8 +54,24 @@ FdSink::~FdSink()
}
+size_t threshold = 256 * 1024 * 1024;
+
+static void warnLargeDump()
+{
+ printMsg(lvlError, "warning: dumping very large path (> 256 MiB); this may
run out of memory");
+}
+
+
void FdSink::write(const unsigned char * data, size_t len)
{
+ static bool warned = false;
+ if (warn && !warned) {
+ written += len;
+ if (written > threshold) {
+ warnLargeDump();
+ warned = true;
+ }
+ }
writeFull(fd, data, len);
}
@@ -256,4 +272,15 @@ template Paths readStrings(Source & source);
template PathSet readStrings(Source & source);
+void StringSink::operator () (const unsigned char * data, size_t len)
+{
+ static bool warned = false;
+ if (!warned && s.size() > threshold) {
+ warnLargeDump();
+ warned = true;
+ }
+ s.append((const char *) data, len);
+}
+
+
}
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index e5a9df1..3d296cf 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -72,6 +72,8 @@ struct BufferedSource : Source
struct FdSink : BufferedSink
{
int fd;
+ bool warn;
+ size_t written;
FdSink() : fd(-1) { }
FdSink(int fd) : fd(fd) { }
@@ -95,10 +97,7 @@ struct FdSource : BufferedSource
struct StringSink : Sink
{
string s;
- void operator () (const unsigned char * data, size_t len)
- {
- s.append((const char *) data, len);
- }
+ void operator () (const unsigned char * data, size_t len);
};
- 25/118: Fix bogus warnings about dumping large paths, (continued)
- 25/118: Fix bogus warnings about dumping large paths, Ludovic Courtès, 2015/05/19
- 20/118: == operator: Ignore string context, Ludovic Courtès, 2015/05/19
- 17/118: nix-env -qa --json: Generate valid JSON even if there are invalid meta attrs, Ludovic Courtès, 2015/05/19
- 23/118: findFile: Realise the context of the path attributes, Ludovic Courtès, 2015/05/19
- 11/118: Rephrase @ operator description, Ludovic Courtès, 2015/05/19
- 29/118: Merge branch 'shlevy-import-native', Ludovic Courtès, 2015/05/19
- 12/118: dev-shell is a bash script, not sh, Ludovic Courtès, 2015/05/19
- 22/118: Share code between scopedImport and import, Ludovic Courtès, 2015/05/19
- 26/118: Don't use member initialisers, Ludovic Courtès, 2015/05/19
- 31/118: Add `--json` argument to `nix-instantiate`, Ludovic Courtès, 2015/05/19
- 18/118: Print a warning when loading a large path into memory,
Ludovic Courtès <=
- 27/118: Add importNative primop, Ludovic Courtès, 2015/05/19
- 24/118: Drop ImportError and FindError, Ludovic Courtès, 2015/05/19
- 28/118: Only add the importNative primop if the allow-arbitrary-code-during-evaluation option is true (default false), Ludovic Courtès, 2015/05/19
- 30/118: allow-arbitrary-code-during-evaluation -> allow-unsafe-native-code-during-evaluation, Ludovic Courtès, 2015/05/19
- 34/118: Add builtin function ‘fromJSON’, Ludovic Courtès, 2015/05/19
- 36/118: Fix compilation error on some versions of GCC, Ludovic Courtès, 2015/05/19
- 32/118: Style fix, Ludovic Courtès, 2015/05/19
- 46/118: Fix use of sysread, Ludovic Courtès, 2015/05/19
- 33/118: Manual: html -> xhtml, Ludovic Courtès, 2015/05/19
- 45/118: nix-copy-closure -s: Do substitutions via ‘nix-store --serve’, Ludovic Courtès, 2015/05/19