From patchwork Tue Jan 24 01:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13113245 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 09145C54E94 for ; Tue, 24 Jan 2023 01:22:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E1016B0075; Mon, 23 Jan 2023 20:22:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 993886B007B; Mon, 23 Jan 2023 20:22:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 795866B007D; Mon, 23 Jan 2023 20:22:21 -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 61F5C6B0075 for ; Mon, 23 Jan 2023 20:22:21 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B121120273 for ; Tue, 24 Jan 2023 01:22:21 +0000 (UTC) X-FDA: 80387942082.26.A5F6721 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf29.hostedemail.com (Postfix) with ESMTP id 68457120009 for ; Tue, 24 Jan 2023 01:22:19 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lC28+7oh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.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=1674523339; 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=KfcVD7riKhkNmAFa0MFNKtAsGnENc7Ta5eoYJ4T+8pkq/S5OtvTwyO0Q0e8NA0IlEuVvrq qBo1cl7kcbN11LPLYSMx/OdfhYakNwzFKyxZzLEvVFUmS6cGEMeKQNlhkEMqTUpNNKDm7g i+Wb6fi7g5sPgy3o0iv2hoc04c8P7ug= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lC28+7oh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674523339; a=rsa-sha256; cv=none; b=nO/eN4FAjWeu0DW5eTHx+n2IOAiLCR2znvtMjCQ3NtzW98xgEZO+UhY1KmDxYOcQkBphxl HLfU8ViwMX/d2pBVrNoGCw6/SQRNj3No5a8y2Nhj0+9WI8up3sB6BZ2mADQQMxNMv0CCnv OqBfH8a7BIBxx2Nx2E1hd1aw2GsgOxk= Received: by mail-pf1-f181.google.com with SMTP id x4so10219566pfj.1 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=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=bCE84gSNxnxhrX0MFw66XXSRuSKLae59tCReuAazI1pit1fya/TfEjj5AzJ+XQeb/7 suOKkl4MQSaz8w+6aLtI6ACuO9cLNIfaLR6SSr/oU+gQPmHK/9QpZzUAxd1Iu68hCZY2 Yv22tw8UT5LIRSmCYHE27Mp/t/SMiRMzoh2ASu2ivBLjDyoHsIKT9Ee3YXn2ENaM4ITp 0qqwEf6Z+EtIY0ZMbCaVplv+1G3N4uwY51fSW5TSUcxeB72j0lkCZfbnWc7XXb0HHhOi HFtK5nbeGzhvpiB7LMrwLF6t4p6XlJJipHH/pPVOWtAbVXm83odxNvYtBQbhkkMzuDpH wVAQ== X-Gm-Message-State: AFqh2kqTuraErxfUTl/LXNDh6xXYsFeRr5LfZ3LkFZmORNsQlvd6PSB7 1j/u767vAjP5aY1cTdb3qkX+aIvjfn8= 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 X-Rspamd-Queue-Id: 68457120009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: nj3moqxhqc9qbughx3ew3kcs189h5qrw X-HE-Tag: 1674523339-385987 X-HE-Meta: U2FsdGVkX18GTZxsIfgjrzVQdD+YYqllmhuSO3hrFZjKyeBUwyYo62vki4Qyhl1D80o42C6JpMjOLCxqu8OHUM9B1xsp4mJwmC7n/pVVdiUxczSabCHudbtVnlBJSIiamBUhKF5kOznDyaJE3LYfU7AoyTTf+ig3cUc4uzt78YxQCDJ9oO+gxf3XFxIRj2HKYa00Kn/7T+fFOmufm1XiCzMbVgAMLVTlPFgoBdmpmny4Qw+9pk7za5HKL7bX1f0TznX39Z5LxWfHEa8zTPnyrEi1zsv2yDWf117HPrGZbYzTi32SM006kN+oHy71vgWzau3RrR2LM8SNGCsQ6f6ANZCnSITjMs/F7FFLJSQdo4soePU7Xev165hJMhYVYFgXAkL5h5WUFaHNRbQskIOckf2MQP3KLZ7v3YtkXPdvrnEDInqcFcjRuj7MNGQqJZvYpY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hqONKbIImV5llhasKA4Y8oLdNJSxdwOrmz/yRX77WUdYI2y1tksTuYW5QC3RK3Q== 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, };