Creating a VM Instance with a Custom Machine Type

Compute Engine offers
predefined machine types
that you can use when you create an instance. A predefined machine type has a
preset number of vCPUs and amount of memory, and are charged at a set price,
described in the pricing page.

If predefined machine types do not meet your needs, you can create
an instance with custom virtualized hardware settings. Specifically, you can
create an instance with a custom number of vCPUs and amount of memory,
effectively using a custom machine type. Custom machine types are available
for general-purpose machine types
only; that is, when you create a custom machine type, you are effectively
deploying a custom machine type from the N1 or N2 machine type family.

Custom machine types are subject to the same persistent disk limits as
general-purpose machine types.
Currently, the max total persistent disk size for each machine type per
instance is 64 TB and the max number of persistent disks is 128.

N1 custom machine types

The maximum number of vCPUs allowed for a custom machine type is determined
by the machine type family you choose. For N1 machine types:

If you deploy in a zone that supports the Skylake CPU platform, you can
create custom machine types with up to 96 vCPUs.

If you deploy in zones that support the Broadwell, Haswell, or Ivy Bridge
CPU platforms, you can deploy custom machine types with up to 64 vCPUs.

By default, the memory per vCPU that you can select for a custom machine type
is determined by the machine type family. For N1 machine types, select
between 0.9 GB and 6.5 GB per vCPU, inclusive. Higher amounts of memory are
possible by enabling extended memory.

Examples of invalid machine types

1 vCPU, 0.2 GB of total memory. Invalid because the total memory is
less than the minimum 0.65 for an N1 machine type.

1 vCPU, 0.9 GB of total memory. Invalid because the total memory
must be a multiple of 256 MB. For 1 vCPU, use a minimum of 1024 MB memory.

Examples of valid machine types

32 vCPUs, 29 GB of total memory. Valid because the total number of
vCPUs is even and the total memory is a multiple of 256 MB. The amount of
memory per vCPU is 0.9 GB, which satisfies the minimum requirement.

1 vCPU, 1 GB of total memory. Valid because it has one vCPU, which
is the minimum value, and the total memory is a multiple of 256 MB. The
amount of memory per vCPU is also between the acceptable range of 0.9 GB to
6.5 GB per vCPU.

N2 custom machine types

The maximum number of vCPUs allowed for a custom machine type is determined by
the machine type family you choose. For N2 machine types, which only support
the Cascade Lake platform, you can deploy custom machine types with 2 to 80
vCPUs.

N2 machines are only available in select zones. To learn more, read the
regions and zones page.

By default, the memory per vCPU that you can select for a custom machine type
is determined by the machine type family. For N2 machine types, select between
0.5 GB and 8.0 GB per vCPU, inclusive. Higher amounts of memory are possible
by enabling extended memory.

If the instance has a vCPU count that is 32 vCPUs or higher, the vCPU count
must be evenly divisible by 4. So, for example, 32, 36, and 40 vCPUs are all
valid but 38 is invalid.

Examples of invalid machine types

2 vCPUs, 0.8 GB of total memory. Invalid because the total memory is
less than the minimum 0.5 for an N2 machine type.

34 vCPUs, 34 GB of total memory. Invalid because the total number of vCPUs
is not divisible by 4.

36 vCPUs, 18 GB of total memory. Valid because the total number of
vCPUs is even and the total memory is a multiple of 256 MB. The amount of
memory per vCPU is 0.5 GB, which satisfies the minimum requirement. Because
the number of vCPUs is larger than 32 vCPUs, the number of vCPUs must be
divisible by 4.

2 vCPU, 7 GB of total memory. Valid because it has two vCPUs, which
is the minimum value, and the total memory is a multiple of 256 MB. The
amount of memory per vCPU is also between the acceptable range of 0.5 GB to
8 GB per vCPU.

Pricing

Google charges for custom machine types based on the number of vCPUs and memory
hours that the instance uses. This is different from how predefined machine
types are charged, so we recommend you review the
pricing page before you create
a custom machine type.

Instances running a custom machine type are subject to the same 1-minute
minimum charge as any other instance, but sustained use discounts for custom
machine types are calculated differently. For more information, read
sustained use discounts
for custom machine types.

Expressing memory in GB or MB

For Google Cloud Platform tools and documentation, machine type memory is
calculated in gigabytes (GB), where 1 GB is 230 bytes. This unit of measurement is also known as a gibibyte (GiB) .
When converting memory from GB to MB, 1 GB = 1024 MB.

In the API, you must always provide memory in MB units. If you use the gcloud
command-line tool, it is possible to provide the total memory for an instance
in GB or MB units. However, the gcloud tool expects the memory value to be an
integer, so you cannot provide a float value. For example, to express 5.75 GB,
convert 5.75 GB into MB instead. In this case, 5.75 GB is 5888 MB.

Creating an instance with a custom machine type

Before you create an instance, make sure you read and understand the
Specifications for creating a custom machine type.

When using the --custom-memory flag, specify the total amount of
memory in GB or in MB. The property must be an integer, so if you want to
specify increments of 0.25 GB for memory, convert that value to MB instead.

To specify an incremental value, such as 2.5 GB of memory, convert the value
to MB and supply the value followed by the MB suffix. The following example
creates an instance running an N2 machine type:

API

In the API, create your instance creation request as you would normally,
but when specifying a
machineType
value, use one of the following formats. Replace NUMBER_OF_CPUS with the
number of CPUs and AMOUNT_OF_MEMORY with the amount of memory you want.
Provide memory in MB units.

Adding extended memory to a machine type

Depending on the machine type, each machine type can have up to a specific
amount of memory by default. For example, if you create a VM with an N1
custom machine type, the VM can have up to 6.5 GB of memory per vCPU. For N2
custom machine types, this number goes up to 8 GB of memory per vCPU.

For some workloads, this might not be enough memory. At an additional cost, you
can get more memory per vCPU beyond the default limit. This is referred to
as extended memory.

With extended memory, you can add memory to a machine type with
no limitations per vCPU. You can add extended memory up to certain limits based
on the machine type:

For N1 machine types, you can add up to a total of 624 GB of memory per VM.

For N2 machine types, you can add up to a total of 640 GB of memory per VM.

If you require more memory, you must use one of the
mega-memory machine types,
which allow you to create instances with a total of 1.4 TB per VM instance.

Determining if you need extended memory

Certain workloads need more than the default amount of memory per vCPU to
deliver optimum results. Workloads that are based on in-memory analytics, high
performance databases, including relational and NoSQL databases such as MS SQL
Server, MongoDB and MemcacheD/Redis, fall into this category. vCPU-based licensing
of operating systems and software stacks also make selecting an optimal VM
memory configuration more challenging with predefined machine types. By using
extended memory, you can add as much memory as you need to reach the best price
and performance for your VM instances.

Extended memory prices differ depending on the region. Instances running with
extended memory are subject to the same 1-minute minimum charge as any other
instance. Extended memory also qualifies for sustained use discounts. For
more information, see
Sustained use discounts for custom machine types

Limitations

You can only add extended memory to custom machine types. Predefined machine
types are not supported.

There is no limit of memory per vCPU that you can add, but there is a maximum
amount of memory you can add to each VM instance. For N1 machine types, you
can add up to 624 GB of memory. For N2 machine types, you can add up to 640 GB
of memory.

Console

Select the zone where you want to host this instance. This will also
filter the list of machine types to only types available in that zone.

Under Machine configuration, select General-purpose.

From the Generation drop-down, select First for N1 custom
machine types or Second for N2 custom machine types.

From the Machine type drop down, select Custom.

Select the amount of memory you want. To add extended memory, check the
Extend memory option. The range of selectable memory expands.

Continue with the instance creation process.

gcloud

For N1 machine types, use the gcloud tool and the instances create
subcommand, followed by the --custom-extensions flag to enable extended
memory. Then, specify the total memory that you want with the --custom-
memory parameter.

For N2 machine types, use the gcloud beta command with the instances create
subcommand. Set the --custom-extensions, --custom-cpu, and --custom-memory
flags, followed by the --custom-vm-type flag, to specify the N2
machine type:

Permissions required for this task

Console

Choose the stopped instance you want to modify from the instance list.

Click Edit at the top of the page.

Under Machine configuration, select General-purpose.

From the Machine type drop down, select Custom.

Select the amount of vCPU you want.

Select the amount of memory you want. To add extended memory, check the
Extend memory option. The range of selectable memory expands.

Save your changes.

gcloud

Using the gcloud command-line tool, use the instances set-machine-type
subcommand, followed by the --custom-extensions flag paired with the
existing --custom-memory parameter. To change from N1 machine types N2
machine types and vice-versa, provide the --custom-vm-type flag.

For example, to add 2 GB memory to an instance named example-instance,
which currently has an N1 machine type with 2 vCPU, 13 GB, in us-central1-b
zone, use the following command: