Why Ollama models unload and when keeping them loaded matters
A shared Ollama server is often healthy all morning and then slow on the first request after a quiet period. The usual cause is not a fault. Ollama keeps a model in memory for a limited time after its last request, and once that time passes the model is unloaded. The next request then pays for a cold load, which means reading the model weights from disk and placing them into GPU or system memory before any tokens can be generated. Teams can either accept that delay or decide, on purpose, how long each model stays resident. The documented default is five minutes of inactivity, and that default is the starting point for every decision in this section.
Keeping models loaded matters most in three situations. The first is a shared assistant, where many people send occasional requests and a single slow first answer makes the tool look broken. The second is an interactive tool such as a coding or chat front end, where a user waits on each reply and a cold load interrupts their flow. The third is a server holding several models at once. Loaded models compete for the same VRAM or RAM, so keeping one model warm can push another out, and the next request to the evicted model becomes the slow one. Before changing any setting, confirm with ollama ps which models are loaded, how much memory each uses and whether a model has already been partly offloaded to the CPU, because that changes what a longer keep-alive will cost.
Keep_alive options and when each one fits
This table compares the server default, the OLLAMA_KEEP_ALIVE setting, the per-request keep_alive field, start-up preloading and the ollama stop command. Read each row for what it controls, where it is set and the trade-off between fast first responses and memory held by idle models. Confirm current default and accepted values in the Ollama FAQ before you set them on a shared server.
| Option | What it controls and where it is set | Trade-off and when it fits |
|---|---|---|
| Server default | Unloads an idle model after the default keep-alive period. No setting needed. | Frees memory quickly. Fits a single user or light traffic, where a cold load on the next request is acceptable. |
| OLLAMA_KEEP_ALIVE | Server environment variable that sets the keep-alive period for all models. Set in the service or container environment. | Keeps the whole fleet warm, so memory use stays higher. Fits a shared server where most models get regular calls. Confirm the default and accepted values. |
| Per-request keep_alive | Field in an API request body that overrides the server setting for that model load. Set by the calling application. | Lets one busy model stay warm while others unload. Fits mixed workloads. Confirm how zero and negative values behave in the current API docs. |
| Start-up preloading | A short request sent for a model after the server starts, with keep_alive set so it stays loaded. | Moves the load time to start-up, so first users get fast responses. Costs memory from the moment the server starts, even if no one calls the model. |
| ollama stop | Command that unloads a running model immediately. Run it on the server, not through a setting. | Frees memory for another model without restarting the server. Fits planned model swaps. Users of the stopped model pay a reload on their next call. |
| Loaded model limit | OLLAMA_MAX_LOADED_MODELS caps models in memory. Default is 3 times the number of GPUs, or 3 on CPU, per the FAQ. | Kept-alive models count toward this cap. Check how Ollama evicts models when the cap is reached before setting long keep-alive values. |
| Warm set size | The number of models you keep loaded at once, measured against available VRAM or system memory. | Each warm model adds memory use. Fits when the full set fits in memory with room for context. Size it with your hardware before rollout. |
Configuring keep_alive and preloading on a shared server
This sequence sets how long Ollama keeps models in memory and loads the right models before users arrive. The result is a shared server where frequently used models answer without a slow first load, and each change can be checked with ollama ps and reversed.
Choose the models that need warm responses
The platform owner reviews which models users call most often and which ones have response-time expectations, such as an internal assistant or a document tool. Ask the team that runs the application for model names, expected concurrency and the hours when traffic peaks. Run
ollama liston the server and copy the exact model tags, because preloading and stopping commands must match them. Done means you have a short list of tags, each with a named owner and a reason it should stay loaded. Models used only occasionally can keep the default behavior.Set OLLAMA_KEEP_ALIVE for the service
The server administrator sets the
OLLAMA_KEEP_ALIVEvariable so the service keeps models in memory longer than the five-minute default. On systemd hosts, runsudo systemctl edit ollama.service, add anEnvironmentline under[Service], then runsudo systemctl daemon-reloadand restart the service. In containers, pass the variable with-eor the composeenvironmentblock and recreate the container. On Windows, add it as a user or system environment variable, then quit Ollama from the tray and start it again. Check withsystemctl show ollama -p Environmentor by inspecting the container, and confirm the value appears.Send a test request with keep_alive
The administrator sends one request from the server with a per-request
keep_alivevalue to confirm the setting works for a single call. Post to the local API at port 11434 with the model tag, a short prompt and thekeep_alivefield, and use the same tag from step one. A per-request value overrides the server default for that request only. Check that the response returns normally and the model appears inollama pswith an expiry time that matches the value you sent. If the model is missing from the list, confirm the tag and the request path before going further.Preload models at start-up
The administrator adds a short start-up step that loads each chosen model before users send traffic. Send a request that names the model but contains no prompt, which asks Ollama to load it into memory without generating text. Run this from a systemd unit or script that starts after the Ollama service, or from the container entrypoint for containerized deployments. Confirm in the Ollama FAQ which request body the version you run accepts for preloading and which values
keep_alivetakes. Done means the model appears inollama psshortly after the service starts, before any user request.Verify loaded models with ollama ps
The administrator runs
ollama pson the server and checks each preloaded model against the expected result. Look at the model name, the memory footprint, the processor column that shows whether the model runs fully on GPU or partly on CPU, and the expiry column. A model that runs partly on CPU may respond slowly even when loaded, so note it for a hardware or context review. Repeat the check after a restart and after a period of no traffic to confirm the expiry behaves as configured. Record the output with the change ticket.Check memory against the other models
The platform owner confirms that the warm models leave enough memory for the other models users call. Each loaded model takes memory, and the server limits how many models stay loaded at once through
OLLAMA_MAX_LOADED_MODELS. Compare the memory shown inollama pswith the GPU or system memory on the host, and keep a margin for requests that run in parallel. If a model that users need is evicted or fails to load, reduce the number of warm models or review the limit in the Ollama FAQ. Done means the warm set fits with room for a second model during a busy period.Free memory with ollama stop
The administrator uses
ollama stopto unload a model that no longer needs to stay warm, which frees memory for another model. Runollama stopwith the exact model tag, then runollama psagain and confirm the model is gone from the list. Do this before loading a large model in a maintenance window, and tell the owning team, because the next request to the stopped model will pay the cold-load cost again. Done means the list shows only the models you intend to keep loaded.Roll back the keep_alive change
The administrator reverses the server setting if warm models cause memory pressure or the change does not help. Remove the
OLLAMA_KEEP_ALIVEline from the systemd override, the container environment or the Windows variable, then reload or restart the service the same way you set it. Remove the start-up preload step as well. Runollama psafter the default period has passed and confirm that idle models unload. Keep the previous configuration in version control so the rollback can be repeated and reviewed.
How a model moves from load to unload
The diagram starts with a request reaching the Ollama server. If the model is not in memory, the server performs a cold load before generating the response. Each request restarts the keep_alive timer, so a model stays resident while traffic keeps arriving. When the timer expires, the model is unloaded, and an explicit ollama stop call frees the memory earlier. Check ollama ps to confirm what is currently loaded.
Requests, cold loads, keep_alive resets and the two unload paths.
Freeing memory for other models with ollama stop
A model kept loaded with keep_alive holds memory that other models and concurrent requests may need, so you should decide deliberately which models stay warm. On a shared server, Ollama limits how many models stay resident through OLLAMA_MAX_LOADED_MODELS, and each loaded model can serve up to OLLAMA_NUM_PARALLEL requests at once. The default for OLLAMA_NUM_PARALLEL is 1 parallel request per model, and the default for OLLAMA_MAX_LOADED_MODELS is 3 times the number of GPUs, or 3 on CPU. When a new model is requested and the limit is reached, or when memory cannot hold it, Ollama must unload something first, and the result can be a slow load for a user who did not expect one. Confirm the values on your own server with the Ollama FAQ, since they change between releases.
Run ollama ps to see which models are loaded, how much memory each uses, and whether any run partly on CPU. Then run ollama stop <model> on a named model to unload it immediately, which frees its memory without restarting the server. Stop a model when a large model is needed for a batch job, when a rarely used model is holding memory a frequently used one needs, or before a planned load test. Stopping a model does not delete it from disk, so the next request pays the cold load cost again. Keeping one model warm therefore reduces latency for its users while reducing the number of other models that can stay resident, and that trade-off should be written into your model change process rather than decided request by request. Test the effect on your own hardware and model sizes before you set a long keep_alive on a model that many teams call.
Security and operational risks of long-lived models
A model kept resident in memory saves time on the next request, but it also holds shared resources and changes what the server is doing at any moment. The four risks below connect memory pressure, an unauthenticated local API, change control and monitoring, so each keep_alive or preloading decision should be checked against all four before it reaches a shared host.
Memory pressure on a shared host
Every model kept loaded occupies memory that other models, or the operating system, may need. Ollama limits how many models stay loaded through OLLAMA_MAX_LOADED_MODELS, which defaults to 3 times the number of GPUs, or 3 on CPU. Before raising keep_alive or preloading several models, confirm the total memory footprint of those models plus the context you expect users to send, and leave headroom for requests that arrive at the same time. Test with the largest model you plan to keep resident.
Ollama FAQUnauthenticated local API controls load state
The local Ollama API at localhost:11434 does not require authentication, and any client that can reach it can load, keep or stop models. By default Ollama binds to 127.0.0.1 port 11434. If you change the bind address with OLLAMA_HOST so other machines can reach it, anyone on that network can change which models are resident. Put an authenticating proxy such as Nginx in front of the server before widening the bind address, and restrict the port at the firewall.
Ollama API authenticationChange control for resident models
Which models stay in memory is a server configuration decision, and it should follow the same approval path as which models users may call. Record the OLLAMA_KEEP_ALIVE value, any per-request keep_alive settings in internal tools, and the list of preloaded models in your configuration management. Ask who approves a change to these settings, and how a model that was approved for one team is prevented from pinning memory that another team depends on.
Monitoring what is loaded with ollama ps
The ollama ps command lists the models currently loaded, their memory use and whether part of the model runs on the CPU. Run it after each change to keep_alive or preloading, and again during peak use, to confirm the server holds the models you expect. Schedule a periodic check and alert when a model you did not approve appears, or when a model is still resident long after its last request, since both point to a configuration that no longer matches the intended design.
Questions teams ask before changing keep_alive
Does changing keep_alive cost money to run?
Changing keep_alive adds no software cost, because Ollama is free to run on hardware you own. Ollama's pricing page states that running models on your own hardware is always unlimited, and its paid plans cover cloud models rather than local memory settings. The real costs are the GPU and system memory that stay occupied while models remain loaded, plus the staff hours to test the change. Memory held for an idle model cannot serve another model or user, so that cost recurs for as long as the setting is in place. When you request a quote, ask it to separate one-time work (measuring, configuring, testing, documenting) from any ongoing review of memory use.
How long does keep_alive setup take, and what drives it?
Setup time depends on the number of servers, models and client applications involved, not on the keep_alive setting itself. A single server with one or two models and a clear owner is mostly a testing exercise. A shared server with many models, clients that send their own keep_alive values, and a service definition or container configuration to update takes longer, because each client's timing must be checked. Ask for the duration in a written, fixed-scope plan that includes baseline timing before the change, tests of cold and warm first responses, and a rollback step. Treat any timeline as provisional until your hardware and model inventory has been reviewed.
Can an internal engineer change keep_alive without outside help?
Yes, a capable engineer can make the change, because OLLAMA_KEEP_ALIVE is a server environment variable and keep_alive is a field in individual API requests. The harder part is verifying the result. The engineer needs to know which models are called, how often, and what else shares the GPU or system memory. They also need to confirm how Ollama is started, whether as a system service, a container or a desktop application, so the variable is set where the server actually reads it. An engineer who has not run a shared Ollama service before will usually benefit from a review of the change plan before it reaches users.
What does the keep_alive work need from our team?
Plan to provide three things: a hardware inventory, a model list and a named service owner. Each one shapes the scope and the quote.
Does keeping models loaded increase operational or stability risk?
Keeping models loaded adds some risk, mainly that memory stays occupied when nothing is asking for it. A model held in GPU memory can slow down other models that need to load, and a long keep_alive across many models can leave little room for new requests. The risk is manageable. Choose a timeout that matches real usage, preload only the models users call often, and check memory use after each change. Queueing and overload behavior should be reviewed alongside this change, since a server under pressure is where held memory causes the most trouble.
Does keep_alive affect data exposure or who can call the API?
No, keep_alive controls how long a model stays in memory, not who can reach the API. The local API at localhost:11434 has no authentication, so any client that can reach the server can send requests, whether or not a model is loaded. Before changing keep_alive, confirm the bind address set with OLLAMA_HOST and the access controls in front of the server. Ollama states that when it runs locally, it does not see your prompts or data, but that does not protect a shared machine from unauthorized callers. Review the Ollama API authentication documentation with your security team before the change goes live.
When should we bring in a partner for this work?
Bring in a partner when the change touches several shared services, when you cannot test it safely in your own environment, or when users depend on consistently fast responses. A partner can help write the scope, measure baseline timing, run the change in a test environment and document the result for your operators. DeployOpen implements, documents and supports self-hosted open-source platforms in infrastructure you control. Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts, and ongoing tuning is available as a retainer. Ask for the written scope before accepting any quote.
How to verify warm responses without guessing
Run a fixed timing test for each model before you change keep_alive settings, so the decision rests on measurements rather than impressions. Start from an unloaded model: stop it with ollama stop, then send one identical request with a short prompt and record the total duration. That first figure is your cold baseline. Send the same request again immediately and record it as a warm baseline. Repeat the sequence at a few points inside the keep-alive window you configured, then at points past it, so you can see exactly when the model is unloaded. Use the same prompt, the same num_ctx and the same parallel settings on every run, or the results will not be comparable. Keep a simple log with the model name, the server version, the keep_alive value in effect, the time since the previous request and the result for each run.
Read the timing fields in the API response, not your stopwatch. Ollama's responses to the generate and chat endpoints include total_duration, load_duration, prompt_eval_duration, eval_count and eval_duration, all reported in nanoseconds. A warm response should show a load_duration close to zero, because the model is already in memory. A cold response shows a large load_duration while generation time stays roughly similar. Separating these fields tells you whether a slow reply came from loading the weights or from generating tokens, which matter for different fixes. Confirm the exact field names and units against the API reference for your installed version, since the timing output is the basis for every later decision in this test.
How DeployOpen scopes keep_alive and preloading work
DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside the client's own infrastructure, including the keep_alive and preloading settings that decide how long Ollama models stay in memory. We start from the workloads, hardware and memory budget your team already has, then agree the written scope before any change is made to a shared server.
How we scope
- We list which models must answer quickly, which are occasional, and which must yield memory to others.
- We record the current keep_alive behavior, start-up configuration and client request patterns as the baseline.
- Scope, deliverables and timelines are agreed in writing before work starts, so you know what is covered.
How we build
- We set OLLAMA_KEEP_ALIVE at server level and document where per-request keep_alive overrides apply.
- We design a start-up preload step for the models that must be warm, and check that it runs after restarts.
- We test memory use with ollama ps and the server logs under realistic concurrent load before sign-off.
How we hand over
- You receive the configuration, service unit or container settings, and a written runbook for changing them.
- The runbook explains how to free memory with ollama stop and how to confirm which models are loaded.
- We walk your platform and operations team through the settings and the trade-offs they now control.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Retainers can cover re-checking keep_alive settings after Ollama version changes or new model additions.
- Confirm with us which environment, host or container platform your team will use before scoping starts.

