warden icon indicating copy to clipboard operation
warden copied to clipboard

mmap() Cannot allocate memory - memory leak for php and elasticsearch on Apple M1

Open antoniocarboni opened this issue 3 years ago • 32 comments

Hi i get an error when i try to perform a simple bin/magento setup:upgrade inside php-fpm. The error is:

mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 70668288) (tried to allocate 5131192 bytes) in /var/www/html/vendor/colinmollenhour/cache-backend-file/File.php on line 202
Fatal error: Out of memory (allocated 70668288) (tried to allocate 5131192 bytes) in /var/www/html/vendor/colinmollenhour/cache-backend-file/File.php on line 202

I've already checked and Docker is set to use 8GB of RAM and 2GB of Swap. I checked the memory limit configuration and it is set to 2GB. I tried increasing it to 4 but the error didn't change.

Same project with same config works correctly on Old mac intel.

antoniocarboni avatar Apr 02 '21 14:04 antoniocarboni

The same problem happens with elasticsearch container

for reference, here is other discussion: https://github.com/docker/for-mac/issues/5204

antoniocarboni avatar Apr 02 '21 14:04 antoniocarboni

Reading around a bit it would seem it is necessary to replace the images with specific images for arm architecture. At this point I think it would be necessary to follow what k4emic has been said here:

https://github.com/davidalger/warden/pull/317

antoniocarboni avatar Apr 04 '21 11:04 antoniocarboni

@antoniocarboni Regarding eleasticsearch I've manage to fix it by using offical elasticsearch image: https://github.com/davidalger/warden/blob/develop/environments/includes/elasticsearch.base.yml#L5

image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0

To fix this memory leak for php arm 64 versions of warden php-fpm imagens needs to be published.

zcuric avatar Apr 12 '21 08:04 zcuric

great! for php-fpm what are specific about warden php images? do they have any particular config? If we can get some general config, maybe we might be able to have a working stack for m1.

antoniocarboni avatar Apr 15 '21 08:04 antoniocarboni

Hello, I have the same issue. Could you tell me how to fix it? I tried to edit .env file and change elasticsearch version to 7.8/7.12. My configuration for elastisearch is:

elasticsearch:
    environment:
      ES_JAVA_OPTS: -Xms64m -Xmx512m
      discovery.type: single-node
      xpack.security.enabled: "false"
    hostname: exampleproject-elasticsearch
    image: docker.io/wardenenv/elasticsearch:7.8
    labels:
      traefik.enable: "true"
      traefik.http.routers.exampleproject-elasticsearch.rule: Host(`elasticsearch.exampleproject.test`)
      traefik.http.routers.exampleproject-elasticsearch.tls: "true"
      traefik.http.services.exampleproject-elasticsearch.loadbalancer.server.port: '9200'
    volumes:
    - esdata:/usr/share/elasticsearch/data:rw

But this problem still occurs. Could you help me to fix it?

webphpprojects avatar Apr 28 '21 10:04 webphpprojects

Hello, I have the same issue. Could you tell me how to fix it? I tried to edit .env file and change elasticsearch version to 7.8/7.12. My configuration for elastisearch is:

elasticsearch:
    environment:
      ES_JAVA_OPTS: -Xms64m -Xmx512m
      discovery.type: single-node
      xpack.security.enabled: "false"
    hostname: exampleproject-elasticsearch
    image: docker.io/wardenenv/elasticsearch:7.8
    labels:
      traefik.enable: "true"
      traefik.http.routers.exampleproject-elasticsearch.rule: Host(`elasticsearch.exampleproject.test`)
      traefik.http.routers.exampleproject-elasticsearch.tls: "true"
      traefik.http.services.exampleproject-elasticsearch.loadbalancer.server.port: '9200'
    volumes:
    - esdata:/usr/share/elasticsearch/data:rw

But this problem still occurs. Could you help me to fix it?

You have to change the image, to:

image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0

zcuric avatar Apr 28 '21 10:04 zcuric

but how? in .env?

webphpprojects avatar Apr 28 '21 10:04 webphpprojects

    environment:
      ES_JAVA_OPTS: -Xms64m -Xmx512m
      discovery.type: single-node
      xpack.security.enabled: "false"
    hostname: exampleproject-elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
    labels:
      traefik.enable: "true"
      traefik.http.routers.exampleproject-elasticsearch.rule: Host(`elasticsearch.exampleproject.test`)
      traefik.http.routers.exampleproject-elasticsearch.tls: "true"
      traefik.http.services.exampleproject-elasticsearch.loadbalancer.server.port: '9200'
    volumes:
    - esdata:/usr/share/elasticsearch/data:rw

zcuric avatar Apr 28 '21 10:04 zcuric

Ok, but what exactly do I need to edit?

webphpprojects avatar Apr 28 '21 10:04 webphpprojects

@webphpprojects

elasticsearch:
    environment:
      ES_JAVA_OPTS: -Xms64m -Xmx512m
      discovery.type: single-node
      xpack.security.enabled: "false"
   	hostname: exampleproject-elasticsearch
-   image: docker.io/wardenenv/elasticsearch:7.8
+   image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
    labels:
      traefik.enable: "true"
      traefik.http.routers.exampleproject-elasticsearch.rule: Host(`elasticsearch.exampleproject.test`)
      traefik.http.routers.exampleproject-elasticsearch.tls: "true"
      traefik.http.services.exampleproject-elasticsearch.loadbalancer.server.port: '9200'
    volumes:
    - esdata:/usr/share/elasticsearch/data:rw

zcuric avatar Apr 28 '21 11:04 zcuric

Ok, maybe my question was not precise enough. Where I can find the file I have to edit? I cannot find it in project folder even in .warden directory.

I see this in docs: https://docs.warden.dev/environments/customizing.html#docker-specific-customizations But I don't have .warden directory in my project

webphpprojects avatar Apr 28 '21 11:04 webphpprojects

.warden directory is in your root folder when you open the terminal.

zcuric avatar Apr 28 '21 11:04 zcuric

Yes, I see this directory, but I don't see there warden-env.yml

webphpprojects avatar Apr 28 '21 11:04 webphpprojects

@webphpprojects /opt/homebrew/Cellar/warden/0.10.2/environments/includes

zcuric avatar Apr 28 '21 12:04 zcuric

@zcuric Thank you :) What do I need to do after changing the proper file? I did warden svc restart and warden env up -d but the problem still occurs.

webphpprojects avatar Apr 28 '21 13:04 webphpprojects

I find the solution. I switched to composer 2 and this problem does not occur.

webphpprojects avatar Apr 28 '21 20:04 webphpprojects

Today I wanted to finish magento 2 installation and have this error:

 bin/magento cache:clean

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 64573440) (tried to allocate 5328896 bytes) in /var/www/html/vendor/colinmollenhour/credis/Client.php on line 1161

Fatal error: Out of memory (allocated 64573440) (tried to allocate 5328896 bytes) in /var/www/html/vendor/colinmollenhour/credis/Client.php on line 1161

How can I fix it?

webphpprojects avatar Apr 29 '21 05:04 webphpprojects

@webphpprojects you can't, not until warden devs update docker images to be compatible with ARM. Because if you read issue from the beginning, we only found solution for elasticsearch.

zcuric avatar Apr 29 '21 06:04 zcuric

OK, but in my case changing elasticsearch image did not solve a problem. I see you are using warden 0.10.2. In my case it's 0.11. Maybe I should switch to older version?

webphpprojects avatar Apr 29 '21 06:04 webphpprojects

@webphpprojects That won't fix your problem. It fixes elasticsearch part of the problem, but php memory issue is up to warden devs.

zcuric avatar Apr 29 '21 08:04 zcuric

So I have to wait for a fix, right?

webphpprojects avatar Apr 29 '21 11:04 webphpprojects

@zcuric I made some research and found this topic and comment: https://github.com/markshust/docker-magento/issues/396#issuecomment-776854665 I hope it is useful for fixing this issue (I will check also).

webphpprojects avatar May 04 '21 21:05 webphpprojects

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Aug 02 '21 22:08 stale[bot]

let's keep it open

ihor-sviziev avatar Aug 30 '21 12:08 ihor-sviziev

This is still relevant and will be until Warden's PHP images have ARM alternatives. I'm currently trying to rebuild the necessary PHP packages from Remi's repository for as ARM versions, but need some assistance here. Does anyone have experience building RPMs with/without Mock? It's critical to get this running since Remi does not have plans to publish ARM packages any time soon as he doesn't have the necessary hardware. @davidalger, any thoughts?

drpayyne avatar Sep 03 '21 09:09 drpayyne

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Dec 02 '21 12:12 stale[bot]

This is definitely still active and valid. :)

drpayyne avatar Dec 02 '21 13:12 drpayyne

Hi @drpayyne, Can we re-use your images just by replacing WARDEN_IMAGE_REPOSITORY with your image prefix? Are there any other modifications required?

ihor-sviziev avatar Feb 13 '22 21:02 ihor-sviziev

I doubt that it'll work right OOTB by just using that tag since my images are still "in-beta" as far as I'm concerned so I've tag names which aren't a direct substitution to existing tag names. For example - I have tags ending in -deb to show that the images are Debian based. That said, I think it'd be good to map it directly after verifying that there is nothing else blocking it, @ihor-sviziev.

drpayyne avatar Feb 13 '22 22:02 drpayyne

Ok. So I'm working on adding arm64 support for all the possible images (for now M2 projects only).

The status is following:

Global services:

  • ✅ Portainer already supports ARM64
  • ✅ Traefik already supports ARM64
  • 🟡 DNSmasq - works fine in emulation, TODO
  • 🟡 Mailhog - works fine in emulation, TODO
  • 🟡 SSH tunnel - works fine in emulation, TODO

Mandatory parts for M2 projects:

  • 🟡 Varnish is not working - https://github.com/davidalger/warden/pull/484
  • 🟡 Redis, MariaDB, RabbitMQ - https://github.com/davidalger/warden/issues/485 I think we can switch to official images as we don't have any modifications and the official ones does has support
  • 🟡 Nginx - works fine in emulation, TODO
  • ❌ Php-FPM + xdebug - works very slow, TODO
  • ❌ Elasticsearch - works very slow, https://github.com/davidalger/warden/pull/488

Optional parts for M2 projects (didn't check status yet):

  • blackfire - TODO
  • allure - TODO
  • selenium + debug - TODO
  • split sales - TODO
  • split checkout - TODO
  • test db - TODO
  • magepack - TODO

ihor-sviziev avatar Feb 16 '22 10:02 ihor-sviziev