Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp43640rdb; Thu, 1 Feb 2024 01:13:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWtxtJelQkhnsMVKFpSX5YwEdiWNJcXp+pe/4lonb9u8op9aYjcwZ7edT7VIOD7yd0RmiT X-Received: by 2002:aa7:c6c2:0:b0:55f:4b07:f383 with SMTP id b2-20020aa7c6c2000000b0055f4b07f383mr2877410eds.17.1706778808454; Thu, 01 Feb 2024 01:13:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706778808; cv=pass; d=google.com; s=arc-20160816; b=pjQye5GWTwCbiEEE9Kk4Eojx4U+EhyWKIyd9LoSPjUmOuju0xn1xySkL/GKq9052JE 0QutLS8aMfueliu5/+M3+tfEs7JwWcXbXjvb8TIQ5KCVyxiHeqN9GIZtIcObvRjVJjiQ n6p1Fq5DgEiqutOP10pwpPpcs0yg72RaHd3/R9JHOBVcEYTi2kefCsVBa0JXnv2nFhHI OrRjZJe2V03UHoaoOyfFr4NZMixvDnJcRfS7evN6w0olfcT/8bVTqoW81qX6AycUEyg+ 2FoHHVBA6srMBaHkovgiqzzGL6Z7kupG/NFwujZxR1qnymc35mAlflyMNMptvNz/cglC 8NFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=1M8jYwv9612qe9L5KWz/mT6ygBJLPpb7W82opbFf1j0=; fh=3HWMHbuf7ROTJtJNbqoGcEORGfYDSvB4nVT+OBR2OnU=; b=G/f5o/WQ474nN+EMrKdVAvtz4MAyY1ZOdNqlFFJqiNq4saMEl+PLrqf5cDT7RzDARi LKVrnbnhyF21i2PVLpMAobQg51v6cL9MlZav5rEiEPT/JaP0FiYKWdR1ROplBsEJGdBz CduuC/pPtrXXDjjBqFkub7SnsVem0zCWrG+5125nHcRyvre5VALxPlPXwiWaKf6VGuNe x5IYWjxfgzm088yv9h+OYP+MATWAcMuWvg2ZxGwmTasy7iYzLQGMfTL1dn0zCT/IofmX dpUVH9qVO/y/Q0I8Ut9MxelX7jhlVsRlzbea/SO39fAd9v1ciOIuUEb0zL//tQayzws4 o2NA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-47834-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCUe8gX9RmeouSzH409eDiXyvxo7OMVqkFvZW9yM9WhWeC6heN0fwIiBjTwAWX+vdyOlrqTbt3VtrEe7IIcn5CRQ8dMMiDOd/EaS2MdBtw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h28-20020a0564020e9c00b0055f1d367f12si3608598eda.1.2024.02.01.01.13.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 01:13:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47834-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-47834-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 294941F29103 for ; Thu, 1 Feb 2024 09:13:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51CEE15B0EA; Thu, 1 Feb 2024 09:13:15 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE9B515A4B1; Thu, 1 Feb 2024 09:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706778794; cv=none; b=oG1S4DnbpHp0tVuxnkzlZ4WpqgPkoa2d7TRU/ayTHUv+ovXVqi4S+w7X4xy74Z9FBtjpo27N+CkDa4aZiFZjfusD2o3w8CqNB8UYZ9fNGlH2ciHGLZvTMIFIsp27h8XzLtbuYgME8ws6xWUkSjHOxlLl+sP7HPtWwFdQAZlf/k0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706778794; c=relaxed/simple; bh=vdcjgpSSe3vHkaNcPGjjlLa0vhqVfEdHpZMs8SYg4f0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AvGA8mjN8vkMyuEcNAqD4aAt5YmZi+UFKAyb1ihKkgCPIdqTDb95WgwyvbRKjF9pXbxnqb9wLpIBqGR0FeX+n6CS8t+PtmKSZ/voAmYHQwjisWlcqUNic1bXnqGKVzigaXnW8fGONF8m9KHxSD744QnRv8/D/gsy46Jxw/VPprc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TQY6s3h8Bz1Q8Ks; Thu, 1 Feb 2024 17:11:17 +0800 (CST) Received: from dggpemd200004.china.huawei.com (unknown [7.185.36.141]) by mail.maildlp.com (Postfix) with ESMTPS id 205971400D4; Thu, 1 Feb 2024 17:13:09 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemd200004.china.huawei.com (7.185.36.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Thu, 1 Feb 2024 17:13:08 +0800 From: Liu Shixin To: Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Andrew Morton CC: , , , Liu Shixin Subject: [PATCH 0/2] Fix I/O high when memory almost met memcg limit Date: Thu, 1 Feb 2024 18:08:33 +0800 Message-ID: <20240201100835.1626685-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) 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@huawei.com/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