diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-01-28 23:43:29 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-01-29 00:14:30 +0900 |
| commit | 8f51793b19c751bde0e41448aaeb9eb54d2fdbb1 (patch) | |
| tree | a4c085d881b499b87fba5932e80059b854229b09 /src | |
| parent | fc95a91eb617beb9130a6b1c7ed7c14a61189f8e (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/BtFileAllocationEntry.cc | 4 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 10 | ||||
| -rw-r--r-- | src/StreamFileAllocationEntry.cc | 4 | ||||
| -rw-r--r-- | src/prefs.cc | 2 | ||||
| -rw-r--r-- | src/prefs.h | 2 | ||||
| -rw-r--r-- | src/usage_text.h | 9 |
6 files changed, 29 insertions, 2 deletions
diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc index ed44e44e..dc9cc04f 100644 --- a/src/BtFileAllocationEntry.cc +++ b/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()) { diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index ef6a8268..87b07cec 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -448,6 +448,16 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers() 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, TEXT_MAX_OVERALL_DOWNLOAD_LIMIT, "0", 0)); diff --git a/src/StreamFileAllocationEntry.cc b/src/StreamFileAllocationEntry.cc index c6d1de2a..e02bbc48 100644 --- a/src/StreamFileAllocationEntry.cc +++ b/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()) { diff --git a/src/prefs.cc b/src/prefs.cc index 15371f96..caffd349 100644 --- a/src/prefs.cc +++ b/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 diff --git a/src/prefs.h b/src/prefs.h index f8115f52..52078fe9 100644 --- a/src/prefs.h +++ b/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 diff --git a/src/usage_text.h b/src/usage_text.h index 09552249..5f11fde4 100644 --- a/src/usage_text.h +++ b/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 |
