[PATCH 0/2] Fix I/O high when memory almost met memcg limit

From: Liu Shixin
Date: Thu Feb 01 2024 - 04:13:27 EST


Recently, when install package in a docker environment where the memory
almost reached the memcg limit, the program have no respond severely for
more than 15 minutes. During this period, the I/O is high(~1G/s) which
cause other programs failed to work properly.

The problem can be constructed in the following way:

1. Download the image:
docker pull centos:7
2. Create a docker with 4G memory limit and 6G memsw limit(cgroupv1):
docker create --name dockerhub_centos7 --cpu-period=100000
--cpu-quota=400000 --memory 4G --memory-swap 6G --cap-add=SYS_PTRACE
--cap-add=SYS_ADMIN --cap-add=NET_ADMIN --cap-add=NET_RAW
--pids-limit=20000 --ulimit nofile=1048576:1048576
--ulimit memlock=-1:-1 dockerhub_centos7:latest /usr/sbin/init
3. Start the docker:
docker start dockerhub_centos7
4. Allocate 6094MB memory in docker.
5. run 'yum install expect'.

We found that this problem is caused by a lot ot meaningless readahead.
Since memory is almost met memcg limit, the readahead page will be
reclaimed immediately and will readahead and reclaim again and again.

These two patch will stop readahead early when memcg charge failed and
will skip readahead when there are too many active refault.

[1] https://lore.kernel.org/linux-mm/c2f4a2fa-3bde-72ce-66f5-db81a373fdbc@xxxxxxxxxx/T/

Liu Shixin (2):
mm/readahead: stop readahead loop if memcg charge fails
mm/readahead: limit sync readahead while too many active refault

include/linux/fs.h | 2 ++
include/linux/pagemap.h | 1 +
mm/filemap.c | 16 ++++++++++++++++
mm/readahead.c | 12 ++++++++++--
4 files changed, 29 insertions(+), 2 deletions(-)

--
2.25.1