Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8896887ybi; Thu, 6 Jun 2019 23:12:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqymQhCHH42Nk7QDSlLdFtp0PPrNfqRiPQLxQvuGhNHPAnbxFrPltLnraZpaInEI5p/MEkBQ X-Received: by 2002:a17:902:b495:: with SMTP id y21mr53321863plr.243.1559887949327; Thu, 06 Jun 2019 23:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559887949; cv=none; d=google.com; s=arc-20160816; b=Zck9W5Bs1+tk77AOALdaXQj/ANAglml1c/xRk9Rbos6IxkC4+enk0kAJ+VMGynmiPl R+GK/m0QO3F2AghjwitpCyPmFQy1iQdDA5DRS/kjpRfLwxZ+kZ5B8RovvCqQcElYRu7V xWacKlHCW1nr+cnuRBM10AOTi81Xqq0WqZeJzoQIfIGOOkD2Q8ugrqgJIxZZ3jXMEmy7 hjoOE/OAUnTSNiJ9s5jQcLlZG/t5wLTttg0tqZsFaOEZUtLwsH/9QITckLkYIzsIfW6L 4R6uVk/0SQxMUhK99Q9omSo9pa7wx+h69UMZO5IbKgmnHRAiMloZH00qDIfevMN/f0hi +CEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=eTktKQuTzdipksXwS2CKl7p1qhwpDhKrtnVfw336+xs=; b=vO5epvcmp/f8mVn7gBTHYm1leidzGn3VqAnjeOzShOaMPiR7zuj9IjSjDEOm4mQCRn 5u3N+Av2FflS/RVZhA18wXCV+foc162ulNnH4gp2LwSnPDHMQV/sX5xvPJcqigI9r/TT SuDaUeJaI8Vgoa0bFYwvl17cTKxSbPLZPG75mhLQlQGsGjV4PpUHMrSzr8PF9JHId8RI cow/mc+RPTlMn7mBW4yyicGwT0y4O6P6m+PeDmdF4SgNmKuPhRzvsex4vXfGC+BTO3Z+ /nzuYo9ERBvzMSjOLa7cxQNNATqaOL/CH8Plc4k1t3cPCIybwt+8tBA+JgzoL1vsLcE/ Wp2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IV4zLHj0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si1027158pls.109.2019.06.06.23.12.12; Thu, 06 Jun 2019 23:12:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IV4zLHj0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726921AbfFGGK2 (ORCPT + 99 others); Fri, 7 Jun 2019 02:10:28 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:33314 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbfFGGK1 (ORCPT ); Fri, 7 Jun 2019 02:10:27 -0400 Received: by mail-it1-f196.google.com with SMTP id v193so3827292itc.0 for ; Thu, 06 Jun 2019 23:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eTktKQuTzdipksXwS2CKl7p1qhwpDhKrtnVfw336+xs=; b=IV4zLHj0L6VpXbqbPfvaZO0ippEsxT1gmsZ7V2S/nWcvEDeFcJtFVigu0otcpMlb4V xAIju+cbPCdOUT/MuR2nvYjv7p64PSoDQV1uECjr4JHKj5Cd399GbXWWJ0gcLYHdTTVU 5Uibii/zVZc66zpE6bfmIS+FyQQHjvFWJQjNEyfTxcbOh2oo2vngN6QmQ/6F2J/S9FKv q9C3T2kLzobgefw3JAKSlbn5eeyfuSdFfkDiWGmOUY612TsQA2FMNDYyalfQvUz6kRuY hybvTl/YG2k1RrhoZC9b2f2XqMGHaltcu1HerUN+9/Ctgc2x3estuK7G6OirSjs9v0/f 6efg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eTktKQuTzdipksXwS2CKl7p1qhwpDhKrtnVfw336+xs=; b=XudIsYKzWpWuy39Vm2xUZ9DIcAbTRuA+xf+Nwa+NMm9GITx96JfHwZ9xo04KW1OTF0 pCw6ZfdLLiJu0qgO41Xg0pkEnZQKTKr/tVWrP9/SG2hXkkRqdGAP1r0RTFwaMl9hAQFM C9z8YLEToDS8g08hqUBYkddnGHDGYuVGDRzzst+4Jb6UThgg4h/dX2s8CwHsHHNX6kgQ NaqITo4l76ERufD6eQ6loMRdXKC7Qco07ZXFngeVEg/JIB4+v6L4yVAmiNlS1Cff0btO Z/bwNRM9dIdMYZRh3SpA0X57578fzWkU9k3vmRzPm7RfujHjM0F5y1boP2UrE7XvOhl7 LTZQ== X-Gm-Message-State: APjAAAV4sSssMUhwCwzy/0Toofvs8uL/g1Y1vORpn+OJ3AZN9euXr8Er XjRSQVuq+XcP1N9aP92tnzVW3gn9oLuO3Ce6WLIYAZA= X-Received: by 2002:a05:6638:40c:: with SMTP id q12mr29265442jap.17.1559887826860; Thu, 06 Jun 2019 23:10:26 -0700 (PDT) MIME-Version: 1.0 References: <1559725820-26138-1-git-send-email-kernelfans@gmail.com> <20190605144912.f0059d4bd13c563ddb37877e@linux-foundation.org> <2b0a65ec-4fb0-430e-3e6a-b713fb5bb28f@nvidia.com> In-Reply-To: <2b0a65ec-4fb0-430e-3e6a-b713fb5bb28f@nvidia.com> From: Pingfan Liu Date: Fri, 7 Jun 2019 14:10:15 +0800 Message-ID: Subject: Re: [PATCHv3 1/2] mm/gup: fix omission of check on FOLL_LONGTERM in get_user_pages_fast() To: John Hubbard Cc: Andrew Morton , linux-mm@kvack.org, Ira Weiny , Mike Rapoport , Dan Williams , Matthew Wilcox , "Aneesh Kumar K.V" , Keith Busch , Christoph Hellwig , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 7, 2019 at 5:17 AM John Hubbard wrote: > > On 6/5/19 7:19 PM, Pingfan Liu wrote: > > On Thu, Jun 6, 2019 at 5:49 AM Andrew Morton wrote: > ... > >>> --- a/mm/gup.c > >>> +++ b/mm/gup.c > >>> @@ -2196,6 +2196,26 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages, > >>> return ret; > >>> } > >>> > >>> +#ifdef CONFIG_CMA > >>> +static inline int reject_cma_pages(int nr_pinned, struct page **pages) > >>> +{ > >>> + int i; > >>> + > >>> + for (i = 0; i < nr_pinned; i++) > >>> + if (is_migrate_cma_page(pages[i])) { > >>> + put_user_pages(pages + i, nr_pinned - i); > >>> + return i; > >>> + } > >>> + > >>> + return nr_pinned; > >>> +} > >> > >> There's no point in inlining this. > > OK, will drop it in V4. > > > >> > >> The code seems inefficient. If it encounters a single CMA page it can > >> end up discarding a possibly significant number of non-CMA pages. I > > The trick is the page is not be discarded, in fact, they are still be > > referrenced by pte. We just leave the slow path to pick up the non-CMA > > pages again. > > > >> guess that doesn't matter much, as get_user_pages(FOLL_LONGTERM) is > >> rare. But could we avoid this (and the second pass across pages[]) by > >> checking for a CMA page within gup_pte_range()? > > It will spread the same logic to hugetlb pte and normal pte. And no > > improvement in performance due to slow path. So I think maybe it is > > not worth. > > > >> > > I think the concern is: for the successful gup_fast case with no CMA > pages, this patch is adding another complete loop through all the > pages. In the fast case. > > If the check were instead done as part of the gup_pte_range(), then > it would be a little more efficient for that case. > > As for whether it's worth it, *probably* this is too small an effect to measure. > But in order to attempt a measurement: running fio (https://github.com/axboe/fio) > with O_DIRECT on an NVMe drive, might shed some light. Here's an fio.conf file > that Jan Kara and Tom Talpey helped me come up with, for related testing: > > [reader] > direct=1 > ioengine=libaio > blocksize=4096 > size=1g > numjobs=1 > rw=read > iodepth=64 > Yeah, agreed. Data is more persuasive. Thanks for your suggestion. I will try to bring out the result. Thanks, Pingfan