Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2504806rwl; Mon, 26 Dec 2022 16:33:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3gIB0iKyz7e9C/gZge1881Zq+Ei7FLZZh9K2J3c/ZUdYFfg+sBQ5oTOLKNvFjXpuWSAxj X-Received: by 2002:a05:6402:6d8:b0:461:1998:217f with SMTP id n24-20020a05640206d800b004611998217fmr17864392edy.4.1672101225514; Mon, 26 Dec 2022 16:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672101225; cv=none; d=google.com; s=arc-20160816; b=naFUThTGXBpWRU2Dc1s4W0fzmInEVx8LGAPS13C5F7NdS/+kmNGUZB4cK46pBpmmMP jY3jGAxnHBMYP97gO4p1/qV4JxCtF8xnpakA/+awuYrLR1Qi2n0bucV+BPYXuAGkL1VK WpC0bQYuZcWnJm6x/xh1+gj4QtuRAByQf0qdK9YK3Cbp3w64TdKddrRKOJzvpXB/Jr3q 8zzXRYTMR+JlypuPGmeIP10o3hGnzhyKCM4tvQrTpMa8yMugGAgum7Xm8m+37f6zfU4U coFPjCn44hxHJYntkwrvwGwZ/OkhdXbAVcMmmIeIY9D9gNvmStsCQy1Om1PgMIdsgJ6a mCTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eLdqYltBVLujlBa34RffV+DhEK2QGJf9sLFKaJk8IOI=; b=C6GS4e/KWXGsknvEPX8iE88n30rmj81o4xgHt4qdCgJcWo4UXgs6m/KlxQOlbcggGj GGStbURowLBLVQxqzQsd26KCQR+44I88lZI6TM8lsdUNE/PpwAfYOa4Ni1QovPRxBOW6 oewPcNiIrsdbGYKz7IwgQx8zfrmzPI98XPzYtgTf4lQgspFijYU7atpfHEGj9kaYZmmm Mi2vIH2F3jMeeK+rx0UWLEm880lFbbfrXeol/cNAXAPaEwUG9pYAQj9FyVJhLo39kl5W kibIOkusehVi5fPnVrtXYsokpdUUcNpz1pSv4sLaUVff+KK6vrx4sKQpfGXqk/Ah9BXP WAeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FuOQiOXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a056402084500b00463b0df4604si11278668edz.488.2022.12.26.16.33.29; Mon, 26 Dec 2022 16:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FuOQiOXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232067AbiL0Aan (ORCPT + 66 others); Mon, 26 Dec 2022 19:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232615AbiL0A3y (ORCPT ); Mon, 26 Dec 2022 19:29:54 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B85126F9 for ; Mon, 26 Dec 2022 16:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672100987; x=1703636987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vd3x7uf76BZx4AuXVaHyrVdNIQHfuHN+j/7ggUNEXew=; b=FuOQiOXknbxkHHl5wg2Cjic+Ln6l1+wZLZzV5nQshTYJesSKn1Azz0rt YeVyfRLh5dw0HMykHtMd9sYco8W7dXqNzFTONsjdyGchbNbtYw/H2nS1y RSg57LghW43pc/1PgSu7DF2OGbhMmtYrar+RVmMHS3g+TDo74yYBxEfwN a/KFnh+5SqYhqJa8sBB1nb5So4Gxt4bxlvQe6wjazHnoaQ9+DnQx0lavh JAF/t4GAFEsBQ8FTmAFQ7EfiEVeVTVeFdkTb/c/l5ANK00FVSfvCO5KbX cVxkyD3OnQSZzhiywtc9XOVVvDaBo1SdfA/lo6n6NYB3eSFUkwcuKewCe A==; X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="322597269" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="322597269" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 16:29:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="760172236" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="760172236" Received: from yyang3-mobl1.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.254.212.104]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 16:29:42 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin Subject: [PATCH 6/8] migrate_pages: move migrate_folio_done() and migrate_folio_unmap() Date: Tue, 27 Dec 2022 08:28:57 +0800 Message-Id: <20221227002859.27740-7-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221227002859.27740-1-ying.huang@intel.com> References: <20221227002859.27740-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just move the position of 2 functions. There's no any functionality change. This is to make it easier to review the next patch via putting code near its position in the next patch. Signed-off-by: "Huang, Ying" Cc: Zi Yan Cc: Yang Shi Cc: Baolin Wang Cc: Oscar Salvador Cc: Matthew Wilcox Cc: Bharata B Rao Cc: Alistair Popple Cc: haoxin --- mm/migrate.c | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index dd68c3de3da8..70b987391296 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1051,6 +1051,23 @@ static void migrate_folio_undo_dst(struct folio *dst, folio_put(dst); } +static void migrate_folio_done(struct folio *src, + enum migrate_reason reason) +{ + /* + * Compaction can migrate also non-LRU pages which are + * not accounted to NR_ISOLATED_*. They can be recognized + * as __PageMovable + */ + if (likely(!__folio_test_movable(src))) + mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + + folio_is_file_lru(src), -folio_nr_pages(src)); + + if (reason != MR_MEMORY_FAILURE) + /* We release the page in page_handle_poison. */ + folio_put(src); +} + static int __migrate_folio_unmap(struct folio *src, struct folio *dst, int force, bool force_lock, enum migrate_mode mode) { @@ -1186,6 +1203,57 @@ static int __migrate_folio_unmap(struct folio *src, struct folio *dst, return rc; } +/* Obtain the lock on page, remove all ptes. */ +static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, + unsigned long private, struct folio *src, + struct folio **dstp, int force, bool force_lock, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret) +{ + struct folio *dst; + int rc = MIGRATEPAGE_UNMAP; + struct page *newpage = NULL; + + if (!thp_migration_supported() && folio_test_transhuge(src)) + return -ENOSYS; + + if (folio_ref_count(src) == 1) { + /* Folio was freed from under us. So we are done. */ + folio_clear_active(src); + folio_clear_unevictable(src); + /* free_pages_prepare() will clear PG_isolated. */ + list_del(&src->lru); + migrate_folio_done(src, reason); + return MIGRATEPAGE_SUCCESS; + } + + newpage = get_new_page(&src->page, private); + if (!newpage) + return -ENOMEM; + dst = page_folio(newpage); + *dstp = dst; + + dst->private = NULL; + rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); + if (rc == MIGRATEPAGE_UNMAP) + return rc; + + /* + * A page that has not been migrated will have kept its + * references and be restored. + */ + /* restore the folio to right list. */ + if (rc != -EAGAIN && rc != -EDEADLOCK) + list_move_tail(&src->lru, ret); + + if (put_new_page) + put_new_page(&dst->page, private); + else + folio_put(dst); + + return rc; +} + static int __migrate_folio_move(struct folio *src, struct folio *dst, enum migrate_mode mode) { @@ -1239,74 +1307,6 @@ static int __migrate_folio_move(struct folio *src, struct folio *dst, return rc; } -static void migrate_folio_done(struct folio *src, - enum migrate_reason reason) -{ - /* - * Compaction can migrate also non-LRU pages which are - * not accounted to NR_ISOLATED_*. They can be recognized - * as __PageMovable - */ - if (likely(!__folio_test_movable(src))) - mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + - folio_is_file_lru(src), -folio_nr_pages(src)); - - if (reason != MR_MEMORY_FAILURE) - /* We release the page in page_handle_poison. */ - folio_put(src); -} - -/* Obtain the lock on page, remove all ptes. */ -static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page, - unsigned long private, struct folio *src, - struct folio **dstp, int force, bool force_lock, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) -{ - struct folio *dst; - int rc = MIGRATEPAGE_UNMAP; - struct page *newpage = NULL; - - if (!thp_migration_supported() && folio_test_transhuge(src)) - return -ENOSYS; - - if (folio_ref_count(src) == 1) { - /* Folio was freed from under us. So we are done. */ - folio_clear_active(src); - folio_clear_unevictable(src); - /* free_pages_prepare() will clear PG_isolated. */ - list_del(&src->lru); - migrate_folio_done(src, reason); - return MIGRATEPAGE_SUCCESS; - } - - newpage = get_new_page(&src->page, private); - if (!newpage) - return -ENOMEM; - dst = page_folio(newpage); - *dstp = dst; - - dst->private = NULL; - rc = __migrate_folio_unmap(src, dst, force, force_lock, mode); - if (rc == MIGRATEPAGE_UNMAP) - return rc; - - /* - * A page that has not been migrated will have kept its - * references and be restored. - */ - /* restore the folio to right list. */ - if (rc != -EAGAIN && rc != -EDEADLOCK) - list_move_tail(&src->lru, ret); - - if (put_new_page) - put_new_page(&dst->page, private); - else - folio_put(dst); - - return rc; -} - /* Migrate the folio to the newly allocated folio in dst. */ static int migrate_folio_move(free_page_t put_new_page, unsigned long private, struct folio *src, struct folio *dst, -- 2.35.1