[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-24。"],[],[],null,["# Configure memory limits for jobs\n\nYou can choose the amount of memory to provide for your Cloud Run\njob. This page describes how to specify the amount of memory\navailable for your job.\n\nUnderstand memory usage\n-----------------------\n\nCloud Run instances that exceed their allowed memory limit are\nterminated.\n\nThe available memory for your instance needs to be sufficient for:\n\n- Running the job executable, because the executable must be loaded to memory\n- Allocating memory in your job process\n- Writing files to the file system\n\nThe size of the deployed container image does not affect memory that is available\nfor the instance.\n\nSet and update memory limits\n----------------------------\n\nYou can set memory limits on Cloud Run jobs.\nBy default, the memory allocated to each job is\n512 MiB.\n\n### Required minimum CPUs\n\nThe amount of allocated memory you choose corresponds to an amount of minimum\nCPU for your job. When setting a memory limit, the following\nminimum CPU limits are required:\n\n### Maximum amount of memory\n\nThe maximum amount of memory you can configure is\n32 gibibyte (`32 Gi`).\n\n### Minimum memory\n\nThe minimum amount of memory you can configure in the\n[second generation](/run/docs/container-contract#sandbox)\nexecution environment is 512 MiB.\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to configure Cloud Run jobs,\n\nask your administrator to grant you the\nfollowing IAM roles:\n\n- [Cloud Run Developer](/iam/docs/roles-permissions/run#run.developer) (`roles/run.developer`) on the Cloud Run job\n- [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity\n\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run job interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/jobs/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nConfigure memory limits\n-----------------------\n\nYou must specify a minimum of 512Mi for a\nCloud Run job. To specify memory for a Cloud Run job: \n\n### Console\n\n\n1. In the Google Cloud console, go to the Cloud Run jobs page:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Select **Jobs** from the menu, and click **Deploy container** to fill out\n the initial job settings page. If you are configuring an existing job,\n select the job, then click **Edit**.\n\n3. Click **Container(s), Volumes, Connections, Security** to expand the job properties page.\n\n4. Click the **Container** tab.\n\n - Select the desired memory size from the **Memory** drop-down list.\n5. Click **Create** or **Update**.\n\n### gcloud\n\n1. To set memory limits when you [create a job](/sdk/gcloud/reference/run/jobs/create):\n\n ```bash\n gcloud run jobs create JOB_NAME --image IMAGE_URL --memory SIZE\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e with the name of your job.\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e: a reference to the [container image](/run/docs/building/containers)---for example, `us-docker.pkg.dev/cloudrun/container/job:latest`.\n - \u003cvar translate=\"no\"\u003eSIZE\u003c/var\u003e with the desired memory size. The format for size is a fixed or floating point number followed by a unit: `G` or `M` corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents: `Gi` or `Mi` corresponding to gibibyte or mebibyte respectively.\n2. To set memory limits when you [update a job](/sdk/gcloud/reference/run/jobs/update):\n\n ```bash\n gcloud run jobs update JOB_NAME --memory SIZE\n ```\n\n### YAML\n\n1. If you are creating a new job, skip this step.\n If you are updating an existing job, download its [YAML configuration](/run/docs/reference/yaml/v1#job):\n\n ```bash\n gcloud run jobs describe JOB_NAME --format export \u003e job.yaml\n ```\n2. Update the `memory` attribute:\n\n ```yaml\n apiVersion: run.googleapis.com/v1\n kind: Job\n metadata:\n name: JOB\n spec:\n template:\n spec:\n template:\n spec:\n containers:\n - image: IMAGE\n resources:\n limits:\n memory: SIZE\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSIZE\u003c/var\u003e with the desired memory size, specifying a minimum\n of 512Mi. The format is a fixed or floating point\n number followed by a unit: `G` or `M` corresponding to gigabyte or megabyte,\n respectively, or use the power-of-two equivalents: `Gi` or `Mi`\n corresponding to gibibyte or mebibyte respectively.\n\n You can also specify more configuration such as environment variables or\n memory limits.\n3. Update the existing job configuration:\n\n ```bash\n gcloud run jobs replace job.yaml\n ```\n\n### Terraform\n\n\u003cbr /\u003e\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\nAdd the following to a [`google_cloud_run_v2_job`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_job) resource in your Terraform configuration: \n\n\u003cbr /\u003e\n\n resource \"google_cloud_run_v2_job\" \"default\" {\n name = \"cloudrun-job\"\n location = \"\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\"\n deletion_protection = false\n\n template {\n template {\n containers {\n image = \"us-docker.pkg.dev/cloudrun/container/job\"\n resources {\n limits = {\n cpu = \"2\"\n memory = \"\u003cvar translate=\"no\"\u003eSIZE\u003c/var\u003e\"\n }\n }\n }\n }\n }\n }\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the Google Cloud region. For example, `europe-west1`.\n- \u003cvar translate=\"no\"\u003eSIZE\u003c/var\u003e with the required memory size, specifying a minimum of 512Mi. The format is a fixed or floating point number followed by a unit: `G` or `M` corresponding to gigabyte or megabyte, respectively, or use the power-of-two equivalents: `Gi` or `Mi` corresponding to gibibyte or mebibyte respectively.\n\nView memory limit settings\n--------------------------\n\nTo view the current memory limit settings for your\nCloud Run job: \n\n### Console\n\n1. In the Google Cloud console, go to the Cloud Run jobs page:\n\n [Go to Cloud Run jobs](https://console.cloud.google.com/run/jobs)\n2. Click the job you are interested in to open the **Job details** page.\n\n3. Click **View and Edit job configuration**.\n\n4. Locate the memory limit setting in the configuration\n details.\n\n### gcloud\n\n1. Use the following command:\n\n ```bash\n gcloud run jobs describe JOB_NAME\n ```\n2. Locate the memory limit setting in the returned\n configuration."]]