# SWAP files inside container

**URL:** <https://forums.balena.io/t/swap-files-inside-container/113664>\
**Category:** Product support\
**Created:** [May 14, 2020, 8:27am UTC](https://forums.balena.io/t/swap-files-inside-container/113664 "2020-05-14T08:27:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [May 14, 2020, 8:27am UTC](https://forums.balena.io/t/swap-files-inside-container/113664/1 "2020-05-14T08:27:16Z")

</div>

Hi Balena team,

is it possible to create swap files inside a specific container? I could not find any documentation about it.  
I know they are slow but sadly necessary for my application 😕

Further more these parts of the documentation seem to be kind of conflicting (i know docker-compose is not the docker deamon):  
The docer-compose documentation list `memswap_limit` as known unsupported

> **[docker-compose.yml fields - Balena Documentation](https://www.balena.io/docs/reference/supervisor/docker-compose/)**
>
> docker-compose.yml fields supported by balena

But [https://github.com/balena-os/balena-engine-cli/blob/master/docs/reference/run.md](https://github.com/balena-os/balena-engine-cli/blob/master/docs/reference/run.md) lists it as run time option `--memory-swap=""`

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [May 14, 2020, 11:47am UTC](https://forums.balena.io/t/swap-files-inside-container/113664/12 "2020-05-14T11:47:00Z")

</div>

Hi @Langhalsdino,  
We currently do not support the `memswap_limit` docker-compose field and do not encourage using swap on IoT devices in general.  
The main reason is that using swap can wear the storage medium of the device really quickly, especially if it is using an SD card.  
BalenaOS is using a readonly filesystem for most of its parts exactly for this reason.

Could you provide some extra info about your use case and the reason that using in container swap files is required?  
I would like to open an internal feature request issue for this and add it to the list of features to consider.

In the mean time, even though we do not officially support swap files, I can point you to a blog post of ours, where we explain how we managed to get a resource heavy application run using a system level swap file:

> **[How we develop balenaCloud, using balenaCloud](https://www.balena.io/blog/how-we-develop-balenacloud-using-balenacloud/#finbob)**
>
> In this post, we'll show you how we use our own platform to build our infrastructure and provide our engineering team with a reliable development environment. Find out how we optimised and refined the configuration of our software stack so the entire...

Keep in mind though that the balenaFin has an industrial grade eMMC storage and also that this was an experiment from our side that we didn’t evaluate how it would work for long periods of time.

Kind regards,  
Thodoris

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [May 15, 2020, 12:45pm UTC](https://forums.balena.io/t/swap-files-inside-container/113664/14 "2020-05-15T12:45:23Z")

</div>

Thanks for the quick reply.

I completely agree that working with swap files in production is not a good idea.  
Our usecase is completly development driven. We work with images / videostreams and Neuronal Networks on the Nvidia Jetson Nano. Since tensorflow is allocating a big chunk of the shared memory (gpu & cpu shared) our first naive approaches some times do not fit into the left memory of the jetson nano. Therefore the container gets killed by the balena engine. Since debugging and profiling our code is a bit hard, when it gets kill as soon as we start it, we would like to have an option to enable swap memory for debugging and profiling purposes.

But if you have any other ideas how to enable debugging and profiling, i am happy to try them out 🙂

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [May 15, 2020, 1:37pm UTC](https://forums.balena.io/t/swap-files-inside-container/113664/15 "2020-05-15T13:37:54Z")

</div>

Hopefully that blog post helps you out as far as getting it to work on your dev devices. Let us know what you encounter though.
