added option to lock disk cache in physical memory

This commit is contained in:
Arvid Norberg
2009-02-06 09:46:13 +00:00
parent 7607286f50
commit 5c12db28d2
5 changed files with 68 additions and 2 deletions

View File

@@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp"
#endif
#ifndef TORRENT_DISABLE_MLOCK
#include <sys/mman.h>
#endif
namespace libtorrent
{
disk_buffer_pool::disk_buffer_pool(int block_size)
@@ -79,6 +83,17 @@ namespace libtorrent
#else
char* ret = (char*)m_pool.ordered_malloc();
#endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualLock(ret, m_block_size);
#else
mlock(ret, m_block_size);
#endif
}
#endif
#ifdef TORRENT_STATS
++m_allocations;
++m_categories[category];
@@ -101,6 +116,16 @@ namespace libtorrent
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
m_buf_to_category.erase(buf);
#endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualUnlock(buf, m_block_size);
#else
munlock(buf, m_block_size);
#endif
}
#endif
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
page_aligned_allocator::free(buf);
#else
@@ -116,6 +141,16 @@ namespace libtorrent
#else
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
#endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualLock(ret, m_block_size * num_blocks);
#else
mlock(ret, m_block_size * num_blocks);
#endif
}
#endif
#ifdef TORRENT_STATS
m_allocations += num_blocks;
m_categories[category] += num_blocks;
@@ -139,6 +174,16 @@ namespace libtorrent
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
m_buf_to_category.erase(buf);
#endif
#ifndef TORRENT_DISABLE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualUnlock(buf, m_block_size * num_blocks);
#else
munlock(buf, m_block_size * num_blocks);
#endif
}
#endif
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
page_aligned_allocator::free(buf);
#else