private static boolean enoughMemoryToAvoidRestart(ApplicationContainerCluster clusterInCurrentModel,
                                                      ApplicationContainerCluster cluster,
                                                      DeployLogger deployLogger) {
        List<ApplicationContainer> containers = cluster.getContainers();
        if (containers.isEmpty()) return true;

        double currentModelCostInGb = onnxModelCostInGb(clusterInCurrentModel);
        double nextModelCostInGb = onnxModelCostInGb(cluster);

        double totalMemory = containers.stream().mapToDouble(c -> c.getHostResource().realResources().memoryGiB()).min().orElseThrow();
        double memoryUsedByModels = currentModelCostInGb + nextModelCostInGb;
        double availableMemory = Math.max(0, totalMemory - Host.memoryOverheadGb - memoryUsedByModels);

        var availableMemoryPercentage = cluster.heapSizePercentageOfAvailable();
        int memoryPercentage = (int) (availableMemory / totalMemory * availableMemoryPercentage);

        var prefix = "Validating Onnx models memory usage for %s".formatted(cluster);
        if (memoryPercentage < percentLimit) {
            deployLogger.log(INFO, ("%s, percentage of available memory " +
                    "too low (%d < %d) to avoid restart, consider a flavor with more memory to avoid this")
                    .formatted(prefix, memoryPercentage, percentLimit));
            return false;
        }

        if (availableMemory < gbLimit) {
            deployLogger.log(INFO, ("%s, available memory too low "
                             + "(%.2f Gb < %.2f Gb) to avoid restart, consider a flavor with more memory to avoid this")
                    .formatted(prefix, availableMemory, gbLimit));
            return false;
        }

        log.log(FINE, "%s, enough available memory (%.2f Gb) to avoid restart (models use %.2f Gb)"
                .formatted(prefix, availableMemory, memoryUsedByModels));
        return true;
    }
If Onnx models change in a way that requires restart of containers in
a container cluster this validator will make sure that restartOnDeploy is set for
configs for this cluster.

@author hmusum
config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/RestartOnDeployForOnnxModelChangesValidator.java