Skip to content

Commit 24fce8e

Browse files
authored
Merge pull request #22246 from mpirvu/disclaim-on-tmp
Do not disclaim on tmpfs/ramfs/nfs
2 parents 4d70258 + fec349d commit 24fce8e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

runtime/compiler/control/J9Options.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include <algorithm>
2626
#include <ctype.h>
2727
#include <stdint.h>
28+
#if defined(LINUX)
29+
#include <sys/statfs.h>
30+
#include <linux/magic.h>
31+
#endif /* LINUX */
32+
2833
#include "jitprotos.h"
2934
#include "j2sever.h"
3035
#include "j9.h"
@@ -2988,6 +2993,7 @@ J9::Options::fePostProcessJIT(void * base)
29882993
bool
29892994
J9::Options::disableMemoryDisclaimIfNeeded(J9JITConfig *jitConfig)
29902995
{
2996+
#if defined (LINUX)
29912997
J9JavaVM * javaVM = jitConfig->javaVM;
29922998
PORT_ACCESS_FROM_JAVAVM(javaVM); // for j9vmem_supported_page_sizes
29932999
OMRPORT_ACCESS_FROM_J9PORT(javaVM->portLibrary); // for omrsysinfo_os_kernel_info
@@ -3019,6 +3025,52 @@ J9::Options::disableMemoryDisclaimIfNeeded(J9JITConfig *jitConfig)
30193025
}
30203026
}
30213027
}
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+
}
30223074
if (shouldDisableMemoryDisclaim)
30233075
{
30243076
TR::Options::getCmdLineOptions()->setOption(TR_DisableDataCacheDisclaiming);
@@ -3027,6 +3079,9 @@ J9::Options::disableMemoryDisclaimIfNeeded(J9JITConfig *jitConfig)
30273079
TR::Options::getCmdLineOptions()->setOption(TR_EnableSharedCacheDisclaiming, false);
30283080
}
30293081
return shouldDisableMemoryDisclaim;
3082+
#else /* if defined(LINUX) */
3083+
return true;
3084+
#endif
30303085
}
30313086

30323087
bool

0 commit comments

Comments
 (0)