[PATCH v4 0/1] mm: memcg: optimize stat output to reduce printf overhead

Jianyue Wu posted 1 patch 2 weeks ago
mm/memcontrol-v1.c | 84 ++++++++++++++++++++++++-------------------
mm/memcontrol-v1.h |  4 +++
mm/memcontrol.c    | 88 +++++++++++++++++++++++++++++++++++++---------
3 files changed, 123 insertions(+), 53 deletions(-)
[PATCH v4 0/1] mm: memcg: optimize stat output to reduce printf overhead
Posted by Jianyue Wu 2 weeks ago
This patch optimizes memcg stat output by replacing seq_buf_printf() with
a lightweight helper and replacing seq_printf() in numa stat functions with
direct seq operations.

Changes in v4:
- Embed separator and newline in buffer to reduce function calls in
  memcg_seq_buf_print_stat() (suggested by JP Kobryn)
- Optimize memory_numa_stat_show() and memcg_numa_stat_show() by replacing
  seq_printf() with seq_puts() and seq_put_decimal_ull()
- Add comments explaining the optimization approach
- Note: Did not add a separate API for the numa stat case because the output
  format "N0=value0 N1=value1" is too specific - the "N" prefix and node ID
  are separate values that don't fit a name=value pattern. Using
  seq_put_decimal_ull() directly is more flexible and clear.

Changes in v3:
- Rebased to latest mm-unstable
- Updated commit message to clarify the optimization approach

Changes in v2:
- Initial version with seq_buf optimization

Performance improvement (1M reads of memory.stat + memory.numa_stat):
- Before: real 0m9.663s, user 0m4.840s, sys 0m4.823s
- After:  real 0m8.909s, user 0m4.661s, sys 0m4.247s
- Result: ~11% sys time reduction

Jianyue Wu (1):
  mm: optimize stat output for 11% sys time reduce

 mm/memcontrol-v1.c | 84 ++++++++++++++++++++++++-------------------
 mm/memcontrol-v1.h |  4 +++
 mm/memcontrol.c    | 88 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 123 insertions(+), 53 deletions(-)

-- 
2.43.0