@@ -905,21 +905,22 @@ class PlasmaStoreRunner {
905
905
PlasmaStoreRunner () {}
906
906
907
907
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) {
909
909
// Create the event loop.
910
910
loop_.reset (new EventLoop);
911
911
store_.reset (
912
912
new PlasmaStore (loop_.get (), system_memory, directory, hugepages_enabled));
913
913
plasma_config = store_->GetPlasmaStoreInfo ();
914
914
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);
923
924
924
925
int socket = BindIpcSock (socket_name, true );
925
926
// TODO(pcm): Check return value.
@@ -955,15 +956,14 @@ void HandleSignal(int signal) {
955
956
}
956
957
957
958
void 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) {
959
960
// Ignore SIGPIPE signals. If we don't do this, then when we attempt to write
960
961
// to a client that has already died, the store could die.
961
962
signal (SIGPIPE, SIG_IGN);
962
963
963
964
g_runner.reset (new PlasmaStoreRunner ());
964
965
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);
967
967
}
968
968
969
969
} // namespace plasma
@@ -975,11 +975,9 @@ int main(int argc, char* argv[]) {
975
975
// Directory where plasma memory mapped files are stored.
976
976
std::string plasma_directory;
977
977
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 ;
980
978
int64_t system_memory = -1 ;
981
979
int c;
982
- while ((c = getopt (argc, argv, " s:m:d:hf " )) != -1 ) {
980
+ while ((c = getopt (argc, argv, " s:m:d:h " )) != -1 ) {
983
981
switch (c) {
984
982
case ' d' :
985
983
plasma_directory = std::string (optarg );
@@ -994,14 +992,16 @@ int main(int argc, char* argv[]) {
994
992
char extra;
995
993
int scanned = sscanf (optarg , " %" SCNd64 " %c" , &system_memory, &extra);
996
994
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));
997
1000
ARROW_LOG (INFO) << " Allowing the Plasma store to use up to "
998
1001
<< static_cast <double >(system_memory) / 1000000000
999
1002
<< " GB of memory." ;
1000
1003
break ;
1001
1004
}
1002
- case ' f' :
1003
- use_one_memory_mapped_file = true ;
1004
- break ;
1005
1005
default :
1006
1006
exit (-1 );
1007
1007
}
@@ -1051,12 +1051,8 @@ int main(int argc, char* argv[]) {
1051
1051
SetMallocGranularity (1024 * 1024 * 1024 ); // 1 GB
1052
1052
}
1053
1053
#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);
1057
1054
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);
1060
1056
plasma::g_runner->Shutdown ();
1061
1057
plasma::g_runner = nullptr ;
1062
1058
0 commit comments