From patchwork Tue Jan 30 09:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 193911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1096268dyb; Tue, 30 Jan 2024 01:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVQeIATJXsebzziU42jFylR/3dF3oQ1/2dqC/Ln55P3znL2R7YfW6xNjlrMI4qgB+d8o0T X-Received: by 2002:a17:906:1c55:b0:a30:be5e:c8e7 with SMTP id l21-20020a1709061c5500b00a30be5ec8e7mr6041979ejg.44.1706606666427; Tue, 30 Jan 2024 01:24:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706606666; cv=pass; d=google.com; s=arc-20160816; b=JXFwfSIt2zkOqF8Jq7BIW94iC1ENvKVe7ko8n9W1u2PaFrXyXubKGKYJPMjIZxoZ3/ HxEEV+UBOYbWixOuoG5kbJ3rvAiLy6cLjJDVZZCsdBdBh4nhBMqMNn/TgZsQMM9ZA8Q8 66pnbAk047EHRrERQD3X1UqEGwnb4EeWrx/dfshL9W3xYtFF3m9li1lerBS8PpYKYRsW kDJzKPmNfHvhKGJ5R8E+QHFaNIz5Trdn/SMGS0SbAz3hfTbNSasyPPteGwW3RIl778Gz O3M6FCC8sqFeKB36/sKNqsegeiSYpBVTp8SlPI0+0y6tKJsxOFQQEAS70abzG73ZUkOU gnuA== 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=GtyQYlGUR90QCV/t91YzKUxn98KdRgsFcRB48NR60oQ=; fh=Pzzgl0Zq3VZxy+cvz4dvysXq3CtsEAMVli1/OY7USBY=; b=grLUELj+myvxwpMq1otICnQRP0/k/xthOy3OMoEdBNmtaq8X4TrrzXlASHigr0BRYf bk5P+JMDElvdv2GxZ3QWF3N97ewVZgQpUsJW2SRM4fV97JtMR4DjlFzvedVI4YR21fpd 3nEgUTI7Io2ko823PTvvbppiVxctHJHjhCl0j1ECRN1oVuRtnW2+PV48K6vFYL00N6ex 5+T506vKS14te6m+hUL8LF7SyX+JtRdE1VSUfmXWZ1px6DP0fMfXorb3LXOOBuhiv3Ic +6Nek+Bj7SpoJUpz22o9AuaMg9PoajMBEtJCzKQFBKJafVfSkSf4ooZUlNnurdjC24hC i7iw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-44249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44249-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dx11-20020a170906a84b00b00a35ef7f6a72si1134400ejb.88.2024.01.30.01.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 01:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-44249-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44249-ouuuleilei=gmail.com@vger.kernel.org" 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 0F1FB1F21E16 for ; Tue, 30 Jan 2024 09:24:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FD6560ECB; Tue, 30 Jan 2024 09:23:30 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 7060A60DC7 for ; Tue, 30 Jan 2024 09:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706606608; cv=none; b=uqHGLcBZpzzBgCylEoZ8CA9b4dHuZ7PG68r1DbSTDcGigSTuIciBSwqn3OKOPprZqrKC9VqJl5oEZq+QEn7JwQZA6GIOinvqaAEs5ITVD9rs2K2DRn0Ixg1YcweyZ584Ym19pd5gkXE8RK9C4DQ8ce7XEpD5Qc31yIus3JHc2Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706606608; c=relaxed/simple; bh=TjCsIPX1bEde3FLQslGPgZXu5fL0mcVt0GKZSwJSPBA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MUHyPFRHSUHTK9Cje9O7fBzCQtcLROhS4316DAhL6FOQln768SPhi7AFWO8geD+PxSSVapQ5RnBN0NjXKiK2urrvKBL9jEAg22qVk71gNJ2GkIbwoeQwlxMgGE9jbXi0ys4bwkgcxZtFBOxiIjEAwajilvyPlzEFjKwQJ/iaW7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 1c5e949a4d1043aaa5c407e53585448b-20240130 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:28105e74-5369-4c3c-a842-f5d8ec487464,IP:15, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-INFO: VERSION:1.1.35,REQID:28105e74-5369-4c3c-a842-f5d8ec487464,IP:15,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:0 X-CID-META: VersionHash:5d391d7,CLOUDID:a4e06983-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:240130171800U5BLH98G,BulkQuantity:0,Recheck:0,SF:66|24|17|19|44|102, TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR X-UUID: 1c5e949a4d1043aaa5c407e53585448b-20240130 X-User: gehao@kylinos.cn Received: from localhost.localdomain [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1414335610; Tue, 30 Jan 2024 17:17:57 +0800 From: Hao Ge To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hao Ge Subject: [PATCH] mm/vmscan: Change the calculation of the number of can reclaim anon pages in zone_reclaimable_pages Date: Tue, 30 Jan 2024 17:17:55 +0800 Message-Id: <20240130091755.21363-1-gehao@kylinos.cn> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789506791683554171 X-GMAIL-MSGID: 1789506791683554171 The spaces of swap devices that can be set by the user are unpredictable values, so we take the minimum value between the anonymous page in the specified zone and the spaces of swap devices. Signed-off-by: Hao Ge --- mm/vmscan.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 4f9c854ce6cc..2deae4232b83 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -341,14 +341,21 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, unsigned long zone_reclaimable_pages(struct zone *zone) { unsigned long nr; - + unsigned long can_reclaim_anon = 0; nr = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_FILE) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_FILE); - if (can_reclaim_anon_pages(NULL, zone_to_nid(zone), NULL)) - nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + + if (can_reclaim_anon_pages(NULL, zone_to_nid(zone), NULL)) { + can_reclaim_anon = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON); - - return nr; + /* + * The spaces of swap devices that can be set by the user are unpredictable values, + * so we take the minimum value between the anonymous page in the specified zone and + * the spaces of swap devices + */ + if (!can_demote(zone_to_nid(zone), NULL)) + can_reclaim_anon = min_t(unsigned long, can_reclaim_anon, get_nr_swap_pages()); + } + return nr + can_reclaim_anon; } /**