diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2021-10-04 22:34:53 +0200 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2021-10-04 22:34:53 +0200 |
commit | 8df87c9e2c0a31c669625c4942d09b03d36c73e9 (patch) | |
tree | 1ac8786b5a56815c0c534f4b8deba011bfc46823 /libgfortran | |
parent | c92ee4037c3a6df882907c06ae6313d2dcb0cc0d (diff) | |
download | gcc-8df87c9e2c0a31c669625c4942d09b03d36c73e9.zip gcc-8df87c9e2c0a31c669625c4942d09b03d36c73e9.tar.gz gcc-8df87c9e2c0a31c669625c4942d09b03d36c73e9.tar.bz2 |
Take memory from envirnoment variables; document those.
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/caf_shared/coarraynative.c | 54 | ||||
-rw-r--r-- | libgfortran/caf_shared/shared_memory.c | 12 | ||||
-rw-r--r-- | libgfortran/caf_shared/shared_memory.h | 2 |
3 files changed, 55 insertions, 13 deletions
diff --git a/libgfortran/caf_shared/coarraynative.c b/libgfortran/caf_shared/coarraynative.c index 1ae0c40..cf72433 100644 --- a/libgfortran/caf_shared/coarraynative.c +++ b/libgfortran/caf_shared/coarraynative.c @@ -35,6 +35,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include <string.h> #define GFORTRAN_ENV_NUM_IMAGES "GFORTRAN_NUM_IMAGES" +#define GFORTRAN_ENV_SHARED_MEMORY_SIZE "GFORTRAN_SHARED_MEMORY_SIZE" nca_local_data *local = NULL; @@ -55,6 +56,54 @@ get_environ_image_num (void) return nimages; } +/* Get the amount of memory for the shared memory block. This is picked from + an environment variable. If that is not there, pick a reasonable default. + Note that on a 64-bit system which allows overcommit, there is no penalty in + reserving a large space and then not using it. */ + +static size_t +get_memory_size (void) +{ + char *e; + size_t sz = 0; + e = getenv (GFORTRAN_ENV_SHARED_MEMORY_SIZE); + if (e) + { + char *num, suffix; + int rv; + rv = sscanf (e, "%zu%1s",&sz, &suffix); + if (rv == 2) + { + switch (suffix) + { + case 'k': + case 'K': + sz *= ((size_t) 1) << 10; + break; + case 'm': + case 'M': + sz *= ((size_t) 1) << 20; + break; + case 'g': + case 'G': + sz *= ((size_t) 1) << 30; + break; + default: + sz = 0; + } + } + } + if (sz == 0) + { + /* Use 256 MB for 32-bit systems and 256 GB for 64-bit systems. */ + if (sizeof (size_t) == 4) + sz = ((size_t) 1) << 28; + else + sz = ((size_t) 1) << 38; + } + return sz; +} + /* Get a master. */ static master * @@ -79,6 +128,8 @@ get_master (void) void ensure_initialization (void) { + size_t shmem_size; + if (local) return; @@ -86,8 +137,9 @@ ensure_initialization (void) // that point? Maybe use // mmap(MAP_ANON) instead pagesize = sysconf (_SC_PAGE_SIZE); + shmem_size = round_to_pagesize (get_memory_size()); local->total_num_images = get_environ_image_num (); - shared_memory_init (&local->sm); + shared_memory_init (&local->sm, shmem_size); shared_memory_prepare (&local->sm); if (this_image.m == NULL) /* A bit of a hack, but we need the master early. */ diff --git a/libgfortran/caf_shared/shared_memory.c b/libgfortran/caf_shared/shared_memory.c index 0c0b36c..bc1a2e9 100644 --- a/libgfortran/caf_shared/shared_memory.c +++ b/libgfortran/caf_shared/shared_memory.c @@ -186,21 +186,11 @@ shared_memory_prepare (shared_memory_act **pmem) shared memory is stored at the beginning. */ void -shared_memory_init (shared_memory_act **pmem) +shared_memory_init (shared_memory_act **pmem, size_t initial_size) { shared_memory_act *mem; int fd; - /* Darwin does not appear to be able to grow shared memory segments. Choose - 256 GB; that will likely be enough. If not, the ftruncate will fail - noisily. */ - -#ifdef __APPLE__ - size_t initial_size = ((size_t) 1) << 38; -#else - size_t initial_size = round_to_pagesize (sizeof (global_shared_memory_meta)); -#endif - mem = malloc (get_shared_memory_act_size (1)); fd = get_shmem_fd (); diff --git a/libgfortran/caf_shared/shared_memory.h b/libgfortran/caf_shared/shared_memory.h index 09692fc..dd03227 100644 --- a/libgfortran/caf_shared/shared_memory.h +++ b/libgfortran/caf_shared/shared_memory.h @@ -53,7 +53,7 @@ typedef struct shared_mem_ptr ssize_t offset; } shared_mem_ptr; -void shared_memory_init (shared_memory *); +void shared_memory_init (shared_memory *, size_t); internal_proto (shared_memory_init); void shared_memory_prepare (shared_memory *); |