From patchwork Thu Apr 11 06:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13625443 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 619DDCD128A for ; Thu, 11 Apr 2024 06:14:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5D2A6B0098; Thu, 11 Apr 2024 02:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0DCE6B0096; Thu, 11 Apr 2024 02:14:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0016B009A; Thu, 11 Apr 2024 02:14:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9EA246B0096 for ; Thu, 11 Apr 2024 02:14:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2E172140A8C for ; Thu, 11 Apr 2024 06:14:34 +0000 (UTC) X-FDA: 81996236868.19.1141723 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf13.hostedemail.com (Postfix) with ESMTP id D81C92000D for ; Thu, 11 Apr 2024 06:14:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ohkAORx1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712816072; a=rsa-sha256; cv=none; b=e5pV6yxBtJUyWjh5oVuAis9u5vknqpu82NTcM8YFdg+ddupEHyfFD4w9QMIHHHThkl2sN/ RSLIgxHjzlCHSgHW8XTccWy4g3KZuW/dIofXAPJBB1wsm+D1tMAVX1tgjwJep6Gy7LuMFN AZy2WOseSe7+5nlap/9gV3d8IDFZJ24= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ohkAORx1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712816072; 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=e96MJPMoqURApb6QyU8wh3HhTh59e9/jJOv1trFgZ/c=; b=AcZAJorjZ1lOtOI01Y1jlVnyM93YhbPT9sHIQJfOsGCLTbxBbeB6bHhoCpAD8wtXe+k9Kl ZxnsUPIv5kimFDVw1wTdDQRmeiLtDZrYgeZ+u7t4mAzNNjku1qP8DkwATTCDKrk4FyoHvM MKoACsEZZoNb8YNpBWXRLtGeYAIVMek= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BBA84CE2F16; Thu, 11 Apr 2024 06:14:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37F82C433B2; Thu, 11 Apr 2024 06:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712816068; bh=6Rigut9B0xei0o3RlU/2pvsNtNjz8VS58APxTOkaTzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ohkAORx1XDD/r3zGvplob2RLchLHYpJtenMlCbrLa21NNHXYHsSFleenl2QJvPwDO BmJobQMM8/tiaJ2dc6Xqc1+pTXwNBj4/zO06Eeu4LRUemG65+A9n/DP1SoCXG6914z vmmFfjvM6AxZfKRbJh6c/IeVBz7S8/GXndViQaqA1DdKxNizoD+AfChC+db9N5Bnp9 7vRT2PZBknD6b550bTqQ9oSG/8iTN94euob/LzgnwW4VPDEHbwNrSjRjnWDXIqu14t sx0a9yK+5/uUZG1uXV0Si3q76gnQPcXFHtNdkX+DnqoIGAZzLazQIpwpJpOYxe4ryU EYYNzK4nJSBNA== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, zik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, hughd@google.com, chrisw@sous-sol.org, david@redhat.com Cc: "Alex Shi (tencent)" , Izik Eidus Subject: [PATCH v5 05/10] mm/ksm: use folio in stable_node_dup Date: Thu, 11 Apr 2024 14:17:06 +0800 Message-ID: <20240411061713.1847574-6-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411061713.1847574-1-alexs@kernel.org> References: <20240411061713.1847574-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D81C92000D X-Stat-Signature: j58xkhcea3dp57wcmw9hq45zqfsngmhn X-HE-Tag: 1712816071-591517 X-HE-Meta: U2FsdGVkX1/WmqcrnmVNsvA4FdXGdbxjAWq7yTAb/Jq5SJ48QV/w26hD22aKBhcbX8kIN5ZMlZqxLlRPv9gfnND4DlpRvKXmSEZ2tab7W3i2K5IlfKsrTFVo88Ih/2DxldypZqwQ1MLKMkGtEGm0usUqfnpj7FBdnEaKqqO1t5YOo6zKvcpNhszF4/DgYvn3JpmVj/qZaLScEAbyfuWeunnMPaflqwU6pch4xFEaslpOncl7mLwlDKauPKo+jXmCZFRWpB2MguDRAHPHL1o43ggRHilDxLCYHFcErzQ+8xtSrPV5ems2d88is8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CFluDAkuPTcVfE+MbZfH79R2aSCqA5K6WYnFHa37vF8T0cxZs3yK+XCMVT9F7lAAZ1qQnIy9Wkf2mMBSjLSYecKR3mnlCsu+ONs/i9aDzAHZHY+PFB/Tez 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: "Alex Shi (tencent)" Use ksm_get_folio() and save 2 compound_head calls. Cc: Izik Eidus Cc: Matthew Wilcox Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Chris Wright Signed-off-by: Alex Shi (tencent) Reviewed-by: David Hildenbrand --- mm/ksm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 1a7b13004589..654400f993fc 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1638,7 +1638,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, { struct ksm_stable_node *dup, *found = NULL, *stable_node = *_stable_node; struct hlist_node *hlist_safe; - struct page *_tree_page, *tree_page = NULL; + struct folio *folio, *tree_folio = NULL; int nr = 0; int found_rmap_hlist_len; @@ -1657,24 +1657,24 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, * We must walk all stable_node_dup to prune the stale * stable nodes during lookup. * - * get_ksm_page can drop the nodes from the + * ksm_get_folio can drop the nodes from the * stable_node->hlist if they point to freed pages * (that's why we do a _safe walk). The "dup" * stable_node parameter itself will be freed from * under us if it returns NULL. */ - _tree_page = get_ksm_page(dup, GET_KSM_PAGE_NOLOCK); - if (!_tree_page) + folio = ksm_get_folio(dup, GET_KSM_PAGE_NOLOCK); + if (!folio) continue; nr += 1; if (is_page_sharing_candidate(dup)) { if (!found || dup->rmap_hlist_len > found_rmap_hlist_len) { if (found) - put_page(tree_page); + folio_put(tree_folio); found = dup; found_rmap_hlist_len = found->rmap_hlist_len; - tree_page = _tree_page; + tree_folio = folio; /* skip put_page for found dup */ if (!prune_stale_stable_nodes) @@ -1682,7 +1682,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, continue; } } - put_page(_tree_page); + folio_put(folio); } if (found) { @@ -1747,7 +1747,7 @@ static struct page *stable_node_dup(struct ksm_stable_node **_stable_node_dup, } *_stable_node_dup = found; - return tree_page; + return &tree_folio->page; } static struct ksm_stable_node *stable_node_dup_any(struct ksm_stable_node *stable_node,