Keeping a Local LLM Resident in Memory: A Systematic Setup

    A local model feels “always ready” only when the inference process stays up after boot and the weights remain loaded, not merely when the files sit on disk. This article separates three lookalike states, then covers service-managed startup, a low-privilege account, idle-unload and warmup policy, repeatable config, and the signals that show whether the model is still actually resident.

    Keeping a local large language model “resident in memory” does not mean pinning weight files in the disk cache forever. It means the inference process stays alive after boot and, under a deliberate policy, keeps model weights in the process address space so each question does not reload the model. In many setups the service is started only in a foreground terminal. Closing the terminal, ending the session, or letting the machine sleep kills the process. Even if the process survives, an idle-unload policy can release the model after a period of quiet. The next request then rereads weights from disk, maps them, and reinitializes the runtime and device context. Latency that should be tens of milliseconds becomes seconds or longer. Moving from “it can run” to “it is ready whenever you ask” requires four things at once: a persistent process, a resident model, permission isolation, and clear resource limits.

    Three different meanings of “still there”

    The first state is that the files are on disk. Downloaded weights only mean the next load can happen offline. They do not mean a usable model is already in memory.

    The second state is that the inference process is still running, but an idle policy has unloaded the model. The port may still accept connections and a health check may pass, yet the first real request triggers a load.

    The third state is the target: the process keeps running and the target model is already loaded into memory (and into accelerator memory when a device is available). Later requests go straight into forward computation.

    When something feels slow, check in this order: whether the process exists, whether the listen port is stable, when the last load was logged, what the idle-reclaim threshold is, and whether the process’s resident memory and device memory match the model size. “The service is started” alone is a false positive. A memory number alone is also misleading, because the file cache, extra instances, and quantized runtimes can all look “about right.”

    Run it as a system service, not in an interactive terminal

    An interactive terminal is tied to a login session. When the session ends, the network drops, or the parent receives a hang-up signal, child processes usually exit with it. Hand the inference program to the operating system’s service manager: start it at boot, restart it on failure according to policy, and send standard output and standard error to the logging system instead of depending on someone leaving a window open.

    A service unit should at least state which account runs it, the working directory, where models and config live, which local dependencies must be ready before start (for example, device nodes), the restart interval and restart limit, and how to stop gracefully so a hard kill does not leave weight mappings behind. Enable it at the multi-user run level, not as a desktop login item. Desktop autostart never runs on a server or remote machine with no graphical login.

    If the machine suspends or uses hybrid sleep, confirm after wake that both the device driver and the inference process have recovered. “The service shows as active” is not enough. Send one very short probe to verify the model is still in memory. Cap how often you probe so the probe itself does not keep resetting the idle timer and hide a real unload.

    A dedicated low-privilege account and device access

    The inference service reads models, writes logs, and touches compute devices. Too much privilege hands the machine to a long-running process. Create a system account used only for this service: no login, its own home or data directory, and membership only in the groups required for inference. A flaw in the program then has a harder time rewriting other services’ data.

    Compute devices are usually exposed as device nodes. Without the right device-group membership, the process can start and then fall back to CPU inference, or fail on the first real compute call. Group membership takes effect only after a new login or a service restart. Editing a config file without reloading the process is a common miss. The model directory, log directory, and temp directory should be owned by the runtime account. Do not “make it work” with world-writable permissions. Administrators can have read access to shared directories; writes should stay with the service account.

    Keep the model actually in memory

    A live process is only the precondition. Also set the idle-unload time: disable unload, or set it far longer than the real idle gap in your workload. On a shared machine, never unloading fills memory and crowds out builds, containers, and other jobs. A safer choice is a timeout matched to usage, plus an active warmup before busy periods. Warmup means one shortest possible request to the target model after the service is ready, so weights enter memory before the first real user pays the cold start.

    When memory is tight, the operating system swaps out inactive pages. Once weights land in swap, the next computation reads them from disk again, and “resident” is only a name. Set a memory ceiling and a priority for the inference service so its working set is not reclaimed casually, while still stopping it from consuming all physical memory without limit. With several models, do not preload all of them by default. Keep one or two hot models according to call frequency and load the rest on demand. Quantized formats reduce footprint, but they only trade precision against speed. They are not a reason to treat residency as unlimited.

    If you use containers or a virtualized development environment, memory limits, device passthrough, and restart policy must apply to the layer that actually runs inference, not only to an outer terminal. Restarting the outer environment kills any process that was not declared as a service. If the inner layer does not persist the model directory, a rebuild also drops weights you already downloaded.

    Make the configuration repeatable and reversible

    Commands typed by hand get lost. Put the account, directory permissions, service definition, environment variables, and warmup steps in version-controlled notes or scripts. Record the idle timeout, preloaded model name, memory ceiling, and restart policy in the change log. After a runtime upgrade or a model-file swap, stop the service in a quiet window, replace the files, start again, and warm up. Confirm memory use and time-to-first-token match expectations before you send traffic back. Rollback means switching to the previous model path and restarting the service. Do not overwrite a file that is currently mapped.

    Environment variables are a good place for the listen address, model root, idle policy, and log level. They are a bad place for secrets inside a world-readable service file. If you expose an API, bind only the interfaces you need and use the host firewall. Staying resident is not the same as opening the service to the whole network.

    What to watch day to day

    Keep four signals: that the process runs as the intended account, that restart counts are not climbing, that load and unload events are logged, and that physical memory and device memory curves look right. A rising restart count usually means a device permission, path, or memory-limit error. Setting “start at boot” again will not fix it. Two simple alerts are enough: the service is not active, and time-to-first-token during working hours suddenly looks like a cold start again. The second case usually means the model was unloaded or swapped out.

    A daily check can stay small. After boot, look at service status, confirm warmup succeeded, sample one short request’s latency, and see whether memory sits near the model’s size. Repeat the same check after a driver, kernel, or runtime change. Residency then stops being a one-off manual trick and becomes an auditable way to run: the operating system owns the process, the model stays in memory for as long as policy allows, privileges stay inside a dedicated account, resource limits are explicit, and problems show up directly in logs and latency.