Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp80044rdb; Wed, 7 Feb 2024 22:27:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfDRtZ8pAN77SEk101HAT3V7CbFDtCG/Do3gXyLePp4vVjWJ5qmJ3nUe9Y/Upt924rhaj+PDMp3PBKj8h9QBJO0I9I2AElRtIUs/GqWw== X-Google-Smtp-Source: AGHT+IFAb/GUd2hSYzbC5dJgZdLjx++9zz4v1FndVT91gl6l6EljK6DtAnn0ZJohmvpZDp5ujlqm X-Received: by 2002:a05:620a:89c:b0:785:a518:3d6 with SMTP id b28-20020a05620a089c00b00785a51803d6mr1973008qka.30.1707373657940; Wed, 07 Feb 2024 22:27:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707373657; cv=pass; d=google.com; s=arc-20160816; b=zLG01ijivZCB9cJQzpPEtNEG+yvNUc+vapg4dMOdJTyz6bYpXUUbG8o8dvp9mUAftM yl3Opvo8oa64PEO7AauECU+zmajpJ906hlvb72Oi331TGtPrvQYRRU0nJKdc9nSX7YSm y6HssykbFojB5aDBgkDVhgtdn/BFQK9CUAqidTrdM4c00luLtakp65Jtb8ZBhS0IHWfR JKXDvkJk25MuFUnI+rkXBoiukFNRwVnMwoXMy6ARe32FEO3VPqcX/XfDJTZQrSOuv5EA 52if++kCCKJr71X+wBxxkFLa31Y+5+Yay65F5zA0uHHpC4ySgZ4cRnnzMIQAG+Xw1one J/YA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=hj/OU3wk3OzsqULfJnD2mvtgwTJyJb/ndDOd9gzDe6E=; fh=JGWKGXRbZFFPidCo8yEYvm77CW8WWpHOGVk5MXNA5V8=; b=u9vdzeREJuycf79bv6hwzPplgjc96c8/7BWNc2h9UNOSDFdsqcQWA3uhdao7+ez2ko hnIHJfwwjVde38PYCSl/ZZOpUAkPal9f5QeN5k9Gq7V5fCcGR6CuP6h6BP2PV8HeX2rv 3Qoo9GdhUEpF/tId7C9+8NcwTttXDcRW0a4z9KFV63Lm8tZfckpNc8BpAyxAwiEPJQo1 eJrCs5EYD/STVHVt/jNoLj7ZimeRM1sFYX1YD7sJ7TcugS4xWJKGBjniEYmhtJga7S2L M+ITQFvQ1HyfulipawsZwZm/X1welPMDX5fqezsfYAgTNmOnLawWjcgsr7WURIte4wMO OwLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-57518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57518-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXzhcK8RGt5r0vSD32aABxAGfbR86dkD4G4UHnmCBM/1SqnPqZFm27NPq79OZV6QEKooacDyrgwp3fv5/VPOtliiZgVH/+hXG998Vfxqw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y2-20020ae9f402000000b00785a72ad34fsi603599qkl.83.2024.02.07.22.27.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 22:27:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-57518-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57518-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A04491C22121 for ; Thu, 8 Feb 2024 06:27:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 352226A014; Thu, 8 Feb 2024 06:26:31 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2881692E4 for ; Thu, 8 Feb 2024 06:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373590; cv=none; b=bKmFdp6dlDigX+VKC9T48VN2IWYsO7ZTDxnq3mT367VaTYbhz38ySRDy/uElRSyfjIgB1MRnR3fzf6UkgpMvRd1yP5+BcXLwSh6C+N4V9dbv93z9ZcdxUIOFDbb++NiM2nLz2Jy0wTREoMo+cN3N5+Z2bTUyeIt8Uf6kWokjl7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373590; c=relaxed/simple; bh=bOo6ompPxEjsShhZOqBiAWkLgDaqfCbo8j/HY5Q8F4Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Ld0Tmayc3z6lA5Jh0DtrGnrOaxazbJxgumznbA1oLniAWF66pGmNltl0u54DHpZZCtldwIS6MuOXbm94APqGxbf+BhWlDWpMrY3YYY7DKKW5ueYomP8f8rkD/mRy6IVsSJazSokkr2kVZtR4g1NRgsagWPaNIvWTMd0RHDFmKYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-d85ff70000001748-86-65c4740be438 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, namit@vmware.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [RESEND PATCH v7 5/8] mm: Separate move/undo doing on folio list from migrate_pages_batch() Date: Thu, 8 Feb 2024 15:26:05 +0900 Message-Id: <20240208062608.44351-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208062608.44351-1-byungchul@sk.com> References: <20240208062608.44351-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsXC9ZZnoS53yZFUg99LJSzmrF/DZvF5wz82 ixcb2hktvq7/xWzx9FMfi8XlXXPYLO6t+c9qcX7XWlaLHUv3MVlcOrCAyeL6roeMFsd7DzBZ zL/3mc1i86apzBbHp0xltPj9A6jj5KzJLA6CHt9b+1g8ds66y+6xYFOpx+YVWh6L97xk8ti0 qpPNY9OnSewe786dY/c4MeM3i8e8k4Ee7/ddZfPY+svOo3HqNTaPz5vkPN7Nf8sWwB/FZZOS mpNZllqkb5fAlXHj/V32gn6dikVzHrI3MK5U7mLk4JAQMJFY9Y2ri5ETzDw7/x0riM0moC5x 48ZPZhBbRMBM4mDrH/YuRi4OZoGPTBKrv3ewgCSEBVIkvp5uZgOxWQRUJbb+u80IYvMKmEq8 f7KSHWKovMTqDQfABnECDdq57RTYAiGgmhezJ7NB1LSzSyy9YwZhS0ocXHGDZQIj7wJGhlWM Qpl5ZbmJmTkmehmVeZkVesn5uZsY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Mr75WnqzV/5WDZRrTz3vbDS8cPpZwfuMj7tpo0eosDtsUH639kdwm n0puic3iyj/ldXTihb9TlvfyuSqxFGckGmoxFxUnAgBFmRGYawIAAA== X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Functionally, no change. This is a preparation for migrc mechanism that requires to use separate folio lists for its own handling at migration. Refactored migrate_pages_batch() and separated move and undo parts operating on folio list, from migrate_pages_batch(). Signed-off-by: Byungchul Park --- mm/migrate.c | 134 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 397f2a6e34cb..bbe1ecef4956 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1611,6 +1611,81 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, return nr_failed; } +static void migrate_folios_move(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + enum migrate_mode mode, int reason, + struct list_head *ret_folios, + struct migrate_pages_stats *stats, + int *retry, int *thp_retry, int *nr_failed, + int *nr_retry_pages) +{ + struct folio *folio, *folio2, *dst, *dst2; + bool is_thp; + int nr_pages; + int rc; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); + nr_pages = folio_nr_pages(folio); + + cond_resched(); + + rc = migrate_folio_move(put_new_folio, private, + folio, dst, mode, + reason, ret_folios); + /* + * The rules are: + * Success: folio will be freed + * -EAGAIN: stay on the unmap_folios list + * Other errno: put on ret_folios list + */ + switch(rc) { + case -EAGAIN: + *retry += 1; + *thp_retry += is_thp; + *nr_retry_pages += nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded += nr_pages; + stats->nr_thp_succeeded += is_thp; + break; + default: + *nr_failed += 1; + stats->nr_thp_failed += is_thp; + stats->nr_failed_pages += nr_pages; + break; + } + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + +static void migrate_folios_undo(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + struct list_head *ret_folios) +{ + struct folio *folio, *folio2, *dst, *dst2; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + int old_page_state = 0; + struct anon_vma *anon_vma = NULL; + + __migrate_folio_extract(dst, &old_page_state, &anon_vma); + migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, + anon_vma, true, ret_folios); + list_del(&dst->lru); + migrate_folio_undo_dst(dst, true, put_new_folio, private); + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + /* * migrate_pages_batch() first unmaps folios in the from list as many as * possible, then move the unmapped folios. @@ -1633,7 +1708,7 @@ static int migrate_pages_batch(struct list_head *from, int pass = 0; bool is_thp = false; bool is_large = false; - struct folio *folio, *folio2, *dst = NULL, *dst2; + struct folio *folio, *folio2, *dst = NULL; int rc, rc_saved = 0, nr_pages; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); @@ -1769,42 +1844,11 @@ static int migrate_pages_batch(struct list_head *from, thp_retry = 0; nr_retry_pages = 0; - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); - nr_pages = folio_nr_pages(folio); - - cond_resched(); - - rc = migrate_folio_move(put_new_folio, private, - folio, dst, mode, - reason, ret_folios); - /* - * The rules are: - * Success: folio will be freed - * -EAGAIN: stay on the unmap_folios list - * Other errno: put on ret_folios list - */ - switch(rc) { - case -EAGAIN: - retry++; - thp_retry += is_thp; - nr_retry_pages += nr_pages; - break; - case MIGRATEPAGE_SUCCESS: - stats->nr_succeeded += nr_pages; - stats->nr_thp_succeeded += is_thp; - break; - default: - nr_failed++; - stats->nr_thp_failed += is_thp; - stats->nr_failed_pages += nr_pages; - break; - } - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + /* Move the unmapped folios */ + migrate_folios_move(&unmap_folios, &dst_folios, + put_new_folio, private, mode, reason, + ret_folios, stats, &retry, &thp_retry, + &nr_failed, &nr_retry_pages); } nr_failed += retry; stats->nr_thp_failed += thp_retry; @@ -1813,20 +1857,8 @@ static int migrate_pages_batch(struct list_head *from, rc = rc_saved ? : nr_failed; out: /* Cleanup remaining folios */ - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - int old_page_state = 0; - struct anon_vma *anon_vma = NULL; - - __migrate_folio_extract(dst, &old_page_state, &anon_vma); - migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, - anon_vma, true, ret_folios); - list_del(&dst->lru); - migrate_folio_undo_dst(dst, true, put_new_folio, private); - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + migrate_folios_undo(&unmap_folios, &dst_folios, + put_new_folio, private, ret_folios); return rc; } -- 2.17.1