Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1766)

Unified Diff: base/trace_event/process_memory_dump.cc

Issue 1398163003: Handle EAGAIN error for the mincore syscall used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resident
Patch Set: Return 0 on error. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/process_memory_dump.cc
diff --git a/base/trace_event/process_memory_dump.cc b/base/trace_event/process_memory_dump.cc
index 0ec007e2ee46f5140bf83ee5580a7f5c1ee221f4..fab111f6da03858c353c98d66c5d348339cb09f1 100644
--- a/base/trace_event/process_memory_dump.cc
+++ b/base/trace_event/process_memory_dump.cc
@@ -43,6 +43,7 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address,
const size_t kMaxChunkSize = 32 * 1024 * 1024;
size_t offset = 0;
size_t total_resident_size = 0;
+ int result = 0;
while (offset < mapped_size) {
void* chunk_start = reinterpret_cast<void*>(start_pointer + offset);
const size_t chunk_size = std::min(mapped_size - offset, kMaxChunkSize);
@@ -51,14 +52,23 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address,
#if defined(OS_MACOSX) || defined(OS_IOS)
std::vector<char> vec(page_count + 1);
- int res = mincore(chunk_start, chunk_size, vector_as_array(&vec));
- DCHECK(!res);
+ // mincore in MAC does not fail with EAGAIN.
+ result = mincore(chunk_start, chunk_size, vector_as_array(&vec));
+ if (result)
+ break;
+
for (size_t i = 0; i < page_count; i++)
resident_page_count += vec[i] & MINCORE_INCORE ? 1 : 0;
#else // defined(OS_MACOSX) || defined(OS_IOS)
std::vector<unsigned char> vec(page_count + 1);
- int res = mincore(chunk_start, chunk_size, vector_as_array(&vec));
- DCHECK(!res);
+ int error_counter = 0;
+ // HANDLE_EINTR tries for 100 times. So following the same pattern.
+ do {
+ result = mincore(chunk_start, chunk_size, vector_as_array(&vec));
+ } while (result == -1 && errno == EAGAIN && error_counter++ < 100);
+ if (result)
+ break;
+
for (size_t i = 0; i < page_count; i++)
resident_page_count += vec[i];
#endif // defined(OS_MACOSX) || defined(OS_IOS)
@@ -66,6 +76,12 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address,
total_resident_size += resident_page_count * page_size;
offset += kMaxChunkSize;
}
+
+ DCHECK_EQ(0, result);
+ if (result) {
+ total_resident_size = 0;
+ LOG(ERROR) << "mincore() call failed. The resident size is invalid";
+ }
return total_resident_size;
}
#endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698