jingfei195887 opened a new pull request, #21952:
URL: https://github.com/apache/nuttx/pull/21952

   ## Summary
   
   - **mm/procfs: refactor mm_notify_pressure to accept heap pointer.**
     Every `malloc()`, `calloc()`, `zalloc()`, `realloc()` and `memalign()`
     called `mm_notify_pressure(mm_heapfree(USR_HEAP),
     mm_heapfree_largest(USR_HEAP))`, so both values were computed on every
     allocation even with nobody listening on `/proc/pressure/memory`, and the
     procfs entry reported values cached at the last allocation.
   
     `mm_notify_pressure()` now takes the heap pointer, returns at once when
     the listener queue is empty (lockless `dq_empty()`), and only then
     computes the largest free block. The cached `g_remaining`/`g_largest`
     globals are removed: `read()` and `poll()` setup query the heap
     directly, so a `free()` is reflected right away.
   
   ## Impact
   
   - API change: `mm_notify_pressure()` in `include/nuttx/mm/mm.h` now takes
     `FAR struct mm_heap_s *`; all in-tree callers (`mm/umm_heap/`) are
     updated. Only built with `CONFIG_FS_PROCFS_INCLUDE_PRESSURE`.
   - Behavior: no heap walk on the allocation path when there is no listener;
     `/proc/pressure/memory` shows the current free memory instead of the
     value at the last allocation.
   - Build, hardware, documentation, security, compatibility: NO.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master
   e9eefaa0e9.
   
   `sim:nsh` with `CONFIG_FS_PROCFS_INCLUDE_PRESSURE`: open
   `/proc/pressure/memory`, `malloc()` and `free()` 1 MiB, then read the entry
   and compare with `mallinfo()`:
   
   Testing logs before change:
   
   ```
   pressure: proc remaining 64132808, largest:59488
   pressure: mallinfo remaining 65182200
   ```
   
   Testing logs after change:
   
   ```
   pressure: proc remaining 65181392, largest:59488
   pressure: mallinfo remaining 65182200
   ```
   
   Before, `remaining` is the value from the `malloc()` call (1 MiB lower);
   after, it matches the free memory after `free()`. The `largest` value comes
   from `mm_heapfree_largest()`, which this PR does not change.
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - `sim:nsh` Make and CMake builds pass with no new warnings in the changed
     files, with `CONFIG_FS_PROCFS_INCLUDE_PRESSURE`; `ostest` exits with
     status 0.
   - Verified on sim only.
   
   ## PR verification Self-Check
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   * [ ] My PR is still work in progress (not ready for review).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to