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=-18.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 8B4CDC433DB for ; Wed, 3 Feb 2021 23:00:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 208DA64E38 for ; Wed, 3 Feb 2021 23:00:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 208DA64E38 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 A97738D0007; Wed, 3 Feb 2021 18:00:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A475A8D0005; Wed, 3 Feb 2021 18:00:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90F4C8D0007; Wed, 3 Feb 2021 18:00:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 721268D0005 for ; Wed, 3 Feb 2021 18:00:04 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2090C362D for ; Wed, 3 Feb 2021 23:00:04 +0000 (UTC) X-FDA: 77778476328.20.box03_3806e0f275d7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id DD99E180C07AB for ; Wed, 3 Feb 2021 23:00:03 +0000 (UTC) X-HE-Tag: box03_3806e0f275d7 X-Filterd-Recvd-Size: 4736 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 23:00:03 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 03 Feb 2021 15:00:01 -0800 Received: from [10.2.50.90] (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 3 Feb 2021 23:00:01 +0000 Subject: Re: [PATCH 1/4] mm/gup: add compound page list iterator To: Joao Martins , CC: , , Andrew Morton , Jason Gunthorpe , Doug Ledford , Matthew Wilcox References: <20210203220025.8568-1-joao.m.martins@oracle.com> <20210203220025.8568-2-joao.m.martins@oracle.com> From: John Hubbard Message-ID: <955dbe68-7302-a8bc-f0b5-e9032d7f190e@nvidia.com> Date: Wed, 3 Feb 2021 15:00:01 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Thunderbird/85.0 MIME-Version: 1.0 In-Reply-To: <20210203220025.8568-2-joao.m.martins@oracle.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612393201; bh=GuboAPGdFAJEcRrueyWlGFwtNTZuZ5B0TDKDNKYBHvU=; h=Subject:To:CC:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; b=mQzhCI696vm94Sa3p78Z7Gskyb/1gBUUyHmSuvieget9Rc7vwBpU7w1r0NFB6C6VN 6aAvOwvLi6U22aNNpBQ7zdVKsYmFcFYFbiYYK2/d0hDMVNzD3HVapXC2aols9M9ZFx FDC4YTZlnb+Up0ADqnFggTaVjcMnd4TldxjnKzsMmSXq8NpwDfX91XoGtosal3fcDy 7vQ1cQz5G25oUkJWRRln+qLOYfC0Ck4gG+5sitFYByg1lN4pdGGjfliZDvYdE7HECH Sikh51jbn4HEimv2sbOTSpP+3ot5se9i9fck6gxuUyABSz+vAW1V5loRYOPukKIZEM FsqxeTUionwTQ== 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 2/3/21 2:00 PM, Joao Martins wrote: > Add an helper that iterates over head pages in a list of pages. It > essentially counts the tails until the next page to process has a > different head that the current. This is going to be used by > unpin_user_pages() family of functions, to batch the head page refcount > updates once for all passed consecutive tail pages. > > Suggested-by: Jason Gunthorpe > Signed-off-by: Joao Martins > --- > mm/gup.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index d68bcb482b11..4f88dcef39f2 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -215,6 +215,35 @@ void unpin_user_page(struct page *page) > } > EXPORT_SYMBOL(unpin_user_page); > > +static inline unsigned int count_ntails(struct page **pages, unsigned long npages) Silly naming nit: could we please name this function count_pagetails()? count_ntails is a bit redundant, plus slightly less clear. > +{ > + struct page *head = compound_head(pages[0]); > + unsigned int ntails; > + > + for (ntails = 1; ntails < npages; ntails++) { > + if (compound_head(pages[ntails]) != head) > + break; > + } > + > + return ntails; > +} > + > +static inline void compound_next(unsigned long i, unsigned long npages, > + struct page **list, struct page **head, > + unsigned int *ntails) > +{ > + if (i >= npages) > + return; > + > + *ntails = count_ntails(list + i, npages - i); > + *head = compound_head(list[i]); > +} > + > +#define for_each_compound_head(i, list, npages, head, ntails) \ When using macros, which are dangerous in general, you have to worry about things like name collisions. I really dislike that C has forced this unsafe pattern upon us, but of course we are stuck with it, for iterator helpers. Given that we're stuck, you should probably use names such as __i, __list, etc, in the the above #define. Otherwise you could stomp on existing variables. > + for (i = 0, compound_next(i, npages, list, &head, &ntails); \ > + i < npages; i += ntails, \ > + compound_next(i, npages, list, &head, &ntails)) > + > /** > * unpin_user_pages_dirty_lock() - release and optionally dirty gup-pinned pages > * @pages: array of pages to be maybe marked dirty, and definitely released. > thanks, -- John Hubbard NVIDIA