Forum Topic - statvfs first call takes 4-5 seconds and subsequent calls taking less than 100 ms: (1 Item)
   
statvfs first call takes 4-5 seconds and subsequent calls taking less than 100 ms  
Operation to be performed:
- Need to check the free size of 1GB of SD card connected to the Hardware. If we don't have free space of 1GB, keep on 
deleting the files from the SD card to make 1GB free.
- This checking of free space we are calling at every file creation on SD card.
- Using the following call to check the free space memory of SD Card:

bool checkSDCardFreeSpace(char *path, unsigned long long space)
{
    struct statvfs diskData;
    unsigned long long freeDiskSpace = 0;

    memset(&diskData, 0, sizeof(struct statvfs));

    if(statvfs(path, &diskData) == -1)
    {
		return false;
    }
    else
    {
        freeDiskSpace = (unsigned long long)diskData.f_bavail * diskData.f_bsize;

        if(freeDiskSpace >= space)
        {
			printf("Demanded memory is free on %s\n", path);
            return true;
        }
        else
        {
			printf("Demanded memory is not available on %s\n", path);
			return false;
        }
    }
}

- after first call of checkSDCardFreeSpace it takes 4-5 seconds to finish it's execution and next all calls of 
checkSDCardFreeSpace only takes less than 100 milisecs.
- Why this behaviour is there I am not able to figure out. I understood one thing - first call of checkSDCardFreeSpace 
cache out the filesystem details in RAM. Therefore it takes 4-5 seconds in first call and in subsequent call of 
checkSDCardFreeSpace uses cache data so it takes less amount of time.
- Actually, we are 3 seconds of watchdog refresh window - because of first call of checkSDCardFreeSpace takes 4-5 
seconds resetting the microcontroller because of 3 seconds watchdog window.
- What is the problem happening here, why it is taking 4-5 seconds for first call?
- What we can do to mitigate this problem with 3 second watchdog window?

Note: QNX 6.5 we are using