From patchwork Wed Jan 25 23:41:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13116415 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 B6D75C54E94 for ; Wed, 25 Jan 2023 23:41:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6DDA6B0083; Wed, 25 Jan 2023 18:41:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F7706B0087; Wed, 25 Jan 2023 18:41:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 898606B0088; Wed, 25 Jan 2023 18:41:54 -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 718816B0083 for ; Wed, 25 Jan 2023 18:41:54 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 49E331A0E98 for ; Wed, 25 Jan 2023 23:41:54 +0000 (UTC) X-FDA: 80394946548.09.96B963B Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf24.hostedemail.com (Postfix) with ESMTP id 79B4B180002 for ; Wed, 25 Jan 2023 23:41:52 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P6CDrkzJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.52 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=1674690112; 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=aN57XfC0N2Z9PnMQ9nUjXYfVmJE2FGzydu2ZVvrzX3Q=; b=sYemF0DG3TOfQQf1p+9aY2pVCMcrn6dbQPbCqEEVWuez6fbtdwixQsjqJ/0LvJrPIotQ9K 85++pDzzWWrJoFvJzI3g3yX+8u9u8xKo4akJFeXC0gJGM/JMqvFIrRFJbVpkYIZ0tSXfVi qq2rMUXRJ6BbLneBVfyfGN2RCQHU3MY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=P6CDrkzJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674690112; a=rsa-sha256; cv=none; b=TWcnsBpwr/SZ9w6gnGkLYnWr6/TyKlkANNMZAOE8HEyQ1D2Oc7w9RnmJa9vgvCI0LLQcDC GeA9akK6A3mXhVeSr+OXHmBd2iFKXpKgwD098qXFAspOtix6O8wdq8kRHhTtx53suvKhKD rHBQH5lEfXsfktuojYf0OexcwVBxT2Q= Received: by mail-pj1-f52.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so270837pjl.0 for ; Wed, 25 Jan 2023 15:41:52 -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=P6CDrkzJSgET54MDlG18KNSNOlZoW3MU7+hkgLqRJ/5Xqzgl8we5PZOg1hkICvX2CV qJuAyZ0zwDf79dalVbx6THwSx5WpRv7irQY4fWrO65cPK9qxlsBx0aRlT9bMDJUF1IWk Vdc3Flt7m1v4/SJ2NceeyIu3ROeYczykNgzpa6MKvRiWkg3DKWUnET3/mPqUh8G50olU TZeUw09UecGDHUoaAyfy+kXlHDrlCQD7OBWh+QrMS+SXz98gVihHyB7H5Lkz5OvooRno IJSQLLalXZorgQX63BTIU5Rmz6BSXpttPAnERpvzhMa9w+rhHUUo1reXjMpAwfuE0P5c DeAw== 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=044yiFSXXL5AxLBfelLBYHeObNqmAu+IbOQZEPK+mxYWF90mA3q6lmi0Tx3y34JTGf eCpW82CWG0geuLHXeusndmAJMz6/W9fZI2hIq/kBpinOE/vgTSnJ28mJ36bPFRoxCH+t hdGEZcsZWztApZzpEfXwZEeqV2ZT3HzwphNsSHP3YNHBiTZ741IS6Ieoq6Zrd2JrGIma j04FdNiJYhHQ+fY0e2aeiUCauNBBVteHLbQuNpbSMDWCDBtjuku9yT/d1OCF26p6NzcC 8FBy4BmB7bDDlD5jl4bpKWKTvK/Qk7E6gpSM0oMiPheHhIutVM9Ptx3j4IhI5SIpk/tY rxpg== X-Gm-Message-State: AFqh2kqqbB9R7F+kVClLipVKO5oNtPnlXO04R5BAeywLR85txCJkNZRm I4+oHSey3Occp2VDnRJfOU36kAdbuBClKw== X-Google-Smtp-Source: AMrXdXulsPWSiWTwVZGqHBrrwSWR9r4OEwxKEGBefyPEA2GtBCq+t9NogNmvV2nutnNPlWn7MjG4Mg== X-Received: by 2002:a17:90a:86ca:b0:225:d697:41ea with SMTP id y10-20020a17090a86ca00b00225d69741eamr36754049pjv.23.1674690111263; Wed, 25 Jan 2023 15:41:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 15:41:50 -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 6/6] mm/mempolicy: Convert migrate_page_add() to migrate_folio_add() Date: Wed, 25 Jan 2023 15:41:34 -0800 Message-Id: <20230125234134.227244-7-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-Server: rspam02 X-Rspamd-Queue-Id: 79B4B180002 X-Stat-Signature: 3am5gszw9pdb5marnehey1feo31wg7hd X-HE-Tag: 1674690112-627493 X-HE-Meta: U2FsdGVkX1+TWDk/N6dIG5/S98dAd93bWk5rKTqb4NqYu71nD9sVXt9Wp0ORvbuMBq65nxHBDkY07iVVoGObmaFraW3oc3JpAPeN3HOWzpwyqOnqZFhC/Wmcp1Zf1nRcu/Xcg5HM1ZUuj1fhC1Mu61TR+ToNIULhNDPMjNKijsLK14ExtaJl3LcjRMsFbaXd59SKAH6QjjJ2kEPoQYV/am3YlaQ2dhekrKR8o0rHdrsRWhCEPv3ePRI5RG8B1KLlUaXDniKrXcWHD56VfN7HxX7b4v+9yR0/gfNWMpGDkoX0oFc70W6qrX54h5zQgf846cAO8sDqMdONABExG9nTUo4rgEZBNdHFfR9xaZHDFOXVK1J6bajXDIj4nBIXy/QBGsmkNxTuXXu3A/CK5dVFpyCsjofARMouLfDTuTjVKwke6aqYlwKG7wOJE8lZ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vhj30ywH3p6Gd2CAxj71eOdt2t5ia1vodWA4vErc5HcXj/9OpJ08893V3Q== 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: 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] = { }, }; -static int migrate_page_add(struct page *page, struct list_head *pagelist, +static int migrate_folio_add(struct folio *folio, struct list_head *foliolist, unsigned long flags); 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 = 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 = true; } else break; @@ -1029,27 +1029,28 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, } #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 *foliolist, unsigned long flags) { - struct page *head = 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) == 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) == 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, unsigned long start) } #else -static int migrate_page_add(struct page *page, struct list_head *pagelist, +static int migrate_folio_add(struct folio *folio, struct list_head *foliolist, unsigned long flags) { return -EIO;