From patchwork Thu Feb 1 10:08:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13540820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36639C47DDB for ; Thu, 1 Feb 2024 09:13:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C20C96B007E; Thu, 1 Feb 2024 04:13:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD04F6B0080; Thu, 1 Feb 2024 04:13:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE6196B0081; Thu, 1 Feb 2024 04:13:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9E8DD6B007E for ; Thu, 1 Feb 2024 04:13:17 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 683161C17BA for ; Thu, 1 Feb 2024 09:13:17 +0000 (UTC) X-FDA: 81742671234.24.EE57D64 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf24.hostedemail.com (Postfix) with ESMTP id 5828618000C for ; Thu, 1 Feb 2024 09:13:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706778795; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=1M8jYwv9612qe9L5KWz/mT6ygBJLPpb7W82opbFf1j0=; b=L0LNeh42wqoLQlAddXwT+oeH9uM1mm0/QlBOucdOgy0RVkyVlxvu4aSthjyGKHAxyTdV2v 2FvP7M6MUUKJ4OTGB/ERwymb0tCVQMxNXY1Jz6hANc1neOW1GVAX2Qgt5tWxgial/XDl23 uMnJf5VpNMlUmy9024uJdQ+7VkslHDo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706778795; a=rsa-sha256; cv=none; b=QSJyOTjOugoon4Mqg35Nuy+cQLBcDTAGxAwyu53I2f/5GaJ2I0SSbjzQpmQD7LLXsxyRYc G/DFgzZlJsNhhmXoGBURMogEbUL6nobOQGYBli5RVn6mA3tCUGyBq4qJtT9NxjK6mY5MGp jOmQSyxURWBpSdjx0o1rlYFKAXJANgI= 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 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5828618000C X-Stat-Signature: d3y7rma3tc68ubaojexg6pzf1gdusbkw X-HE-Tag: 1706778793-150914 X-HE-Meta: U2FsdGVkX19+8KTfQwl75Gy40mMPJDsN4PxwDzkJuIlAzAHR/ibkBgrwQiJYidH+pTqgyvUlCkgkGm04GFpS/SYG9mXjN36luNi0rrBuPOe/V6H5VEhg6Y4gcHYyMTobWvxV/k4QAWvZqK63tHdTdhqr/36yKDhTgfUdRCYUOmD1/zDGGnlTdd5fs2aBJ3vGafbv53KiE+Fsjcwdsasy3oOoKaxc3jUOfNZHJ0B6baeEZWpgtd7WgGqbmjJ0AHL307Ad+HColpPUjuU7qx22JJbna6uuuD7t7bEiKxGjcbjdSNy9+yX4ANI7WnZeIUwDScc9FAtZKgXuPwSop3Oc0cRxGRMmgfMrtoqX3nqKk0pJAp4H7dCvFJn4tQqy2PTVQYD3eD+bEy6ZoyDjdlIZeRmqGLs2ZEcrKZn2TsE6fNQw8XiWxzQ6qFgnykAHeuaPuSdXo8kULQPULxLPlhiK2VBTFVySTo61bpjc8M/vc8oIjl7px9wX0ZHJimw0e6EL2zP/FVCOp1ekpQVaImfTsqfjpFXmFI5n2OmdyvJi0A4BWF/QEDrSF3Nf8dXFVyNRFuUyQx7WFLKZJnGTDJ2EdyiOcdpqUzjAgiPRWkFaXe2vNI+vrSldv9FsSrSJXJyrdOn9F3dy61yahJhuYcim46W37IrT7jLDvaADKQ2xqyIBIfr3rIotkF8MwOtT8Y9q3KV00dUjStAT1YTwUY5lp/5Cqq3HAO9rXk2mOEHCy0H3wedxdzkWXCyjKzfpniANKKlwfNbeGZqI4iuVANrIk9oAXbWuHFTG3fIFe0fHnjzWaB3DRhWHEkrSB5gb0IUhCwGg9nrL5S0+fVfNdb5N8w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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(-)