Skip to content

Commit

Permalink
QGIS main: increase soft limit of maximum number of files to 4096 on …
Browse files Browse the repository at this point in the history
…all Unix (refs #43620)
  • Loading branch information
rouault authored and nyalldawson committed Sep 23, 2021
1 parent bf946f8 commit 80d7014
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/app/main.cpp
Expand Up @@ -67,9 +67,12 @@ int _fmode = _O_BINARY;
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
typedef SInt32 SRefCon;
#endif
// For setting the maximum open files limit higher
#endif

#ifdef Q_OS_UNIX
// For getrlimit() / setrlimit()
#include <sys/resource.h>
#include <limits.h>
#include <sys/time.h>
#endif

#if defined(__GLIBC__) || defined(__FreeBSD__)
Expand Down Expand Up @@ -473,7 +476,7 @@ int main( int argc, char *argv[] )
//log messages written before creating QgsApplication
QStringList preApplicationLogMessages;

#ifdef Q_OS_MACX
#ifdef Q_OS_UNIX
// Increase file resource limits (i.e., number of allowed open files)
// (from code provided by Larry Biehl, Purdue University, USA, from 'MultiSpec' project)
// This is generally 256 for the soft limit on Mac
Expand All @@ -483,29 +486,28 @@ int main( int argc, char *argv[] )
struct rlimit rescLimit;
if ( getrlimit( RLIMIT_NOFILE, &rescLimit ) == 0 )
{
rlim_t oldSoft( rescLimit.rlim_cur );
rlim_t oldHard( rescLimit.rlim_max );
const rlim_t oldSoft( rescLimit.rlim_cur );
#ifdef OPEN_MAX
rlim_t newSoft( OPEN_MAX );
rlim_t newHard( std::min( oldHard, newSoft ) );
#else
rlim_t newSoft( 4096 );
rlim_t newHard( std::min( ( rlim_t )8192, oldHard ) );
#endif
if ( rescLimit.rlim_cur < newSoft )
const char *qgisMaxFileCount = getenv( "QGIS_MAX_FILE_COUNT" );
if ( qgisMaxFileCount )
newSoft = static_cast<rlim_t>( atoi( qgisMaxFileCount ) );
if ( rescLimit.rlim_cur < newSoft || qgisMaxFileCount )
{
rescLimit.rlim_cur = newSoft;
rescLimit.rlim_max = newHard;
rescLimit.rlim_cur = std::min( newSoft, rescLimit.rlim_max );

if ( setrlimit( RLIMIT_NOFILE, &rescLimit ) == 0 )
{
QgsDebugMsg( QStringLiteral( "Mac RLIMIT_NOFILE Soft/Hard NEW: %1 / %2" )
QgsDebugMsg( QStringLiteral( "RLIMIT_NOFILE Soft NEW: %1 / %2" )
.arg( rescLimit.rlim_cur ).arg( rescLimit.rlim_max ) );
}
}
Q_UNUSED( oldSoft ) //avoid warnings
QgsDebugMsg( QStringLiteral( "Mac RLIMIT_NOFILE Soft/Hard ORIG: %1 / %2" )
.arg( oldSoft ).arg( oldHard ) );
QgsDebugMsg( QStringLiteral( "RLIMIT_NOFILE Soft/Hard ORIG: %1 / %2" )
.arg( oldSoft ).arg( rescLimit.rlim_max ) );
}
#endif

Expand Down

0 comments on commit 80d7014

Please sign in to comment.