Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1350762lqt; Wed, 20 Mar 2024 00:37:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZUVSIMUAir9gFIvNAVLaYCmr0XP8IxCvBJFzOJ67AZRQo+pjPX2D/Svz6nl7pEfOACH8vPNDrAGaKGILy7ESnw3DTyT/gD7HuxTSFmA== X-Google-Smtp-Source: AGHT+IHt6qirTyjNvoKGkrBVY1W8Elkr7HFjXANc/o7Bjn7dLXVV1Lkbn/D8feF6jrq1IE3NPHmx X-Received: by 2002:a17:906:6d98:b0:a46:a81a:330f with SMTP id h24-20020a1709066d9800b00a46a81a330fmr7733077ejt.5.1710920276506; Wed, 20 Mar 2024 00:37:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710920276; cv=pass; d=google.com; s=arc-20160816; b=Oj4TDfJmdrZro17PFmZaFmsI3Tpey89OvEz/oKNmltyInNvKx9PLYhlEBxKEVjIX7i GQWXqSFYuXEGCQSKHg9sR7lbGYkhPOD+C4WkaXlqyFB6TfE6iDCpsJCUZJemvfn7WqY2 mfrpcOtwNTwzYdudbDASPSDPSWmbBsoocUUu6TMKC/P9NJGO7OFRH0XYC9IgMtHFMo2V r7q5NZhMSIQaBwIKgR/3X7QDu10W6KRhwqYlGeLrHftjXMOydxl8jJRgcxC08kFuB01R HSx0I9Fq9S2EoRMQ5/l5fC+im6KBA75EbVZ00oJukAPBgw3kclppU0j4rKpB8sClru6g F39A== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PEpOEeNnd7l1doLqgw8v+weOW16uqOzVr8P7QMSTpZE=; fh=HTsbfkBy5TsRnyWiG7NOinEtk+/LWD8E51EQEMbLwTM=; b=jOBKxAEynOfgpWnUlL0iSCQZpLV60Pr2x/sz33v/JLDcCSCsuKxZM1aaGtcyCB3LL5 LV8dG6eowGKZNf1bP8AzLL0v9zvshKS+xh+iwDQZcjF+lnOwYSwDIYHUDGXKBNW/hOHu knaA3xn/HXm+AAwTIftv7NfjETp8GPkzPmKQg77YN/JuS5NdT1ytx6oxDfSKoDRDi2R2 D1YQw6/53wm6xb27xJYfM908IGl7vLal4x1Kng+Zdz0McxWyUN3pdg/aNBaXNwfFZb8n ZsrrRN31/gfMA4gLrHDau69GZo0B5lQC9U8/Cx2eLAUOK27O4QeV0dtEY2v+f3jFfUPP o+xA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lrtdz9EN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108550-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n27-20020a170906089b00b00a46ce4be6cdsi2084826eje.664.2024.03.20.00.37.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 00:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lrtdz9EN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108550-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 1777B1F232C5 for ; Wed, 20 Mar 2024 07:37:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E999D3612D; Wed, 20 Mar 2024 07:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lrtdz9EN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 206672208B for ; Wed, 20 Mar 2024 07:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710920261; cv=none; b=NDfuqzf1NeUNzYAgM9wE2E5oEUgcbkbTx4WQ6J3YRRcPV34/8Ursv267vaRdM3GoG82+7FzOlc7HdSYwJ1p4l58u0IsQKFygLhYOmW4Rw9+r7C81vuiFFoXQGc4fYCbc/rRb3oOpSaK3s/jkBS/FJvFJXi3eEn25RooGqT/Ub7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710920261; c=relaxed/simple; bh=hzC9nwLvXTVgwQOMkdq44QZXi1tFep4qsRHVCT+3k4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vw3iRTdZ5dasSspZPjkz5q+f8zvIzWgKaogyVB+kYeX++pAIMhFs3q2SDH3jJ0yymKSR+NGJ+5kl5pdqTQ1kNaKbLgujL6oSUyqtZc6pD3slZ02po54F+MZFYLmrWnuCddCDDy1vwReVpjXBcBiMqmllyAyAZ8LvW7F4CoSDUG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lrtdz9EN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3238BC43399; Wed, 20 Mar 2024 07:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710920260; bh=hzC9nwLvXTVgwQOMkdq44QZXi1tFep4qsRHVCT+3k4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lrtdz9ENRa11JSKhFuvNFzK8VDpY0QZ3x4rb6MBEa4oyMr2NJgCWpbHV2jZYw40bR o+z3HRQmduCdwuPMRFCiwdzy6MGkVlEhjTWCTGNYqu7oxcFus/w9HLX0YwV8uDh04h LqiI/CIgTKp/fa+5dnIicIq1hBK7r/Bdj41woNUyiRQVRrHmwoMRNKzSXt64RKgzyn p/CBIhtJBRbJtxgEIVB1GFVMzThQDWNeS2DCDX1aXc6SdcK1MXKOFDNN+2z8JuEzkQ NWaikWuHwAh6prjmxQyspSNviArYSxO43vZLCD5/cZuz28n+XaeKJc9r+l7JG9GlYp ttRhrdmd7DzPQ== From: alexs@kernel.org To: Izik Eidus , Matthew Wilcox , Andrea Arcangeli , Hugh Dickins , Chris Wright , kasong@tencent.com, Andrew Morton , linux-mm@kvack.org (open list:MEMORY MANAGEMENT), linux-kernel@vger.kernel.org (open list) Cc: linux-kernel@vger.kernel.org, "Alex Shi (tencent)" Subject: [PATCH 01/11] mm/ksm: Convert get_ksm_page to return a folio Date: Wed, 20 Mar 2024 15:40:37 +0800 Message-ID: <20240320074049.4130552-2-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240320074049.4130552-1-alexs@kernel.org> References: <20240320074049.4130552-1-alexs@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Alex Shi (tencent)" The ksm only contains single pages, so use folio instead of pages to save a couple of compound_head calls. Signed-off-by: Alex Shi (tencent) Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright --- mm/ksm.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 8c001819cf10..fda291b054c2 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -915,10 +915,10 @@ enum get_ksm_page_flags { * a page to put something that might look like our key in page->mapping. * is on its way to being freed; but it is an anomaly to bear in mind. */ -static struct page *get_ksm_page(struct ksm_stable_node *stable_node, +static void *get_ksm_page(struct ksm_stable_node *stable_node, enum get_ksm_page_flags flags) { - struct page *page; + struct folio *folio; void *expected_mapping; unsigned long kpfn; @@ -926,8 +926,8 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, PAGE_MAPPING_KSM); again: kpfn = READ_ONCE(stable_node->kpfn); /* Address dependency. */ - page = pfn_to_page(kpfn); - if (READ_ONCE(page->mapping) != expected_mapping) + folio = pfn_folio(kpfn); + if (READ_ONCE(folio->mapping) != expected_mapping) goto stale; /* @@ -940,7 +940,7 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, * in folio_migrate_mapping(), it might still be our page, * in which case it's essential to keep the node. */ - while (!get_page_unless_zero(page)) { + while (!folio_try_get(folio)) { /* * Another check for page->mapping != expected_mapping would * work here too. We have chosen the !PageSwapCache test to @@ -949,32 +949,32 @@ static struct page *get_ksm_page(struct ksm_stable_node *stable_node, * in the ref_freeze section of __remove_mapping(); but Anon * page->mapping reset to NULL later, in free_pages_prepare(). */ - if (!PageSwapCache(page)) + if (!folio_test_swapcache(folio)) goto stale; cpu_relax(); } - if (READ_ONCE(page->mapping) != expected_mapping) { - put_page(page); + if (READ_ONCE(folio->mapping) != expected_mapping) { + folio_put(folio); goto stale; } if (flags == GET_KSM_PAGE_TRYLOCK) { - if (!trylock_page(page)) { - put_page(page); + if (!folio_trylock(folio)) { + folio_put(folio); return ERR_PTR(-EBUSY); } } else if (flags == GET_KSM_PAGE_LOCK) - lock_page(page); + folio_lock(folio); if (flags != GET_KSM_PAGE_NOLOCK) { - if (READ_ONCE(page->mapping) != expected_mapping) { - unlock_page(page); - put_page(page); + if (READ_ONCE(folio->mapping) != expected_mapping) { + folio_unlock(folio); + folio_put(folio); goto stale; } } - return page; + return folio; stale: /* -- 2.43.0