mm: memory pressure support returns the maximum available memory

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2024-06-30 18:00:12 +08:00 committed by Xiang Xiao
parent 49d1b4198f
commit 2cdfda149a
7 changed files with 27 additions and 12 deletions

View File

@ -57,6 +57,7 @@ struct pressure_file_s
static dq_queue_t g_pressure_memory_queue;
static spinlock_t g_pressure_lock;
static size_t g_remaining;
static size_t g_largest;
/****************************************************************************
* Private Function Prototypes
@ -160,14 +161,17 @@ static ssize_t pressure_read(FAR struct file *filep, FAR char *buffer,
char buf[128];
uint32_t flags;
size_t remain;
size_t largest;
off_t offset;
ssize_t ret;
flags = spin_lock_irqsave(&g_pressure_lock);
remain = g_remaining;
flags = spin_lock_irqsave(&g_pressure_lock);
remain = g_remaining;
largest = g_largest;
spin_unlock_irqrestore(&g_pressure_lock, flags);
ret = procfs_snprintf(buf, sizeof(buf), "remaining %zu\n", remain);
ret = procfs_snprintf(buf, sizeof(buf), "remaining %zu, largest:%zu\n",
remain, largest);
if (ret > buflen)
{
@ -410,7 +414,7 @@ static int pressure_stat(const char *relpath, struct stat *buf)
* mm_notify_pressure
****************************************************************************/
void mm_notify_pressure(size_t remaining)
void mm_notify_pressure(size_t remaining, size_t largest)
{
clock_t current = clock_systime_ticks();
FAR dq_entry_t *entry;
@ -419,12 +423,18 @@ void mm_notify_pressure(size_t remaining)
flags = spin_lock_irqsave(&g_pressure_lock);
g_remaining = remaining;
g_largest = largest;
dq_for_every_safe(&g_pressure_memory_queue, entry, tmp)
{
FAR struct pressure_file_s *pressure =
container_of(entry, struct pressure_file_s, entry);
if (remaining > pressure->threshold)
/* If the largest available block is less than the threshold,
* send a notification
*/
if (largest > pressure->threshold)
{
continue;
}

View File

@ -437,9 +437,9 @@ FAR void kmm_checkcorruption(void);
/* Functions contained in fs_procfspressure.c *******************************/
#ifdef CONFIG_FS_PROCFS_INCLUDE_PRESSURE
void mm_notify_pressure(size_t remaining);
void mm_notify_pressure(size_t remaining, size_t largest);
#else
# define mm_notify_pressure(remaining)
# define mm_notify_pressure(remaining, largest)
#endif
#undef EXTERN

View File

@ -78,7 +78,8 @@ FAR void *calloc(size_t n, size_t elem_size)
}
else
{
mm_notify_pressure(mm_heapfree(USR_HEAP));
mm_notify_pressure(mm_heapfree(USR_HEAP),
mm_heapfree_largest(USR_HEAP));
}
return mem;

View File

@ -68,7 +68,8 @@ FAR void *malloc(size_t size)
}
else
{
mm_notify_pressure(mm_heapfree(USR_HEAP));
mm_notify_pressure(mm_heapfree(USR_HEAP),
mm_heapfree_largest(USR_HEAP));
}
return ret;

View File

@ -95,7 +95,8 @@ FAR void *memalign(size_t alignment, size_t size)
}
else
{
mm_notify_pressure(mm_heapfree(USR_HEAP));
mm_notify_pressure(mm_heapfree(USR_HEAP),
mm_heapfree_largest(USR_HEAP));
}
return ret;

View File

@ -97,7 +97,8 @@ FAR void *realloc(FAR void *oldmem, size_t size)
}
else
{
mm_notify_pressure(mm_heapfree(USR_HEAP));
mm_notify_pressure(mm_heapfree(USR_HEAP),
mm_heapfree_largest(USR_HEAP));
}
return ret;

View File

@ -74,7 +74,8 @@ FAR void *zalloc(size_t size)
}
else
{
mm_notify_pressure(mm_heapfree(USR_HEAP));
mm_notify_pressure(mm_heapfree(USR_HEAP),
mm_heapfree_largest(USR_HEAP));
}
return ret;