From patchwork Wed Jan 25 23:41:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13116413 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 2F070C27C76 for ; Wed, 25 Jan 2023 23:41:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F5066B0085; Wed, 25 Jan 2023 18:41:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8987B6B0083; Wed, 25 Jan 2023 18:41:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 738246B0085; Wed, 25 Jan 2023 18:41:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 63CD46B0081 for ; Wed, 25 Jan 2023 18:41:52 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 415CC1A0E98 for ; Wed, 25 Jan 2023 23:41:52 +0000 (UTC) X-FDA: 80394946464.19.9F70306 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf19.hostedemail.com (Postfix) with ESMTP id 511E71A001A for ; Wed, 25 Jan 2023 23:41:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dmcxWY8U; spf=pass (imf19.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674690110; a=rsa-sha256; cv=none; b=Yfo0D3hrmyU/WL/R432LXwjlOnV/dR3GP54GFks0+xHyyfpc8SCDQxMXP93YF9bPxN/ELg aV6RbSqaSpWBN8P32KFYzaJn2zoq2aWwopMsW0RDZR2aUvfytwb4WryXOgofbyRTVXS/om 9/2h76bO0NwY+8XLyv7QudzvuXS9E+M= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dmcxWY8U; spf=pass (imf19.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674690110; 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=Sz4HU32GWbuxfmIkQjW0u4ISqBHZ5RIiVnsfOJ2Lp54=; b=r8zzmpvAbXcheHTpcb0fHWztrotHV6LugIk2QKCDnXpCStrhlRECizbSS3306vomCoLUDK JnuUVb6tKVwakHh4qO7PG+7CPxps+ou6168bSyhr4co09nboSZB0s7mfmx77hMaQKWB9R1 FHwnsh9P4nlczy3qj7JecOhPdQpUyhU= Received: by mail-pj1-f44.google.com with SMTP id b24-20020a17090a551800b0022beefa7a23so3715798pji.5 for ; Wed, 25 Jan 2023 15:41:50 -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=dmcxWY8U8wAh2AlCeZFmiUjni88jRf+FuhGzSc73OspKeJg/jDgHIv8asRJVZPLE7M GeKI9hjadJUH2P0ponOvP3pbBraa8S/sk+8nTl4/oqYo8JIFSVUDaHw97FrPx7bfNMeo IJM+6DNiaCAdp7b5r7OTFO2h/cIicEasMLMQulW80HW0FxGMwht/P0Z1SgDxEeIXj8ay 2XqexkXBfBMFdPiiPa5MRPZOB4u9lcaP/PQFrDUw4y91ocEY92PcwC3UgXttppZ+VloB bHpeYO3CnwoDG+CP4gqrrpWVu95EqQynL873hIUCRONzU4/DRWp2/OjNZ5OfpzIHluv5 h5Vw== 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=s1ZkoeH/pZJ7GMViUcJ8fZRK5+Skt2CwiOuNhw+ocqkzCV8nHGYEou6/PFQ5EnJbiL I1IaSautcCKYmSc3GT+QJIxUP3GDElmmxJhDalvjKrHc7KsyTz8obxb2KsNUvP6lT9kJ /rzmZJVEmTm0C6aUtJc5gNgH8XuWdfY/W07+SK9yzrokwDdz9IyAnzt4jPEH5CumHVlo Ant0NmnvwLmCATIYsUgA+D/eDhxeIQxJaVWdrnrUlevADLeQDm1SfARRTqKKTk0t/Koh Zzj5RzL5nGjf4wd3t6bUtqju9xv+q6grHOeh3ioSaSSj1Z8A8uq5yvzH431ISgCJLTag K/Ng== X-Gm-Message-State: AFqh2kpTSYY/85mpSY5VDcQvFz8qY+32P+rZqT2EsJ0ka99A4d0Z6sGY yrIIeT7ZGmf1sE0ou0PXcIsj7MujtQrKNA== X-Google-Smtp-Source: AMrXdXsXHo3GclXuQ2bpTqlIoBZsCQOEjXZP3AX7aqO/uZ63Y2s2D6JyQLIgnnmthEvorHx4y3b9Fg== X-Received: by 2002:a17:90b:4fc2:b0:229:680:1729 with SMTP id qa2-20020a17090b4fc200b0022906801729mr34762484pjb.10.1674690108968; Wed, 25 Jan 2023 15:41:48 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::4e4b]) by smtp.googlemail.com with ESMTPSA id e8-20020a17090a630800b00219752c8ea5sm2226806pjj.37.2023.01.25.15.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 15:41:48 -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 v3 4/6] mm/mempolicy: Convert queue_pages_hugetlb() to queue_folios_hugetlb() Date: Wed, 25 Jan 2023 15:41:32 -0800 Message-Id: <20230125234134.227244-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230125234134.227244-1-vishal.moola@gmail.com> References: <20230125234134.227244-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 511E71A001A X-Rspamd-Server: rspam01 X-Stat-Signature: gw13a6izg8jegrrmqsi3hnxhzyf5mxj7 X-HE-Tag: 1674690110-53618 X-HE-Meta: U2FsdGVkX18woAi5gppqzSeLkv0iL6yr02uN0HHKhMvWXZdItsr7uJuI1b5ilnYW5PvCSw+x4iVztEfDn+ikTtKPa0GYHv2GAszWADXO6Q8HaOn/Z0Jaudec/e9EroJF9zuTNJ2kSp73Ln/X4/MaV9/4LjYdfJ/xBJP/3GVRRIZwSqwzWOqvcNH34NP3ziqNSub7/XZkW9/B+rn0KnHibEH2QcqgHlHVwlkVBS1IqgPWe0bBsRrlwHxiIucIppZwJmeKpGlypl7mwfmhhSd08Wm6EsxqKtW39XpWZulzP/focK83pf21BPUkt+ncYNvFOvTGskTTnNOpPpwaYiBFkIoYa0nIf9J2zOpH5OrDjrlJLM1Q9KLu2g7iSh46cCFhWg2yzXgTniRptXBXc4rjZNxYj3iZi3uMToq9ppgXUOIIaXOix16j9eIeM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DtusNulXXYzJiiRcOdl0eTWUda+SuK1LwA8xrfR6dvgLPJZqmTe783By+P5O20FRc2xy6J4EqvoA== 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 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 != 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,20 +591,27 @@ 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)) { - if (isolate_hugetlb(page_folio(page), qp->pagelist) && + (flags & MPOL_MF_MOVE && folio_estimated_mapcount(folio) == 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 = 1; @@ -702,7 +709,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, };