From 55cd19d1e2b2a79617054ff9ea149b86afd188e1 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 13 Mar 2016 15:59:58 -0400 Subject: [PATCH] remove the purgable control patch. It adds a lot of complexity and it does not perform well --- include/libtorrent/config.hpp | 6 -- src/block_cache.cpp | 105 ---------------------------------- src/disk_buffer_pool.cpp | 25 -------- 3 files changed, 136 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 35853c16a..eb5d76b33 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -169,8 +169,6 @@ POSSIBILITY OF SUCH DAMAGE. # endif #include -#define TORRENT_USE_PURGABLE_CONTROL 1 - #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 // on OSX, use the built-in common crypto for built-in # if !defined TORRENT_USE_OPENSSL && !defined TORRENT_USE_GCRYPT @@ -611,10 +609,6 @@ int snprintf(char* buf, int len, char const* fmt, ...) #define TORRENT_HAS_BOOST_UNORDERED 1 #endif -#ifndef TORRENT_USE_PURGABLE_CONTROL -#define TORRENT_USE_PURGABLE_CONTROL 0 -#endif - #if !defined TORRENT_IOV_MAX #ifdef IOV_MAX #define TORRENT_IOV_MAX IOV_MAX diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 9ecc88874..03141a5d3 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -49,20 +49,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #endif -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#if TORRENT_USE_PURGABLE_CONTROL -#include -// see comments at: -// http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c - -const vm_purgable_t vm_purgable_set_state = VM_PURGABLE_SET_STATE; -const vm_purgable_t vm_purgable_nonvolatile = VM_PURGABLE_NONVOLATILE; - -#endif - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - /* The disk cache mimics ARC (adaptive replacement cache). @@ -1381,40 +1367,9 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t TORRENT_UNUSED(ret); // suppress warning TORRENT_ASSERT(ret); } - else - { -#if TORRENT_USE_PURGABLE_CONTROL && defined TORRENT_DISABLE_POOL_ALLOCATOR - // volatile read blocks are group 0, regular reads are group 1 - int state = VM_PURGABLE_VOLATILE | ((j->flags & disk_io_job::volatile_read) ? VM_VOLATILE_GROUP_0 : VM_VOLATILE_GROUP_1); - kern_return_t ret = vm_purgable_control( - mach_task_self(), - reinterpret_cast(pe->blocks[block].buf), - vm_purgable_set_state, - &state); -#ifdef TORRENT_DEBUG -// if ((random() % 200) == 0) ret = 1; -#endif - if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) - { - fprintf(stderr, "insert_blocks(piece=%d block=%d): " - "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" - , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); - free_buffer(pe->blocks[block].buf); - pe->blocks[block].buf = NULL; - --pe->num_blocks; - --m_read_cache_size; - if (j->flags & disk_io_job::volatile_read) --m_volatile_size; - } -#endif - } } -#if TORRENT_USE_PURGABLE_CONTROL && defined TORRENT_DISABLE_POOL_ALLOCATOR - TORRENT_ASSERT(pe->blocks[block].buf != NULL - || (flags & blocks_inc_refcount) == 0); -#else TORRENT_ASSERT(pe->blocks[block].buf != NULL); -#endif } TORRENT_PIECE_ASSERT(pe->cache_state != cached_piece_entry::read_lru1_ghost, pe); @@ -1431,36 +1386,6 @@ bool block_cache::inc_block_refcount(cached_piece_entry* pe, int block, int reas TORRENT_PIECE_ASSERT(pe->blocks[block].refcount < cached_block_entry::max_refcount, pe); if (pe->blocks[block].refcount == 0) { -#if TORRENT_USE_PURGABLE_CONTROL && defined TORRENT_DISABLE_POOL_ALLOCATOR - // we're adding the first refcount to this block, first make sure - // its still here. It's only volatile if it's not dirty and has refcount == 0 - if (!pe->blocks[block].dirty) - { - int state = vm_purgable_nonvolatile; - kern_return_t ret = vm_purgable_control( - mach_task_self(), - reinterpret_cast(pe->blocks[block].buf), - vm_purgable_set_state, - &state); -#ifdef TORRENT_DEBUG -// if ((random() % 200) == 0) ret = 1; -#endif - if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) - { - fprintf(stderr, "inc_block_refcount(piece=%d block=%d): " - "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" - , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); - - free_buffer(pe->blocks[block].buf); - pe->blocks[block].buf = NULL; - --pe->num_blocks; - --m_read_cache_size; - if (pe->cache_state == cached_piece_entry::volatile_read_lru) - --m_volatile_size; - return false; - } - } -#endif ++pe->pinned; ++m_pinned_blocks; } @@ -1498,36 +1423,6 @@ void block_cache::dec_block_refcount(cached_piece_entry* pe, int block, int reas --pe->pinned; TORRENT_PIECE_ASSERT(m_pinned_blocks > 0, pe); --m_pinned_blocks; - -#if TORRENT_USE_PURGABLE_CONTROL && defined TORRENT_DISABLE_POOL_ALLOCATOR - // we're removing the last refcount to this block, first make sure - // its still here. It's only volatile if it's not dirty and has refcount == 0 - if (!pe->blocks[block].dirty) - { - // group 0 is the first one to be reclaimed - int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_1; - kern_return_t ret = vm_purgable_control( - mach_task_self(), - reinterpret_cast(pe->blocks[block].buf), - vm_purgable_set_state, - &state); -#ifdef TORRENT_DEBUG -// if ((random() % 200) == 0) ret = 1; -#endif - if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) - { - fprintf(stderr, "dec_block_refcount(piece=%d block=%d): " - "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" - , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); - free_buffer(pe->blocks[block].buf); - pe->blocks[block].buf = NULL; - --pe->num_blocks; - --m_read_cache_size; - if (pe->cache_state == cached_piece_entry::volatile_read_lru) - --m_volatile_size; - } - } -#endif } #if TORRENT_USE_ASSERTS switch (reason) diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 79486d75e..d74dd6410 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -60,12 +60,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if TORRENT_USE_PURGABLE_CONTROL -#include -// see comments at: -// http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c -#endif - #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent @@ -355,18 +349,7 @@ namespace libtorrent { #if defined TORRENT_DISABLE_POOL_ALLOCATOR -#if TORRENT_USE_PURGABLE_CONTROL - kern_return_t res = vm_allocate( - mach_task_self(), - reinterpret_cast(&ret), - 0x4000, - VM_FLAGS_PURGABLE | - VM_FLAGS_ANYWHERE); - if (res != KERN_SUCCESS) - ret = NULL; -#else ret = page_aligned_allocator::malloc(m_block_size); -#endif // TORRENT_USE_PURGABLE_CONTROL #else if (m_using_pool_allocator) @@ -641,15 +624,7 @@ namespace libtorrent { #if defined TORRENT_DISABLE_POOL_ALLOCATOR -#if TORRENT_USE_PURGABLE_CONTROL - vm_deallocate( - mach_task_self(), - reinterpret_cast(buf), - 0x4000 - ); -#else page_aligned_allocator::free(buf); -#endif // TORRENT_USE_PURGABLE_CONTROL #else if (m_using_pool_allocator)