From patchwork Thu Jan 11 18:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13517691 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 84ADBC4725D for ; Thu, 11 Jan 2024 18:12:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 950D06B00A2; Thu, 11 Jan 2024 13:12:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DA746B00A3; Thu, 11 Jan 2024 13:12:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7794D6B00A4; Thu, 11 Jan 2024 13:12:42 -0500 (EST) 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 5F61C6B00A2 for ; Thu, 11 Jan 2024 13:12:42 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38B09A227F for ; Thu, 11 Jan 2024 18:12:42 +0000 (UTC) X-FDA: 81667825764.08.6BFD9A3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 8E602A0027 for ; Thu, 11 Jan 2024 18:12:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NzLVjgjx; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704996760; a=rsa-sha256; cv=none; b=BtVWxpB8Rjw+fYOUNd0raC6+rYEvmEhLdkpye8aAn/uA0ZN36GbFiZg8MyBErtwo3zFBfE DfOx8MQvGoYtUYiTozil5pvzMx0kBg7IzuoRd80yemyK/d7HXZ328JzUpP84DtBSY6At1c 5J9ybrifxhPucSd0EWvaWf3XlIOnk5E= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NzLVjgjx; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704996760; 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=nikFvHd6fGdNzCCFcNOYGz8RI17m7m/j0Xdu8XjTLzg=; b=Pi//VzaCqHtGW7qDvqiBOg7ubyW9b5KSx0SYAYefx9iYse4NY38XNh+d3P7q8/9lO5fS9f ivwrluUZ7qlFe1oMU7LYei8GJ6qVq/cINVnddB/iUbuV3N+cj+iWyWM9Zv0mfbDd3cJgGE yOTOUhoOcBBJgdgKRd4IDISs1MV6694= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nikFvHd6fGdNzCCFcNOYGz8RI17m7m/j0Xdu8XjTLzg=; b=NzLVjgjxox29jd/ntluwYpxv4D bVQK+95YJVxZUge/U0z3zh9L1AJkU+dtkQI0vJBHiQXWP7Od0DP/G9gDUXy87CxK3KgNxdSPTT5HR 4a1cml7L8wwn7+lcP+W5YXasDVWmtYm7YGb+S8SvcEK4vzPQgi1s8UNicyRWgpLnwwbpKMFpLJmdD KAYRPeAeqb5unTOtACQs9g9kjsUq7eGxUXvrc2QLo9HMvmTSHOmpp0wg2x87GmWZ1ORqHaqRYi+Uq 3XTcUNqJE/iRjVjPej2pgW4RSTr1eQamHjSbX5fI9IRUQ4gm3+W6wnez2+YYyTf7AJ/ACmR4HByoe kxmGEwgQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rNzXR-00EWr2-Ke; Thu, 11 Jan 2024 18:12:21 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] memcg: Use a folio in get_mctgt_type Date: Thu, 11 Jan 2024 18:12:18 +0000 Message-Id: <20240111181219.3462852-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20240111181219.3462852-1-willy@infradead.org> References: <20240111181219.3462852-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8E602A0027 X-Stat-Signature: hnqe96q7ejfahzezrdj8bakgpkfbxu78 X-Rspam-User: X-HE-Tag: 1704996760-883216 X-HE-Meta: U2FsdGVkX1/9ADLwg+GkM2F6sYN2AzuK7QtDCxhkVZfhvimFynvqY25JFVTGvGSTSgBkzMcPmK+bTf3Tk1QZQUdPuqFbhJC5IHpScmJc7ciICviGhQ+1Rx7soxI9QHDrqAxcpqFBdqptsOZEd2QWa8hCB4PYVF3CfVdAd/NoRLXThGv8hZ6NAcbLd/ers/bnoyBNPNQ5LrB/zp/J7wZcMZpXw9TzYu9e3WToKIwUYenVxrIFRDO3EIhcMvMkH3nzheriIzSLG4lfq2eOzujYxTvug10yIBN3FS1z09f74aT4FF6XyD6mPm51vjjxN/ztL7pdi/MuRuy+oZttLr9FncieoCuv+zAv+VBfRJ80rWk9CrjTQalYnKP1xiXiFXnxYu4VKoVPGMjyZAjDxrT3bE1cUKkrt15wFsl4I+CU3FUxsQ/qeFGkeIUwKPZzdclEaXiCbpQWNCrbq4vlJWEiEh2+VtF2jDeFpKGP12puT/pf27iwn6UP3DnQtoo+x4pMTyM1q4e8nTBidzsz5ntLkD8RCh+NPqFm+ausXLVk5jgQ1O1qSJWjr8Qe3DFEevI6Q/9uIuSp6qMff2f81BNTD5KGmWLgyNeXK8evdLuFcXfXeN0Vqmt7QWlfTZPvPaUhBzOc/bHFVRoMXAMz0aBXVDqvel8FVHocpzGayVfoGKvFEQUEagioOgluHtHm8UgyRdIdvr/c7zquzAznuokISgLsqNEJW54f8A7zYL58m5savB570cxNbJ90znkT4fs4HKyY2S+9m00tf19JdgTu5+LFt47oFlvdoitDdlARl4NQ85qhcaoR6G3H531XkyzLwo2ev8F9fAFncxqJCa4Zb1hIt2fzI2ZkCnB6WU3qg4SSaE7v1psmHMtemXyo3zKbSGScBhzT/ilUP278xMdQO3exAYu2BZ0MtgpQn7mJQ5da/D3QO4ft1nkMcsFVV0hZhZw6sVHTGnb4ZzSCe+i hbHao1vN Iw5jk1NN+zWqJc0WXXo//VSU/r7m6qpIIuMg6CJISSpe0cMBKDKtlFskuthDzI9Uma4G96OK3gJ77ucKy+/6poiaj0KgVFw8JeoiGgHPAYjz5o0QJBedLHl/yLOycMTSDfBC2w9/Y01f0aaqzgnf9tj6lfeQkdq9BSDnOiMaHFESQtVWKOO/tHjGvD+cTjg83o9MMcyH6gWYgIBBi3Z7/bRNxAnkOy+6g85nG 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: Replace seven calls to compound_head() with one. We still use the page as page_mapped() is different from folio_mapped(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Johannes Weiner Reviewed-by: Muchun Song --- mm/memcontrol.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d14fe0740b37..b6096c34b3e4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6076,6 +6076,7 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, unsigned long addr, pte_t ptent, union mc_target *target) { struct page *page = NULL; + struct folio *folio; enum mc_target_type ret = MC_TARGET_NONE; swp_entry_t ent = { .val = 0 }; @@ -6090,9 +6091,11 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, else if (is_swap_pte(ptent)) page = mc_handle_swap_pte(vma, ptent, &ent); + if (page) + folio = page_folio(page); if (target && page) { - if (!trylock_page(page)) { - put_page(page); + if (!folio_trylock(folio)) { + folio_put(folio); return ret; } /* @@ -6107,8 +6110,8 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, * Alas, skip moving the page in this case. */ if (!pte_present(ptent) && page_mapped(page)) { - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); return ret; } } @@ -6121,18 +6124,18 @@ static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma, * mem_cgroup_move_account() checks the page is valid or * not under LRU exclusion. */ - if (page_memcg(page) == mc.from) { + if (folio_memcg(folio) == mc.from) { ret = MC_TARGET_PAGE; - if (is_device_private_page(page) || - is_device_coherent_page(page)) + if (folio_is_device_private(folio) || + folio_is_device_coherent(folio)) ret = MC_TARGET_DEVICE; if (target) - target->folio = page_folio(page); + target->folio = folio; } if (!ret || !target) { if (target) - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); } } /*