Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil() and...
[folly.git] / folly / MemoryMapping.cpp
index bc094d380a65fd4b4c494edbec256807c9535cd7..89799fd143d5f38fc3deea189b39654c4bcdec66 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -129,7 +129,7 @@ void MemoryMapping::init(off_t offset, off_t length) {
   }
 
   if (pageSize == 0) {
-    pageSize = sysconf(_SC_PAGESIZE);
+    pageSize = off_t(sysconf(_SC_PAGESIZE));
   }
 
   CHECK_GT(pageSize, 0);
@@ -137,7 +137,7 @@ void MemoryMapping::init(off_t offset, off_t length) {
   CHECK_GE(offset, 0);
 
   // Round down the start of the mapped region
-  size_t skipStart = offset % pageSize;
+  off_t skipStart = offset % pageSize;
   offset -= skipStart;
 
   mapLength_ = length;
@@ -206,7 +206,7 @@ off_t memOpChunkSize(off_t length, off_t pageSize) {
     return chunkSize;
   }
 
-  chunkSize = FLAGS_mlock_chunk_size;
+  chunkSize = off_t(FLAGS_mlock_chunk_size);
   off_t r = chunkSize % pageSize;
   if (r) {
     chunkSize += (pageSize - r);
@@ -231,7 +231,7 @@ bool memOpInChunks(std::function<int(void*, size_t)> op,
   // chunks breaks the locking into intervals and lets other threads do memory
   // operations of their own.
 
-  size_t chunkSize = memOpChunkSize(bufSize, pageSize);
+  size_t chunkSize = memOpChunkSize(off_t(bufSize), pageSize);
 
   char* addr = static_cast<char*>(mem);
   amountSucceeded = 0;
@@ -258,10 +258,11 @@ bool MemoryMapping::mlock(LockMode lock) {
   }
 
   auto msg =
-    folly::sformat("mlock({}) failed at {}", mapLength_, amountSucceeded);
-
-  if (lock == LockMode::TRY_LOCK && (errno == EPERM || errno == ENOMEM)) {
+      folly::format("mlock({}) failed at {}", mapLength_, amountSucceeded);
+  if (lock == LockMode::TRY_LOCK && errno == EPERM) {
     PLOG(WARNING) << msg;
+  } else if (lock == LockMode::TRY_LOCK && errno == ENOMEM) {
+    VLOG(1) << msg;
   } else {
     PLOG(FATAL) << msg;
   }
@@ -308,7 +309,7 @@ MemoryMapping::~MemoryMapping() {
 void MemoryMapping::advise(int advice) const { advise(advice, 0, mapLength_); }
 
 void MemoryMapping::advise(int advice, size_t offset, size_t length) const {
-  CHECK_LE(offset + length, mapLength_)
+  CHECK_LE(offset + length, size_t(mapLength_))
     << " offset: " << offset
     << " length: " << length
     << " mapLength_: " << mapLength_;
@@ -376,7 +377,7 @@ void mmapFileCopy(const char* src, const char* dest, mode_t mode) {
   MemoryMapping destMap(
       File(dest, O_RDWR | O_CREAT | O_TRUNC, mode),
       0,
-      srcMap.range().size(),
+      off_t(srcMap.range().size()),
       MemoryMapping::writable());
 
   alignedForwardMemcpy(destMap.writableRange().data(),