From patchwork Tue Jun 4 04:24:47 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: 13684611 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 613E9C25B74 for ; Tue, 4 Jun 2024 04:21:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46D056B009B; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41A646B009C; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294756B009D; Tue, 4 Jun 2024 00:21:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EE60E6B009C for ; Tue, 4 Jun 2024 00:21:52 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A7615C0CF2 for ; Tue, 4 Jun 2024 04:21:52 +0000 (UTC) X-FDA: 82191908064.07.4EA906B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf08.hostedemail.com (Postfix) with ESMTP id 7070416000E for ; Tue, 4 Jun 2024 04:21:50 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MDSl5xy6; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717474911; a=rsa-sha256; cv=none; b=KW0VBe/ArXZ9CB8lVFfLWlRrJxqfqvNZyaxj8luzk25WQOCagVMgxi0IQyT073T74awh2L 8lZ5zsYHzRIrlkYSWE7ybO6CKsBYPDJdrQIeg8Rm1YpcZ9jSk/bs7AI6pm6Yl2QiUf75dT ApG2uHRcKch7j9RU4SCUEnJOWlcYMr4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MDSl5xy6; spf=pass (imf08.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717474911; 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=k/DC64RVeyqPliY9iy4ZmvrEyGxjD2DKSlqV1GS9qDQ=; b=Sbf/Q3o2TrhF8W/WRvxjZ8HZCwxaR5PXMVpS+z5gELUeuX2tvHcr6/JoNClYQeIbPZw8w0 NU6jXLYr48UWMSe5cWYRUfy8yCawLmTqaejWBBLwQRmxxv1yw+XRrIgVaRQ/lL1De7qI6x c8viUqFFrP+9LbYY1Qj7Tm0sJi2Puv4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 93F8FCE100F; Tue, 4 Jun 2024 04:21:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F76EC2BBFC; Tue, 4 Jun 2024 04:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717474906; bh=coNrFyNql7rzA+Wu1zS+Imisztx1VEYHkdkeqtcLPJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MDSl5xy6AfvB2jwDYUYciKw0WAPH6HVMDLpvUtKv4MiMW2nJPsr8687kDmSuMgS2i 8ir4mEf4IzJsZxyqCpwMRG7zPuqEQoO2FcqBJt1Toe9V6ugm2H3oSFrRFxB0nJRYvO 6ZjV1r2iscSWsLM8U1FBXXxPO9kLwGNyw46O7MPHow2J0CcrcBysxPOMtS9OSJHTXn kLsG0fd7lCw5iMa882oNvtx9mV5k5rsta8bJgKJcmH9Tjy3MLvJBxnK5D0J6VcqtKB /pWRYqxUdW7oaEdmPbUUkTDWV9VnNFT8B2tYE9n58p6TzwY1lajVhpANa7W9F7pRhx S/9+Par00zx4g== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, izik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com, david@redhat.com Cc: "Alex Shi (tencent)" Subject: [PATCH 05/10] mm/ksm: use folio in stable_tree_search Date: Tue, 4 Jun 2024 12:24:47 +0800 Message-ID: <20240604042454.2012091-6-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604042454.2012091-1-alexs@kernel.org> References: <20240604042454.2012091-1-alexs@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7070416000E X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: fxu9mkg47e5pygued8ipugqzyuxeajqe X-HE-Tag: 1717474910-737125 X-HE-Meta: U2FsdGVkX1+WNw5ja1qo6yvxxLxVT7W/JKayJGJ6YhsaV8L7ScmULZI0lEo7VohSu/S+/zL4qSjcexSe+4v4hw6FpjV74ycJaUTByv62TJ1I0z2Xlou9sIX5I3hQg7Ji0qEl1uF1tmgL1BEX8BTmpAd89sbgXQG1TiK5v1JOBmXwmF9nR9p3fwQGzv/VuBBQiPPolj6+A4ZXKI2Z1PS8XYgZrH8XwhB4K03etXJfEno9aD+WwpkWTjfyy7SUVhf3/vkKqu5z8+Z5+ptCeu3JuH4/5454UlV17PDdPTfkzTHmFnEG8rZpQMTAaBX03hYNaB0Nm3GlxCf/uvW9HpXU19y/NQsnuguamU+iskcbLgAseguLJwx7EtR7RzTNkyqV3cEt56UDyVvTm23STPFnGdV2NWIMv3OvoXBKeZaR2HksTARU+l41S2oTNbu/PKG1r8oo5Xur14+9Kb1ygRqxIrthdsuaadvwB9GT2e7u12T55TRFnDE4CtVr2i19tDdegKmkGjf85cvybAvDPv6nw2pONXkjV9Vyas4B0h564LF+zwHLAPCGBA6MKmCMI6BSbzcxlRY6gZCTKbJZYAe4N2xnopWFTtf1oKcnlkvoJuboOslp2U4+npAUEiOwrzCni5jIDFGrjRT3iKD3ZeGxIDFJJfF/BWKXxNyHLlpofSBk/7XOvoCQRzoJtySgAx5ZG0AdFxztJrAbWabFnYxc1fI6bmRDK6XDt4IyScF7P6AjNnyS9u4wybJSkBx5AKczx90zCCMxJzfyNheulTq0MvMz9aFs6iigb3Xn9woLCu75BROc5ylHdikDpbF8aVNXkJUAjSbajmRg/e+l0OiqEY2g/V0vKHq84E0eD1ni/cDIo74JUR6oAOuMjgnxSknqibHWPz3338w8UXmBaP0qMBgQ/c+hF25NhhxCSQH1D9Ew59pzYwCqANoJN21vAjGPpyGr2U4nlCr7l500mum dNmb6mDr gRnK81qPZxAmhVzKh475CD0t6b4gvMJn42VU5AIwz1TU+b0exlMD4JoB33tuRpjKt+nwJJuiIo7N3/cSvpCMNcyKT6PziU2vbAJQll01iU5ewEA22QWnhBwJdLIbI63IkRXwuoHqzmerbHu98kRWbfb3b2fgBMnGmAyxuPuW1XhNnb9xVqOlgp4y2f+O2LYhGCIHm4zYun8FNLpi7V6UZE4ICcKWY7ouMlBf7mzQzFNIunPMu+Ma2CKBrzwmiub3MkUewbFa6LC7uJa4TJXCmU6LTP73dtKSJ2s+N0d9BRKd8uH7933FntPu6FL6uUTkTtBZi+gV15CJ7Uuc= 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)" The stable_tree_search() function is actually using folio internal, just pass the folio parameter from cmp_and_merge_page(). And in cmp_and_merge_page(), the parameter 'page' is actually a folio too, so use folio to save a few compound check in necessnary context. Signed-off-by: Alex Shi (tencent) --- mm/ksm.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 2e4790842515..f68779651841 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1825,7 +1825,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d, * This function returns the stable tree node of identical content if found, * NULL otherwise. */ -static struct page *stable_tree_search(struct page *page) +static struct folio *stable_tree_search(struct folio *folio) { int nid; struct rb_root *root; @@ -1833,14 +1833,12 @@ static struct page *stable_tree_search(struct page *page) struct rb_node *parent; struct ksm_stable_node *stable_node, *stable_node_dup, *stable_node_any; struct ksm_stable_node *page_node; - struct folio *folio; - folio = page_folio(page); page_node = folio_stable_node(folio); if (page_node && page_node->head != &migrate_nodes) { /* ksm page forked */ folio_get(folio); - return &folio->page; + return folio; } nid = get_kpfn_nid(folio_pfn(folio)); @@ -1907,7 +1905,7 @@ static struct page *stable_tree_search(struct page *page) goto again; } - ret = memcmp_pages(page, &tree_folio->page); + ret = memcmp_pages(folio_page(folio, 0), &tree_folio->page); folio_put(tree_folio); parent = *new; @@ -1973,7 +1971,7 @@ static struct page *stable_tree_search(struct page *page) folio_put(tree_folio); goto replace; } - return &tree_folio->page; + return tree_folio; } } @@ -1987,7 +1985,7 @@ static struct page *stable_tree_search(struct page *page) out: if (is_page_sharing_candidate(page_node)) { folio_get(folio); - return &folio->page; + return folio; } else return NULL; @@ -2037,7 +2035,7 @@ static struct page *stable_tree_search(struct page *page) } stable_node_dup->head = &migrate_nodes; list_add(&stable_node_dup->list, stable_node_dup->head); - return &folio->page; + return folio; chain_append: /* stable_node_dup could be null if it reached the limit */ @@ -2324,6 +2322,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite unsigned int checksum; int err; bool max_page_sharing_bypass = false; + struct folio *folio, *kfolio; stable_node = page_stable_node(page); if (stable_node) { @@ -2346,30 +2345,31 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite } /* We first start with searching the page inside the stable tree */ - kpage = stable_tree_search(page); - if (kpage == page && rmap_item->head == stable_node) { - put_page(kpage); + folio = page_folio(page); + kfolio = stable_tree_search(folio); + if (kfolio == folio && rmap_item->head == stable_node) { + folio_put(kfolio); return; } remove_rmap_item_from_tree(rmap_item); - if (kpage) { - if (PTR_ERR(kpage) == -EBUSY) + if (kfolio) { + if (kfolio == ERR_PTR(-EBUSY)) return; - err = try_to_merge_with_ksm_page(rmap_item, page, kpage); + err = try_to_merge_with_ksm_page(rmap_item, page, folio_page(kfolio, 0)); if (!err) { /* * The page was successfully merged: * add its rmap_item to the stable tree. */ - lock_page(kpage); - stable_tree_append(rmap_item, page_stable_node(kpage), + folio_lock(kfolio); + stable_tree_append(rmap_item, folio_stable_node(kfolio), max_page_sharing_bypass); - unlock_page(kpage); + folio_unlock(kfolio); } - put_page(kpage); + folio_put(kfolio); return; }