From patchwork Fri Oct 27 09:30:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruifeng Su X-Patchwork-Id: 13438029 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 DD590C25B48 for ; Fri, 27 Oct 2023 01:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E51AF6B039A; Thu, 26 Oct 2023 21:34:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E01686B039B; Thu, 26 Oct 2023 21:34:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF0886B039C; Thu, 26 Oct 2023 21:34:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BD9366B039A for ; Thu, 26 Oct 2023 21:34:58 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 99307160F0A for ; Fri, 27 Oct 2023 01:34:58 +0000 (UTC) X-FDA: 81389522676.01.B842E47 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf08.hostedemail.com (Postfix) with ESMTP id 536B016000F for ; Fri, 27 Oct 2023 01:34:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of suruifeng1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=suruifeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698370496; 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=5/zpWM7ArWj/juaBPdaqeUioVNX91UPCg2f+q9y4RJw=; b=K9MoeodfOS4UEELA6DMgvj5PfYApVb7DH3W9XBCJ9C0xIHS+26yd5fAQgbc97t85hK2j6P sryAPXHLRCJOfgkMsCwOhlTRMaixkGhx2QujBMWneWrWwgaQp8W7F7AjKkYe91lU9E7BED SgEGx0Vrmlr/HmAvegS78p7b7ayRywk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of suruifeng1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=suruifeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698370496; a=rsa-sha256; cv=none; b=b4ANTqfY3m7YghVek4WggB8YUspJ+da+LPzryxOgwsRJjX1yHlVLIfr4G65x031JHcVh9Q 5xh/Upu5GsrLpnJUYtIZX4vUBvswXztZe9P57juAM5k37+P7yzpFA6HpgBE3TakDL6aqgF iS9JJbiEij5W0KsmYzG+iPDKg7K3PeU= Received: from dggpeml500015.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SGlWK4mvVz1L9FJ; Fri, 27 Oct 2023 09:31:41 +0800 (CST) Received: from huawei.com (10.174.149.20) by dggpeml500015.china.huawei.com (7.185.36.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 27 Oct 2023 09:34:35 +0800 From: Ruifeng Su To: CC: , , , , , , Subject: [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory Date: Fri, 27 Oct 2023 17:30:04 +0800 Message-ID: <20231027093004.681270-1-suruifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.174.149.20] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500015.china.huawei.com (7.185.36.226) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 536B016000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 641zsn39peekemf55o4s6mzgapked188 X-HE-Tag: 1698370494-337594 X-HE-Meta: U2FsdGVkX191Md3UazFtXVtfdZiO+UFnW3NhOo1yAqZ4TwgJDsxEHACtTQ0u+MRhQWdgEUu/8tPWMKMJuB+J+zF3gwFZAA1X7jfvemyrAjIOlXIz2n/dfnBzkQOpTSylEz0G+8uO8AKmWu4n/iW/SlrYghfPJ3bifjOMLXGZxJw5mtAct0PLXzpttyY38g9WTQmpEI3xx87TySzHfIJr5zp9Gbkty1wTqT9miS3ECXul6tAT/lxrs9LAa15A5AZWAxErsRtilSEMB6biJy98uLuxIrNwQ/AaNBmEEB2EqOyHWjdSalnlQwOlHCOQWoYiReFTnP+XvP6UubVzG/+BiqeeJuLA8XH4PiyUCw8o4Q44tQKwTknGsXMcNTt3TyQwQr61b7V5G62G6nKE78ah8SO891K+2UJAlSkSsZrmajY6YTCy+kzZjb4Ex2u/Wdnx/bAXAFLQ7LkFaet8xyFVFLVErjzLYurn6eSRBnAbWb4cOxPAQEwknEHeHXaJu7NrjK8/KcHaNa1qPGX+cpYctjzuLfTgM1j6OBXyV2cl1L+7faLkSTNAAnHPuBVLPu2gfKhPP+XHrMAxAVuN2TLkBRn6496zR1NFEJDk/3dMWzG+rbwgZyMvpLY4/1aOnpE7nr4rddgNci+X24XQa1eQs4wrTtWn+KAHI8Yc6r5oXg+M3yfpXo1Tw+03h3yhNv9W/TKDVm7gTmmL+BXwdLNTlOABpdTLgFtb/jotzd/7UYdZbjozYCuGeXcXd50z7nNqjzIspfOg4zLD2zh0iHMXypxbasYvzYeUn69vqCXDTgDe8BaoVZg9KkI/1JkhInLZY2aFhylRKRlLGcmLLCTFP0PiviX4TQRV1VeEfZtwfvAWSo+4jBxwXfMdagBwIeeijsraT5H7HWuKN3AgGIG4uwMcPifutNaDB04OGW//0xlN9TjgyK49FQh346qdl5cE+PYkcf7HHeX2TM75vK4 d+npD7JY t/ckWFzFTgP5Bmwt4EXlPf+78+RlPJ1NsFNTdFq9QbwI5/FQyPHEFRltqmHl5MMztVr74jlL7H6cQJkmh16OgQ5aAGS64++bqEdirYcinK9OqwE3tRy7e40+ND2r4aWUYWL9Nln2qend95NZbjRgBA5dxcZt/fVkEM67Dqq7IYuX6oeX1YyDbnLFOmQ== 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: When the number of alloc anonymous pages exceeds the memory.high, exc_page_fault successfully alloc code pages, and is released by mem_cgroup_handle_over_high before return to user mode. As a result, the program is trapped in a loop to exc page fault and reclaim pages. Here is an example of test code(do_alloc_memory is static compilation): Execution Procedure: mkdir -p /sys/fs/cgroup/memory/memcg_high_A echo 50M > /sys/fs/cgroup/memory/memcg_high_A/memory.high cgexec -g memory:memcg_high_A ./common/do_alloc_memory anon 100M & Phenomenon: [root@localhost memcg_high_A]# cat memory.usage_in_bytes 53903360 The test result shows that the program frequently sync iCache & dcache. As a result, the number of anon pages requested by the program cannot increase. This patch changes the behavior of retry recycling. As long as the number of successfully reclaimed pages is less than the target number of reclaimed pages, memory reclamation exits, indicating that there is no more memory to reclaim directly. Signed-off-by: Ruifeng Su --- mm/memcontrol.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5b009b233ab8..e6b5d2ddb4d2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2561,7 +2561,6 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) unsigned long pflags; unsigned long nr_reclaimed; unsigned int nr_pages = current->memcg_nr_pages_over_high; - int nr_retries = MAX_RECLAIM_RETRIES; struct mem_cgroup *memcg; bool in_retry = false; @@ -2616,7 +2615,7 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) * memory.high, we want to encourage that rather than doing allocator * throttling. */ - if (nr_reclaimed || nr_retries--) { + if (nr_reclaimed >= (in_retry ? SWAP_CLUSTER_MAX : nr_pages)) { in_retry = true; goto retry_reclaim; }