From mboxrd@z Thu Jan 1 00:00:00 1970 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 F3CD6C77B7F for ; Mon, 15 May 2023 01:55:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15EAF900003; Sun, 14 May 2023 21:55:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E979900002; Sun, 14 May 2023 21:55:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECA50900003; Sun, 14 May 2023 21:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D9662900002 for ; Sun, 14 May 2023 21:55:52 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B15AC1C8874 for ; Mon, 15 May 2023 01:55:52 +0000 (UTC) X-FDA: 80790823344.21.9581D13 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf25.hostedemail.com (Postfix) with ESMTP id 5E07AA000D for ; Mon, 15 May 2023 01:55:49 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fhykjwuv; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684115749; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iEedlGq794srWWOxHKhVxcvhtIFU/6EV1mPrX6CVoBc=; b=CBRssJr9OaY5DZ1kyv6SwaL9UiST2w2T/QFAcxkF4qxUFubIzKNs+wv/H4ShDdloHPmD1s /Lznu9ZnBy7vLZsPF5ImHU3fj+K2FBKbdIRMoiOSs4a+JN5G4V+oesaxhzpK7iNdHU7R/6 9o70naFkcmaB56eOsY+tY7khmUCbACg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fhykjwuv; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684115749; a=rsa-sha256; cv=none; b=dfP5mcGjFRRs6heI1f1RG+V2DEK9/0gg2gPsdnIDmP0DGCYi6KShq1bvkuTA/CfPqndTMq mBGUTH6WNYU9Vg5087Iaz5E+mlFaco2+8n5wm9qM+ULxWrGjcPe0IpjaP5+m6NHbxeiK9h aBhQ4AF+K9Xusv4TqD+Ve9O2VNbJUYY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684115749; x=1715651749; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=v1CZsr9uUVuMpoTTd7cKj2dNWhpse1KMOCdKLzbB9ww=; b=fhykjwuv5TWnIJM98BuD056cSG+Sbdm3rJMIrWArTOIO00Zt9yO/K4HO 474fSeWSWRK4Tvutrg4mZUJPBnSCt0E0m14IYGa2OuHm4wzdIFyS2yOUG 6Ids4efmI5ss+/QO6El8Y+nVweqMbeSiftho3MatVQElci/mg4NOOZ+qC PsLtxPDVDjgjJ33ilkOD8ef/P9A8kFg4gI53pSJUJCrFhH/CYL2/GksCT M+ah3fv3ABcFkORMpX8x31+Cp0m5DZ1K6LI4kFG6yekc8Au+Ri2cKQ1jh J44RLUKvkDj6IWGjAs8LJLtKLiR7FXaZxeZ3lPPyj874a52aS9Or+6W1f g==; X-IronPort-AV: E=McAfee;i="6600,9927,10710"; a="379245142" X-IronPort-AV: E=Sophos;i="5.99,275,1677571200"; d="scan'208";a="379245142" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 18:55:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10710"; a="733688885" X-IronPort-AV: E=Sophos;i="5.99,275,1677571200"; d="scan'208";a="733688885" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 18:55:44 -0700 From: "Huang, Ying" To: Alistair Popple Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xin Hao , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador Subject: Re: [PATCH -V2] migrate_pages_batch: simplify retrying and failure counting of large folios References: <20230510031829.11513-1-ying.huang@intel.com> <871qjoblqg.fsf@nvidia.com> Date: Mon, 15 May 2023 09:54:34 +0800 In-Reply-To: <871qjoblqg.fsf@nvidia.com> (Alistair Popple's message of "Wed, 10 May 2023 19:04:13 +1000") Message-ID: <87ilcu8ilh.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Stat-Signature: zubq9n35xm9zr35obscwwq4d3dgyh7bb X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5E07AA000D X-Rspam-User: X-HE-Tag: 1684115749-618085 X-HE-Meta: U2FsdGVkX1++/Epf8icGgFKfl+ErqS1ehXM7Bxx1sR+QRBHQAcFhYnkiheWC5m1Gl2N/YvChP+eF+oAw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KI9k31+8jo0fEYF4Y14c+X1SWAZqoPsbKbU0YpRNUSr8y6hNGLGRkoK1yfUL2qOc+kOxJZQPZKVrAW/+4LMe0qZfRMx/B9a7HkGGaPIjwUKD9sq13gTRvtKdaAJoHWKStSX+S 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: Hi, Alistair, Alistair Popple writes: > Looks good. Please add my reviewed by from v1 as well: > > Reviewed-by: Alistair Popple Sorry, I just found your email in my junk email folder. It appears that there are some bugs in my email system. I will be more careful in the future and try to find a way to fix my email system. Thanks Andrew to help add your reviewed-by in his merged version. Best Regards, Huang, Ying > Huang Ying writes: > >> After recent changes to the retrying and failure counting in >> migrate_pages_batch(), it was found that it's unnecessary to count >> retrying and failure for normal, large, and THP folios separately. >> Because we don't use retrying and failure number of large folios >> directly. So, in this patch, we simplified retrying and failure >> counting of large folios via counting retrying and failure of normal >> and large folios together. This results in the reduced line number. >> >> Previously, in migrate_pages_batch we need to track whether the source >> folio is large/THP before splitting. So is_large is used to cache >> folio_test_large() result. Now, we don't need that variable any more >> because we don't count retrying and failure of large folios (only >> counting that of THP folios). So, in this patch, is_large is removed >> to simplify the code. >> >> This is just code cleanup, no functionality changes are expected. >> >> Signed-off-by: "Huang, Ying" >> Reviewed-by: Xin Hao >> Reviewed-by: Zi Yan >> Cc: Yang Shi >> Cc: Baolin Wang >> Cc: Oscar Salvador >> Cc: Alistair Popple >> --- >> mm/migrate.c | 110 ++++++++++++++++----------------------------------- >> 1 file changed, 35 insertions(+), 75 deletions(-) >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index 01cac26a3127..2ac927a82bbc 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -1614,13 +1614,10 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> int nr_pass) >> { >> int retry = 1; >> - int large_retry = 1; >> int thp_retry = 1; >> int nr_failed = 0; >> int nr_retry_pages = 0; >> - int nr_large_failed = 0; >> int pass = 0; >> - bool is_large = false; >> bool is_thp = false; >> struct folio *folio, *folio2, *dst = NULL, *dst2; >> int rc, rc_saved = 0, nr_pages; >> @@ -1631,20 +1628,13 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> VM_WARN_ON_ONCE(mode != MIGRATE_ASYNC && >> !list_empty(from) && !list_is_singular(from)); >> >> - for (pass = 0; pass < nr_pass && (retry || large_retry); pass++) { >> + for (pass = 0; pass < nr_pass && retry; pass++) { >> retry = 0; >> - large_retry = 0; >> thp_retry = 0; >> nr_retry_pages = 0; >> >> list_for_each_entry_safe(folio, folio2, from, lru) { >> - /* >> - * Large folio statistics is based on the source large >> - * folio. Capture required information that might get >> - * lost during migration. >> - */ >> - is_large = folio_test_large(folio); >> - is_thp = is_large && folio_test_pmd_mappable(folio); >> + is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); >> nr_pages = folio_nr_pages(folio); >> >> cond_resched(); >> @@ -1660,7 +1650,7 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> * list is processed. >> */ >> if (!thp_migration_supported() && is_thp) { >> - nr_large_failed++; >> + nr_failed++; >> stats->nr_thp_failed++; >> if (!try_split_folio(folio, split_folios)) { >> stats->nr_thp_split++; >> @@ -1688,38 +1678,33 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> * When memory is low, don't bother to try to migrate >> * other folios, move unmapped folios, then exit. >> */ >> - if (is_large) { >> - nr_large_failed++; >> - stats->nr_thp_failed += is_thp; >> - /* Large folio NUMA faulting doesn't split to retry. */ >> - if (!nosplit) { >> - int ret = try_split_folio(folio, split_folios); >> + nr_failed++; >> + stats->nr_thp_failed += is_thp; >> + /* Large folio NUMA faulting doesn't split to retry. */ >> + if (folio_test_large(folio) && !nosplit) { >> + int ret = try_split_folio(folio, split_folios); >> >> - if (!ret) { >> - stats->nr_thp_split += is_thp; >> - break; >> - } else if (reason == MR_LONGTERM_PIN && >> - ret == -EAGAIN) { >> - /* >> - * Try again to split large folio to >> - * mitigate the failure of longterm pinning. >> - */ >> - large_retry++; >> - thp_retry += is_thp; >> - nr_retry_pages += nr_pages; >> - /* Undo duplicated failure counting. */ >> - nr_large_failed--; >> - stats->nr_thp_failed -= is_thp; >> - break; >> - } >> + if (!ret) { >> + stats->nr_thp_split += is_thp; >> + break; >> + } else if (reason == MR_LONGTERM_PIN && >> + ret == -EAGAIN) { >> + /* >> + * Try again to split large folio to >> + * mitigate the failure of longterm pinning. >> + */ >> + retry++; >> + thp_retry += is_thp; >> + nr_retry_pages += nr_pages; >> + /* Undo duplicated failure counting. */ >> + nr_failed--; >> + stats->nr_thp_failed -= is_thp; >> + break; >> } >> - } else { >> - nr_failed++; >> } >> >> stats->nr_failed_pages += nr_pages + nr_retry_pages; >> /* nr_failed isn't updated for not used */ >> - nr_large_failed += large_retry; >> stats->nr_thp_failed += thp_retry; >> rc_saved = rc; >> if (list_empty(&unmap_folios)) >> @@ -1727,12 +1712,8 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> else >> goto move; >> case -EAGAIN: >> - if (is_large) { >> - large_retry++; >> - thp_retry += is_thp; >> - } else { >> - retry++; >> - } >> + retry++; >> + thp_retry += is_thp; >> nr_retry_pages += nr_pages; >> break; >> case MIGRATEPAGE_SUCCESS: >> @@ -1750,20 +1731,14 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> * removed from migration folio list and not >> * retried in the next outer loop. >> */ >> - if (is_large) { >> - nr_large_failed++; >> - stats->nr_thp_failed += is_thp; >> - } else { >> - nr_failed++; >> - } >> - >> + nr_failed++; >> + stats->nr_thp_failed += is_thp; >> stats->nr_failed_pages += nr_pages; >> break; >> } >> } >> } >> nr_failed += retry; >> - nr_large_failed += large_retry; >> stats->nr_thp_failed += thp_retry; >> stats->nr_failed_pages += nr_retry_pages; >> move: >> @@ -1771,17 +1746,15 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> try_to_unmap_flush(); >> >> retry = 1; >> - for (pass = 0; pass < nr_pass && (retry || large_retry); pass++) { >> + for (pass = 0; pass < nr_pass && retry; pass++) { >> retry = 0; >> - large_retry = 0; >> 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_large = folio_test_large(folio); >> - is_thp = is_large && folio_test_pmd_mappable(folio); >> + is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); >> nr_pages = folio_nr_pages(folio); >> >> cond_resched(); >> @@ -1797,12 +1770,8 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> */ >> switch(rc) { >> case -EAGAIN: >> - if (is_large) { >> - large_retry++; >> - thp_retry += is_thp; >> - } else { >> - retry++; >> - } >> + retry++; >> + thp_retry += is_thp; >> nr_retry_pages += nr_pages; >> break; >> case MIGRATEPAGE_SUCCESS: >> @@ -1810,13 +1779,8 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> stats->nr_thp_succeeded += is_thp; >> break; >> default: >> - if (is_large) { >> - nr_large_failed++; >> - stats->nr_thp_failed += is_thp; >> - } else { >> - nr_failed++; >> - } >> - >> + nr_failed++; >> + stats->nr_thp_failed += is_thp; >> stats->nr_failed_pages += nr_pages; >> break; >> } >> @@ -1825,14 +1789,10 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, >> } >> } >> nr_failed += retry; >> - nr_large_failed += large_retry; >> stats->nr_thp_failed += thp_retry; >> stats->nr_failed_pages += nr_retry_pages; >> >> - if (rc_saved) >> - rc = rc_saved; >> - else >> - rc = nr_failed + nr_large_failed; >> + rc = rc_saved ? : nr_failed; >> out: >> /* Cleanup remaining folios */ >> dst = list_first_entry(&dst_folios, struct folio, lru);