From patchwork Mon Jun 17 23:11:37 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: 13701544 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 75FECC27C79 for ; Mon, 17 Jun 2024 23:12:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502026B00B8; Mon, 17 Jun 2024 19:12:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C7306B00B2; Mon, 17 Jun 2024 19:12:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E0CC6B0136; Mon, 17 Jun 2024 19:12:17 -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 C14536B00A2 for ; Mon, 17 Jun 2024 19:12:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 41724A1941 for ; Mon, 17 Jun 2024 23:12:16 +0000 (UTC) X-FDA: 82241931072.23.EBE4D6A Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf20.hostedemail.com (Postfix) with ESMTP id 5D6151C000B for ; Mon, 17 Jun 2024 23:12:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K5c/tBJK"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718665931; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=a/6IvNPq7zBKKnaxHPBCi1/tR/zzV0S3hLEc92Majycbtn02uHhCp+mz7jeBDvqiwoD9wq BSZBEdGJoj/kBIS0ohrDyxj/XNPicvdzZo9RtNrdwfbMR/l/RrGODo9i2nwkNvyaPk8Ahf lxy3qxpn3L5tghpcWssSDNFI3Rz27wA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K5c/tBJK"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718665931; a=rsa-sha256; cv=none; b=cPqHie3V3qO4SAJPTp6oteYjpB9hGZSMd4ibQu1S1j/oczVI3MzoHV0TcztUQ2ia2B91/I KeRlDWniWEr1tS+C0uISmL/oig6Fv9lRUtG/fFwh4DZMn6wLkBfRokft69MFEk3QQ56MtQ uV0dCboK0HjemweGcLcYRvIJCG1NYNA= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f7028196f2so39745685ad.2 for ; Mon, 17 Jun 2024 16:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718665933; x=1719270733; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=K5c/tBJKDcUi9UdkqM3dhUgdNQ0cEEx+4khRzsP34FiEtzGew+o4ki7gxCoqvZ421C Os7O5snXqHKZbQXr0/vpSenP7gi6PwnETqmmnJT5LxsAvGJ9SV+NbHx0pEWQZ51Qz5Yo clwuvcut1mUo+zGLsag7+FFp8rliCsedTXMJBvStwEs9XlWsJ/PnM/IcWbDXDnjPXc7R xF+mV/y9TJTxuQ+H0pjA2oDej82vAI6MbvGq34iaPki11E2GwI5F9949MYZdaUIqb5Q6 zjjhRSAm+RDsx/1XKeNl4esKa7+/cIvxVJEz4RaZTrR4lCudPaCv5mjglJ+HqSH0Mg9D 12Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718665933; x=1719270733; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=d7NUYb24ZR3FLa4o1iFzLwJkcM8b2vZvTiqELo7oo4IpncxqZTDz8wrjOe8p551kZF wCYGFv0AjHtD1nMhhKdBAoz51vOYTxs2sLxnM3twYpb8rp3sI+WHlRz/yXikbob1Nw1T LvZ/GS5UjAPi9jN31qzN3HpGALgfkQv6Y+NI2GKFA1wPiMDEwLNcRhjFHqCqMji8QsVY r0BVSFnZI4/KL/PSDeSwraEn6a4zzclt8DkNBREtPHK+L76cRLCFIUDf/g+7XuMjr8kF Xzb83uOCpBGy/L6Iopoe9Ps0Yf59uKgbpFVKiAGNuN8prt9iu8/J18YsbTYLcIOa7/7a D8gg== X-Forwarded-Encrypted: i=1; AJvYcCVkfz900GPvtWfHMjBJ1XrUKMg5Hreroqgk3c5laZ5Aetizea+UVLYd/qPu1+Zd/NRP2Sb5QfYntzaiP+nrDoc/cYc= X-Gm-Message-State: AOJu0YwP9oTzWVeNOYSHZijzCFGGIwIU3aWrP5BfL2ERqsgg4BIWxnaJ qvkvOlN9mlMCNmJXEdfar7IFrXIpUeSxb6Qfts/zO9uX8SrQ7W1BH8k/oa9I X-Google-Smtp-Source: AGHT+IGdavghqDun57MXIuOzQguy6J6tZOKWjsQvvQ/r2qtBVtLUA3Gz519TstrQYTx82XqkXwmIAw== X-Received: by 2002:a17:903:2305:b0:1f7:eb9:945a with SMTP id d9443c01a7336-1f862806364mr90512405ad.44.1718665933275; Mon, 17 Jun 2024 16:12:13 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5a0d5sm84658605ad.43.2024.06.17.16.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 16:12:12 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, Shuai Yuan Subject: [PATCH v2 3/3] mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap() Date: Tue, 18 Jun 2024 11:11:37 +1200 Message-Id: <20240617231137.80726-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617231137.80726-1-21cnbao@gmail.com> References: <20240617231137.80726-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5D6151C000B X-Stat-Signature: gahqyi9k4ug1qaaabiu8wdy1gsyd9arq X-HE-Tag: 1718665934-617875 X-HE-Meta: U2FsdGVkX1++jvbiIGSRrfI3T8HUbxD8r5KAvJBCBsZOfnK41YtFwYG0AOrd37NP7VtXVeddXqOXAeSm3wPlfgVgkFqvPdiouxvS6Bex05nwXlN42mE5tSny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UUnIAKcpf2S/tQejYGWJbx7aUHCkehWw9eFE+EtloNshXfY9j69F1xesnt0Z84WUMet3c/lFFs/EwedF9aSyL48jZnVPBmXDFDVYb4k65S7lOWjBwusBVt7Y1eipiT9Ag3pR8J/F/qRc97c+T7PK7AArqvyvDDmfLTUZ4TbcmgSq7UW1C08zDOvEvZmHtKNXMODFYwsGCS+TBYMu6SmUGS2bNzslQNgUdxlAc/46LQO2hJuHGGtVylgFdcwW5g3QJqO37Zd2LHFj/s76Dn/tQ== 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: Barry Song The folio_test_anon(folio)==false cases has been relocated to folio_add_new_anon_rmap(). Additionally, four other callers consistently pass anonymous folios. stack 1: remove_migration_pmd -> folio_add_anon_rmap_pmd -> __folio_add_anon_rmap stack 2: __split_huge_pmd_locked -> folio_add_anon_rmap_ptes -> __folio_add_anon_rmap stack 3: remove_migration_pmd -> folio_add_anon_rmap_pmd -> __folio_add_anon_rmap (RMAP_LEVEL_PMD) stack 4: try_to_merge_one_page -> replace_page -> folio_add_anon_rmap_pte -> __folio_add_anon_rmap __folio_add_anon_rmap() only needs to handle the cases folio_test_anon(folio)==true now. We can remove the !folio_test_anon(folio)) path within __folio_add_anon_rmap() now. Suggested-by: David Hildenbrand Signed-off-by: Barry Song Tested-by: Shuai Yuan Acked-by: David Hildenbrand --- mm/rmap.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 2b19bb92eda5..ddcdda752982 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1297,23 +1297,12 @@ static __always_inline void __folio_add_anon_rmap(struct folio *folio, { int i, nr, nr_pmdmapped = 0; + VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); + nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped); - if (unlikely(!folio_test_anon(folio))) { - VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); - /* - * For a PTE-mapped large folio, we only know that the single - * PTE is exclusive. Further, __folio_set_anon() might not get - * folio->index right when not given the address of the head - * page. - */ - VM_WARN_ON_FOLIO(folio_test_large(folio) && - level != RMAP_LEVEL_PMD, folio); - __folio_set_anon(folio, vma, address, - !!(flags & RMAP_EXCLUSIVE)); - } else if (likely(!folio_test_ksm(folio))) { + if (likely(!folio_test_ksm(folio))) __page_check_anon_rmap(folio, page, vma, address); - } __folio_mod_stat(folio, nr, nr_pmdmapped);