# Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Cannot allocate memory in Unknown on line 0

- **ID:** `php/opcache-memory-corruption`
- **Domain:** php
- **Category:** system_error
- **Error Code:** `E_WARNING`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

OPcache's huge code pages feature fails when the system's transparent hugepage support is misconfigured or the kernel cannot allocate contiguous huge pages, often due to memory fragmentation or insufficient hugepage pool size.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |
| PHP 8.4 | active | — | — |
| Linux kernel 5.15+ | active | — | — |
| Linux kernel 6.x | active | — | — |

## Workarounds

1. **Disable huge code pages in php.ini by setting `opcache.huge_code_pages=0`, then restart PHP-FPM: `sudo systemctl restart php8.2-fpm`** (95% success)
   ```
   Disable huge code pages in php.ini by setting `opcache.huge_code_pages=0`, then restart PHP-FPM: `sudo systemctl restart php8.2-fpm`
   ```
2. **Configure transparent hugepages on the system: run `echo always > /sys/kernel/mm/transparent_hugepage/enabled` and ensure `vm.nr_hugepages` is set high enough in `/etc/sysctl.conf` (e.g., `vm.nr_hugepages=1024`), then reboot.** (85% success)
   ```
   Configure transparent hugepages on the system: run `echo always > /sys/kernel/mm/transparent_hugepage/enabled` and ensure `vm.nr_hugepages` is set high enough in `/etc/sysctl.conf` (e.g., `vm.nr_hugepages=1024`), then reboot.
   ```

## Dead Ends

- **** — The error stems from the OS kernel state, not the PHP process; a restart only clears temporary state but does not fix the underlying hugepage allocation failure. (95% fail)
- **** — This directive controls the size of the shared memory segment for cached scripts, not the huge page mechanism. The error is triggered during huge page allocation, independent of memory consumption. (90% fail)
