Message ID | 20230721014116.3388-1-yangyifei03@kuaishou.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3505762vqt; Thu, 20 Jul 2023 19:21:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFRl1OaLh1soQZ80qs6HCo/I3IS9qZDMt6K9/4APCarWtFznyAqoy23BMsCptshuS0P6wDz X-Received: by 2002:a17:906:73c7:b0:994:356a:2034 with SMTP id n7-20020a17090673c700b00994356a2034mr489040ejl.43.1689906060441; Thu, 20 Jul 2023 19:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689906060; cv=none; d=google.com; s=arc-20160816; b=b/HMVDopcMRr1EjxAzUGrDPtSyakLZgl9gN0C6OyF4iqLXallHU6AmH8rn58dRnWkV IecF/V/Td2t6BSN3kw7u4u9sHWslhhZWYRmw/DIjZsPYZxOo7pVBnFSVbVj8BUzLY4ib ysTAefZNhz/KjgHtj6uX8+XXUOjAbIdD2WNsWFVcaCh9LeMlxNGlHGMfJCEqa2EI7TQn Es6DrDkHI0yehMBd/+NVaoKZXno8UUvI+93V3KbiPrhHcuy4EnCVDPPsu7fAu7kefxqN bzRN3xrFrwXz15DplRybruoHOrLQtF8I+SRn0sqLylUVzbIlG65pd7tPcETvcN8lnUVu MfWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=WfBeYmQN+HAjcDnQhJBJiepaQUpxGJpfp8LGbLzGAuw=; fh=HI7o3/5We/f9kB/V8Qj2n/r8iiWvPBEjT2tSeDYIT0Q=; b=rTeyFch6bR1O+g+7937hWzxoHpALSoD6xovKj3wKbsMKBCZDPfIWCGbhSInDQwGeTY hTaxqUgn7YHpSnFZrdEl0wO6BdImvxtAvP0rW/+3QxtlWpIPhoqDZF6+XW+RXf7G0TkF B0BQIiiYKm9aXZetbAn5m/TXqa8D7IaS/DedvSmttwjKdaBT7tCADbEn2PLjhjszNz6b kHXJBUMcFu7I0bnjH+UIj8nOC1ZGuL8lTt/4YrjRTO1wg6oT2uG0Mj8ovcNfeUkCG1t4 5e8tBBEdkTzjJRwuj522N/xmTDOrmkjliRbHqYKotwdzDItRyxntXAz/e2CLWA7oCJGy vpbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kuaishou.com header.s=dkim header.b=Uaujp7Jr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kuaishou.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020a1709060ad900b009930740da67si1459929ejf.380.2023.07.20.19.20.36; Thu, 20 Jul 2023 19:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kuaishou.com header.s=dkim header.b=Uaujp7Jr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kuaishou.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbjGUBoI (ORCPT <rfc822;chrisben.tianve@gmail.com> + 99 others); Thu, 20 Jul 2023 21:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjGUBoH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Jul 2023 21:44:07 -0400 Received: from bjm7-spam01.kuaishou.com (smtpcn03.kuaishou.com [103.107.217.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A45B8186; Thu, 20 Jul 2023 18:44:05 -0700 (PDT) Received: from bjm7-pm-mail12.kuaishou.com ([172.28.1.94]) by bjm7-spam01.kuaishou.com with ESMTPS id 36L1hd8D011485 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Jul 2023 09:43:39 +0800 (GMT-8) (envelope-from yangyifei03@kuaishou.com) DKIM-Signature: v=1; a=rsa-sha256; d=kuaishou.com; s=dkim; c=relaxed/relaxed; t=1689903819; h=from:subject:to:date:message-id; bh=WfBeYmQN+HAjcDnQhJBJiepaQUpxGJpfp8LGbLzGAuw=; b=Uaujp7JrVr1HhJ67/IKB8PC6lCzPwguABUa/mYbRzCJlEzSqAEHPT0u5lEaBUcmfYhVglsuMskD zNAu9f2cVSHPRTkK2DKpir1lJq754dPe/xWT7D0VITqwOEDznIdlwlwb4C36JHtvxa6y3QNe7yz8J QjoFX/q8VCAyp35S4jU= 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; Fri, 21 Jul 2023 09:43:38 +0800 From: Efly Young <yangyifei03@kuaishou.com> To: <hannes@cmpxchg.org> CC: <bpf@vger.kernel.org>, <cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>, <mhocko@suse.com>, <shakeelb@google.com>, <yosryahmed@google.com>, <yangyifei03@kuaishou.com> Subject: [PATCH] mm:vmscan: fix inaccurate reclaim during proactive reclaim Date: Fri, 21 Jul 2023 09:41:16 +0800 Message-ID: <20230721014116.3388-1-yangyifei03@kuaishou.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.28.1.32] X-ClientProxiedBy: bjxm-pm-mail01.kuaishou.com (172.28.128.1) To bjm7-pm-mail12.kuaishou.com (172.28.1.94) X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: bjm7-spam01.kuaishou.com 36L1hd8D011485 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771994937451859107 X-GMAIL-MSGID: 1771994937451859107 |
Series |
mm:vmscan: fix inaccurate reclaim during proactive reclaim
|
|
Commit Message
Efly Young
July 21, 2023, 1:41 a.m. UTC
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 <yangyifei03@kuaishou.com> Suggested-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> --- 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;