Unable to add swap memory, has `swap_size_mb` been deprecated?

My app needs about 4GB ram while booting for building an index, but then runs comfortably on less than 1GB. However swap_size_mb line in fly.toml doesn’t seem to be parsed properly. Here is my fly.toml:

primary_region = 'eze'

[build]

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1
  swap_size_mb = 4096

I save the file, run fly deploy aaaaaannd… nothing happens. The machine fails (out of memory) and the settings don’t show any added swap memory. Does anybody know what could be the problem? Also RootFS appears “awaiting sync”.

Here’s the log:

2024-08-23T20:09:09.781 app[9080e50ecd77e8] eze [info] 2024-08-23T20:09:09.780970504 [01J60DH0E7TKN461NW99C2XNW4:main] Running Firecracker v1.7.0

2024-08-23T20:09:10.102 app[9080e50ecd77e8] eze [info] [ 0.273477] PCI: Fatal: No config space access function found

2024-08-23T20:09:10.421 app[9080e50ecd77e8] eze [info] INFO Starting init (commit: 20f21dc5f)...

2024-08-23T20:09:10.454 app[9080e50ecd77e8] eze [info] INFO Preparing to run: `uvicorn src.main:app --host 0.0.0.0 --port 8080` as root

2024-08-23T20:09:10.460 app[9080e50ecd77e8] eze [info] INFO [fly api proxy] listening at /.fly/api

2024-08-23T20:09:10.467 app[9080e50ecd77e8] eze [info] 2024/08/23 20:09:10 INFO SSH listening listen_address=[fdaa:1:d1b1:a7b:148:38d5:9032:2]:22 dns_server=[fdaa::3]:53

2024-08-23T20:09:10.507 runner[9080e50ecd77e8] eze [info] Machine started in 777ms

2024-08-23T20:09:15.535 app[9080e50ecd77e8] eze [info] [ 5.703096] Out of memory: Killed process 322 (uvicorn) total-vm:1146888kB, anon-rss:853308kB, file-rss:4kB, shmem-rss:0kB, UID:0 pgtables:1924kB oom_score_adj:0

2024-08-23T20:09:16.468 app[9080e50ecd77e8] eze [info] INFO Main child exited with signal (with signal 'SIGKILL', core dumped? false)

2024-08-23T20:09:16.469 app[9080e50ecd77e8] eze [info] INFO Process appears to have been OOM killed!

2024-08-23T20:09:16.469 app[9080e50ecd77e8] eze [info] INFO Starting clean up.

2024-08-23T20:09:16.470 app[9080e50ecd77e8] eze [info] WARN could not unmount /rootfs: EINVAL: Invalid argument

2024-08-23T20:09:16.471 app[9080e50ecd77e8] eze [info] [ 6.640452] reboot: Restarting system

2024-08-23T20:09:16.621 app[9080e50ecd77e8] eze [info] Out of memory: Killed process

2024-08-23T20:09:16.650 runner[9080e50ecd77e8] eze [info] machine has reached its max restart count (10)
1 Like

Try moving swap_size_mb way up to the top of the file, right after primary_region.

(It would logically make sense under [[vm]], but…)

1 Like

Sadly the behaviour is the same, no swap is found on the resulting fly machine. I’m kind of lost here as I really need to be able to use swap.

Hm… How about reducing it to 512 now, in this new position?

(That would at least confirm that it’s detecting the configuration line.)

fly.toml from an application that uses swap:

Verification that it works:

% fly ssh console -C swapon
Connecting to fdaa:0:cfd4:a7b:e5:2b6b:9ec9:2... complete
NAME     TYPE      SIZE USED PRIO
/dev/vdc partition   2G 2.5M   -2
1 Like

Is the max 2GB? OP is trying w/ 4GB, maybe that’s why it isn’t working for OP.

I can confirm that 4GB works, and as @mayailurus said, the line had to be way up in the file right after “primary region”. I’m sorry I initially said it didn’t work that way, I made a mistake. Thanks to everyone!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.