Files
Richard Raya 74ada5fc95 mm: Fix OOM crash by limiting memory allocation
This commit reverts:
   - 409a04b5c274ece58afaa53426322119c06bb5c1 {"proc: add seq_put_decimal_ull_width to speed up /proc/pid/smaps"}
   - ea84caeed6a527f081c62e8b96faef560c34a6a1 {"fs/proc/task_mmu.c: do not show VmExe bigger than total executable virtual memory"}

This commit addresses a critical issue that led to app crashes due to out-of-memory (OOM) conditions. The issue arose when certain apps, such as "Livin' by Mandiri" attempted to allocate close to 1 GB of memory, causing the app to crash. The root cause of the problem was traced to memory allocation logic that allowed excessive memory usage. The commit introduces changes to several source files to mitigate this issue.

1. In fs/proc/meminfo.c:
   - The show_val_kb function has been modified to ensure proper formatting of output.
   - A buffer v is introduced to hold the converted numeric value.
   - A constant array blanks is used to manage alignment.
   - The modified function now properly formats the output to the seq_file.

2. In fs/proc/task_mmu.c:
   - The task_mem function has undergone significant changes to accurately report memory statistics.
   - Numeric values are now properly converted and formatted using the seq_printf function.
   - The function now outputs memory statistics such as VmPeak, VmSize, VmRSS, RssAnon, and more.

3. In fs/proc/task_mmu.c (continued):
   - The show_smap function has been refactored to address formatting issues.
   - Numeric values are formatted and displayed using the seq_printf function.
   - The function now properly reports memory-related attributes like Rss, Pss, Shared_Clean, and more.

4. In fs/seq_file.c:
   - The seq_put_decimal_ull function has been renamed from seq_put_decimal_ull_width.
   - The function's behavior has been adjusted to simplify usage and improve consistency.
   - Calls to seq_put_decimal_ull_width in the codebase have been updated to use seq_put_decimal_ull.

5. In include/linux/kernel.h and include/linux/seq_file.h:
   - The declarations of the seq_put_decimal_ull_width functions have been removed and replaced with the modified seq_put_decimal_ull.

6. In lib/vsprintf.c:
   - The num_to_str function has been simplified, removing width adjustments that caused formatting issues.
   - The function now focuses on converting and formatting numeric values accurately.

These changes address the underlying issue of apps crashing due to excessive memory allocation. By correctly formatting and reporting memory statistics, this commit ensures that apps like "Livin' by Mandiri" can safely allocate memory without encountering OOM crashes.

Suggested-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: Richard Raya <rdxzv.dev@gmail.com>
Change-Id: I0ce431006730f0586321fc37c85c41e2c15c83d1
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
2023-09-17 13:33:10 +03:00

32 KiB