0
votes

There are two examples on kubernetes.io about how to specify memory request and limits and they are very confusing.

(I removed cpu and the unnecessary quote characters from the following examples.)

Example 1:

https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

resources:
  requests:
    memory: 64Mi
  limits:
    memory: 128Mi

Example 2:

https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/

resources:
  limits:
    memory: 200Mi
  requests:
    memory: 100Mi

Both examples are valid expressions but when using power-of-two suffix shouldn't you aim for always using 8, 16, 32, 64, 128, 256, 512, 1028 and so on?

I think that the person from example nr 2 didn't really know what she/he was doing and she/he should have used fixed-point suffix, 200M and 100M, instead?

If I were to specify 268435456 bytes using power-of-two suffix how would I express that in my yaml config; 250Mi or 256Mi?

1
100Mi is 104,857,600 bytes; there's nothing syntactically or semantically wrong with it as a limit, and it's about 20% less memory than 128Mi.David Maze

1 Answers

1
votes

I think that the person from example nr 2 didn't really know what she/he was doing and she/he should have used fixed-point suffix, 200M and 100M, instead?

No. Mi and M are units representing certain number of bytes. Mi is (210)2 bytes (1048576 bytes) and M is (103)2 bytes (1000000 bytes). The number you place before these units doesn't matter except for as a multiplication factor. There is no requirement that the prefix number should be a multiple of two or anything.

200M = 200 x (103)2 bytes = 200000000 bytes

200Mi = 200 x (210)2 bytes = 209715200 bytes


If I were to specify 268435456 bytes using power-of-two suffix how would I express that in my yaml config; 250Mi or 256Mi?

268435456 bytes = 268435456/1048576 Mi = 256Mi

268435456 bytes = 268435456/1000000 M = 268.435456M


From docs

Limits and requests for memory are measured in bytes. You can express memory as a plain integer or as a fixed-point number using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki. For example, the following represent roughly the same value:

128974848, 129e6, 129M, 123Mi