From patchwork Thu Jul 20 07:27:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Efly Young X-Patchwork-Id: 13319937 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 586B1EB64DA for ; Thu, 20 Jul 2023 07:29:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAC282800C9; Thu, 20 Jul 2023 03:29:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5B2E28004C; Thu, 20 Jul 2023 03:29:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A23922800C9; Thu, 20 Jul 2023 03:29:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8EA0428004C for ; Thu, 20 Jul 2023 03:29:36 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 59118C01A1 for ; Thu, 20 Jul 2023 07:29:36 +0000 (UTC) X-FDA: 81031165152.23.810BF6E Received: from bjm7-spam02.kuaishou.com (smtpcn03.kuaishou.com [103.107.217.217]) by imf11.hostedemail.com (Postfix) with ESMTP id C460540016 for ; Thu, 20 Jul 2023 07:29:32 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kuaishou.com header.s=dkim header.b=Ov9ON0jO; dmarc=pass (policy=none) header.from=kuaishou.com; spf=pass (imf11.hostedemail.com: domain of yangyifei03@kuaishou.com designates 103.107.217.217 as permitted sender) smtp.mailfrom=yangyifei03@kuaishou.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689838173; 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:dkim-signature; bh=2hvt2nAb9FQGc8JWV2zRVOy7HcAR3TW4z5ZsrMla/mw=; b=2PNWUtfvd+Ob0sbx6cQuWmTD0t20+zlQNmDwTfNVyzi7taHM++v8HX5Pn4Cxmgmq+69PZP mVpJbu0yAboqu12UyeT6R9f1WU4EqH2eTdn+xQ8MJbwZYL1oEmwACZO7r2istw4k+7lApy qGwAdEuiAnY8UlYgDoeHaEk28OzVhcA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kuaishou.com header.s=dkim header.b=Ov9ON0jO; dmarc=pass (policy=none) header.from=kuaishou.com; spf=pass (imf11.hostedemail.com: domain of yangyifei03@kuaishou.com designates 103.107.217.217 as permitted sender) smtp.mailfrom=yangyifei03@kuaishou.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689838173; a=rsa-sha256; cv=none; b=qhu+FpIPoXVk8mHNcANwRO7Z+mdXNxpzUQKJzOZY8bW3gmzwAPUJDVOstW1Lj+wJbywv+h GCoFfavfQX2eJ8YPEHUmhWmdtae84QZM/955kpnCUTlwxHg+gf+c0xaSzMZHRSnQ85yoe7 0JlqhJlI02gVTNqyxOojn4HG/f321Tw= Received: from bjm7-pm-mail12.kuaishou.com ([172.28.1.94]) by bjm7-spam02.kuaishou.com with ESMTPS id 36K7RmOj078771 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 20 Jul 2023 15:27:54 +0800 (GMT-8) (envelope-from yangyifei03@kuaishou.com) DKIM-Signature: v=1; a=rsa-sha256; d=kuaishou.com; s=dkim; c=relaxed/relaxed; t=1689838068; h=from:subject:to:date:message-id; bh=2hvt2nAb9FQGc8JWV2zRVOy7HcAR3TW4z5ZsrMla/mw=; b=Ov9ON0jOMvPY7tYxtSF27RXIYX5/ESwleAfyzbMcRkfahhvPD8+vCRgUolm4nuFAX7xrxXLLqLP VC0ugqxGe1jauqIjydi7S9YH2M2vjCjTteErwqG546qEglqgQx2dxnNycFZVOCvZX9fbPRgt69Um7 2ew2dB1E6Kom/DkdCz0= Received: from public-bjmt-d51.idcyz.hb1.kwaidc.com (172.28.1.32) by bjm7-pm-mail12.kuaishou.com (172.28.1.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Thu, 20 Jul 2023 15:27:48 +0800 From: Efly Young To: CC: , , , Subject: [PATCH] mm:vmscan: fix inaccurate reclaim during proactive reclaim Date: Thu, 20 Jul 2023 15:27:08 +0800 Message-ID: <20230720072708.55067-1-yangyifei03@kuaishou.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Originating-IP: [172.28.1.32] X-ClientProxiedBy: bjxm-pm-mail02.kuaishou.com (172.28.128.2) To bjm7-pm-mail12.kuaishou.com (172.28.1.94) X-DNSRBL: X-MAIL: bjm7-spam02.kuaishou.com 36K7RmOj078771 X-Rspamd-Queue-Id: C460540016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: oz4yyqu4zhdtnghxkkg9r6r7c1tpdm4w X-HE-Tag: 1689838172-896262 X-HE-Meta: U2FsdGVkX1/ascJ8MR/lyqVL9JBA31sfZyFtvs186cgV1wxIzc5WGVaruf+yxhgnlDkixLKoeWEyBK26ZMpW/t740ARTDH6M+UHQGtpLK3oRo1978XRdOgw1LXnMvpEagU/fZ+fqUPCmc3ajjzSlaMIRS294p5aqKNV6ogh48R2+OXimQGXAUpb1UdhD73wdId992guIf3Eun5nvnpFkdwnaO4q2JsZJBww9lmLzXHCkieuRtiaKnLlZ6ym7XY/MaBqswyS4IT+1cKdtFu7rfGo0srVZdkyajSCD/T8zxphRnEixKI/+TNw8EQZystzesJJ631msgM4TO94Wijd6zi1vY9XUrJbM9kldrWTJqsQUP7vFFhhEpsQyUMJfK2fE44wMl01QcClXY34/rXm4fhZJTlXwReWDZW28L5QYeGLHDxMjXxCIMkqsUHY0owH6Vgp6a903MQ8h3PJLg8Fv+0SbJ8TUHvZsrF/Syg2vgOXaxYDqMurZ48cxliBxYU5R3ybimk/zSodqT77f36IXC3QsATqMwlcA7puzQOIxK0v0rbnewGs4gz7AQ93SK1AlzgxmlyMi7kjIX55fmyxroGeroKPIs/41b7Qp6ZYyYGj/GlvCmTgaF8dKL7Q71uqbUs5EMHqXUoSFHCqt6SKULKrxXwDk7SkpBMhzvZ5XUGAojkZDnsyxyVP/H9vPEjFT+Q4GFO9vKRWDDdy9HbQiE5ondFBW7ifchK+xZMqHjCTy9j6VFC7ADe+PpH967P/rIjRxNKMUSh5UMCHMDBTr9WAynapckgLxQAZ3TXElWu2MxI8MhqlNqN/Udu+OFCjPgs4MiHne/FP239gNtogjKdgfKVH0CFzv6equ8oa6fbbWnJN9OHS6y1YkQfQDXqs3OeRBm26+7uqi350duZyjMiSay+wzxiIaeLHi5mxPZSTBg9Y6X+fVWxrg5ZwMKnWM6bc9diZaFM5KUOh/kGB FROQlLxj wW1t9oMXt5kRNiP2RKaJ2s43AFx8/JUFeV4TyyIfc9OmLCK/ng8qLGXMSlBlt003GMyArms435Mre/JAbiOunPLKiI/7hG5AuKjEXIaedxprPPQukq5OiUnByg/sUNGDOIjD0feiPnvRJP/TttrzEbk49beAw+pSkvpZVKnEIXDJHogXmPajKn+AL4lJXu0vvDcNYBXRAnIg6J7AehmfMNuhW4JbEXMbMfhm9RTJ4m2BVy1aszZPaySuxqbHFZAEQdOvF32XDkzWPnZ8eRIDCsgEJVOD9qMzewVl863tXtI8SM8lbkR4BTI6wng== 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: Before commit f53af4285d77 ("mm: vmscan: fix extreme overreclaim and swap floods"), proactive reclaim will extreme overreclaim sometimes. But proactive reclaim still inaccurate and some extent overreclaim. Problematic case is easy to construct. Allocate lots of anonymous memory (e.g., 20G) in a memcg, then swapping by writing memory.recalim and there is a certain probability of overreclaim. For example, request 1G by writing memory.reclaim will eventually reclaim 1.7G or other values more than 1G. The reason is that reclaimer may have already reclaimed part of requested memory in one loop, but before adjust sc->nr_to_reclaim in outer loop, call shrink_lruvec() again will still follow the current sc->nr_to_reclaim to work. It will eventually lead to overreclaim. In theory, the amount of reclaimed would be in [request, 2 * request). Reclaimer usually tends to reclaim more than request. But either direct or kswapd reclaim have much smaller nr_to_reclaim targets, so it is less noticeable and not have much impact. Proactive reclaim can usually come in with a larger value, so the error is difficult to ignore. Considering proactive reclaim is usually low frequency, handle the batching into smaller chunks is a better approach. Signed-off-by: Efly Young Signed-off-by: Johannes Weiner Acked-by: Johannes Weiner --- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4b27e24..d36cf88 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6741,8 +6741,8 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, lru_add_drain_all(); reclaimed = try_to_free_mem_cgroup_pages(memcg, - nr_to_reclaim - nr_reclaimed, - GFP_KERNEL, reclaim_options); + min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), + GFP_KERNEL, reclaim_options); if (!reclaimed && !nr_retries--) return -EAGAIN;