Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84678

Addition of a max memory limit setting to prevent OOMKill and enforce PHP graceful exit

      We'd like a $CFG->maxmemorylimit (naming?) to ensure that Moodle (and third party plugins) never raises memory limit higher than a certain point. Perhaps the only exception being when the shutdown handler is running to make sure it has enough memory to finish the graceful exit. (in case shutdown handler was called after hitting memory_limit)

      Example scenario:
      Running Moodle in Kubernetes you'd have set some resource constraints. Let's say we've allocated 256 MB to a pod running our Moodle and set memory_limit to 128 MB in php.ini.

      This setup means we'll have 128 MB available in PHP and a buffer of 128 MB for the rest of the pod. (Assuming only one PHP script will be executed simultaneously, since memory_limit is per script)

      Now to the issue.
      Moodle and a lot of third party plugins use the ini_set() and raise_memory_limit() functions to change PHP memory_limit from the php.ini value during runtime.

      If the memory_limit is set to a value higher than the total allocated memory in the pod (256 MB in this scenario), then when the pod's memory of 256 MB has been exhausted by PHP, it will be the kernel OOM killer that handles the exhaustion instead of PHP, causing a non-graceful exit. (Meaning Moodle's shutdown handler doesn't get called)

      We have a lot of issues where this happens during both normal web requests but also the execution of an adhoc_task causing the task to never be marked as failed and appears as still running to Moodle. This can potentially lead to the task blocking execution of other queued adhoc_tasks depending on your Moodle's configuration. ($CFG->task_concurrency_limit)

        1. test.php
          2 kB
          Frederik Milling Pytlick
        2. screenshot-1.png
          175 kB
          Frederik Milling Pytlick

            frederikmillingpytlick Frederik Milling Pytlick
            frederikmillingpytlick Frederik Milling Pytlick
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.