Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp677137pxb; Wed, 3 Feb 2021 15:07:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFdomFsMKq0qIw/TQW7bJPlxGRY99DIIbXIjICPxYdtgFtP+l/7JY36abuLMUaaIIpX7ma X-Received: by 2002:a17:906:5857:: with SMTP id h23mr5253102ejs.465.1612393624867; Wed, 03 Feb 2021 15:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612393624; cv=none; d=google.com; s=arc-20160816; b=eyvSeOojqkjRSVcaDPe07HY0uk3ZO9fQIDwyDE0D2+ecIAxZOEstVVU6JDd10o8L3p HRjx1ZAsvbLyhsk9mPRrH9LXwOsxU91R+Fnip4IzQC7NcMaHfni/fCjTnhv3I6BClAta q1NOX7zyb+YQniggF/4XvS1S8H0GMOdW10Jutg8AlIAn1mQ3E4GjspkU1fqoWvWuSzsX EGA/3yq1zAd5I3pw2+Cv4MOFbdorBRE1mU1JBYpQ+/b7V3uW+RJYNwT4TuTP5yoM8oQV /di85LXXzrAnLAaNHn6ENdnvt/QC+XZ33kOOgnWsF/eCiG2S5OwdbQwmq7ziHle+3a6l B0Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=GuboAPGdFAJEcRrueyWlGFwtNTZuZ5B0TDKDNKYBHvU=; b=QZBbnZywpQpaxQqfjwXNo1KYG1y4vlHlDtEB9HFRNW51HCIUNzBv3m2SEDM6S7PFr4 Q0a0Od/3V9fN0kcXC4EW4FT634uXuOsdNFZRPoaDYKeFsb+80jR5M+ECIHhynkGqT50V /3vhiyp7IuS1hL+Q3E6pfrvCO9Xy5h1lRYOobFLCPK3RKZeuKw0TqcYXQcZ0mHuHgkus JVD2RUm039W4jHR6AUbVw3T56zLBfXqkTU1igkRbVQXER7xP7p7+1Q5RTBducaSGRUut tg6oeJT2sHud7V+58nY0Bpz9thdB9bzZGvcvLvovp+aTL6K20MMPiCNqxHNVBH+P+UyB Vi9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=mQzhCI69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si2305466edv.410.2021.02.03.15.06.40; Wed, 03 Feb 2021 15:07:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=mQzhCI69; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233253AbhBCXCj (ORCPT + 99 others); Wed, 3 Feb 2021 18:02:39 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:11023 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbhBCXAo (ORCPT ); Wed, 3 Feb 2021 18:00:44 -0500 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== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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