From patchwork Tue Apr 2 07:32:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13613507 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 234BFCD1284 for ; Tue, 2 Apr 2024 07:33:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D89F6B0092; Tue, 2 Apr 2024 03:33:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AF8C6B0095; Tue, 2 Apr 2024 03:33:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74FF96B0098; Tue, 2 Apr 2024 03:33:13 -0400 (EDT) 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 56C4B6B0092 for ; Tue, 2 Apr 2024 03:33:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E8EB140A19 for ; Tue, 2 Apr 2024 07:33:12 +0000 (UTC) X-FDA: 81963775824.17.7E50CC9 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf11.hostedemail.com (Postfix) with ESMTP id 1333E40004 for ; Tue, 2 Apr 2024 07:33:10 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SE+1BhVI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712043191; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O6zOKBip9tcW2yKqv67ogMIPuHDVX+LrEKHPk0SxbO0=; b=xFfyQPC5y7L9rA1zDWy8BzAP0iTESOszAEOOmZMYgdfDtI+u/EFsfmB3I9P7lLm+OOkFgx EEniC8IiFHv4WA0AlLBe+/fMmEPa3YXwzDhkABK6Xce/LAkZVLp6LbIZ4I24atX1ElgJMD FTKG8WtoHqZEgrsma0ElN3RLshjUpjI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SE+1BhVI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712043191; a=rsa-sha256; cv=none; b=rtRWSBW4GfR0IwnLEYyyBSRDjFv6RGzKBmA5TJPu11DQMHVBwCv6qKcLuyJoZTcinsI5hO boKnvDkaFoUpOmCFyyk32/qs6m2glrGdKa4dWrTXNCK1U07q/n3VMiGp2VXNaox//L2CXx IaSZQAYyQgiDYFNhuzAEaLEV1+EPcDw= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6eae2b57ff2so3689624b3a.2 for ; Tue, 02 Apr 2024 00:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712043190; x=1712647990; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O6zOKBip9tcW2yKqv67ogMIPuHDVX+LrEKHPk0SxbO0=; b=SE+1BhVIZGHHKynFwfBGuoumFxDk7BU2qWnVPVuBMdJtKxj1rc4NZnAoyMpnwQg4LM sfUSc9LFVY91h0FgrNV7OZRarf+u4ethw6NYF3BPeak8JDv6CjCVVSE9lzMYsvGkGKlB 2d46cEule/jwKRFWiAzQyhd656pga96fkFDf8ubUWuvt8ndgX3PZA9SuXvzKfrwOq9dT TAgsIJIe3PPVQWBMdVSJF6q2vCWO9r+QAkW91TBWt2iJPVa9x6BgX215p5cejcIJDNkU leEFbwHEqY8zDaIeKb73tWWfJIoU1xvMo0c8BKlZ5bGaJb2gNw329s1WG6waG3wCC2Y/ 7+/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712043190; x=1712647990; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O6zOKBip9tcW2yKqv67ogMIPuHDVX+LrEKHPk0SxbO0=; b=Coijp1WKbalI8oBIOENyyluSdANnnyS7eqIZM+xcmpa6RcK7pHJn3boGoeemVNCgCl K5dwhV95hR3aup2dCLyPpyHIFPqY7EZ+mb+6GM9egsmF79C9+uMK7xZXRWO3F9WT/n2q rEsFpWP+5Gyei7AQhTzWSzp+rUpjddVulrXH8J6vsTdrc2KO6Pdi/RaWDrZfNpWkw8eD bRxeF+6IAC528GpF1iWxhuHRNx3i7CUnEump9DZc759EQWQxv/ESj6GIbSIY6XvPWFJy EHo44ct9zryW/9lYLdFu/bq9bL3XAAzpyBKgpfogPBhOrhdGrjaVssFx9FmB1+PGEfbV D7JQ== X-Forwarded-Encrypted: i=1; AJvYcCUbw6XlYi6PfKA3rE9AtlqXA/H2TCEUHYqr07+0KD9XnI0z/EH1gonLzkrnX2UcLqV9rbwfjHlPfR94WggJfOguSyM= X-Gm-Message-State: AOJu0YxBpwgLvlC1fn+Q8A4mvCCakyruZ325O42oGaponLIH9zCS+vhS yDGA33zMSDP6U7eEyrg1yKiLd+QTrarCpku7MIyxx9ORAMXK3fZy X-Google-Smtp-Source: AGHT+IFu8667qqHLR0wMKmYAhROFagzkwq+9TEq9aLVUMSzEu/u8+FjteDvnnmd7ONKMBz9GkxxvAA== X-Received: by 2002:a05:6a20:bf28:b0:1a3:e0b5:418 with SMTP id gc40-20020a056a20bf2800b001a3e0b50418mr9500313pzb.36.1712043189947; Tue, 02 Apr 2024 00:33:09 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id x15-20020a170902ec8f00b001dc9422891esm10187588plg.30.2024.04.02.00.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 00:33:09 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: david@redhat.com, willy@infradead.org, ryan.roberts@arm.com, yosryahmed@google.com, hughd@google.com, hannes@cmpxchg.org, surenb@google.com, xiang@kernel.org, yuzhao@google.com, ying.huang@intel.com, chrisl@kernel.org, kasong@tencent.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, hanchuanhua@oppo.com, Barry Song Subject: [PATCH 2/4] mm: swap: make should_try_to_free_swap() support large-folio Date: Tue, 2 Apr 2024 20:32:35 +1300 Message-Id: <20240402073237.240995-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240402073237.240995-1-21cnbao@gmail.com> References: <20240402073237.240995-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1333E40004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: prjjs7ot6qpwejbueu1ch6hkfkdf9zdk X-HE-Tag: 1712043190-243257 X-HE-Meta: U2FsdGVkX18yN7kSi7cCPMpbeq3MPPq7yAheSGNxUTmToLnzgl74t8g3REdeoi6HD9iZqgb2pAxFVwbSJ9SQ2TWBbG8uXW7yLroSM5uWOvXocYU5e22qswZu66t4FnGmzTW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LLszfOxN6Lgi7SH/i40sew7sJsE5SwMfPICLKSAvx0Rrd2NWiFbkCZFh78xKn6Len3gYrY1we2SoJjS7N/qOw62+yHqE7WIARIZqZWuyh6pY8aA06oumAiHS6rqzV6X4afYutBTGvhHxq2+sWLJawz80nWAasr7EQki2rh2+GqohAjg0ipBEKUgJvwKfK7OCJypybilJPp2ur6HCY8dgmC/DVjxh911mrRwXMmlJPjgc6OuMsYs1JzTYOGEzN1vbukYS6t58lIrZM+PPsbJ9GuzW/lv9vouyFauIye0BSHBxafXmEHi7SQbhIc+oAC6k8o3LsIqdKMyyMIlwMo5tFwGeim6fLmUeC//jtIKf3doZ/9o6dQfL24yGjqKPKCbhPe54b/bC399cDCXNMm4/JjJK5R1g0X9Dss11ahWpiYCdsyxedtCIFk92uHhaERQ/XrKimDBjVRcI5AL9ikyMRzfvttEYhaygA+MbD5HaC4ht+ 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: From: Chuanhua Han The function should_try_to_free_swap() operates under the assumption that swap-in always occurs at the normal page granularity, i.e., folio_nr_pages = 1. However, in reality, for large folios, add_to_swap_cache() will invoke folio_ref_add(folio, nr). To accommodate large folio swap-in, this patch eliminates this assumption. Signed-off-by: Chuanhua Han Co-developed-by: Barry Song Signed-off-by: Barry Song Acked-by: Chris Li Reviewed-by: Ryan Roberts --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 010e7bb20d2b..f6377cc4c1ca 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3850,7 +3850,7 @@ static inline bool should_try_to_free_swap(struct folio *folio, * reference only in case it's likely that we'll be the exlusive user. */ return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) && - folio_ref_count(folio) == 2; + folio_ref_count(folio) == (1 + folio_nr_pages(folio)); } static vm_fault_t pte_marker_clear(struct vm_fault *vmf)