<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/126071/including-zms-makes-a-delayed-application-on-time</link><description>Hi List, I am using ZMS to log data. While performing stress tests, I see few issues: 
 
 Including zms in the projects makes the application boot time delayed. The delay is ~2 minutes which is not acceptable for the application. 
 The zms_mount() is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Jan 2026 15:00:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/126071/including-zms-makes-a-delayed-application-on-time" /><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/558056?ContentTypeID=1</link><pubDate>Tue, 06 Jan 2026 15:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d8cd97d-41c1-479c-af33-b7ef16c89b89</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Sarma,&lt;/p&gt;
&lt;p&gt;There is no explicit way to trigger GC with ZMS. However, there are ways around this, explained under &lt;a href="https://docs.nordicsemi.com/bundle/ncs-3.2.1/page/zephyr/services/storage/zms/zms.html#triggering_garbage_collection"&gt;Triggering garbage collection&lt;/a&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;For data larger than 8 byte (like your 12 byte data), you need to account for an additional 16 byte ATE header. See &lt;a href="https://docs.nordicsemi.com/bundle/ncs-3.2.1/page/zephyr/services/storage/zms/zms.html#large_data_values"&gt;Large data values&lt;/a&gt;. Can you show how you calculated 1290 records?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The -22 (EINVAL) when calling zsm_mount(). I suggest narrowing down by debugging in the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/ec78104f15691cccd94682cf4b22e0a013f28dd8/subsys/fs/zms/zms.c#L1478-L1550"&gt;implementation&lt;/a&gt; to see which of the many checks there that can cause this return value (or enable logging so that you get a printout indicating which check failed).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Br,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Einar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/557156?ContentTypeID=1</link><pubDate>Wed, 17 Dec 2025 06:30:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b56c577-dae8-4726-a859-71a0c5d61eac</guid><dc:creator>Sarma</dc:creator><description>&lt;p&gt;Hello Einar,&lt;br /&gt;The ZMS activity is running in a low priority thread(Pri = 10). The code in the main thread is commented out (See line # 96 in main().)&lt;br /&gt;&lt;br /&gt;Here&amp;#39;s the code with the &lt;em&gt;#ifdefs&lt;/em&gt; removed and GPIOs used to measure the actual time with LOGS removed.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
/*
 * Copyright (c) 2024 BayLibre SAS
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * ZMS Sample for Zephyr using high level API.
 *
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/sys/reboot.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;zephyr/drivers/flash.h&amp;gt;
#include &amp;lt;zephyr/storage/flash_map.h&amp;gt;
#include &amp;lt;zephyr/fs/zms.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;dk_buttons_and_leds.h&amp;gt;


#define ZMS_PARTITION        storage_partition
#define ZMS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZMS_PARTITION)
#define ZMS_PARTITION_OFFSET FIXED_PARTITION_OFFSET(ZMS_PARTITION)

#define IP_ADDRESS_ID 1
#define KEY_VALUE_ID  0xbeefdead
#define CNT_ID        2
#define LONG_DATA_ID  3

#define THREAD_LED_PRIORITY     (4)
#define THREAD_ZVS_PRIORITY     (10)
#define RUN_LED_BLINK_INTERVAL  (15000) //Second
#define RUN_STATUS_LED          DK_LED1
#define THREAD0_STACKSIZE       (4096)

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

static struct zms_fs fs;

static int delete_and_verify_items(struct zms_fs *fs, uint32_t id)
{
	int rc = 0;

	rc = zms_delete(fs, id);
	if (rc) {
		LOG_ERR(&amp;quot;Error while deleting item rc=%d\n&amp;quot;, rc);
		return rc;
	}
	rc = zms_get_data_length(fs, id);
	if (rc &amp;gt; 0) {
		LOG_ERR(&amp;quot;Error, Delete failed item should not be present\n&amp;quot;);
		return -1;
	}

	return 0;
}

static int delete_basic_items(struct zms_fs *fs)
{
	int rc = 0;

	rc = delete_and_verify_items(fs, IP_ADDRESS_ID);
	if (rc) {
		LOG_INF(&amp;quot;Error while deleting item %x rc=%d\n&amp;quot;, IP_ADDRESS_ID, rc);
		return rc;
	}
	rc = delete_and_verify_items(fs, KEY_VALUE_ID);
	if (rc) {
		LOG_INF(&amp;quot;Error while deleting item %x rc=%d\n&amp;quot;, KEY_VALUE_ID, rc);
		return rc;
	}
	rc = delete_and_verify_items(fs, CNT_ID);
	if (rc) {
		LOG_INF(&amp;quot;Error while deleting item %x rc=%d\n&amp;quot;, CNT_ID, rc);
		return rc;
	}
	rc = delete_and_verify_items(fs, LONG_DATA_ID);
	if (rc) {
		LOG_INF(&amp;quot;Error while deleting item %x rc=%d\n&amp;quot;, LONG_DATA_ID, rc);
	}

	return rc;
}

int main(void)
{
	static bool led_stat = false;  

	LOG_INF(&amp;quot;App started\n&amp;quot;);

	int err = dk_leds_init();
    dk_set_led(RUN_STATUS_LED, true);
	if (err) 
    {
		LOG_INF(&amp;quot;LEDs init failed (err %d)\n&amp;quot;, err);
		return 0;
	}
    dk_set_led(RUN_STATUS_LED, false);
	while (1) 
    {
        k_sleep(K_MSEC(25000));
    	dk_set_led(DK_LED2, led_stat);
        led_stat = !led_stat;
    }
	return 0;
}

void ledThread(void)
{
	static bool led_stat = false; 

    while (1) 
    {
        k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
    	dk_set_led(DK_LED3, led_stat);
        led_stat = !led_stat;
    }
}

void zvsTestThread(void)
{
	int rc = 0;
	uint64_t time_stamp;
	int64_t delta_time;

	uint32_t i;
	uint32_t id = 0;
	ssize_t free_space = 0;
	struct flash_pages_info info;

	uint8_t read_buf[5][16] = {0};

    /* define the zms file system by settings with:
	 *	sector_size equal to the pagesize,
	 *	3 sectors starting at ZMS_PARTITION_OFFSET
	 */
	fs.flash_device = ZMS_PARTITION_DEVICE;
	if (!device_is_ready(fs.flash_device)) 
	{
		LOG_INF(&amp;quot;Storage device %s is not ready\n&amp;quot;, fs.flash_device-&amp;gt;name);
		return 0;
	}
	fs.offset = ZMS_PARTITION_OFFSET;
	rc = flash_get_page_info_by_offs(fs.flash_device, fs.offset, &amp;amp;info);
	if (rc) 
	{
		LOG_INF(&amp;quot;Unable to get page info, rc=%d\n&amp;quot;, rc);
		return 0;
	}

	fs.sector_size = info.size;
	fs.sector_count = 10U;

	// time_stamp = k_uptime_get();
	rc = zms_mount(&amp;amp;fs);
	// delta_time = k_uptime_delta(&amp;amp;time_stamp);
	dk_set_led(RUN_STATUS_LED, true);
	if (rc) 
	{
		LOG_INF(&amp;quot;Storage Init failed, rc=%d\n&amp;quot;, rc);
		k_sleep(K_SECONDS(5));
		return 0;
	}
	else
	{
		LOG_INF(&amp;quot;ZMS initialized in %lu ms&amp;quot;, delta_time);
	}

	free_space = zms_calc_free_space(&amp;amp;fs);
	if (free_space &amp;lt; 0) 
	{
		LOG_INF(&amp;quot;Error while computing free space, rc=%d\n&amp;quot;, free_space);
		return 0;
	}

	LOG_INF(&amp;quot;Free space in storage is %u bytes\n&amp;quot;, free_space);
	uint8_t rec[12];
	LOG_INF(&amp;quot;Rec size %u bytes\n&amp;quot;, sizeof(rec));
	i = 0;	// write count
	time_stamp = k_uptime_get();
	while (1) 
	{
		dk_set_led(RUN_STATUS_LED, false);
		/* fill all storage */
		*(uint32_t*)&amp;amp;rec[0] = i++;
		rc = zms_write(&amp;amp;fs, id, rec, sizeof(rec));
		// k_sleep(K_MSEC(10));

		if (i % 10000 == 0)
		{
			printk(&amp;quot;\tfreespace=%u, data length[%d]=%u\n\r&amp;quot;, zms_calc_free_space(&amp;amp;fs), id, zms_get_data_length(&amp;amp;fs, id));
		}

		if ((i != 0) &amp;amp;&amp;amp; (i % 50000 == 0))
		{
			delta_time = k_uptime_delta(&amp;amp;time_stamp);
			printk(&amp;quot;Filled %u records in %lu ms\n\r&amp;quot;, i, delta_time);
			time_stamp = k_uptime_get();
			rc = zms_read_hist(&amp;amp;fs, id, read_buf[0], sizeof(rec), 100); // Read last 100th record. 0 being the last record. 
			rc = zms_read_hist(&amp;amp;fs, id, read_buf[1], sizeof(rec), 99);  // Read last 100th record. 0 being the last record. 
			rc = zms_read_hist(&amp;amp;fs, id, read_buf[2], sizeof(rec), 98);  // Read last 100th record. 0 being the last record. 
			rc = zms_read_hist(&amp;amp;fs, id, read_buf[3], sizeof(rec), 97);  // Read last 100th record. 0 being the last record. 
			rc = zms_read_hist(&amp;amp;fs, id, read_buf[4], sizeof(rec), 96);  // Read last 100th record. 0 being the last record. 
			delta_time = k_uptime_delta(&amp;amp;time_stamp);
			printk(&amp;quot;\tRead 5 hist_record in %lu ms\n&amp;quot;, delta_time);
			LOG_HEXDUMP_INF(read_buf[0], sizeof(read_buf[0]), &amp;quot;100:&amp;quot;);
			LOG_HEXDUMP_INF(read_buf[1], sizeof(read_buf[1]), &amp;quot;99:&amp;quot;);
			LOG_HEXDUMP_INF(read_buf[2], sizeof(read_buf[2]), &amp;quot;98:&amp;quot;);
			LOG_HEXDUMP_INF(read_buf[3], sizeof(read_buf[3]), &amp;quot;97:&amp;quot;);
			LOG_HEXDUMP_INF(read_buf[4], sizeof(read_buf[4]), &amp;quot;96:&amp;quot;);

			// printk(&amp;quot;freespace=%u, data length of %d=%u&amp;quot;, zms_calc_free_space(&amp;amp;fs), id, zms_get_data_length(&amp;amp;fs, id));

			time_stamp = k_uptime_get();
		}
		// i++;
		// LOG_INF(&amp;quot;Writing record with id %u, rc=%d\n&amp;quot;, id, rc);
		if (rc &amp;lt; 0) {
			break;
		}
		id++;
		id %= 2;//Limit to only 2 records
		dk_set_led(RUN_STATUS_LED, true);
	}

	LOG_INF(&amp;quot;Total recs filled, id=%u, rc=%d\n&amp;quot;, id, rc);
	LOG_INF(&amp;quot;Profiling: total allocated: %u. Free space according to ZMS %u. Used for records of size %u: %u (Total bytes: %u) \n&amp;quot;,
		 fs.sector_size*fs.sector_count, free_space, sizeof(rec), id, id * sizeof(rec));
	if (rc == -ENOSPC) 
	{
		/* Calculate free space and verify that it is 0 */
		free_space = zms_calc_free_space(&amp;amp;fs);
		if (free_space &amp;lt; 0) {
			LOG_INF(&amp;quot;Error while computing free space, rc=%d\n&amp;quot;, free_space);
			return 0;
		}
		if (free_space &amp;gt; 0) {
			LOG_INF(&amp;quot;Error: free_space should be 0, computed %u\n&amp;quot;, free_space);
			return 0;
		}
		LOG_INF(&amp;quot;Memory is full let&amp;#39;s delete all items\n&amp;quot;);

		/* Now delete all previously written items */
		for (uint32_t n = 0; n &amp;lt; id; n++) {
			rc = delete_and_verify_items(&amp;amp;fs, n);
			if (rc) {
				LOG_INF(&amp;quot;Error deleting at id %u\n&amp;quot;, n);
				return 0;
			}
		}
	}

	/*
	 * Let&amp;#39;s compute free space in storage. But before doing that let&amp;#39;s Garbage collect
	 * all sectors where we deleted all entries and then compute the free space
	 */
	for (i = 0; i &amp;lt; fs.sector_count; i++) 
	{
		rc = zms_sector_use_next(&amp;amp;fs);
		if (rc) 
		{
			LOG_INF(&amp;quot;Error while changing sector rc=%d\n&amp;quot;, rc);
		}
	}
	free_space = zms_calc_free_space(&amp;amp;fs);
	if (free_space &amp;lt; 0) {
		LOG_INF(&amp;quot;Error while computing free space, rc=%d\n&amp;quot;, free_space);
		return 0;
	}
	LOG_INF(&amp;quot;Free space in storage is %u bytes\n&amp;quot;, free_space);

	/* Let&amp;#39;s clean the storage now */
	rc = zms_clear(&amp;amp;fs);
	if (rc &amp;lt; 0) {
		LOG_INF(&amp;quot;Error while cleaning the storage, rc=%d\n&amp;quot;, rc);
	}

	LOG_INF(&amp;quot;Sample code finished Successfully\n&amp;quot;);
}


K_THREAD_DEFINE(ledThread_id, THREAD0_STACKSIZE, ledThread, NULL, NULL, NULL, THREAD_LED_PRIORITY, 0, 0);
K_THREAD_DEFINE(rramThread_id, THREAD0_STACKSIZE, zvsTestThread, NULL, NULL, NULL, THREAD_ZVS_PRIORITY, 0, 0);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This LOG mechanism prints the data on serial terminal&amp;nbsp;via an ultra low priority thread. This clarifies the delay in logs since the LED toggles start, which I considered as actual delay.The first concern stands cleared!.&lt;/li&gt;
&lt;li&gt;I am still not clear with how to initiate GC from my code as I still see the ZMSThread not letting higher priority threads not execute (or starve) when its executing GC. This can be a problem for my application.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The available space for User data is not consistant with the large data values details given here:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-3.0.2/page/zephyr/services/storage/zms/zms.html#:~:text=Device%20lifetime%20calculation&amp;amp;text=The%20partition%20has%204%20sectors,moving%20blocks%20all%20the%20time"&gt;https://docs.nordicsemi.com/bundle/ncs-3.0.2/page/zephyr/services/storage/zms/zms.html#:~:text=Device%20lifetime%20calculation&amp;amp;text=The%20partition%20has%204%20sectors,moving%20blocks%20all%20the%20time&lt;/a&gt;.
&lt;ul&gt;
&lt;li&gt;In my example, I have used 10 sectors of 4096 byte to store data of length 12 byte (large data model).&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Expecting to save 1290 records without overwriting in the memory but was able to save only 1094 records.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The zms_mount() fails with an error. This is not consistant but when happens, the recovery path is not clear.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please advice.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards&lt;br /&gt;Sarma&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/556953?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2025 11:53:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f2cd5a7-429b-4281-9a72-3ef0c48ee7dd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you done any other debugging to see what is happening? Looking at your code, your LED blink thread has priority 4. This is lower than the main therad, which as a&amp;nbsp;default priority of 0 (higher number = lower priority). And you have a lot of ZMS work being done in main. I suspect this is what takes time, and this will block your other lower priority threads.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/556948?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2025 06:07:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0001afcd-11f3-46c9-a593-672af7b284e0</guid><dc:creator>Sarma</dc:creator><description>&lt;p&gt;The Boot time is monitored without any timer or HW support by observation. As the logs were set to &amp;quot;INF&amp;quot;, there was no detail in the log. Moving to &amp;quot;DBG&amp;quot; was further delaying.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The Delay is measured between the start of the LED Toggle (high priority tasks) and the first INF log in the ZMS thread in the sample code attached.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/556894?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2025 15:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ca2c251-412b-4414-aa04-ba8f3511da6d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. But do you have any logging not in ZMS or any debug information that can shed some light on what is happening? I am very curious about what is taking two minutes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/556822?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2025 05:55:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3b03cd1-1528-435a-9d67-81ccc1fded89</guid><dc:creator>Sarma</dc:creator><description>&lt;p&gt;SDK Version is 3.1.0. Logging is set to INF level.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Including ZMS makes a delayed Application ON time</title><link>https://devzone.nordicsemi.com/thread/556758?ContentTypeID=1</link><pubDate>Thu, 11 Dec 2025 07:32:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02940ec5-0ee9-4cef-81ef-1695a1faa529</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Sarma,&lt;/p&gt;
&lt;p&gt;Which SDK version are you using?&lt;/p&gt;
&lt;p&gt;Also, 2 minutes is a very long time. Do you have logging (UART or RTT or other data or debug findings showing what is happening during that time)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>