Skip to content

Commit

Permalink
Add an option to control uncounted sharing in apc
Browse files Browse the repository at this point in the history
Summary:
For really huge arrays, where almost every element has a refcount > 1,
tracking the shared elements adds considerable overhead, so add an
option to disable that for now.

Reviewed By: binliu19

Differential Revision: D7116889

fbshipit-source-id: 41f53ca765778bce3655945078121c1fcef48ec0
  • Loading branch information
Mark Williams authored and hhvm-bot committed Mar 1, 2018
1 parent a434618 commit cf3c5eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hphp/runtime/base/apc-array.cpp
Expand Up @@ -52,7 +52,8 @@ APCArray::MakeSharedImpl(ArrayData* arr,
APCHandleLevel level,
A shared, B uncounted, C serialized) {
if (level == APCHandleLevel::Outer) {
auto const seenArrs = std::make_unique<PointerMap>();
auto const seenArrs = apcExtension::ShareUncounted ?
std::make_unique<PointerMap>() : nullptr;
// only need to call traverseData() on the toplevel array
DataWalker walker(DataWalker::LookupFeature::HasObjectOrResource);
DataWalker::DataFeature features = walker.traverseData(arr, seenArrs.get());
Expand All @@ -65,7 +66,8 @@ APCArray::MakeSharedImpl(ArrayData* arr,
!arr->empty()) {
auto const base_size = use_jemalloc ?
tl_heap->getAllocated() - tl_heap->getDeallocated() :
getMemSize(seenArrs.get());
seenArrs.get() ? getMemSize(seenArrs.get()) :
::HPHP::getMemSize(arr, true);
auto const uncounted_arr = uncounted(seenArrs.get());
auto const size = use_jemalloc ?
tl_heap->getAllocated() - tl_heap->getDeallocated() - base_size :
Expand Down
3 changes: 3 additions & 0 deletions hphp/runtime/ext/apc/ext_apc.cpp
Expand Up @@ -197,6 +197,8 @@ void apcExtension::moduleLoad(const IniSetting::Map& ini, Hdf config) {
Config::Bind(UseUncounted, ini, config, "Server.APC.MemModelTreadmill",
RuntimeOption::ServerExecutionMode());
#endif
Config::Bind(ShareUncounted, ini, config, "Server.APC.ShareUncounted", true);
if (!UseUncounted && ShareUncounted) ShareUncounted = false;

IniSetting::Bind(this, IniSetting::PHP_INI_SYSTEM, "apc.enabled", &Enable);
IniSetting::Bind(this, IniSetting::PHP_INI_SYSTEM, "apc.stat",
Expand Down Expand Up @@ -302,6 +304,7 @@ bool apcExtension::UseUncounted = true;
#else
bool apcExtension::UseUncounted = false;
#endif
bool apcExtension::ShareUncounted = true;
bool apcExtension::Stat = true;
// Different from zend default but matches what we've been returning for years
bool apcExtension::EnableCLI = true;
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/ext/apc/ext_apc.h
Expand Up @@ -63,6 +63,7 @@ struct apcExtension final : Extension {
static bool FileStorageKeepFileLinked;
static std::vector<std::string> NoTTLPrefix;
static bool UseUncounted;
static bool ShareUncounted;
static bool Stat;
static bool EnableCLI;

Expand Down

0 comments on commit cf3c5eb

Please sign in to comment.