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 X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E224FC433E4 for ; Fri, 10 Jul 2020 16:20:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A6E9B20657 for ; Fri, 10 Jul 2020 16:20:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="CsSiPpre" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A6E9B20657 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 209428D0003; Fri, 10 Jul 2020 12:20:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B8858D0001; Fri, 10 Jul 2020 12:20:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CEC38D0003; Fri, 10 Jul 2020 12:20:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id E8C2C8D0001 for ; Fri, 10 Jul 2020 12:20:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 648B640FE for ; Fri, 10 Jul 2020 16:20:06 +0000 (UTC) X-FDA: 77022678012.20.robin39_581463e26ecf Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 2D4B4180C0609 for ; Fri, 10 Jul 2020 16:20:06 +0000 (UTC) X-HE-Tag: robin39_581463e26ecf X-Filterd-Recvd-Size: 4921 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jul 2020 16:20:05 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 10 Jul 2020 09:18:15 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 10 Jul 2020 09:20:04 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 10 Jul 2020 09:20:04 -0700 Received: from rcampbell-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 10 Jul 2020 16:19:57 +0000 Subject: Re: [PATCH 1/2] mm/migrate: optimize migrate_vma_setup() for holes To: CC: , , , , "Jerome Glisse" , John Hubbard , "Christoph Hellwig" , Jason Gunthorpe , Shuah Khan , Andrew Morton References: <20200709165711.26584-1-rcampbell@nvidia.com> <20200709165711.26584-2-rcampbell@nvidia.com> <20200710063509.GE7902@in.ibm.com> From: Ralph Campbell X-Nvconfidentiality: public Message-ID: <72557537-3d64-7082-11f7-d70b41f7d0e6@nvidia.com> Date: Fri, 10 Jul 2020 09:19:56 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200710063509.GE7902@in.ibm.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1594397895; bh=Ue/frzFxUQ5xNe2FlvXb4r/DHKPE3j0pZwT+2iMRx4s=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=CsSiPpre9qxK1jS02numnr4cfl7QmxJ0/oYmekUMhjtq34QymiInNuhlkiCDn0E7p Bl+cgS3sGUonpda8dBJFP7ibbOFONADHdtgHtgcRKvXQArVDB0uEePCFyqO8B5UHlb KR1pBKdSmVPdg062vI5u3K6IVK2DExOIGzrUf2dX5pQySstXbXRvhrXpWDd6xWF+c8 TMjfbHedmpP4pZt21f75Zm+hj4lVqe8Ny94gFMGjxbEqdutYx1QT/u3g8DBXsjb5a0 DtGKN67dVzTn8mziAEBNJI/0nEz200XIpALyu/RdCHrI+Df8RJivh9s4L720y+2BV3 M0oTYVkJHwS9g== X-Rspamd-Queue-Id: 2D4B4180C0609 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 7/9/20 11:35 PM, Bharata B Rao wrote: > On Thu, Jul 09, 2020 at 09:57:10AM -0700, Ralph Campbell wrote: >> When migrating system memory to device private memory, if the source >> address range is a valid VMA range and there is no memory or a zero page, >> the source PFN array is marked as valid but with no PFN. This lets the >> device driver allocate private memory and clear it, then insert the new >> device private struct page into the CPU's page tables when >> migrate_vma_pages() is called. migrate_vma_pages() only inserts the >> new page if the VMA is an anonymous range. There is no point in telling >> the device driver to allocate device private memory and then not migrate >> the page. Instead, mark the source PFN array entries as not migrating to >> avoid this overhead. >> >> Signed-off-by: Ralph Campbell >> --- >> mm/migrate.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index b0125c082549..8aa434691577 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -2204,9 +2204,13 @@ static int migrate_vma_collect_hole(unsigned long start, >> { >> struct migrate_vma *migrate = walk->private; >> unsigned long addr; >> + unsigned long flags; >> + >> + /* Only allow populating anonymous memory. */ >> + flags = vma_is_anonymous(walk->vma) ? MIGRATE_PFN_MIGRATE : 0; >> >> for (addr = start; addr < end; addr += PAGE_SIZE) { >> - migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE; >> + migrate->src[migrate->npages] = flags; > > I see a few other such cases where we directly populate MIGRATE_PFN_MIGRATE > w/o a pfn in migrate_vma_collect_pmd() and wonder why the vma_is_anonymous() > check can't help there as well? > > 1. pte_none() check in migrate_vma_collect_pmd() > 2. is_zero_pfn() check in migrate_vma_collect_pmd() > > Regards, > Bharata. For case 1, this seems like a useful addition. For case 2, the zero page is only inserted if the VMA is marked read-only and anonymous so I don't think the check is needed. I'll post a v2 with the change. Thanks for the suggestions!