Configure memory limits for services

You can choose the amount of memory to provide for your Cloud Runservice. This page describes how to specify the amount of memoryavailable for your service.

Understand memory usage

Cloud Run instances that exceed their allowed memory limit areterminated.

The available memory for your instance needs to be sufficient for:

  • Running the service executable, because the executable must be loaded tomemory
  • Allocating memory in your service process
  • Writing files to the file system

The size of the deployed container image does not affect memory that is availablefor the instance.

Set and update memory limits

You can set memory limits on Cloud Run services.By default, the memory allocated to each instance of a revision is512 MiB, and the memoryallocated for a function is 256 MiB.

Required memory when setting a CPU value

When setting a CPU value, the following memory is required:

CPUsMemory required
.08 vCPUUp to 512 MiB
.5 vCPUUp to 1 GiB
1 vCPUUp to 4 GiB
2 vCPUUp to 8 GiB
4 vCPU2 to 16 GiB
6 vCPU4 to 24 GiB
8 vCPU4 to 32 GiB
If you use less than 512 MiB of memory, you should use thefirst generation execution environment.

Important: If your single-threaded application's memory needs require you toselect a configuration with 2 or more vCPUs, be aware that this can lead topotential "vCPU hotspots," resulting in inefficient CPU-based autoscaling.In such scenarios, carefully tuning concurrency settings becomes essentialfor managing load and achieving desired scaling behavior.

Maximum amount of memory

The maximum amount of memory you can configure is32 gibibyte (32 Gi).

You can enforce a maximum memory limit by using
custom organization policies.

Minimum memory

The minimum memory setting varies depending on whether you usefirst generation or second generationexecution environment:

  • 128 MiB for first generation
  • 512 MiB for second generation

Required roles

To get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:

If you are deploying aserviceorfunction from source code, youmust also have additional roles granted to you on your project andCloud Build service account.

For a list of IAM roles and permissions that are associated withCloud Run, seeCloud Run IAM rolesandCloud Run IAM permissions.If your Cloud Run service interfaces withGoogle Cloud APIs, such as Cloud Client Libraries, see theservice identity configuration guide.For more information about granting roles, seedeployment permissionsandmanage access.

Configure memory limits

Any configuration change leads to thecreation of a new revision. Subsequent revisions will also automatically getthis configuration setting unless you make explicit updates to change it.

For Cloud Run services, you can set memory limits using the Google Cloud console, the gcloudcommand line, or a YAML file when youcreate a new service ordeploy a new revision:

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. SelectServices from the Cloud Run navigation menu, and clickDeploy container to configure a new service.If you are configuring an existing service, click theservice, then clickEdit and deploy new revision.

  3. If you are configuring a new service, fill out the initial servicesettings page, then clickContainer(s), Volumes, Networking, Security to expand theservice configuration page.

  4. Click theContainer tab.

    image

    • Select the desired memory size from theMemory dropdown list.
  5. ClickCreate orDeploy.

gcloud

You canupdate the memory allocationof a given service by using the following command:

gcloudrunservicesupdateSERVICE--memorySIZE

ReplaceSERVICE with the name of your service andSIZE with the desiredmemory size. The format for size is a fixed or floating point number followedby a unit:G orM corresponding to gigabyte or megabyte,respectively, or use the power-of-two equivalents:Gi orMicorresponding to gibibyte or mebibyte respectively.

You can also set memory limits duringdeployment using the command:

gcloudrundeploy--imageIMAGE_URL--memorySIZE

Replace the following:

  • IMAGE_URL: a reference to the container image, forexample,us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.
  • SIZE: the values described above.
Note: If you are using the gcloud CLI to deploying from source, make sure to have therequired roles granted to you and to use--source instead of--image, and add--function if deploying a function.

YAML

  1. If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:

    gcloudrunservicesdescribeSERVICE--formatexport>service.yaml
  2. Update thememory attribute:

    apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICEspec:template:metadata:name:REVISIONspec:containers:-image:IMAGEresources:limits:memory:SIZE

    Replace the following:

    • SERVICE: the name of your Cloud Run service.
    • IMAGE_URL: a reference to the container image, forexample,us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,therepositoryREPO_NAME mustalready be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.
    • SIZE: the desired memory size.The format is a fixed or floating point number followed by a unit:G orM corresponding to gigabyte or megabyte,respectively, or use the power-of-two equivalents:Gi orMicorresponding to gibibyte or mebibyte respectively.
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, itmust meet the following criteria:
      • Starts withSERVICE-
      • Contains only lowercase letters, numbers and-
      • Does not end with a-
      • Does not exceed 63 characters
  3. Create or update the service using the following command:

    gcloudrunservicesreplaceservice.yaml

Terraform

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Add the following to agoogle_cloud_run_v2_service resource in your Terraform configuration:

resource"google_cloud_run_v2_service""default"{name="cloudrun-service-memory-limits"location="us-central1"deletion_protection=false # set to "true" in productiontemplate{containers{image="us-docker.pkg.dev/cloudrun/container/hello"resources{limits={          # Memory usage limit (per container)memory="512Mi"}}}}}

Undertemplate.containers.resources.limits, replace512Mi with yourservice's desired memory limit.

Optimize memory for services

For a Cloud Run service, you can determine the peak memory requirement for a service using thefollowing:(Standing Memory) + (Memory per Request) * (Service Concurrency)

Accordingly,

  • If you raise the concurrency of your service, you should alsoincrease the memory limit to account for peak usage.

  • If you lower the concurrency of your service, consider reducing the memorylimit to save on memory usage costs.

For more guidance on minimizing per request memory usage readDevelopment Tips on Global Variables.

View memory limit settings

To view the current memory limit settings for yourCloud Run service:

Console

  1. In the Google Cloud console, go to the Cloud RunServices page:

    Go to Cloud Run

  2. Click the service you are interested in to open theService detailspage.

  3. Click theRevisions tab.

  4. In the details panel at the right, the memory limit settingis listed under theContainer tab.

gcloud

  1. Use the following command:

    gcloudrunservicesdescribeSERVICE
  2. Locate the memory limit setting in the returnedconfiguration.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.