25
25
#include < algorithm>
26
26
#include < ctype.h>
27
27
#include < stdint.h>
28
+ #if defined(LINUX)
29
+ #include < sys/statfs.h>
30
+ #include < linux/magic.h>
31
+ #endif /* LINUX */
32
+
28
33
#include " jitprotos.h"
29
34
#include " j2sever.h"
30
35
#include " j9.h"
@@ -2988,6 +2993,7 @@ J9::Options::fePostProcessJIT(void * base)
2988
2993
bool
2989
2994
J9::Options::disableMemoryDisclaimIfNeeded (J9JITConfig *jitConfig)
2990
2995
{
2996
+ #if defined (LINUX)
2991
2997
J9JavaVM * javaVM = jitConfig->javaVM ;
2992
2998
PORT_ACCESS_FROM_JAVAVM (javaVM); // for j9vmem_supported_page_sizes
2993
2999
OMRPORT_ACCESS_FROM_J9PORT (javaVM->portLibrary ); // for omrsysinfo_os_kernel_info
@@ -3019,6 +3025,52 @@ J9::Options::disableMemoryDisclaimIfNeeded(J9JITConfig *jitConfig)
3019
3025
}
3020
3026
}
3021
3027
}
3028
+ if (!shouldDisableMemoryDisclaim)
3029
+ {
3030
+ // The backing file for the disclaimed memory is on /tmp.
3031
+ // Do not disclaim if the filesystem for /tmp is tmpfs or ramfs because they use RAM memory.
3032
+ // Also, do not disclaim if /tmp is on nfs because the latency is unpredictable.
3033
+ // In these cases, attempt to disclaim on swap if possible.
3034
+ TR::CompilationInfo *compInfo = TR::CompilationInfo::get (jitConfig);
3035
+ if (TR::Options::getCmdLineOptions ()->getOption (TR_DontDisclaimMemoryOnSwap) ||
3036
+ !TR::Options::getCmdLineOptions ()->getOption (TR_DisclaimMemoryOnSwap) ||
3037
+ compInfo->isSwapMemoryDisabled ())
3038
+ {
3039
+ // Disclaim on backing file is preferred (or the only possibility)
3040
+ // TODO: enhance the omr portlib (omrfile_stat/updateJ9FileStat/J9FileStat) to give us the desired information
3041
+ struct statfs statfsbuf;
3042
+ int retVal = statfs (" /tmp" , &statfsbuf);
3043
+ if (retVal != 0 ||
3044
+ statfsbuf.f_type == TMPFS_MAGIC ||
3045
+ statfsbuf.f_type == RAMFS_MAGIC ||
3046
+ statfsbuf.f_type == NFS_SUPER_MAGIC)
3047
+ {
3048
+ // Check whether swap is available and whether the user allows the usage of swap.
3049
+ if (TR::Options::getCmdLineOptions ()->getOption (TR_DontDisclaimMemoryOnSwap) || compInfo->isSwapMemoryDisabled ())
3050
+ {
3051
+ shouldDisableMemoryDisclaim = true ;
3052
+ if (TR::Options::getVerboseOption (TR_VerbosePerformance))
3053
+ {
3054
+ TR_VerboseLog::writeLineLocked (TR_Vlog_PERF, " WARNING: Disclaim feature disabled because /tmp is not suitable and swap is not available/allowed" );
3055
+ }
3056
+ TR::Options::getCmdLineOptions ()->setOption (TR_DisclaimMemoryOnSwap, false );
3057
+ }
3058
+ else
3059
+ {
3060
+ // Force the usage of swap space for disclaiming.
3061
+ TR::Options::getCmdLineOptions ()->setOption (TR_DisclaimMemoryOnSwap);
3062
+ if (TR::Options::getVerboseOption (TR_VerbosePerformance))
3063
+ {
3064
+ TR_VerboseLog::writeLineLocked (TR_Vlog_PERF, " Memory disclaim will be done on swap because /tmp is not suitable" );
3065
+ }
3066
+ }
3067
+ }
3068
+ }
3069
+ else // Disclaim on swap is preferred
3070
+ {
3071
+
3072
+ }
3073
+ }
3022
3074
if (shouldDisableMemoryDisclaim)
3023
3075
{
3024
3076
TR::Options::getCmdLineOptions ()->setOption (TR_DisableDataCacheDisclaiming);
@@ -3027,6 +3079,9 @@ J9::Options::disableMemoryDisclaimIfNeeded(J9JITConfig *jitConfig)
3027
3079
TR::Options::getCmdLineOptions ()->setOption (TR_EnableSharedCacheDisclaiming, false );
3028
3080
}
3029
3081
return shouldDisableMemoryDisclaim;
3082
+ #else /* if defined(LINUX) */
3083
+ return true ;
3084
+ #endif
3030
3085
}
3031
3086
3032
3087
bool
0 commit comments