[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 944177e4: Library (pointer.c): clear warning m
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 944177e4: Library (pointer.c): clear warning message in failed memory map |
Date: |
Thu, 8 Feb 2024 15:57:35 -0500 (EST) |
branch: master
commit 944177e43cfa7b528a3d0009d6e7cea42acac0e2
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Library (pointer.c): clear warning message in failed memory map
Until now, when memory mapping attempted even though enough there was
enough RAM, the message would incorrectly say that there isn't enough RAM.
With this commit, the warning message also conditionally mentions that
there was enough RAM, but allocation in RAM failed.
This was reported by Rahna Payyasseri Thanduparackal.
---
doc/announce-acknowledge.txt | 1 +
doc/gnuastro.texi | 5 ++++-
lib/gnuastro/pointer.h | 3 ++-
lib/pointer.c | 29 +++++++++++++++++++----------
4 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index f53790cf..ac22daa0 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -2,6 +2,7 @@ Alphabetically ordered list to acknowledge in the next release.
Jesús Vega
Phil Wyett
+Rahna Payyasseri Thanduparackal
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 352ca308..5ed02cc3 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -37396,7 +37396,7 @@ For more on memory management in Gnuastro, please see
@ref{Memory management}.
The various arguments are more fully explained in the two functions above.
@end deftypefun
-@deftypefun {void *} gal_pointer_mmap_allocate (size_t @code{size}, uint8_t
@code{type}, int @code{clear}, char @code{**mmapname})
+@deftypefun {void *} gal_pointer_mmap_allocate (size_t @code{size}, uint8_t
@code{type}, int @code{clear}, char @code{**mmapname}, int @code{allocfailed})
Allocate the necessary space to keep @code{size} elements of type @code{type}
in HDD/SSD (a file, not in RAM).
For the type codes, see @ref{Library data types}.
If @code{clear!=0}, then the allocated space will also be cleared.
@@ -37415,6 +37415,9 @@ Just delete the file (and the allocated space for the
filename) with the command
remove(mmapname);
free(mmapname);
@end example
+
+If @code{allocfailed!=0} and the memory mapping attempt fails, the warning
message will say something like this (assuming you have tried something like
@code{malloc} before calling this function): even though there was enough space
in RAM, the previous attempts at allocation in RAM failed, so we tried memory
mapping, but that also failed.
+
@end deftypefun
@deftypefun void gal_pointer_mmap_free (char @code{**mmapname}, int
@code{quietmmap})
diff --git a/lib/gnuastro/pointer.h b/lib/gnuastro/pointer.h
index 3bae9526..1b496572 100644
--- a/lib/gnuastro/pointer.h
+++ b/lib/gnuastro/pointer.h
@@ -60,7 +60,8 @@ gal_pointer_allocate(uint8_t type, size_t size, int clear,
void *
gal_pointer_mmap_allocate(uint8_t type, size_t size, int clear,
- char **filename, int quiet);
+ char **filename, int quietmmap,
+ int allocfailed);
void
gal_pointer_mmap_free(char **mmapname, int quietmmap);
diff --git a/lib/pointer.c b/lib/pointer.c
index 19f41aea..76a32897 100644
--- a/lib/pointer.c
+++ b/lib/pointer.c
@@ -106,7 +106,8 @@ gal_pointer_allocate(uint8_t type, size_t size, int clear,
void *
gal_pointer_mmap_allocate(uint8_t type, size_t size, int clear,
- char **filename, int quietmmap)
+ char **filename, int quietmmap,
+ int allocfailed)
{
void *out;
int filedes;
@@ -177,13 +178,21 @@ gal_pointer_mmap_allocate(uint8_t type, size_t size, int
clear,
out=mmap(NULL, bsize, PROT_READ | PROT_WRITE, MAP_SHARED, filedes, 0);
if(out==MAP_FAILED)
{
- fprintf(stderr, "\n%s: WARNING: the following error may be due to "
- "many mmap allocations. Recall that the kernel only allows "
- "finite number of mmap allocations. It is recommended to use "
- "ordinary RAM allocation for smaller arrays and keep mmap'd "
- "allocation only for the large volumes.\n\n", __func__);
- error(EXIT_FAILURE, errno, "couldn't map %zu bytes into the file '%s'",
- bsize, *filename);
+ if(allocfailed)
+ fprintf(stderr, "\n%s: WARNING: 'malloc' or 'calloc' could not "
+ "allocate %zu bytes in RAM, while there is space "
+ "available (the problem is with the kernel/OS, not "
+ "Gnuastro)! A subsequent attempt to use memory-mapping "
+ "also failed (see message below).\n\n", __func__, bsize);
+ else
+ fprintf(stderr, "\n%s: WARNING: the following error may be "
+ "due to many mmap allocations. Recall that the kernel "
+ "only allows finite number of mmap allocations. It is "
+ "recommended to use ordinary RAM allocation for smaller "
+ "arrays and keep mmap'd allocation only for the large "
+ "volumes.\n\n", __func__);
+ error(EXIT_FAILURE, errno, "couldn't map %zu bytes into the "
+ "file '%s'", bsize, *filename);
}
@@ -242,7 +251,7 @@ gal_pointer_allocate_ram_or_mmap(uint8_t type, size_t size,
int clear,
/* If it is decided to do memory-mapping, then do it. */
if( gal_checkset_need_mmap(bytesize, minmapsize, quietmmap) )
out=gal_pointer_mmap_allocate(type, size, clear, mmapname,
- quietmmap);
+ quietmmap, 0);
else
{
/* Allocate the necessary space in the RAM. */
@@ -257,7 +266,7 @@ gal_pointer_allocate_ram_or_mmap(uint8_t type, size_t size,
int clear,
need to read the available RAM). */
if(out==NULL)
out=gal_pointer_mmap_allocate(type, size, clear,
- mmapname, quietmmap);
+ mmapname, quietmmap, 1);
/* The 'errno' is re-set to zero just in case 'malloc'
changed it, which may cause problems later. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 944177e4: Library (pointer.c): clear warning message in failed memory map,
Mohammad Akhlaghi <=