From patchwork Mon Jan 30 20:18:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13121758 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 7E00DC636D3 for ; Mon, 30 Jan 2023 20:18:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B91E66B0078; Mon, 30 Jan 2023 15:18:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B429D6B007B; Mon, 30 Jan 2023 15:18:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D1806B007D; Mon, 30 Jan 2023 15:18:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 80C816B0078 for ; Mon, 30 Jan 2023 15:18:48 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 59EFA140B5C for ; Mon, 30 Jan 2023 20:18:48 +0000 (UTC) X-FDA: 80412578736.23.21D1BF9 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf02.hostedemail.com (Postfix) with ESMTP id 76D1080006 for ; Mon, 30 Jan 2023 20:18:46 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Uoo5nyF2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675109926; 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=SSeBOBmV5irVttghOKU/WEyUh0YnA4r3UGGroMyochk=; b=WYe+r0mJD9KexTRa9J1HDIIuuZDDNHoz1o0FIpq+vUSVb+f1xrkzuPh5ir13K8yToVYn3P 6ehnLuhogopxyrN2er6vHp/85qenCMDnVyYLel/gjW9Il19Ue7YEiGJOzg52qIksAytA0e qYNA6l4svUrCiLZ29KO1I3Eq2tLaWmg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Uoo5nyF2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675109926; a=rsa-sha256; cv=none; b=wzEFcUg8OCPL4S0AFHPBFzkMWlEl5nEAl7W31ZGJKKbRfsduCb5Aag2SaqJw9amMwQFfUW uoUzfH80V4kYr8DlaTllghjqpRI0GqqdldwBaIkvj65pipWdwsUtqlHKHG1e5IjoXF0jcy ESXCDKndVvp+H62+vQh2XsImHCluGd8= Received: by mail-pg1-f181.google.com with SMTP id g68so8486452pgc.11 for ; Mon, 30 Jan 2023 12:18:46 -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=SSeBOBmV5irVttghOKU/WEyUh0YnA4r3UGGroMyochk=; b=Uoo5nyF2OvMxPs0CxInigN1mJkJMwm5kATVUZBZlY8FvxSKwsrCYPNOpgk9ixI1C13 jjmHWadhrt9csTXfa3+84oLpPKGjkm5nWzcKsmF3eCUMdqoCWKJzjSItxDE1yFsLl266 9YgCoQXUE60Y10w/pTt7qjpCo4MjYCMpgGlnTRfQpj0XPFYYYBG2zNd2r66nMD/Pmh/n 0Ujs1OUPo1skoLWFTbngUeBk9H47O+nou8ws2yllTFrC6eEE4HEPj4iGeUJUviOPlI4g /gvHSiUfmZYXMkFrMNKUMKPQvcCtnMffPqy38v0jcPg2BOydF1h0qE4YIIqwlenrzOl6 RCaQ== 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=SSeBOBmV5irVttghOKU/WEyUh0YnA4r3UGGroMyochk=; b=SndJNQBz1cIl8ndPh2UFzNKk8saMC70WAACuZtfgWuFfDSQsqX4g7zR9lyHWukPFq+ o0vjnJal8wHaVdcU0pi9jvbECOgC6vi7Dxy9+PDd4E7bdtFwbeEyj1zYIJeMW/oGzGHz QD59K9/iRwMUUH40bv/2F6Nj5c2zZ7c2o09mvaGcyHTQPD6t/GBuYIlkKrsH1q8Ys1W1 67FXYMp/Kdoc+aNrRXk/CLN0Y3JNNM59LCr9Si7rLWy7K4j0/XKADBrSYFxBwHaHC/u+ TVj0FwiJAVWx4kiexUaTj+B/jofAPtHCx1dorq/ranLHNgwfsHNgXpEGIBM8kUDqG2Fl XT6g== X-Gm-Message-State: AO0yUKXYOzMNcwj1BJp7qEgq7/qu014d7UzQMUzPVv1d99/HuIgnmeiP KATBwLpxCJaznk0J+mwPGTrXXucvUDY= X-Google-Smtp-Source: AK7set+DszPwpSPBVBkWWwuActthXmx+XqB/olsEL1Pq6RwXLA89syW3jS5kw/6r1MPLSHmjUCv5yg== X-Received: by 2002:aa7:8883:0:b0:58d:ca02:3fd6 with SMTP id z3-20020aa78883000000b0058dca023fd6mr12047476pfe.25.1675109925162; Mon, 30 Jan 2023 12:18:45 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:937f:7f20::a8cd]) by smtp.googlemail.com with ESMTPSA id g9-20020a056a000b8900b0058d9730ede0sm113262pfj.210.2023.01.30.12.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 12:18:44 -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 v4 4/6] mm/mempolicy: convert queue_pages_hugetlb() to queue_folios_hugetlb() Date: Mon, 30 Jan 2023 12:18:31 -0800 Message-Id: <20230130201833.27042-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230130201833.27042-1-vishal.moola@gmail.com> References: <20230130201833.27042-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 76D1080006 X-Stat-Signature: jf4gha63gmckwc87y4gtisf9o4bo93je X-HE-Tag: 1675109926-164083 X-HE-Meta: U2FsdGVkX1+OPw/+X08g0ev3sVj17aB3lS7eTbNMrMD42igUtjcNKZYTHAf+AgIqiP0aztdfZ+tLoX8nQKsTkjQQntPv4WdvEfdwx3dL0YV4p8bCHkQR+WI8GyD3B1tYjOrKqeOamL85zhScGCj0b+IQXKTNjy5jbf5loe3fAOY30ydCjkZPgyPfFCFIvtWDbToUWUsqP3KzDsI522m+6pauNRY/0ByP5FMKnFdIGHIzCZxKp/gu4OopdoLAoAqRmnz0M3CQ6IOA+f/ue4c/ETQnj3KMgjKL28IC2P5Rncme4Yd9FY9NZs2dw22i880Ih93p+XOkMXbyJFBGmQjNT6wNfuSvDX2hFKbFKTGbP2w9aIVzvGpSM9GKA17TtVnrnlGGQOWwwAKfl5BWRGSBErjBvYIEUX7Su0NCfhaLsW2/VepQjNq89OWEv3/tbDrTs+aL0/d+M1GsV4ExXU468BWHeyrrxEr3s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NLe1MAvHiwBOjNbJcnHfs0Pivn8QEh0tA== 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: 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 b0805bb87655..668392493500 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 != end ? -EIO : 0; } -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 long hmask, #ifdef CONFIG_HUGETLB_PAGE struct queue_pages *qp = walk->private; unsigned long flags = (qp->flags & MPOL_MF_VALID); - struct page *page; + struct folio *folio; spinlock_t *ptl; pte_t entry; @@ -574,13 +574,13 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask, entry = huge_ptep_get(pte); if (!pte_present(entry)) goto unlock; - page = pte_page(entry); - if (!queue_pages_required(page, qp)) + folio = pfn_folio(pte_pfn(entry)); + if (!queue_pages_required(&folio->page, qp)) goto unlock; if (flags == 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 = -EIO; @@ -591,21 +591,28 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long 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 = 1; goto unlock; } - /* 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) == 1 && + (flags & MPOL_MF_MOVE && folio_estimated_sharers(folio) == 1 && !hugetlb_pmd_shared(pte))) { - if (isolate_hugetlb(page_folio(page), qp->pagelist) && + 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 pages * which have been queued. */ ret = 1; @@ -703,7 +710,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, } static const struct mm_walk_ops queue_pages_walk_ops = { - .hugetlb_entry = queue_pages_hugetlb, + .hugetlb_entry = queue_folios_hugetlb, .pmd_entry = queue_folios_pte_range, .test_walk = queue_pages_test_walk, };