From patchwork Tue Jan 7 00:03:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13927912 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 85260E77188 for ; Tue, 7 Jan 2025 00:04:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D233D6B00CB; Mon, 6 Jan 2025 19:04:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C5A536B00CC; Mon, 6 Jan 2025 19:04:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAC9F6B00CD; Mon, 6 Jan 2025 19:04:03 -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 888E26B00CB for ; Mon, 6 Jan 2025 19:04:03 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 46A9F43802 for ; Tue, 7 Jan 2025 00:04:03 +0000 (UTC) X-FDA: 82978707966.20.B2F3C51 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf01.hostedemail.com (Postfix) with ESMTP id 6B0DD40016 for ; Tue, 7 Jan 2025 00:04:01 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=uA7u9b2V; spf=pass (imf01.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.170 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736208241; 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=Tds7HvhDScwv0+DAQP1llxCN/3UO28LajkOSfhGyREo=; b=IrPP60dHkIzvWB8QB/99iNwA+2ewWm3pm90ZBCwqOt+2oEeSyYMXK1duYgG1k65yNQLZtt 15FuPcMUfSYV1j6pfxtieb4/Y1eyEb7pCiZIboRbxBhDbZ660S/+6H8gP3teYKa+9m+2o2 SJRwlKFcBqs0iQqC0quTYSAF/nSk+RA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=uA7u9b2V; spf=pass (imf01.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.170 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736208241; a=rsa-sha256; cv=none; b=A2Mp6VWNJ2Ahbzr5An7q1fb6GV8bEnWHfB6G1UMC0FKkUK3zcAdgC4coPUCuB+8xJtnr5e H+jGw1oBJxUgdak3gZDoirNccHdZ1vBK7A4ndqW2jR+dKNAPHNtPfZQCGABxg2Abs+FSNf itYKKf6t6gjsPmnw0EekABPqrlCno1c= Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b6f0afda3fso1436093385a.2 for ; Mon, 06 Jan 2025 16:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736208240; x=1736813040; darn=kvack.org; 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=Tds7HvhDScwv0+DAQP1llxCN/3UO28LajkOSfhGyREo=; b=uA7u9b2VpII6wM43sn2662gy/VeERXWqgMzgZPyQcp/u3sm9s9pZJ5nc6bcR83HkfC xcwthly5HdcJjQVoYWQB1cjv3YNZwqD2NKj/FIrdKS0y6zRswyMNr4d1T5akS6OIIVRR Peg0N3qyeT1EGPE5R9jTLu4rgpXNWfBTqDmiAZ5ISPkr45zX5J7XdPEnGLb3y6dgsSmz Hb4xdK1SshO2xqPZgzhBIr3QZQUpJoE5sLVp0YnuWHDBv07tGNpY7wolx6LfgnVJit9v TYY2RJavIdS+8uZQDKIEIvefNwGFy4KlJe5eUVpYO3KPhQKbHHmgl17XMb/haYQies+l vapg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736208240; x=1736813040; 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=Tds7HvhDScwv0+DAQP1llxCN/3UO28LajkOSfhGyREo=; b=f7jW3j3KhvwaMMBlhBED77lfJZdDiypROAxKXxk9cgvOKOvhE0IVmILEJKhQyqkin7 cbcDz5j7RbrSbRqi3Lm6meekFmrcV9OFR5OGKzS97w3AXvokyTxiFLmrbQvcVHTpSHeW Gd9dRW88DydT5BkT3UJ7lLkSgJ6xM+5ycIwiEwkeGGfYYvzxLGpFyRZ+NsyKKW0v7cXG RJrx3o6LKq8jg5kdl9gjP6etthwFfu0LT2WYVZJagLzBJ1C4jAML404le9onW5IO3g9i ou0h1HJYsVJXElco48Tc0A2OlGdntGoi4t3wAHhNmW+50Y9hM8RlqY0twoEM0eq7IBoY tvRA== X-Gm-Message-State: AOJu0YxF+ramultSs/es6py5HK9iuOsx4zJC2mItHQLUbsenHuXsmTTY +EmpoLzbHJ3Y+M+dOa91cF8YZ0inoJodL6gXzdVX6f2WfwXkWG8NdNNRiAbEu1nMcPUxEolWVvw c X-Gm-Gg: ASbGncuwHNGKqqKWEw5+Mlp0le/zzEbYV6RaYQh8ZtjRU2UrJWamE3Ea5/a5r/EXQgD FOweINwgYwPppTnD688RLRuABa9NnK1eFMMA9uFDPEqCQ9HXui4TtQk9Db/QiEfOQKoqSfALBGI lti/uP5P7ui8iilAGaqJUrG2Nlk1BQHnmA0ZY/Mclzt4WI+kZbhlqVqB+IlRHIDq07l+ULBz+AN ArthXbRH1xVYY6Dhz1TOsh/809id09hkCnSef/BZpM2+PCz0uDwDCNBDb54B7rKoCfjEo9tKZRl sSF9De/bizrUOqoT9Vj1J9eBYNXG+3dr8fSQKFU8oRNf X-Google-Smtp-Source: AGHT+IEehELWmcBbdecL9es36IQOdasnFILqW/uOVVAwd8+bi/x2W25liHS2wXN9vDABgW4tYHvLfg== X-Received: by 2002:a05:6214:766:b0:6d4:1b2b:c836 with SMTP id 6a1803df08f44-6dd233b7f4cmr1061964726d6.47.1736208240369; Mon, 06 Jan 2025 16:04:00 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18137218sm174104476d6.57.2025.01.06.16.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 16:04:00 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, nehagholkar@meta.com, abhishekd@meta.com, david@redhat.com, nphamcs@gmail.com, gourry@gourry.net, akpm@linux-foundation.org, hannes@cmpxchg.org, kbusch@meta.com, ying.huang@linux.alibaba.com, feng.tang@intel.com, donettom@linux.ibm.com Subject: [PATCH v3 5/6] migrate: implement migrate_misplaced_folio_batch Date: Mon, 6 Jan 2025 19:03:45 -0500 Message-ID: <20250107000346.1338481-6-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250107000346.1338481-1-gourry@gourry.net> References: <20250107000346.1338481-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 8n5anpz71qbuqk7yzmpcrbwd3fbhqsb3 X-Rspamd-Queue-Id: 6B0DD40016 X-Rspam-User: X-HE-Tag: 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st8e5A9qr66IlBKqlrzRNfA8LA4n25aCcQ6ky0Fmi8qCYCwcTIMRzmt0qX4//Cjgij6v6/LcIiRfTifyPsHVJFd11GGKM8qAsPkbN5LKh6Hvj9JXXkGY0B1OMzC2BJw9odTsPiuDQVxGwIg3Pdq1sxVipum0bTWY4//jpLmWKOQwbBvFbc2d2MqLs8OlzUSRN8cWtUORUp+wSdp+H7N8yeFJyMsrjR/DVPxEMbPvrD+/AxwDCt0yZsfhntSuAa1GEIQxvCshkWHXr/Z627nfllSRnFc2L 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: List-Subscribe: List-Unsubscribe: A common operation in tiering is to migrate multiple pages at once. The migrate_misplaced_folio function requires one call for each individual folio. Expose a batch-variant of the same call for use when doing batch migrations. Signed-off-by: Gregory Price --- include/linux/migrate.h | 5 +++++ mm/migrate.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 29919faea2f1..3dfbe7c1cc83 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -145,6 +145,7 @@ const struct movable_operations *page_movable_ops(struct page *page) int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node); int migrate_misplaced_folio(struct folio *folio, int node); +int migrate_misplaced_folio_batch(struct list_head *foliolist, int node); #else static inline int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node) @@ -155,6 +156,10 @@ static inline int migrate_misplaced_folio(struct folio *folio, int node) { return -EAGAIN; /* can't migrate now */ } +int migrate_misplaced_folio_batch(struct list_head *foliolist, int node) +{ + return -EAGAIN; /* can't migrate now */ +} #endif /* CONFIG_NUMA_BALANCING */ #ifdef CONFIG_MIGRATION diff --git a/mm/migrate.c b/mm/migrate.c index ea20d9bc4f40..a751a995f2d9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2705,5 +2705,36 @@ int migrate_misplaced_folio(struct folio *folio, int node) BUG_ON(!list_empty(&migratepages)); return nr_remaining ? -EAGAIN : 0; } + +/* + * Batch variant of migrate_misplaced_folio. Attempts to migrate + * a folio list to the specified destination. + * + * Caller is expected to have isolated the folios by calling + * migrate_misplaced_folio_prepare(), which will result in an + * elevated reference count on the folio. + * + * This function will un-isolate the folios, dereference them, and + * remove them from the list before returning. + */ +int migrate_misplaced_folio_batch(struct list_head *folio_list, int node) +{ + pg_data_t *pgdat = NODE_DATA(node); + unsigned int nr_succeeded; + int nr_remaining; + + nr_remaining = migrate_pages(folio_list, alloc_misplaced_dst_folio, + NULL, node, MIGRATE_ASYNC, + MR_NUMA_MISPLACED, &nr_succeeded); + if (nr_remaining) + putback_movable_pages(folio_list); + + if (nr_succeeded) { + count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); + mod_node_page_state(pgdat, PGPROMOTE_SUCCESS, nr_succeeded); + } + BUG_ON(!list_empty(folio_list)); + return nr_remaining ? -EAGAIN : 0; +} #endif /* CONFIG_NUMA_BALANCING */ #endif /* CONFIG_NUMA */