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 A1C6EEE49A5 for ; Mon, 21 Aug 2023 07:53:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DC39900002; Mon, 21 Aug 2023 03:53:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98D118D0001; Mon, 21 Aug 2023 03:53:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85387900002; Mon, 21 Aug 2023 03:53:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 752848D0001 for ; Mon, 21 Aug 2023 03:53:03 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3E433A03EB for ; Mon, 21 Aug 2023 07:53:03 +0000 (UTC) X-FDA: 81147345846.26.04560CC Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf24.hostedemail.com (Postfix) with ESMTP id 0E91218001E for ; Mon, 21 Aug 2023 07:52:58 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692604381; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1H1+6z7gQWmpQfU53m3wusM5MBA7D95sxzTNzJz1u4M=; b=p02Y0uUcgUasw6lz9bG0bd5kSAwcD5a7KXqdXLe3MeCjPvZfqI63Tlmhe5/hGndYR+fs+u 6ciMla9T8mrxir4HtA9rFKAKpDzjpiSfmO0eFYpjHU3zS0LzLlim8LkWhvassdxheuACS8 UeNNEN5YxJKiD9b7NN5jhfgWtDnqN2g= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692604381; a=rsa-sha256; cv=none; b=HuLLZLZ24bZuKXc0SFj6gGTrTo8OneQnMyNIUgSSl9jEBn4HjnFg1cW3HG6qqNmPX1WknZ ZVztgmKO8hZnj54dtqxP09lgOd7yTqIYE5QlNhdQx7bSzvvqDnM/bfSLaJWlhrQBju7o6t zJhCWt5ICHU8bnPVcm0kdP7DqEGNuPM= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VqE2ap9_1692604372; Received: from 30.97.48.69(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VqE2ap9_1692604372) by smtp.aliyun-inc.com; Mon, 21 Aug 2023 15:52:53 +0800 Message-ID: Date: Mon, 21 Aug 2023 15:52:53 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH 1/4] mm: migrate: move migration validation into numa_migrate_prep() To: "Huang, Ying" Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, shy828301@gmail.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <87h6otdtm6.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Baolin Wang In-Reply-To: <87h6otdtm6.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 0E91218001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dzh3acebftt8fd9h93y76puhpotej9e9 X-HE-Tag: 1692604378-809779 X-HE-Meta: U2FsdGVkX19pROEChTrDFG0OQXg3V9agT+KxrDOcBbxrxIAZG7Pc4nxxbMgpcG64QU7SrieQG9pbd0Sc8VG8n6Ua7x/5mMoyna626Yl55kJ+CAubRywS9dqhZDNhYqRLUJUJEovhlnkdqBEGEi17aPuCqjWhFItDoZgu2jgBbTdHb6qTvbfIcnpiY2CfpVb4Z51oMqvui+5qJ/HJR01q/kAj5jqwuB2A81YYP3Odgpagpvn0xRAFzUiuDiClrnNDw9CrNoGhCrjyzVsvPi9WFVpkCKZpN7RBVhO0jeV0RSdDtHNvWJLUBUrWh0jkU5wLHAQqrAx+VmXT4lytrpvS5DPjr/d1K/lw7XlKZn6Xy0c4Vx9ECIrFO8zEC+MPz6wul606VDm3tiEs4eu7mIh4MuFC5Aj0Et3OLyLjdaidqx+G7hUQ3/DACxnmRcNXj0Qw8uOoLbWeT3GNEtpzJar2EzjK703kcM4hfuSs55coWB6o70IxlsgcE83Hem8MKpnjTTd/z1/i0NEduWaag10v2BaVo9oQ1lUAWy89EGi9YhVT1UVRbY+qZF9LF4YegzBMHX6rnvtRkOH7H2ZaTlBNOYbqYkdVaPzIZPnhh/O+uBCfNXLhha+eXrnd87Ax2EZYcXz90Zue70br/NF1DHExQw02SvccfJE/31hns8TDPbAXYn1Y1G9K2W8aNSLpHv84w94OWTQAoP6+aZByeZjL5PKZIPrWj8qGUTRi4/K5jZYcjIJjfoIXTcqrM21lsMUWjyj7nCPThchMAf9NtqmUe761XY1Q3rO6kH0UXPElhwn1SrpxxGnTydlhQuhYHUhl7FLcSTiLj5b4Va/+LkP17Pjhidpka8UjE1+GyTY0hYBJUI/0UZuXae/6Agf3Swte57UM3MGMpVTBEbyYHP9Adog64SO8/a1i/sJq0XpQVCubEMpQp6XjYCWh4mb6UVQeu9f/BPBsyJo61BI/HJ1 wWMb1bbg Tn991c/Z4Rkjm3FMtwS8JC6XH+AJun+UjSGE3XwTHMS5f+QpbTc06BDncAAPGIMZwjNh7cNh0XRnx1IotFPSWkooxbL1In6iY5T51pfHLj21kKAQ7glHnpcRgZkT7L3ZghbrcKDsl5hfg22dOnCnFkHPn8w== 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: On 8/21/2023 10:20 AM, Huang, Ying wrote: > Baolin Wang writes: > >> Now there are 3 places will validate if a page can mirate or not, and >> some validations are performed later, which will waste some CPU to call >> numa_migrate_prep(). >> >> Thus we can move all the migration validation into numa_migrate_prep(), >> which is more maintainable as well as saving some CPU resources. Another >> benefit is that it can serve as a preparation for supporting batch migration >> in do_numa_page() in future. >> >> Signed-off-by: Baolin Wang >> --- >> mm/memory.c | 19 +++++++++++++++++++ >> mm/migrate.c | 19 ------------------- >> 2 files changed, 19 insertions(+), 19 deletions(-) >> >> diff --git a/mm/memory.c b/mm/memory.c >> index d003076b218d..bee9b1e86ef0 100644 >> --- a/mm/memory.c >> +++ b/mm/memory.c >> @@ -4747,6 +4747,25 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, >> *flags |= TNF_FAULT_LOCAL; >> } >> >> + /* >> + * Don't migrate file pages that are mapped in multiple processes >> + * with execute permissions as they are probably shared libraries. >> + */ >> + if (page_mapcount(page) != 1 && page_is_file_lru(page) && >> + (vma->vm_flags & VM_EXEC)) >> + return NUMA_NO_NODE; >> + >> + /* >> + * Also do not migrate dirty pages as not all filesystems can move >> + * dirty pages in MIGRATE_ASYNC mode which is a waste of cycles. >> + */ >> + if (page_is_file_lru(page) && PageDirty(page)) >> + return NUMA_NO_NODE; >> + >> + /* Do not migrate THP mapped by multiple processes */ >> + if (PageTransHuge(page) && total_mapcount(page) > 1) >> + return NUMA_NO_NODE; >> + >> return mpol_misplaced(page, vma, addr); > > In mpol_misplaced()->should_numa_migrate_memory(), accessing CPU and PID > will be recorded. So the code change above will introduce some behavior > change. Indeed. > > How about move these checks into a separate function which is called > between numa_migrate_prep() and migrate_misplaced_page() after unlocking > PTL? Sounds reasonable to me. Thanks for your input. > > -- > Best Regards, > Huang, Ying > >> } >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index e21d5a7e7447..9cc98fb1d6ec 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -2485,10 +2485,6 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) >> >> VM_BUG_ON_PAGE(order && !PageTransHuge(page), page); >> >> - /* Do not migrate THP mapped by multiple processes */ >> - if (PageTransHuge(page) && total_mapcount(page) > 1) >> - return 0; >> - >> /* Avoid migrating to a node that is nearly full */ >> if (!migrate_balanced_pgdat(pgdat, nr_pages)) { >> int z; >> @@ -2533,21 +2529,6 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, >> LIST_HEAD(migratepages); >> int nr_pages = thp_nr_pages(page); >> >> - /* >> - * Don't migrate file pages that are mapped in multiple processes >> - * with execute permissions as they are probably shared libraries. >> - */ >> - if (page_mapcount(page) != 1 && page_is_file_lru(page) && >> - (vma->vm_flags & VM_EXEC)) >> - goto out; >> - >> - /* >> - * Also do not migrate dirty pages as not all filesystems can move >> - * dirty pages in MIGRATE_ASYNC mode which is a waste of cycles. >> - */ >> - if (page_is_file_lru(page) && PageDirty(page)) >> - goto out; >> - >> isolated = numamigrate_isolate_page(pgdat, page); >> if (!isolated) >> goto out;