Memory use in high-level applications
This topic provides details about memory use in high-level applications. See Manage memory and latency considerations for information about the memory available for real-time capable applications (RTApps).
High-level applications have access to the following memory and storage:
- 256 KiB RAM on the high-level core, reserved entirely for high-level application use. Up to 1 KiB of this space may be allocated for each shared buffer channel through which high-level applications and RTApps communicate.
- 1 MiB read-only flash memory, which is shared between the high-level and real-time cores.
- Read/write (mutable) storage, which persists when a device reboots. For information about mutable storage, see Using storage on Azure Sphere.
Determine flash memory usage
To determine your flash memory usage, consider only the size of the image package file, which includes the image metadata and application manifest in addition to the executable image. You don't need to account for the storage required by Microsoft-provided components such as the Azure Sphere OS or the run-time services and shared libraries that control peripherals and enable connection to an Azure IoT Hub. Likewise, you don't need to include the size of a full backup copy of your application or the components that enable failover or rollback in case of corruption or problems with over-the-air update.
During development and debugging, however, the size of the debugger does count against the limit. The debugger is automatically added by azsphere device enable-development and removed by azsphere device enable-cloud-test. You can find the size of the debugger used by your SDK by looking for gdbserver.imagepackage in the DebugTools folder of the Microsoft Azure Sphere SDK installation directory.
The azsphere device sideload command returns an error if the application image package, plus the debugger (if present), exceeds the 1 MiB total limit. The following commands, which upload applications to the Azure Sphere Security Service, also return an error if the image package exceeds 1MiB:
- azsphere image add ... --filepath filename
- azsphere device-group deployment create ... --filepath filename
The 256 KiB RAM limit applies to the application alone; you do not need to allow for RAM used by the debugger.
The available flash and RAM may increase, but will never decrease, for applications written for the current Azure Sphere chip (MT3620). Future Azure Sphere chips may have different limits.
Out of memory conditions
If your application uses too much memory, the Azure Sphere OS terminates it with a SIGKILL signal. For example, in the debugger you'll see the following:
Child terminated with signal = 0x9 (SIGKILL)
The SIGKILL signal also occurs if a high-level application fails to handle the SIGTERM request; see Lifecycle of an application for details.
Determine run-time application memory usage
You can get information about your application's memory usage during debugging with Visual Studio by issuing commands to the Visual Studio MI Debug Engine.
Open a Command Window in Visual Studio by selecting View > Other Windows > Command Window.
Pause the application.
Type the following command in the Command Window prompt:
Debug.MIDebugExec info proc status
This command returns the equivalent of proc/self/stat in Linux.
The following sample shows information from a sample Azure Sphere application. Note the VmPeak and VmSize entries, which list the peak and average virtual memory used by the application:
>Debug.MIDebugExec info proc status process 101 Name: app Umask: 0022 State: t (tracing stop) Tgid: 101 Ngid: 0 Pid: 101 PPid: 98 TracerPid: 98 Uid: 1007 1007 1007 1007 Gid: 1007 1007 1007 1007 FDSize: 32 Groups: 5 10 NStgid: 101 NSpid: 101 NSpgid: 101 NSsid: 0 VmPeak: 1728 kB VmSize: 1728 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 100 kB VmRSS: 100 kB RssAnon: 100 kB RssFile: 0 kB RssShmem: 0 kB VmData: 76 kB VmStk: 100 kB VmExe: 40 kB VmLib: 1508 kB VmPTE: 6 kB VmPMD: 0 kB VmSwap: 0 kB Threads: 1 SigQ: 1/55 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000200001000 SigCgt: 0000000000004000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 Speculation_Store_Bypass: unknown Cpus_allowed: 1 Cpus_allowed_list: 0 voluntary_ctxt_switches: 5914 nonvoluntary_ctxt_switches: 380