mm: memory pressure support returns the maximum available memory
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
49d1b4198f
commit
2cdfda149a
@ -57,6 +57,7 @@ struct pressure_file_s
|
|||||||
static dq_queue_t g_pressure_memory_queue;
|
static dq_queue_t g_pressure_memory_queue;
|
||||||
static spinlock_t g_pressure_lock;
|
static spinlock_t g_pressure_lock;
|
||||||
static size_t g_remaining;
|
static size_t g_remaining;
|
||||||
|
static size_t g_largest;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
@ -160,14 +161,17 @@ static ssize_t pressure_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
char buf[128];
|
char buf[128];
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
size_t remain;
|
size_t remain;
|
||||||
|
size_t largest;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
flags = spin_lock_irqsave(&g_pressure_lock);
|
flags = spin_lock_irqsave(&g_pressure_lock);
|
||||||
remain = g_remaining;
|
remain = g_remaining;
|
||||||
|
largest = g_largest;
|
||||||
spin_unlock_irqrestore(&g_pressure_lock, flags);
|
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)
|
if (ret > buflen)
|
||||||
{
|
{
|
||||||
@ -410,7 +414,7 @@ static int pressure_stat(const char *relpath, struct stat *buf)
|
|||||||
* mm_notify_pressure
|
* 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();
|
clock_t current = clock_systime_ticks();
|
||||||
FAR dq_entry_t *entry;
|
FAR dq_entry_t *entry;
|
||||||
@ -419,12 +423,18 @@ void mm_notify_pressure(size_t remaining)
|
|||||||
|
|
||||||
flags = spin_lock_irqsave(&g_pressure_lock);
|
flags = spin_lock_irqsave(&g_pressure_lock);
|
||||||
g_remaining = remaining;
|
g_remaining = remaining;
|
||||||
|
g_largest = largest;
|
||||||
|
|
||||||
dq_for_every_safe(&g_pressure_memory_queue, entry, tmp)
|
dq_for_every_safe(&g_pressure_memory_queue, entry, tmp)
|
||||||
{
|
{
|
||||||
FAR struct pressure_file_s *pressure =
|
FAR struct pressure_file_s *pressure =
|
||||||
container_of(entry, struct pressure_file_s, entry);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -437,9 +437,9 @@ FAR void kmm_checkcorruption(void);
|
|||||||
/* Functions contained in fs_procfspressure.c *******************************/
|
/* Functions contained in fs_procfspressure.c *******************************/
|
||||||
|
|
||||||
#ifdef CONFIG_FS_PROCFS_INCLUDE_PRESSURE
|
#ifdef CONFIG_FS_PROCFS_INCLUDE_PRESSURE
|
||||||
void mm_notify_pressure(size_t remaining);
|
void mm_notify_pressure(size_t remaining, size_t largest);
|
||||||
#else
|
#else
|
||||||
# define mm_notify_pressure(remaining)
|
# define mm_notify_pressure(remaining, largest)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
@ -78,7 +78,8 @@ FAR void *calloc(size_t n, size_t elem_size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mm_notify_pressure(mm_heapfree(USR_HEAP));
|
mm_notify_pressure(mm_heapfree(USR_HEAP),
|
||||||
|
mm_heapfree_largest(USR_HEAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
@ -68,7 +68,8 @@ FAR void *malloc(size_t size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mm_notify_pressure(mm_heapfree(USR_HEAP));
|
mm_notify_pressure(mm_heapfree(USR_HEAP),
|
||||||
|
mm_heapfree_largest(USR_HEAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -95,7 +95,8 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mm_notify_pressure(mm_heapfree(USR_HEAP));
|
mm_notify_pressure(mm_heapfree(USR_HEAP),
|
||||||
|
mm_heapfree_largest(USR_HEAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -97,7 +97,8 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mm_notify_pressure(mm_heapfree(USR_HEAP));
|
mm_notify_pressure(mm_heapfree(USR_HEAP),
|
||||||
|
mm_heapfree_largest(USR_HEAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -74,7 +74,8 @@ FAR void *zalloc(size_t size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mm_notify_pressure(mm_heapfree(USR_HEAP));
|
mm_notify_pressure(mm_heapfree(USR_HEAP),
|
||||||
|
mm_heapfree_largest(USR_HEAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user