From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF036C54E94 for ; Tue, 24 Jan 2023 01:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232753AbjAXBWT (ORCPT ); Mon, 23 Jan 2023 20:22:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbjAXBWQ (ORCPT ); Mon, 23 Jan 2023 20:22:16 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01B1B74B for ; Mon, 23 Jan 2023 17:22:15 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id x4so10219478pfj.1 for ; Mon, 23 Jan 2023 17:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=g4yYO75/EwQZJYH40lk5sQ9ghbUufbuHyMXdhMR3QCQ=; b=Szcl6AW6otWDqobuZJtGwtF7glIsetJ71TVMtKHGZGZCFaMHizeHwXV0GBU46ckXD8 AN03PI7hEuIMhWD4c1RA5sz5Wtm0fMxgKre5TWnzTXjzlDSiM160wux/hWv/nzN1CHUP R4EnE3slgjF0R/6ei4HCL+ijvHGjHIqm07siw61r2CmMthT9q78b3av8tIsayCUVJdIX Wn9VAjNm+k2HfFN9Obbc/ey33I9I4xxPmyFz5bNRWXizKCXMsohhMOA5Zi4XFNzY/717 gPoldZwss7g2sYCp+RKJRKbjpWnwlpDf34GjSqD+FxKsv2ctHsqvnkUUIpjvVyeOlSps j9Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=g4yYO75/EwQZJYH40lk5sQ9ghbUufbuHyMXdhMR3QCQ=; b=vRPmEQ12zCeaQDzQg05y0AcRTZKU44WvXp1Qv0k4e3XNKlqKNhVTwfpljkb3HCoQZt UTVn6Jm3R/Kp1TvLwbju4SLPOjexwh+glqqa5KblsbOMwQgUMr8Clsz4zMwkjyZU1I4n llBgTbN3RjZnUgBKxbWy5+FioXyD3PR385/iVsfCSBX1q4ppmCsqMLTj0h72wsI3GLet /J1TTtnBTxvabR8xljWm1aSmLYwPJjmHtgSPdQWt3eFS0HFxUzgGD+2KS0pB4V4dgqUE dd8Vq7uhI/UCPgqcQSXGCTg+h4pMZQFncm8FvqUUC2TjD8F5q9EmtqUEPaopBT20kEeB zXng== X-Gm-Message-State: AFqh2kpAczKVUSrl+LHTPREkx8yh5zW/lJm41Ua/HndV1Na2WqysDhy2 D/UcO/saQFSrHaFl0x1621rJfEVYgCE= X-Google-Smtp-Source: AMrXdXvHdIldO2gQfEASMMQES9OCx71pQy0FZT6R+4tjFAeePnD43v8oa4X1PBOCFGYQ88pQyytS3w== X-Received: by 2002:a62:e911:0:b0:578:ac9f:79a9 with SMTP id j17-20020a62e911000000b00578ac9f79a9mr23724189pfh.15.1674523335209; Mon, 23 Jan 2023 17:22:15 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:14 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 1/6] mm: Add folio_estimated_mapcount() Date: Mon, 23 Jan 2023 17:22:05 -0800 Message-Id: <20230124012210.13963-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" folio_estimated_mapcount() takes in a folio and calls page_mapcount() on the first page of that folio. This is necessary for folio conversions where we only care about either the entire_mapcount of a large folio, or the mapcount of a not large folio. This is in contrast to folio_mapcount() which calculates the total number of the times a folio and its subpages are mapped. Signed-off-by: Vishal Moola (Oracle) --- include/linux/mm.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index c9db257f09b3..543c360f7ecc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -875,6 +875,11 @@ static inline int page_mapcount(struct page *page) return mapcount; } =20 +static inline int folio_estimated_mapcount(struct folio *folio) +{ + return page_mapcount(folio_page(folio, 0)); +} + int folio_total_mapcount(struct folio *folio); =20 /** --=20 2.38.1 From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04F2BC54EED for ; Tue, 24 Jan 2023 01:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjAXBWW (ORCPT ); Mon, 23 Jan 2023 20:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232415AbjAXBWR (ORCPT ); Mon, 23 Jan 2023 20:22:17 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46CF8A7A for ; Mon, 23 Jan 2023 17:22:16 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id r18so10326005pgr.12 for ; Mon, 23 Jan 2023 17:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=1khdYzxT7PMCcz7jBx9VZXJLxnPij2EE71ujrUVxn1A=; b=AQFA3PSKomBpZe5gurflYfaoGq6UO7+JSQrD/eFXn7DBVKYwU0lAuRqrv6GxCbLet2 ZYY3M1EU7g5+hFtI0ELOwlQINs/vbumoHskfRHq5wnlvKsUF/l+Wu9dTzLGCbeC+yyLZ 1IQGEjtGmR9Qv/BmzIV6kz5BRs1XM+FvZ9xTyoltiC/Jbz7hp1uo/CqieYoyGHbCRZkV cQuSasuhjAi4VrOVZ8FspI81LB1vNTSUlHIKh4KN4Ho8vG5ViS7RiguK2VdNCAheBcmT 7yDjGx0eTBYwv9ulybCtiSf4t7DyfDQSO5+r6WLwoWyfqrKcDBphe0mryJEh58FaiuZK FTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=1khdYzxT7PMCcz7jBx9VZXJLxnPij2EE71ujrUVxn1A=; b=t3TaT9Ngc/yJx+UfNu2qdwCDlIuRPuEUNUQVIu01RYDZ1VSwt6CvQMuY4PJDZ7Qp2b RzlXV/S8cZwT8+ya7y86FRNUwWFe0xxTgtqew7VICbgrZJcsCFPcen4tltuU64ZTIS8u zzmen8KS1UUnKV6h/bDtXn/60/hlb6NTAw8O4/xq7vopBWHVg5G1m3iDSoTeuvArs+2T kgBfjSvyHX70zm9UTtllHJhJ+r7mIFKzr7WoISQa8u4NfrmXSEWp/Qdw73m+sNwJ566Z /wp57AF2lYhbDUXkn3Tw4KPalzewVpxSH8RmnAZqcd34BC+/ErBQN0XebEdTj+iicd9K /u4g== X-Gm-Message-State: AFqh2kqUXKhgsuVPtG+YKK9fH6PnPZEtI9AzM9KKpWGR39W6ekdG+7jy 4WbGls7J2pfGEaE6VNDfL3Q= X-Google-Smtp-Source: AMrXdXuX4J13uTAEIumzs2XPLcTlVHJgPNwGg7gH1qZU0DCzEzh0s6K/AVoOfbakTeWPmmGphfpZhQ== X-Received: by 2002:aa7:96f7:0:b0:580:c223:90e9 with SMTP id i23-20020aa796f7000000b00580c22390e9mr28511220pfq.6.1674523336159; Mon, 23 Jan 2023 17:22:16 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:15 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 2/6] mm/mempolicy: Convert queue_pages_pmd() to queue_folios_pmd() Date: Mon, 23 Jan 2023 17:22:06 -0800 Message-Id: <20230124012210.13963-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function now operates on a folio instead of the page associated with a pmd. This change is in preparation for the conversion of queue_pages_required() to queue_folio_required() and migrate_page_add() to migrate_folio_add(). Signed-off-by: Vishal Moola (Oracle) --- mm/mempolicy.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index fd99d303e34f..00fffa93adae 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -442,21 +442,21 @@ static inline bool queue_pages_required(struct page *= page, } =20 /* - * queue_pages_pmd() has three possible return values: - * 0 - pages are placed on the right node or queued successfully, or + * queue_folios_pmd() has three possible return values: + * 0 - folios are placed on the right node or queued successfully, or * special page is met, i.e. huge zero page. - * 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were + * 1 - there is unmovable folio, and MPOL_MF_MOVE* & MPOL_MF_STRICT were * specified. * -EIO - is migration entry or only MPOL_MF_STRICT was specified and an - * existing page was already on a node that does not follow the + * existing folio was already on a node that does not follow the * policy. */ -static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr, +static int queue_folios_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long add= r, unsigned long end, struct mm_walk *walk) __releases(ptl) { int ret =3D 0; - struct page *page; + struct folio *folio; struct queue_pages *qp =3D walk->private; unsigned long flags; =20 @@ -464,19 +464,19 @@ static int queue_pages_pmd(pmd_t *pmd, spinlock_t *pt= l, unsigned long addr, ret =3D -EIO; goto unlock; } - page =3D pmd_page(*pmd); - if (is_huge_zero_page(page)) { + folio =3D pfn_folio(pmd_pfn(*pmd)); + if (is_huge_zero_page(&folio->page)) { walk->action =3D ACTION_CONTINUE; goto unlock; } - if (!queue_pages_required(page, qp)) + if (!queue_pages_required(&folio->page, qp)) goto unlock; =20 flags =3D qp->flags; - /* go to thp migration */ + /* go to folio migration */ if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) { if (!vma_migratable(walk->vma) || - migrate_page_add(page, qp->pagelist, flags)) { + migrate_page_add(&folio->page, qp->pagelist, flags)) { ret =3D 1; goto unlock; } @@ -512,7 +512,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned l= ong addr, =20 ptl =3D pmd_trans_huge_lock(pmd, vma); if (ptl) - return queue_pages_pmd(pmd, ptl, addr, end, walk); + return queue_folios_pmd(pmd, ptl, addr, end, walk); =20 if (pmd_trans_unstable(pmd)) return 0; --=20 2.38.1 From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A389C25B50 for ; Tue, 24 Jan 2023 01:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232499AbjAXBW0 (ORCPT ); Mon, 23 Jan 2023 20:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232745AbjAXBWS (ORCPT ); Mon, 23 Jan 2023 20:22:18 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B344118AA3 for ; Mon, 23 Jan 2023 17:22:17 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id e10-20020a17090a630a00b0022bedd66e6dso440724pjj.1 for ; Mon, 23 Jan 2023 17:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=8vZic6jN1vVBvksvwJz1xQpCGfyGjrm+SSW90x/iIgk=; b=qBPhBTvMV2Owf9VhJgprVatzzsuTmrmdgujWu+ZXhk/taMI+CI//vfjdnStMaEicO+ eRgtXHtbKN7WoA1D0BW1aQx3ngg0C6oyKnkPB2n8LbLYUDvFVEEsQvMko7UurU0FYDrP rgmkiL0x6/F6KFse2M+VNc9uZfljnpTYBKUgzeZ1yUHeJQjjeCbIDNUZ/Lip+HXAfpnO 4tlP4om8xgFnrzu1DFjHz/F68qaZoC4b7pEDtOxU940nWGKICHTJUPqT20Z07wsTUnI0 pg4tdKzTzZA53en87NnjKZ8kjpBE7Zm2e0Jw98pVKixaY+TCAziFoR/c+QD2ckTpoMq2 fkaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=8vZic6jN1vVBvksvwJz1xQpCGfyGjrm+SSW90x/iIgk=; b=HPq6JQMvvwWG7yFezXJJQimD4ZGQG12Hs7xOa8U2loWlo0umhu8SRA9eS5YEnoDZ72 tCqRGR/gO/OE23KKN+Sf4hrea0d62pTAZwki9WQepwTAhn35s7CASXrS69aF/2aBIz4L b4Zegum2mttbdfXTYFp9aNcvwpW3dYI743nYNB/NhiJP+7MRZW3qFVhvf/4MQACv7Q4m 6go5zM9TGXZqiGfCAvxbiRXLLNUx4Qsh+cDGpAcozpQ1Y6s5FkpMlhM79KYo4jE1P3ZJ v87PNXT4N5LVJHEhjuWZv92t9cfYPa3Gbz+YAE1yQuJHuBBi8U2A6wKUJD4rv/WaYccS 4Y+A== X-Gm-Message-State: AFqh2krYa98F16OaRnwv9iiaUyCRGpDQh0M+di0Zg5Ca1c+FZ+fKxxAF sll/UEunxWmmAJgPVhSKejQ= X-Google-Smtp-Source: AMrXdXudmDodnBv1VMH7m3m7RLcq8yi1x0STxfkEaumfHAX7TMVdKWRHhpFOBALkU+Vbi6tmSMYlaQ== X-Received: by 2002:a05:6a20:9597:b0:af:7762:3c29 with SMTP id iu23-20020a056a20959700b000af77623c29mr28570275pzb.10.1674523337108; Mon, 23 Jan 2023 17:22:17 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:16 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 3/6] mm/mempolicy: Convert queue_pages_pte_range() to queue_folios_pte_range() Date: Mon, 23 Jan 2023 17:22:07 -0800 Message-Id: <20230124012210.13963-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This function now operates on folios associated with ptes instead of pages. This change is in preparation for the conversion of queue_pages_required() to queue_folio_required() and migrate_page_add() to migrate_folio_add(). Signed-off-by: Vishal Moola (Oracle) --- mm/mempolicy.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 00fffa93adae..ae9d16124f45 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -491,19 +491,19 @@ static int queue_folios_pmd(pmd_t *pmd, spinlock_t *p= tl, unsigned long addr, * Scan through pages checking if pages follow certain conditions, * and move them to the pagelist if they do. * - * queue_pages_pte_range() has three possible return values: - * 0 - pages are placed on the right node or queued successfully, or + * queue_folios_pte_range() has three possible return values: + * 0 - folios are placed on the right node or queued successfully, or * special page is met, i.e. zero page. - * 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were + * 1 - there is unmovable folio, and MPOL_MF_MOVE* & MPOL_MF_STRICT were * specified. - * -EIO - only MPOL_MF_STRICT was specified and an existing page was alrea= dy + * -EIO - only MPOL_MF_STRICT was specified and an existing folio was alre= ady * on a node that does not follow the policy. */ -static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, +static int queue_folios_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct mm_walk *walk) { struct vm_area_struct *vma =3D walk->vma; - struct page *page; + struct folio *folio; struct queue_pages *qp =3D walk->private; unsigned long flags =3D qp->flags; bool has_unmovable =3D false; @@ -521,16 +521,16 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned= long addr, for (; addr !=3D end; pte++, addr +=3D PAGE_SIZE) { if (!pte_present(*pte)) continue; - page =3D vm_normal_page(vma, addr, *pte); - if (!page || is_zone_device_page(page)) + folio =3D vm_normal_folio(vma, addr, *pte); + if (!folio || folio_is_zone_device(folio)) continue; /* - * vm_normal_page() filters out zero pages, but there might - * still be PageReserved pages to skip, perhaps in a VDSO. + * vm_normal_folio() filters out zero pages, but there might + * still be reserved folios to skip, perhaps in a VDSO. */ - if (PageReserved(page)) + if (folio_test_reserved(folio)) continue; - if (!queue_pages_required(page, qp)) + if (!queue_pages_required(&folio->page, qp)) continue; if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) { /* MPOL_MF_STRICT must be specified if we get here */ @@ -544,7 +544,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned l= ong addr, * temporary off LRU pages in the range. Still * need migrate other LRU pages. */ - if (migrate_page_add(page, qp->pagelist, flags)) + if (migrate_page_add(&folio->page, qp->pagelist, flags)) has_unmovable =3D true; } else break; @@ -703,7 +703,7 @@ static int queue_pages_test_walk(unsigned long start, u= nsigned long end, =20 static const struct mm_walk_ops queue_pages_walk_ops =3D { .hugetlb_entry =3D queue_pages_hugetlb, - .pmd_entry =3D queue_pages_pte_range, + .pmd_entry =3D queue_folios_pte_range, .test_walk =3D queue_pages_test_walk, }; =20 --=20 2.38.1 From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57933C25B50 for ; Tue, 24 Jan 2023 01:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231503AbjAXBW2 (ORCPT ); Mon, 23 Jan 2023 20:22:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231589AbjAXBWT (ORCPT ); Mon, 23 Jan 2023 20:22:19 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75BC36FFF for ; Mon, 23 Jan 2023 17:22:18 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id z3so10223247pfb.2 for ; Mon, 23 Jan 2023 17:22:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Sz4HU32GWbuxfmIkQjW0u4ISqBHZ5RIiVnsfOJ2Lp54=; b=lC28+7ohH3L7RY2bT2i8tSpTM0xlFz3lF6bAgzWUGWWmFuxCK9elPf2m6zudfvrEGg C0P+RSe+ZqsLvrnAo/JiYETRIQ66yDmYy1Y+7m15EK3VYcvv3JnlHD7zTuXxrywpBwQd 9vHqfvl85thXMoCB+qYDT5sRsYpyOmjbSf5RadBW37gCwnBEzxoAHepyNfuXCw3YMT1d P6nO/DzbweEpICN9rva8V8Muh+vEGKcmGeavnWMFEJSIl5BcYihei18T9xvc3bRKoguG cdMZ1rBREAS4SrcIYWfHIGtpcBBJoUpS1fYsZShm49witX7KWcPvTkXRYtg1UZjBWUSm 109w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Sz4HU32GWbuxfmIkQjW0u4ISqBHZ5RIiVnsfOJ2Lp54=; b=cpwgaYla1MxnwPM89uri6S306y4OTntEBJbZ/IzCH/Iw1hgSf70koz9eqvCtXC0Vbm 4jRThe4jjllQyH5z+R81LZg4OYsWnMzVkA/9bdOOIDzuYigzuOttIhC0TO3x8R9c/Fb1 fpZGWWz7fwYSzULakN6TCbTIwKvIypD7dquW89wo1lr/5baBau67mqlZ2HVBY880h3I3 a/cBKlkOy0jPM6BlrFXnHex9m5N4W27JbVCNjOrG5YiHnfazql0lHIRDlXgmjIgID6p1 XwpDzoQnN9uqCiAnXZ3xsdUUUdxGwLNSuefZVcJyI1nBT3UXGB8mlu8uDazul+6J4LQ4 aDDw== X-Gm-Message-State: AFqh2kqlXOsSAVUBLric/Lqzoy82vHtte//fumb6oNinqXkl+uBMgGWu hDEyh9jv4IdRRdKzGnW4iKA= X-Google-Smtp-Source: AMrXdXtw7DPU0fDVIuSIik2FPwLQBTsSwI80gyL0ccUmEB45ha4+fG/kppN5E/z9R4rdHRg23IBUug== X-Received: by 2002:a05:6a00:3006:b0:58b:5f9d:c2fe with SMTP id ay6-20020a056a00300600b0058b5f9dc2femr27661373pfb.29.1674523338114; Mon, 23 Jan 2023 17:22:18 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:17 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 4/6] mm/mempolicy: Convert queue_pages_hugetlb() to queue_folios_hugetlb() Date: Mon, 23 Jan 2023 17:22:08 -0800 Message-Id: <20230124012210.13963-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This change is in preparation for the conversion of queue_pages_required() to queue_folio_required() and migrate_page_add() to migrate_folio_add(). Signed-off-by: Vishal Moola (Oracle) --- mm/mempolicy.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ae9d16124f45..ea8cac447e04 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -558,7 +558,7 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned = long addr, return addr !=3D end ? -EIO : 0; } =20 -static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask, +static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, unsigned long end, struct mm_walk *walk) { @@ -566,7 +566,7 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned lon= g hmask, #ifdef CONFIG_HUGETLB_PAGE struct queue_pages *qp =3D walk->private; unsigned long flags =3D (qp->flags & MPOL_MF_VALID); - struct page *page; + struct folio *folio; spinlock_t *ptl; pte_t entry; =20 @@ -574,13 +574,13 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned l= ong hmask, entry =3D huge_ptep_get(pte); if (!pte_present(entry)) goto unlock; - page =3D pte_page(entry); - if (!queue_pages_required(page, qp)) + folio =3D pfn_folio(pte_pfn(entry)); + if (!queue_pages_required(&folio->page, qp)) goto unlock; =20 if (flags =3D=3D MPOL_MF_STRICT) { /* - * STRICT alone means only detecting misplaced page and no + * STRICT alone means only detecting misplaced folio and no * need to further check other vma. */ ret =3D -EIO; @@ -591,20 +591,27 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned l= ong hmask, /* * Must be STRICT with MOVE*, otherwise .test_walk() have * stopped walking current vma. - * Detecting misplaced page but allow migrating pages which + * Detecting misplaced folio but allow migrating folios which * have been queued. */ ret =3D 1; goto unlock; } =20 - /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ + /* + * With MPOL_MF_MOVE, we try to migrate only unshared folios. If it + * is shared it is likely not worth migrating. + * + * To check if the folio is shared, ideally we want to make sure + * every page is mapped to the same process. Doing that is very + * expensive, so check the estimated mapcount of the folio instead. + */ if (flags & (MPOL_MF_MOVE_ALL) || - (flags & MPOL_MF_MOVE && page_mapcount(page) =3D=3D 1)) { - if (isolate_hugetlb(page_folio(page), qp->pagelist) && + (flags & MPOL_MF_MOVE && folio_estimated_mapcount(folio) =3D=3D 1)) { + if (isolate_hugetlb(folio, qp->pagelist) && (flags & MPOL_MF_STRICT)) /* - * Failed to isolate page but allow migrating pages + * Failed to isolate folio but allow migrating folios * which have been queued. */ ret =3D 1; @@ -702,7 +709,7 @@ static int queue_pages_test_walk(unsigned long start, u= nsigned long end, } =20 static const struct mm_walk_ops queue_pages_walk_ops =3D { - .hugetlb_entry =3D queue_pages_hugetlb, + .hugetlb_entry =3D queue_folios_hugetlb, .pmd_entry =3D queue_folios_pte_range, .test_walk =3D queue_pages_test_walk, }; --=20 2.38.1 From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C3E5C25B50 for ; Tue, 24 Jan 2023 01:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232276AbjAXBWb (ORCPT ); Mon, 23 Jan 2023 20:22:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232757AbjAXBWU (ORCPT ); Mon, 23 Jan 2023 20:22:20 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A54139B9E for ; Mon, 23 Jan 2023 17:22:19 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id d3so13249919plr.10 for ; Mon, 23 Jan 2023 17:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=nE+3UuHIJTsmxu1JqArGmSE4JP62IBIElITMZZ15/p0=; b=ZP/5bObP5pqsvaY9t0h8rIoT9dI9iJBk3mx62rI2nojE2rF17RJDpgzpAJ838bLs/U 6kRuTVVhRzVrpXQBJQ78n2+00oBc8IN+Qr4UmE90EnJV14gUU4AKy9lGkW4u4LtenMm7 nNmyb7o9J1AjOT0Yzvb5W29TbD6D52DH1LSYkfBlcnUV7VBOl5yKEIAG1RBVMFbc663g RLNNMG4tMyd0Qw6zqvgCGsrHo0cHg2hi/rBgbW25Jg1UoelSwenfNsqRSAJzZSPNwYsY HOZe0gaG/lQCzN42ApROK0PrZ8T/HL5yRfeRvFK0HwVF97BGf3YOY1mK9uyGsG2s0OVf zR2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=nE+3UuHIJTsmxu1JqArGmSE4JP62IBIElITMZZ15/p0=; b=m5dxDVK2wvRRDvZbJdRArxyx0sy7KmJT/5v63oLsZvrcI1CC5VUCXsR2V+khdXwcwh H2eWEH7bX2llE+dh6jY0IjrQeNCpUqqdiSudgdy/EH69JqC1o/aLKswkEzdbUe47nAHy onCcJRoESosGT/qiK3V9fQq3T8HSnrR643t6bv9BdZn6iC2FZncCmsuybG7dcAmcEF6u +hJnXlmKeVfKVe2kR1M/uazhLSs0oTsLyBJiGoUXelq6aF21j05C4RDKJhdawBrUVKnK a1tKv09h2WFo+2O1CDTz4gXKZjfnhH3aVJpoIZGOwm/qFcO3O8JQIKG/lwCm7fN5yphc 2sig== X-Gm-Message-State: AFqh2kpZmnSBUll+XccBt9WMXBLrkYSB0gvU20WqC3wJXab+KYentwzq DRQygYMUCD5dybiadCZ7/g/MaauES98= X-Google-Smtp-Source: AMrXdXs0B1T1RoQ7VAB/8nsyU5key1ZZZZtdA3fPrHEjotnA1Vx130RbBWsgiLsAjdttNXdx7IZk6Q== X-Received: by 2002:a05:6a20:4407:b0:b8:66f6:6263 with SMTP id ce7-20020a056a20440700b000b866f66263mr38103651pzb.23.1674523338995; Mon, 23 Jan 2023 17:22:18 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:18 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 5/6] mm/mempolicy: Convert queue_pages_required() to queue_folio_required() Date: Mon, 23 Jan 2023 17:22:09 -0800 Message-Id: <20230124012210.13963-6-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace queue_pages_required() with queue_folio_required(). queue_folio_required() does the same as queue_pages_required(), except takes in a folio instead of a page. Signed-off-by: Vishal Moola (Oracle) --- mm/mempolicy.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ea8cac447e04..da87644430e3 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -427,15 +427,15 @@ struct queue_pages { }; =20 /* - * Check if the page's nid is in qp->nmask. + * Check if the folio's nid is in qp->nmask. * * If MPOL_MF_INVERT is set in qp->flags, check if the nid is * in the invert of qp->nmask. */ -static inline bool queue_pages_required(struct page *page, +static inline bool queue_folio_required(struct folio *folio, struct queue_pages *qp) { - int nid =3D page_to_nid(page); + int nid =3D folio_nid(folio); unsigned long flags =3D qp->flags; =20 return node_isset(nid, *qp->nmask) =3D=3D !(flags & MPOL_MF_INVERT); @@ -469,7 +469,7 @@ static int queue_folios_pmd(pmd_t *pmd, spinlock_t *ptl= , unsigned long addr, walk->action =3D ACTION_CONTINUE; goto unlock; } - if (!queue_pages_required(&folio->page, qp)) + if (!queue_folio_required(folio, qp)) goto unlock; =20 flags =3D qp->flags; @@ -530,7 +530,7 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned = long addr, */ if (folio_test_reserved(folio)) continue; - if (!queue_pages_required(&folio->page, qp)) + if (!queue_folio_required(folio, qp)) continue; if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) { /* MPOL_MF_STRICT must be specified if we get here */ @@ -575,7 +575,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned lo= ng hmask, if (!pte_present(entry)) goto unlock; folio =3D pfn_folio(pte_pfn(entry)); - if (!queue_pages_required(&folio->page, qp)) + if (!queue_folio_required(folio, qp)) goto unlock; =20 if (flags =3D=3D MPOL_MF_STRICT) { --=20 2.38.1 From nobody Sun Sep 14 09:35:45 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7028C05027 for ; Tue, 24 Jan 2023 01:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbjAXBWe (ORCPT ); Mon, 23 Jan 2023 20:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232415AbjAXBWY (ORCPT ); Mon, 23 Jan 2023 20:22:24 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A5517CE3 for ; Mon, 23 Jan 2023 17:22:20 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 7so10356820pga.1 for ; Mon, 23 Jan 2023 17:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=aN57XfC0N2Z9PnMQ9nUjXYfVmJE2FGzydu2ZVvrzX3Q=; b=C/U/++SQ2raDEJiXZtLwp/aQPJIL2snP32r34/JamWV0YT5a5TsRoxvkNwbqlG+WDL Ps9wGzMk2fiKNQXMr2OEKdhMvvQfUMMtwtVHTbBPYYhV8nQcLx8qaQELNcPzo8v7Ttmf VmKiBt4Qr55YGjL0lwWS3LlD/Buk97PMiEpFshtmKPPbhX+1xEZd87JnVl7KpInH2k5c R2I/J6j7A0NCijafjBjis/f0LP6dYdH2w6/hgAka5LvRlZ5Tg5e//B6nTlGW6Z+W2fGt UmVFycoXRWSqB05rk6sYjNnEASAC57l7Sc6+Gmba8spUW3oIL05EE51CkXLabKhrLqo4 V3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=aN57XfC0N2Z9PnMQ9nUjXYfVmJE2FGzydu2ZVvrzX3Q=; b=oHD90n+tRp8YiN2As7J/EKp+kl9UPp3qszgnR6/bCLCfX7ORAY5o8KyWZ8CKxGAqi1 w8KyGghjIaPdtTDbGaLdVaKWm/CnYCYNGg8tnnn9O2fwOIZozSZdTFb6RfY17Ou0Rml6 2M3MY/7AZch6fITZ2X4LDxpMG00DXIq1t5y9dAyf/+uAJGGOJNXG/Z6Sz1KZpiXj4i5z L7sP15ac0dUihBbxWHGQO5kAhfHa9KBIHtE64KT9gqBq3jb1UEjeO783XLmhk5Mu+WjJ 7BYCGKr55pG6Fs7ReQaYHEg1L15zcp9Yh+QQsmQhiO5hPJiSviYjlgVtSyKRDg4EMxsT x+Lg== X-Gm-Message-State: AFqh2kqJi4i/jvWa6yX83wmrUrmM/uXWqYfgxjVITbH1N39CLI1nV1/3 eJOn5m3QSoKdBnBQOqGz034= X-Google-Smtp-Source: AMrXdXsUcKBht35TPhoeIdubPl8bcQOBoTQINC0wEB8tAeEYBIKQ/4JjGSme0DY/zIDwqcq5kn6xZw== X-Received: by 2002:a05:6a00:2986:b0:58c:8bdd:2e3c with SMTP id cj6-20020a056a00298600b0058c8bdd2e3cmr28301423pfb.20.1674523339887; Mon, 23 Jan 2023 17:22:19 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id 68-20020a620547000000b005825b8e0540sm213335pff.204.2023.01.23.17.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:22:19 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v2 6/6] mm/mempolicy: Convert migrate_page_add() to migrate_folio_add() Date: Mon, 23 Jan 2023 17:22:10 -0800 Message-Id: <20230124012210.13963-7-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230124012210.13963-1-vishal.moola@gmail.com> References: <20230124012210.13963-1-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace migrate_page_add() with migrate_folio_add(). migrate_folio_add() does the same a migrate_page_add() but takes in a folio instead of a page. This removes a couple of calls to compound_head(). Signed-off-by: Vishal Moola (Oracle) --- mm/mempolicy.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index da87644430e3..9bb4600c4294 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -414,7 +414,7 @@ static const struct mempolicy_operations mpol_ops[MPOL_= MAX] =3D { }, }; =20 -static int migrate_page_add(struct page *page, struct list_head *pagelist, +static int migrate_folio_add(struct folio *folio, struct list_head *foliol= ist, unsigned long flags); =20 struct queue_pages { @@ -476,7 +476,7 @@ static int queue_folios_pmd(pmd_t *pmd, spinlock_t *ptl= , unsigned long addr, /* go to folio migration */ if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) { if (!vma_migratable(walk->vma) || - migrate_page_add(&folio->page, qp->pagelist, flags)) { + migrate_folio_add(folio, qp->pagelist, flags)) { ret =3D 1; goto unlock; } @@ -544,7 +544,7 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned = long addr, * temporary off LRU pages in the range. Still * need migrate other LRU pages. */ - if (migrate_page_add(&folio->page, qp->pagelist, flags)) + if (migrate_folio_add(folio, qp->pagelist, flags)) has_unmovable =3D true; } else break; @@ -1029,27 +1029,28 @@ static long do_get_mempolicy(int *policy, nodemask_= t *nmask, } =20 #ifdef CONFIG_MIGRATION -/* - * page migration, thp tail pages can be passed. - */ -static int migrate_page_add(struct page *page, struct list_head *pagelist, +static int migrate_folio_add(struct folio *folio, struct list_head *foliol= ist, unsigned long flags) { - struct page *head =3D compound_head(page); /* - * Avoid migrating a page that is shared with others. + * We try to migrate only unshared folios. If it is shared it + * is likely not worth migrating. + * + * To check if the folio is shared, ideally we want to make sure + * every page is mapped to the same process. Doing that is very + * expensive, so check the estimated mapcount of the folio instead. */ - if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(head) =3D=3D 1) { - if (!isolate_lru_page(head)) { - list_add_tail(&head->lru, pagelist); - mod_node_page_state(page_pgdat(head), - NR_ISOLATED_ANON + page_is_file_lru(head), - thp_nr_pages(head)); + if ((flags & MPOL_MF_MOVE_ALL) || folio_estimated_mapcount(folio) =3D=3D = 1) { + if (!folio_isolate_lru(folio)) { + list_add_tail(&folio->lru, foliolist); + node_stat_mod_folio(folio, + NR_ISOLATED_ANON + folio_is_file_lru(folio), + folio_nr_pages(folio)); } else if (flags & MPOL_MF_STRICT) { /* - * Non-movable page may reach here. And, there may be - * temporary off LRU pages or non-LRU movable pages. - * Treat them as unmovable pages since they can't be + * Non-movable folio may reach here. And, there may be + * temporary off LRU folios or non-LRU movable folios. + * Treat them as unmovable folios since they can't be * isolated, so they can't be moved at the moment. It * should return -EIO for this case too. */ @@ -1241,7 +1242,7 @@ static struct page *new_page(struct page *page, unsig= ned long start) } #else =20 -static int migrate_page_add(struct page *page, struct list_head *pagelist, +static int migrate_folio_add(struct folio *folio, struct list_head *foliol= ist, unsigned long flags) { return -EIO; --=20 2.38.1