walnux/fs/procfs
yinshengkai f44a31c337 procfs: add memory pressure notification support
This is a memory monitoring interface implemented with reference to Linux's PSI (Pressure Stall Information),
which can send notifications when the system's remaining memory is below the threshold.

The following example code sets two different thresholds.
When the system memory is below 10MB, a notification is triggered.
When the system memory is below 20 MB, a notification (POLLPRI event) is triggered every 1s.

```
int main(int argc, FAR char *argv[])
{
  struct pollfd fds[2];
  int ret;

  if (argc == 2)
    {
      char *ptr = malloc(1024*1024*atoi(argv[1]));
      printf("Allocating %d MB\n", atoi(argv[1]));
      ptr[0] = 0;
      return 0;
    }

  fds[0].fd = open("/proc/pressure/memory", O_RDWR);
  fds[1].fd = open("/proc/pressure/memory", O_RDWR);
  fds[0].events = POLLPRI;
  fds[1].events = POLLPRI;

  dprintf(fds[0].fd, "%llu -1", 1024LLU*1024 * 10);
  dprintf(fds[1].fd, "%llu 1000000", 1024LLU*1024 * 20);

  while (1)
    {
      ret = poll(fds, 2, -1);
      if (ret > 0)
        {
          printf("Memory pressure: POLLPRI, %d\n", ret);
        }
    }

  return 0;
}
```

https://docs.kernel.org/accounting/psi.html
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00
..
CMakeLists.txt cmake:complete missing changes during cmake reforming for fs 2023-09-08 21:20:16 +03:00
fs_procfs.c procfs: add memory pressure notification support 2024-08-25 23:09:28 +08:00
fs_procfscpuinfo.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
fs_procfscpuload.c cpuload: change cpuload type to clock_t 2024-03-03 02:15:40 +08:00
fs_procfscritmon.c [BugFix]Command "critmon" error 2024-08-23 08:53:15 +08:00
fs_procfsfdt.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
fs_procfsiobinfo.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
fs_procfsmeminfo.c procfs/meminfo: free delaylist for PROTECTED 2024-08-03 01:30:04 +08:00
fs_procfspressure.c procfs: add memory pressure notification support 2024-08-25 23:09:28 +08:00
fs_procfsproc.c fs/procfs: refine file backtrace 2024-06-30 17:30:42 +08:00
fs_procfstcbinfo.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
fs_procfsuptime.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
fs_procfsutil.c procfs:add /proc/cpuinfo 2023-05-27 03:29:41 +08:00
fs_procfsversion.c fs/procfs: add build config to /proc/version 2024-02-26 21:46:28 +08:00
fs_skeleton.c fs: procfs add poll support 2023-12-26 19:23:13 -08:00
Kconfig procfs: add memory pressure notification support 2024-08-25 23:09:28 +08:00
Make.defs procfs: add memory pressure notification support 2024-08-25 23:09:28 +08:00