Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3511355rdg; Tue, 17 Oct 2023 18:30:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwlDrliJcabJUcGJ71lr8oHZvMrdSD2aQQsqzbIgM3OYpFC/CMUsDmwKbjko+T3ss/y/ZI X-Received: by 2002:a05:6a20:3ca1:b0:15e:a8:6bb4 with SMTP id b33-20020a056a203ca100b0015e00a86bb4mr4373713pzj.8.1697592603793; Tue, 17 Oct 2023 18:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697592603; cv=none; d=google.com; s=arc-20160816; b=IInSnqaLwJBw/WX6mbDuG/ZquL7L3vhY6MwBKnuaG7CIEaWVjorjDELiOvIwQAOm1s 5IEMY2NVTBqVJ6bzRI7Haoi4jL9Dh12mCaHU6WAw2vuKc6kaVK2wMt0wiMZ+2eElqcFB JHt2s0KOOoPuoDqgdwxApG8nvzAnws74pBHZ3UxeRTpgu8KVzrd2bwJKgLkf5GeozWj7 VnM9f1huQT6MS7gkIHHwivavsXtoB0qG5/NWLpGuytI+l+1VvQmXvwDgUCrQZlHJDpOh fKhPaE7J+Vrsk966PnEnURko7+ifYdxwRrSM9+g4tixvZ09ioMdiBVAUbqgIRjp+Craj tmoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=vaw8zIvgGlXKtDMjy2DZ0BApCcqgVKX1mSilwsVtjd4=; fh=2J663/jND28f9ia/ysABfOMjXeEjMwF13Si0RJUBh5s=; b=jc2pCyYmd+mYeCDTTKze/qypclP8xrOAy0BZWoMHBoyMFyfqawyH3A4dXD+jAaWZMe 3M08LKX732bWLNuaKjeJcoDjFMCL+So+YdJ4kmHOA0ZstyJHQ5uNxVWopaeRMWPbL8VU 0U9AIf2pEnn/EqDEqxPQFj1SF5FpPT4fCvxNmm24MfWaJbBsjZdEWQOMYnWs9zhxnfva 94F3T0fGYtPk3dMaX1xiLdTPHxP0hibkuKsYUDknB94iI5nEN0qwxQhO7kd8JPBspMZm GcgkOrXhd8NfYjCpsLW/u9R452iVQJV0aR5r74W4LbKQr96zEJYkIHp5a+/klQ1zyM+r USsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iHF/bDjP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id kk16-20020a17090b4a1000b0027d32c5bd43si408941pjb.164.2023.10.17.18.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 18:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iHF/bDjP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7681E8027A61; Tue, 17 Oct 2023 18:30:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344199AbjJRB3s (ORCPT + 99 others); Tue, 17 Oct 2023 21:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjJRB3r (ORCPT ); Tue, 17 Oct 2023 21:29:47 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8659890 for ; Tue, 17 Oct 2023 18:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697592585; x=1729128585; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=JeZ5du+/IDSiEG8X9Aw/xnmtEi44zSfNXT00j2yIjG0=; b=iHF/bDjPEMr+RuusI87PihaUpHuA3cGLJKbFlhCYvSK1yWHzMWvWM7ZB /THuOmYurJJKMiQKoyIR4mXYd1zwfwG9ccyErkYNwBWsAdZ0YgLDhEI76 5PNQfwcGy+GdE8Fafzg7OKCP4ajhcsKIy8vlH3VIVgDtJzXQMkef72mJH ScKIRorCtIMbVMuqS6DRa07qYC1Za8ixPfuAbEkMSbgG5wGk0RWJ8KtrO 8ateiCvuUWniRhTy1FJ8HqGaDmjbvembIMHQEQLLAIzvwD5T+DYSZRz/A cvV8vcnSKxbQKtE5+yMfl6gansXVTpuffngMh2Jmxfp7HlLDXS6NTXRU1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="383136881" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="383136881" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 18:29:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10866"; a="1003568528" X-IronPort-AV: E=Sophos;i="6.03,233,1694761200"; d="scan'208";a="1003568528" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 18:29:42 -0700 From: "Huang, Ying" To: Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , Baolin Wang Subject: Re: [PATCH v3 1/2] mm/migrate: correct nr_failed in migrate_pages_sync() In-Reply-To: <20231017163129.2025214-1-zi.yan@sent.com> (Zi Yan's message of "Tue, 17 Oct 2023 12:31:28 -0400") References: <20231017163129.2025214-1-zi.yan@sent.com> Date: Wed, 18 Oct 2023 09:27:41 +0800 Message-ID: <878r8090tu.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 18:30:00 -0700 (PDT) Zi Yan writes: > From: Zi Yan > > nr_failed was missing the large folio splits from migrate_pages_batch() > and can cause a mismatch between migrate_pages() return value and the > number of not migrated pages, i.e., when the return value of > migrate_pages() is 0, there are still pages left in the from page list. > It will happen when a non-PMD THP large folio fails to migrate due to > -ENOMEM and is split successfully but not all the split pages are not > migrated, migrate_pages_batch() would return non-zero, but > astats.nr_thp_split = 0. nr_failed would be 0 and returned to the caller > of migrate_pages(), but the not migrated pages are left in the from page > list without being added back to LRU lists. > > Fix it by adding a new nr_split counter for large folio splits and adding > it to nr_failed in migrate_page_sync() after migrate_pages_batch() is > done. > > Fixes: 2ef7dbb26990 ("migrate_pages: try migrate in batch asynchronously firstly") > Signed-off-by: Zi Yan > Cc: Baolin Wang > Cc: David Hildenbrand > Cc: Huang Ying > Cc: Matthew Wilcox LGTM except a trivial issue below, not a big deal. Thanks! Reviewed-by: "Huang, Ying" > --- > mm/migrate.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index c602bf6dec97..fc2e70b17704 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1495,6 +1495,7 @@ struct migrate_pages_stats { > int nr_thp_succeeded; /* THP migrated successfully */ > int nr_thp_failed; /* THP failed to be migrated */ > int nr_thp_split; /* THP split before migrating */ > + int nr_split; /* Large folio (include THP) split before migrating */ > }; > > /* > @@ -1614,6 +1615,7 @@ static int migrate_pages_batch(struct list_head *from, > int nr_retry_pages = 0; > int pass = 0; > bool is_thp = false; > + bool is_large = false; > struct folio *folio, *folio2, *dst = NULL, *dst2; > int rc, rc_saved = 0, nr_pages; > LIST_HEAD(unmap_folios); > @@ -1629,7 +1631,8 @@ static int migrate_pages_batch(struct list_head *from, > nr_retry_pages = 0; > > list_for_each_entry_safe(folio, folio2, from, lru) { > - is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); > + is_large = folio_test_large(folio); > + is_thp = is_large && folio_test_pmd_mappable(folio); > nr_pages = folio_nr_pages(folio); > > cond_resched(); > @@ -1649,6 +1652,7 @@ static int migrate_pages_batch(struct list_head *from, > stats->nr_thp_failed++; > if (!try_split_folio(folio, split_folios)) { > stats->nr_thp_split++; > + stats->nr_split++; > continue; > } > stats->nr_failed_pages += nr_pages; > @@ -1677,11 +1681,12 @@ static int migrate_pages_batch(struct list_head *from, > nr_failed++; > stats->nr_thp_failed += is_thp; > /* Large folio NUMA faulting doesn't split to retry. */ > - if (folio_test_large(folio) && !nosplit) { > + if (is_large && !nosplit) { > int ret = try_split_folio(folio, split_folios); > > if (!ret) { > stats->nr_thp_split += is_thp; > + stats->nr_split += is_large; We have tested is_large above, so, "++" is enough here. Not a big deal, only change it if you think it's necessary. > break; > } else if (reason == MR_LONGTERM_PIN && > ret == -EAGAIN) { > @@ -1827,6 +1832,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio, > stats->nr_succeeded += astats.nr_succeeded; > stats->nr_thp_succeeded += astats.nr_thp_succeeded; > stats->nr_thp_split += astats.nr_thp_split; > + stats->nr_split += astats.nr_split; > if (rc < 0) { > stats->nr_failed_pages += astats.nr_failed_pages; > stats->nr_thp_failed += astats.nr_thp_failed; > @@ -1834,7 +1840,11 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio, > return rc; > } > stats->nr_thp_failed += astats.nr_thp_split; > - nr_failed += astats.nr_thp_split; > + /* > + * Do not count rc, as pages will be retried below. > + * Count nr_split only, since it includes nr_thp_split. > + */ > + nr_failed += astats.nr_split; > /* > * Fall back to migrate all failed folios one by one synchronously. All > * failed folios except split THPs will be retried, so their failure -- Best Regards, Huang, Ying