@@ -92,13 +92,23 @@ const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES =
9292 OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_MB * 1_000_000 ;
9393
9494/**
95- * The minimum memory (in MB) that must be available for CodeQL to perform overlay
96- * analysis. If CodeQL will be given less memory than this threshold, then the
97- * action will not perform overlay analysis unless overlay analysis has been
98- * explicitly enabled via environment variable.
95+ * The minimum memory (in MB) that must be available for CodeQL to perform overlay analysis. If
96+ * CodeQL will be given less memory than this threshold, then the action will not perform overlay
97+ * analysis unless overlay analysis has been explicitly enabled via environment variable.
98+ *
99+ * This check is not performed for CodeQL >= `CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE` since
100+ * improved memory usage in that version makes the check unnecessary.
99101 */
100102const OVERLAY_MINIMUM_MEMORY_MB = 5 * 1024 ;
101103
104+ /**
105+ * Versions 2.24.3+ of CodeQL reduce overlay analysis's peak RAM usage.
106+ *
107+ * In particular, RAM usage with overlay analysis enabled should generally be no higher than it is
108+ * without overlay analysis for these versions.
109+ */
110+ const CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE = "2.24.3" ;
111+
102112export type RegistryConfigWithCredentials = RegistryConfigNoCredentials & {
103113 // Token to use when downloading packs from this registry.
104114 token : string ;
@@ -683,16 +693,12 @@ async function isOverlayAnalysisFeatureEnabled(
683693 return true ;
684694}
685695
686- /**
687- * Checks if the runner supports overlay analysis based on available disk space
688- * and the maximum memory CodeQL will be allowed to use.
689- */
690- async function runnerSupportsOverlayAnalysis (
696+ /** Checks if the runner has enough disk space for overlay analysis. */
697+ function runnerHasSufficientDiskSpace (
691698 diskUsage : DiskUsage | undefined ,
692- ramInput : string | undefined ,
693699 logger : Logger ,
694700 useV2ResourceChecks : boolean ,
695- ) : Promise < boolean > {
701+ ) : boolean {
696702 const minimumDiskSpaceBytes = useV2ResourceChecks
697703 ? OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES
698704 : OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_BYTES ;
@@ -711,6 +717,26 @@ async function runnerSupportsOverlayAnalysis(
711717 ) ;
712718 return false ;
713719 }
720+ return true ;
721+ }
722+
723+ /** Checks if the runner has enough memory for overlay analysis. */
724+ async function runnerHasSufficientMemory (
725+ codeql : CodeQL ,
726+ ramInput : string | undefined ,
727+ logger : Logger ,
728+ ) : Promise < boolean > {
729+ if (
730+ await codeQlVersionAtLeast (
731+ codeql ,
732+ CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE ,
733+ )
734+ ) {
735+ logger . debug (
736+ `Skipping memory check for overlay analysis because CodeQL version is at least ${ CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE } .` ,
737+ ) ;
738+ return true ;
739+ }
714740
715741 const memoryFlagValue = getCodeQLMemoryLimit ( ramInput , logger ) ;
716742 if ( memoryFlagValue < OVERLAY_MINIMUM_MEMORY_MB ) {
@@ -721,6 +747,29 @@ async function runnerSupportsOverlayAnalysis(
721747 return false ;
722748 }
723749
750+ logger . debug (
751+ `Memory available for CodeQL analysis is ${ memoryFlagValue } MB, which is above the minimum of ${ OVERLAY_MINIMUM_MEMORY_MB } MB.` ,
752+ ) ;
753+ return true ;
754+ }
755+
756+ /**
757+ * Checks if the runner supports overlay analysis based on available disk space
758+ * and the maximum memory CodeQL will be allowed to use.
759+ */
760+ async function runnerSupportsOverlayAnalysis (
761+ codeql : CodeQL ,
762+ diskUsage : DiskUsage | undefined ,
763+ ramInput : string | undefined ,
764+ logger : Logger ,
765+ useV2ResourceChecks : boolean ,
766+ ) : Promise < boolean > {
767+ if ( ! runnerHasSufficientDiskSpace ( diskUsage , logger , useV2ResourceChecks ) ) {
768+ return false ;
769+ }
770+ if ( ! ( await runnerHasSufficientMemory ( codeql , ramInput , logger ) ) ) {
771+ return false ;
772+ }
724773 return true ;
725774}
726775
@@ -812,6 +861,7 @@ export async function getOverlayDatabaseMode(
812861 if (
813862 performResourceChecks &&
814863 ! ( await runnerSupportsOverlayAnalysis (
864+ codeql ,
815865 diskUsage ,
816866 ramInput ,
817867 logger ,
0 commit comments