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 1EB7CC64ED6 for ; Wed, 1 Mar 2023 06:47:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D7796B0073; Wed, 1 Mar 2023 01:46:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 888E66B0074; Wed, 1 Mar 2023 01:46:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 728CE6B0075; Wed, 1 Mar 2023 01:46:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5F90B6B0073 for ; Wed, 1 Mar 2023 01:46:59 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2EA0F8125D for ; Wed, 1 Mar 2023 06:46:59 +0000 (UTC) X-FDA: 80519396958.26.2E240A5 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf28.hostedemail.com (Postfix) with ESMTP id 5C567C0003 for ; Wed, 1 Mar 2023 06:46:57 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aN1xo625; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677653217; 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=j4wPZF4CNsbWSynBrFcgIaSY0egkPPHLosV5c2A5sKE=; b=sPkB3CjKuEqLj8XlvqcVOCdkhchpSkQgu+5YPmEnfHp5F4VxBfP9fnQjY9ceWjRisx/NJC u+ia+4VYnHJYznwz7Zrl+ZqpyRkjYzqAzOt7OS5qZT8KpMpLBKyEuJTJkquYnYUqSlASyV Jx4683OFPD+1ZHoInNlKlG2Wx0TLFeU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aN1xo625; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677653217; a=rsa-sha256; cv=none; b=U9HtRznv4/LdbcSKeIho57VUsXUCcg8TqJ6X5FN814G9Ot5ym7jOVco4jzXs8r46BDBaLf kucmRuPnQ3zyNNJ0dLeufECzQyh1pYrRWqh7ox2Jd2EKtXoqCoEJIhhfGYLT/+GK5Pa8ZY SY+nEq+FzgqXY9m8k0ct1mNo1RJOwz0= Received: by mail-qt1-f179.google.com with SMTP id c19so13189192qtn.13 for ; Tue, 28 Feb 2023 22:46:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677653216; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=j4wPZF4CNsbWSynBrFcgIaSY0egkPPHLosV5c2A5sKE=; b=aN1xo625SNX4a+IGPlEI/k/zzV8b8809XXx9YiKlwBsfr8Q3+mWN8EWBDpH9QJhSEr EGUrhZWG7CXIU2/PkSmJfPS3n6BoHQH0qUytpnE7qgRcK2hoFvLBdFAq7XmEQDOj7x9F jYuF8jlB/cKV2cYy/u7Ix9+MQzeF4iKqffziw65wN1wFnbGxHsKVda7EsUgMXCcwAGSm AsEypPE5E776gVCexmId+MKXIv7CTASHUX7lPJyxZSn7SPMW3asRg/7JPQuTKCPIguNU ms1R2DhGNaI+/rOkrkg6yNtYVu7k6kIA2I5Tetv3ArW42wymlqNd84WiUjG5fi//oRY0 ktxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677653216; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j4wPZF4CNsbWSynBrFcgIaSY0egkPPHLosV5c2A5sKE=; b=2bixsmifbWJIEiLYG8r/G7zhTQUalbMWC4mHSEn9jTdhcPV5UduJCNs4gl5BALzwZ1 u7X5+jk8EgkOUMu2QjE166T7LGQDl1xF015O0GXKD/l0Pzdz5rfhXVrS5EPXKE47a84K Ho3t+jjVc9mY3VWjPUhdQHsr9m82dVZ+tdgZC+ZEHB3p6m+ejR1ekcaSpaJflUk2F4/T B0E3iF0xRhVY1ckUXQZmnnzFRQ9654bHX5RSZSyZ6rlO97aOSFrk0bBugvAjVhbXnxPt fHifp5u6mCGuIsV+UU0yKk+YUEzGs+Fz0gqnu26rc1RT5OzLJ1n/DN90woLpUyilAxLJ BkIg== X-Gm-Message-State: AO0yUKXa3oZYHadwz5M8TLUGYDHUU9mIxBwJO8Suh1CDbG9sgDInncZK uonMuNrb/oz0MbJTYES75QWipA== X-Google-Smtp-Source: AK7set/tYVT5D0UtWAI/7a8bpZlD3noJ/msNxV/h6vdxkkuBpxubPm3sw4EBjoo8zKASeKyjUaxM5A== X-Received: by 2002:ac8:5f84:0:b0:3b8:2b94:5bf5 with SMTP id j4-20020ac85f84000000b003b82b945bf5mr9217394qta.55.1677653216338; Tue, 28 Feb 2023 22:46:56 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id k13-20020ac8074d000000b003bfd27755d7sm5789695qth.19.2023.02.28.22.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 22:46:55 -0800 (PST) Date: Tue, 28 Feb 2023 22:46:47 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: "Huang, Ying" cc: Hugh Dickins , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Xu, Pengfei" , Christoph Hellwig , Stefan Roesch , Tejun Heo , Xin Hao , Zi Yan , Yang Shi , Baolin Wang , Matthew Wilcox , Mike Kravetz Subject: Re: [PATCH 3/3] migrate_pages: try migrate in batch asynchronously firstly In-Reply-To: <874jr5atqf.fsf@yhuang6-desk2.ccr.corp.intel.com> Message-ID: References: <20230224141145.96814-1-ying.huang@intel.com> <20230224141145.96814-4-ying.huang@intel.com> <87cz5ub5dr.fsf@yhuang6-desk2.ccr.corp.intel.com> <070f71-9af-c29a-30b9-758b5cdf6766@google.com> <874jr5atqf.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: f59qe4yp6wzfdok91ekf6z8xn7ouoij1 X-Rspamd-Queue-Id: 5C567C0003 X-HE-Tag: 1677653217-818470 X-HE-Meta: U2FsdGVkX1/uvUFxWPffdt5qBR0hWBPO1EbuJ830ZBSn7l9nX9NKvuD8LX/nVLrUJoftA3tRHp1RxDIb0Bwhm8yF5aN0wNqAuhMz5fcsSwPXwNaCN4/b5ft+sdd6LESLy7RJ/nQnmRCd2JOaueMAxDqz7T+f4BrRp9jRqykYzSZDDx8GYKlzy24lW0RgOzqdyWerkgmJfL81qtoTEVR/TZE9zxQkMVshPsKoXNV0Fb28oQcWyNV11+/zqcV2NNAVI5wNOytMbX0H685wkOA8S0YVxarUp4I2Lvy/t2BiY+2YRBYzzaECgIvcJFh6TStD/rl3Km7FcOHLiZZA/OPYLjwBLKf1IJUmLyTrUSh1McZOVhUTVxMEp+2Kh8jY0cMDKq/We8PWJm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bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 1 Mar 2023, Huang, Ying wrote: > Hugh Dickins writes: > > On Tue, 28 Feb 2023, Huang, Ying wrote: > >> Hugh Dickins writes: > >> > On Fri, 24 Feb 2023, Huang Ying wrote: > >> >> > >> >> diff --git a/mm/migrate.c b/mm/migrate.c > >> >> index 91198b487e49..c17ce5ee8d92 100644 > >> >> --- a/mm/migrate.c > >> >> +++ b/mm/migrate.c > >> >> @@ -1843,6 +1843,51 @@ static int migrate_pages_batch(struct list_head *from, new_page_t get_new_page, > >> >> return rc; > >> >> } > >> >> > >> >> +static int migrate_pages_sync(struct list_head *from, new_page_t get_new_page, > >> >> + free_page_t put_new_page, unsigned long private, > >> >> + enum migrate_mode mode, int reason, struct list_head *ret_folios, > >> >> + struct list_head *split_folios, struct migrate_pages_stats *stats) > >> >> +{ > >> >> + int rc, nr_failed = 0; > >> >> + LIST_HEAD(folios); > >> >> + struct migrate_pages_stats astats; > >> >> + > >> >> + memset(&astats, 0, sizeof(astats)); > >> >> + /* Try to migrate in batch with MIGRATE_ASYNC mode firstly */ > >> >> + rc = migrate_pages_batch(from, get_new_page, put_new_page, private, MIGRATE_ASYNC, > >> >> + reason, &folios, split_folios, &astats, > >> >> + NR_MAX_MIGRATE_PAGES_RETRY); > >> > > >> > I wonder if that and below would better be NR_MAX_MIGRATE_PAGES_RETRY / 2. > >> > > >> > Though I've never got down to adjusting that number (and it's not a job > >> > to be done in this set of patches), those 10 retries sometimes terrify > >> > me, from a latency point of view. They can have such different weights: > >> > in the unmapped case, 10 retries is okay; but when a pinned page is mapped > >> > into 1000 processes, the thought of all that unmapping and TLB flushing > >> > and remapping is terrifying. > >> > > >> > Since you're retrying below, halve both numbers of retries for now? > >> > >> Yes. These are reasonable concerns. > >> > >> And in the original implementation, we only wait to lock page and wait > >> the writeback to complete if pass > 2. This is kind of trying to > >> migrate asynchronously for 3 times before the real synchronous > >> migration. So, should we delete the "force" logic (in > >> migrate_folio_unmap()), and try to migrate asynchronously for 3 times in > >> batch before migrating synchronously for 7 times one by one? > > > > Oh, that's a good idea (but please don't imagine I've thought it through): > > I hadn't realized the way in which your migrate_pages_sync() addition is > > kind of duplicating the way that the "force" argument conditions behaviour, > > It would be very appealing to delete the "force" argument now if you can. > > Sure. Will do that in the next version. > > > But aside from that, you've also made me wonder (again, please remember I > > don't have a good picture of the new migrate_pages() sequence in my head) > > whether you have already made a *great* strike against my 10 retries > > terror. Am I reading it right, that the unmapping is now done on the > > first try, and the remove_migration_ptes after the last try (all the > > pages involved having remained locked throughout)? > > Yes. You are right. Now, unmapping and moving are two separate steps, > and they are retried separately. After a folio has been unmapped > successfully, we will not remap/unmap it 10 times if the folio is pinned > so that failed to move (migrate_folio_move()). So the latency caused by > retrying is much better now. But I still tend to keep the total retry > number as before. Do you agree? Yes, I agree, keep the total retry number 10 as before: maybe someone in future will show that more than 5 is a waste of time, but there's little need to get into that now: if you've put an end to that 10 times unmapping and remapping, that's a great step forward, quite apart from the TLB flush batching itself. (I did change "no need" to "little need" above: I do have some some anxiety about the increased latencies from keeping folios locked and migration entries in place for significantly longer than before your batching: I won't be surprised if the maximum batch size has to be lowered, if reports of latency spikes come in; and that might extend to the retry count too.) Hugh