mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-05 06:10:33 +05:00
PAL16631 (SALOME crash after a mesh computation failed due to lack of memory)
use SMDS_MemoryLimit in CheckMemory() to know a lower memory limit
This commit is contained in:
parent
b18c323afd
commit
490be5a7f0
@ -43,6 +43,7 @@ using namespace std;
|
|||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
/*!
|
/*!
|
||||||
* \brief Raise an exception if free memory (ram+swap) too low
|
* \brief Raise an exception if free memory (ram+swap) too low
|
||||||
@ -59,18 +60,35 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
|
|||||||
if ( err )
|
if ( err )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
static int limit = -1;
|
||||||
|
if ( limit < 0 ) {
|
||||||
|
int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
|
||||||
|
if (status >= 0 ) {
|
||||||
|
limit = WEXITSTATUS(status);
|
||||||
|
}
|
||||||
|
if ( limit < 20 )
|
||||||
|
limit = 20;
|
||||||
|
else
|
||||||
|
limit = int( limit * 1.5 );
|
||||||
|
#ifdef _DEBUG_
|
||||||
|
cout << "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned long Mbyte = 1024 * 1024;
|
const unsigned long Mbyte = 1024 * 1024;
|
||||||
// compute separately to avoid overflow
|
// compute separately to avoid overflow
|
||||||
int freeMb =
|
int freeMb =
|
||||||
( si.freeram * si.mem_unit ) / Mbyte +
|
( si.freeram * si.mem_unit ) / Mbyte +
|
||||||
( si.freeswap * si.mem_unit ) / Mbyte;
|
( si.freeswap * si.mem_unit ) / Mbyte;
|
||||||
|
|
||||||
if ( freeMb > 4 )
|
if ( freeMb > limit )
|
||||||
return freeMb;
|
return freeMb - limit;
|
||||||
|
|
||||||
if ( doNotRaise )
|
if ( doNotRaise )
|
||||||
return 0;
|
return 0;
|
||||||
cout<<"SMDS_Mesh::CheckMemory() throws std::bad_alloc() as freeMb="<<freeMb<<endl;
|
#ifdef _DEBUG_
|
||||||
|
cout<<"SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" << endl;
|
||||||
|
#endif
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
#else
|
#else
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user