# systemMemSizeMB flag - can it be set externally

**URL:** <https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367>\
**Category:** Percona Operator for MongoDB\
**Created:** [July 15, 2021, 8:33am UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367 "2021-07-15T08:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamoser](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jamoser](https://forums.percona.com/u/jamoser)\
**Post date:** [July 15, 2021, 8:33am UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367/1 "2021-07-15T08:33:36Z")

</div>

Debugging the whole setup on GKE, it turns out that mongod in a Kubernetes container sees the max RAM of the node instead of the limits.memory set for the pod.

So in our case mongod sees 49GB (from the node) and I guess does not respect the limit of 8GB set in limits.memory.

Basically this means the pod gets OOM killed sooner or later.

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [July 19, 2021, 10:19am UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367/2 "2021-07-19T10:19:32Z")

</div>

Hello @jamoser ,

Thank you for reporting this.  
I see it is the common issue:

> <https://stackoverflow.com/questions/66223623/mongodb-on-kubernetes-exceed-memory-limit-available-memory-is-less-than-system>

> **[MongoDB container exceeds k8s RAM limit](https://www.mongodb.com/community/forums/t/mongodb-container-exceeds-k8s-ram-limit/11965)**
>
> Hi! I have this problem, my MongoDB container always exceeds my k8s memory limits after a while. For example after working an hour on load, it can reach even 4/6GiB of ram. My k8s yaml contains: resources: requests: ...

Let me see what can be done here.

---

<div class="post-metadata">

**Author:** ![jamoser](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jamoser](https://forums.percona.com/u/jamoser)\
**Post date:** [July 19, 2021, 9:52pm UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367/3 "2021-07-19T21:52:09Z")

</div>

Hi @Sergey_Pronin

Thanks - we are now tracking the memory consumption and have a alert, when a certain memory used limit is reached. May be some time in the future there is some kind of auto-scaling based on memory surge in the operator … 🙂

Regards  
John

---

<div class="post-metadata">

**Author:** ![jamoser](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jamoser](https://forums.percona.com/u/jamoser)\
**Post date:** [July 21, 2021, 1:03pm UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367/4 "2021-07-21T13:03:37Z")

</div>

May be as an input for others - to avoid the Memory Usage Peak, we load the databases on demand into MongoDB. This way we can have a lot fewer db’s active and in case a pod gets rescheduled, it need most likely much less memory.

---

<div class="post-metadata">

**Author:** ![jamoser](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jamoser](https://forums.percona.com/u/jamoser)\
**Post date:** [December 27, 2022, 3:43pm UTC](https://forums.percona.com/t/systemmemsizemb-flag-can-it-be-set-externally/11367/5 "2022-12-27T15:43:20Z")

</div>

> <https://github.com/mongodb/mongodb-kubernetes-operator/issues/936>
>
> Hello guys, I have a MongoDB Operator deployed in HA, and I'm facing this proble…m that even limiting the amount of memory that mongod must use, this limit is not being respected, which ends up taking a high memory consumption and consequently the pod is dropped.
> 
> The node itself has 32gb of ram and we are reserving 30gb for the mongod container and limiting consumption to 23GB
> 
> I have here some information from Grafana, showing the consumption of the container before a failure.
> 
> !\[memory\](https://user-images.githubusercontent.com/20954739/161768821-f190f044-8fe2-432f-ac6d-c047db488f42.png)
> 
> Just like the mongodb CRD yaml.
> 
> \`\`\`yaml
> apiVersion: v1
> items:
> \- apiVersion: mongodbcommunity.mongodb.com/v1
> kind: MongoDBCommunity
> metadata:
> annotations:
> mongodb.com/v1.lastAppliedMongoDBVersion: 5.0.6
> generation: 9
> name: prd-mongodb
> namespace: shared-database
> spec:
> additionalMongodConfig:
> storage.wiredTiger.engineConfig.cacheSizeGB: 23
> storage.wiredTiger.engineConfig.journalCompressor: zlib
> members: 3
> security:
> authentication:
> modes:
> - SCRAM
> statefulSet:
> spec:
> template:
> spec:
> containers:
> - env:
> - name: MANAGED\_SECURITY\_CONTEX
> value: "true"
> name: mongod
> resources:
> limits:
> cpu: "3.5"
> memory: 30Gi
> requests:
> cpu: "2"
> memory: 14Gi
> - env:
> - name: MANAGED\_SECURITY\_CONTEX
> value: "true"
> name: mongodb-agent
> resources:
> limits:
> cpu: "0.5"
> memory: 512M
> requests:
> cpu: "0.2"
> memory: 200M
> volumeClaimTemplates:
> - metadata:
> name: data-volume
> spec:
> accessModes:
> - ReadWriteOnce
> resources:
> requests:
> storage: 50Gi
> storageClassName: managed-premium
> - metadata:
> name: logs-volume
> spec:
> accessModes:
> - ReadWriteOnce
> resources:
> requests:
> storage: 10Gi
> storageClassName: managed-premium
> type: ReplicaSet
> users:
> - db: admin
> name: prd-mongodb-user
> passwordSecretRef:
> name: prd-mongodb-user-password
> roles:
> - db: admin
> name: clusterAdmin
> - db: admin
> name: userAdminAnyDatabase
> - db: admin
> name: root
> scramCredentialsSecretName: my-scram
> version: 5.0.6
> status:
> currentMongoDBMembers: 3
> currentStatefulSetReplicas: 3
> mongoUri: \<HIDE\>
> phase: Running
> kind: List
> metadata:
> resourceVersion: ""
> selfLink: ""
> \`\`\`
> Thank you so much everyone for your attention.
