diff --git a/fs/procfs/fs_procfspressure.c b/fs/procfs/fs_procfspressure.c index 9b2dd582cb..73f0fbab07 100644 --- a/fs/procfs/fs_procfspressure.c +++ b/fs/procfs/fs_procfspressure.c @@ -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; } diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 0f434afa3c..e5d27d63d0 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -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 diff --git a/mm/umm_heap/umm_calloc.c b/mm/umm_heap/umm_calloc.c index ee698d1f51..43b10e913f 100644 --- a/mm/umm_heap/umm_calloc.c +++ b/mm/umm_heap/umm_calloc.c @@ -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; diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c index 3fa63eb59a..6be51611c3 100644 --- a/mm/umm_heap/umm_malloc.c +++ b/mm/umm_heap/umm_malloc.c @@ -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; diff --git a/mm/umm_heap/umm_memalign.c b/mm/umm_heap/umm_memalign.c index 9338bb6abf..52e53e3bd5 100644 --- a/mm/umm_heap/umm_memalign.c +++ b/mm/umm_heap/umm_memalign.c @@ -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; diff --git a/mm/umm_heap/umm_realloc.c b/mm/umm_heap/umm_realloc.c index d31b8de7a0..45eb1732b6 100644 --- a/mm/umm_heap/umm_realloc.c +++ b/mm/umm_heap/umm_realloc.c @@ -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; diff --git a/mm/umm_heap/umm_zalloc.c b/mm/umm_heap/umm_zalloc.c index 69ec6a2c9d..2155d3000e 100644 --- a/mm/umm_heap/umm_zalloc.c +++ b/mm/umm_heap/umm_zalloc.c @@ -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;