@@ -905,21 +905,22 @@ class PlasmaStoreRunner {
905905 PlasmaStoreRunner () {}
906906
907907 void Start (char * socket_name, int64_t system_memory, std::string directory,
908- bool hugepages_enabled, bool use_one_memory_mapped_file ) {
908+ bool hugepages_enabled) {
909909 // Create the event loop.
910910 loop_.reset (new EventLoop);
911911 store_.reset (
912912 new PlasmaStore (loop_.get (), system_memory, directory, hugepages_enabled));
913913 plasma_config = store_->GetPlasmaStoreInfo ();
914914
915- // If the store is configured to use a single memory-mapped file, then we
916- // achieve that by mallocing and freeing a single large amount of space.
917- // that maximum allowed size up front.
918- if (use_one_memory_mapped_file) {
919- void * pointer = plasma::dlmemalign (kBlockSize , system_memory);
920- ARROW_CHECK (pointer != nullptr );
921- plasma::dlfree (pointer);
922- }
915+ // We are using a single memory-mapped file by mallocing and freeing a single
916+ // large amount of space up front. According to the documentation,
917+ // dlmalloc might need up to 128*sizeof(size_t) bytes for internal
918+ // bookkeeping.
919+ void * pointer = plasma::dlmemalign (kBlockSize , system_memory - 256 * sizeof (size_t ));
920+ ARROW_CHECK (pointer != nullptr );
921+ // This will unmap the file, but the next one created will be as large
922+ // as this one (this is an implementation detail of dlmalloc).
923+ plasma::dlfree (pointer);
923924
924925 int socket = BindIpcSock (socket_name, true );
925926 // TODO(pcm): Check return value.
@@ -955,15 +956,14 @@ void HandleSignal(int signal) {
955956}
956957
957958void StartServer (char * socket_name, int64_t system_memory, std::string plasma_directory,
958- bool hugepages_enabled, bool use_one_memory_mapped_file ) {
959+ bool hugepages_enabled) {
959960 // Ignore SIGPIPE signals. If we don't do this, then when we attempt to write
960961 // to a client that has already died, the store could die.
961962 signal (SIGPIPE, SIG_IGN);
962963
963964 g_runner.reset (new PlasmaStoreRunner ());
964965 signal (SIGTERM, HandleSignal);
965- g_runner->Start (socket_name, system_memory, plasma_directory, hugepages_enabled,
966- use_one_memory_mapped_file);
966+ g_runner->Start (socket_name, system_memory, plasma_directory, hugepages_enabled);
967967}
968968
969969} // namespace plasma
@@ -975,11 +975,9 @@ int main(int argc, char* argv[]) {
975975 // Directory where plasma memory mapped files are stored.
976976 std::string plasma_directory;
977977 bool hugepages_enabled = false ;
978- // True if a single large memory-mapped file should be created at startup.
979- bool use_one_memory_mapped_file = false ;
980978 int64_t system_memory = -1 ;
981979 int c;
982- while ((c = getopt (argc, argv, " s:m:d:hf " )) != -1 ) {
980+ while ((c = getopt (argc, argv, " s:m:d:h " )) != -1 ) {
983981 switch (c) {
984982 case ' d' :
985983 plasma_directory = std::string (optarg);
@@ -994,14 +992,16 @@ int main(int argc, char* argv[]) {
994992 char extra;
995993 int scanned = sscanf (optarg, " %" SCNd64 " %c" , &system_memory, &extra);
996994 ARROW_CHECK (scanned == 1 );
995+ // Set system memory, potentially rounding it to a page size
996+ // Also make it so dlmalloc fails if we try to request more memory than
997+ // is available.
998+ system_memory =
999+ plasma::dlmalloc_set_footprint_limit (static_cast <size_t >(system_memory));
9971000 ARROW_LOG (INFO) << " Allowing the Plasma store to use up to "
9981001 << static_cast <double >(system_memory) / 1000000000
9991002 << " GB of memory." ;
10001003 break ;
10011004 }
1002- case ' f' :
1003- use_one_memory_mapped_file = true ;
1004- break ;
10051005 default :
10061006 exit (-1 );
10071007 }
@@ -1051,12 +1051,8 @@ int main(int argc, char* argv[]) {
10511051 SetMallocGranularity (1024 * 1024 * 1024 ); // 1 GB
10521052 }
10531053#endif
1054- // Make it so dlmalloc fails if we try to request more memory than is
1055- // available.
1056- plasma::dlmalloc_set_footprint_limit ((size_t )system_memory);
10571054 ARROW_LOG (DEBUG) << " starting server listening on " << socket_name;
1058- plasma::StartServer (socket_name, system_memory, plasma_directory, hugepages_enabled,
1059- use_one_memory_mapped_file);
1055+ plasma::StartServer (socket_name, system_memory, plasma_directory, hugepages_enabled);
10601056 plasma::g_runner->Shutdown ();
10611057 plasma::g_runner = nullptr ;
10621058
0 commit comments