src/libruntime/rmem/cache.c
/**
 * @brief Evicts pages from the cache based on the LIFO replacement policy.
 *
 * @param pgnum Number of the target page.
 *
 * @returns Upon successful completion, the index of the page is
 * returned. Upon failure a negative error code is returned instead.
 */
@brief Evicts pages from the cache based on the LIFO replacement policy.
@param pgnum Number of the target page.

@returns Upon successful completion, the index of the page is
returned. Upon failure a negative error code is returned instead.
@brief Evicts pages from the cache based on the LIFO replacement policy . @param pgnum Number of the target page . @returns Upon successful completion the index of the page is returned . Upon failure a negative error code is returned instead .
static int nanvix_rcache_lifo(void)
{
	int idx;
	int age;
	int max_age;
	cache_time++;
	for (int i = 0; i < RMEM_CACHE_LENGTH; i++)
	{
		if (cache_lines[i*RMEM_CACHE_BLOCK_SIZE].pgnum == RMEM_NULL)
		    return (i*RMEM_CACHE_BLOCK_SIZE);
	}
	max_age = cache_lines[idx = 0].age;
	for (int i = 1; i < RMEM_CACHE_LENGTH; i++)
	{
		if ((age = cache_lines[i*RMEM_CACHE_BLOCK_SIZE].age) > max_age)
		{
		    idx = i*RMEM_CACHE_BLOCK_SIZE;
		    max_age = age;
		}
	}
	if (nanvix_rcache_flush(cache_lines[idx].pgnum) < 0)
		return (-EFAULT);
	return idx;
}
static int nanvix_rcache_lifo ( void ) { int idx ; int age ; int max_age ; cache_time ++ ; for ( int i = 0 ; i < RMEM_CACHE_LENGTH ; i ++ ) { if ( cache_lines [ i * RMEM_CACHE_BLOCK_SIZE ] . pgnum == RMEM_NULL ) return ( i * RMEM_CACHE_BLOCK_SIZE ) ; } max_age = cache_lines [ idx = 0 ] . age ; for ( int i = 1 ; i < RMEM_CACHE_LENGTH ; i ++ ) { if ( ( age = cache_lines [ i * RMEM_CACHE_BLOCK_SIZE ] . age ) > max_age ) { idx = i * RMEM_CACHE_BLOCK_SIZE ; max_age = age ; } } if ( nanvix_rcache_flush ( cache_lines [ idx ] . pgnum ) < 0 ) return ( - EFAULT ) ; return idx ; }
@brief Evicts pages from the cache based on the LIFO replacement policy.
@brief Evicts pages from the cache based on the LIFO replacement policy .
/* Cache has space. */ /* No space. Make evict. */