Parcourir la source

Add --max-mmap-limit option

Set the maximum file size to enable mmap (see --enable-mmap
option). The file size is determined by the sum of all files contained
in one download. For example, if a download contains 5 files, then
file size is the total size of those files. If file size is strictly
greater than the size specified in this option, mmap will be disabled.
Tatsuhiro Tsujikawa il y a 9 ans
Parent
commit
8f51793b19

+ 11 - 0
doc/manual-src/en/aria2c.rst

@@ -1375,6 +1375,16 @@ Advanced Options
   downloads. Specifying 0 means no download result is kept. Default:
   ``1000``
 
+.. option:: --max-mmap-limit=<SIZE>
+
+  Set the maximum file size to enable mmap (see
+  :option:`--enable-mmap` option). The file size is determined by the
+  sum of all files contained in one download. For example, if a
+  download contains 5 files, then file size is the total size of those
+  files. If file size is strictly greater than the size specified in
+  this option, mmap will be disabled.
+  Default: ``9223372036854775807``
+
 .. option:: --max-resume-failure-tries=<N>
 
   When used with :option:`--always-resume=false, <--always-resume>` aria2 downloads file from
@@ -2040,6 +2050,7 @@ of URIs. These optional lines must start with white space(s).
   * :option:`max-connection-per-server <-x>`
   * :option:`max-download-limit <--max-download-limit>`
   * :option:`max-file-not-found <--max-file-not-found>`
+  * :option:`max-mmap-limit <--max-mmap-limit>`
   * :option:`max-resume-failure-tries <--max-resume-failure-tries>`
   * :option:`max-tries <-m>`
   * :option:`max-upload-limit <-u>`

+ 3 - 1
src/BtFileAllocationEntry.cc

@@ -64,7 +64,9 @@ void BtFileAllocationEntry::prepareForNextAction(
 
   BtSetup().setup(commands, getRequestGroup(), e, option.get());
   if (option->getAsBool(PREF_ENABLE_MMAP) &&
-      option->get(PREF_FILE_ALLOCATION) != V_NONE) {
+      option->get(PREF_FILE_ALLOCATION) != V_NONE &&
+      getRequestGroup()->getPieceStorage()->getDiskAdaptor()->size() <=
+          option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
     getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap();
   }
   if (!getRequestGroup()->downloadFinished()) {

+ 10 - 0
src/OptionHandlerFactory.cc

@@ -447,6 +447,16 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     op->setChangeGlobalOption(true);
     handlers.push_back(op);
   }
+  {
+    OptionHandler* op(new UnitNumberOptionHandler(
+        PREF_MAX_MMAP_LIMIT, TEXT_MAX_MMAP_LIMIT,
+        util::itos(std::numeric_limits<int64_t>::max()), 0));
+    op->addTag(TAG_ADVANCED);
+    op->setInitialOption(true);
+    op->setChangeGlobalOption(true);
+    op->setChangeOptionForReserved(true);
+    handlers.push_back(op);
+  }
   {
     OptionHandler* op(
         new UnitNumberOptionHandler(PREF_MAX_OVERALL_DOWNLOAD_LIMIT,

+ 3 - 1
src/StreamFileAllocationEntry.cc

@@ -66,7 +66,9 @@ void StreamFileAllocationEntry::prepareForNextAction(
   // RequestGroup::createInitialCommand()
   getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
   if (option->getAsBool(PREF_ENABLE_MMAP) &&
-      option->get(PREF_FILE_ALLOCATION) != V_NONE) {
+      option->get(PREF_FILE_ALLOCATION) != V_NONE &&
+      getRequestGroup()->getPieceStorage()->getDiskAdaptor()->size() <=
+          option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
     getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap();
   }
   if (getNextCommand()) {

+ 2 - 0
src/prefs.cc

@@ -357,6 +357,8 @@ PrefPtr PREF_RLIMIT_NOFILE = makePref("rlimit-nofile");
 PrefPtr PREF_MIN_TLS_VERSION = makePref("min-tls-version");
 // value: 1*digit
 PrefPtr PREF_SOCKET_RECV_BUFFER_SIZE = makePref("socket-recv-buffer-size");
+// value: 1*digit
+PrefPtr PREF_MAX_MMAP_LIMIT = makePref("max-mmap-limit");
 
 /**
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -314,6 +314,8 @@ extern PrefPtr PREF_RLIMIT_NOFILE;
 extern PrefPtr PREF_MIN_TLS_VERSION;
 // value: 1*digit
 extern PrefPtr PREF_SOCKET_RECV_BUFFER_SIZE;
+// value: 1*digit
+extern PrefPtr PREF_MAX_MMAP_LIMIT;
 
 /**
  * FTP related preferences

+ 9 - 0
src/usage_text.h

@@ -1057,5 +1057,14 @@
     "                              the command given by --on-bt-download-complete\n" \
     "                              is executed. To disable this action, give false\n" \
     "                              to this option.")
+#define TEXT_MAX_MMAP_LIMIT                                             \
+  _(" --max-mmap-limit=SIZE        Set the maximum file size to enable mmap (see\n" \
+    "                              --enable-mmap option). The file size is\n" \
+    "                              determined by the sum of all files contained in\n" \
+    "                              one download. For example, if a download\n" \
+    "                              contains 5 files, then file size is the total\n" \
+    "                              size of those files. If file size is strictly\n" \
+    "                              greater than the size specified in this option,\n" \
+    "                              mmap will be disabled.")
 
 // clang-format on