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=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 98FFCC47E49 for ; Mon, 4 Nov 2019 16:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EAE8214B2 for ; Mon, 4 Nov 2019 16:51:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FA5pznYb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728796AbfKDQvg (ORCPT ); Mon, 4 Nov 2019 11:51:36 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:42099 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728174AbfKDQvg (ORCPT ); Mon, 4 Nov 2019 11:51:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572886294; h=from:from: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=TXrEUfVJUcd1erXFQw9FjfdFZzoYFLyJ24kgJsiz4yg=; b=FA5pznYbTukMnXNxUYEsr2a+sllUt2kUWtAghROFSu5I3R1caZebkFMC7bhvO3LvtAkDE/ Q+vG1DDObqg4RQRmF1Ui4k8QwslEzxZl3u5pAyodA4YKKyO29NUXIZJsgk++a/ZANOwxAf 057fbnJH43/COtEdZ8dXVklRKI09/xQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-zE3MYcgnMCiZjQzFEos_IQ-1; Mon, 04 Nov 2019 11:51:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AF6E8017DD; Mon, 4 Nov 2019 16:51:26 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.178]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E86D5C1B2; Mon, 4 Nov 2019 16:51:20 +0000 (UTC) Date: Mon, 4 Nov 2019 11:51:18 -0500 From: Jerome Glisse To: John Hubbard Cc: Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jonathan Corbet , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko , Mike Kravetz , Paul Mackerras , Shuah Khan , Vlastimil Babka , bpf@vger.kernel.org, dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, linux-rdma@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, linux-mm@kvack.org, LKML , Christoph Hellwig , "Aneesh Kumar K . V" Subject: Re: [PATCH v2 02/18] mm/gup: factor out duplicate code from four routines Message-ID: <20191104165118.GB5134@redhat.com> References: <20191103211813.213227-1-jhubbard@nvidia.com> <20191103211813.213227-3-jhubbard@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20191103211813.213227-3-jhubbard@nvidia.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: zE3MYcgnMCiZjQzFEos_IQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Sun, Nov 03, 2019 at 01:17:57PM -0800, John Hubbard wrote: > There are four locations in gup.c that have a fair amount of code > duplication. This means that changing one requires making the same > changes in four places, not to mention reading the same code four > times, and wondering if there are subtle differences. >=20 > Factor out the common code into static functions, thus reducing the > overall line count and the code's complexity. >=20 > Also, take the opportunity to slightly improve the efficiency of the > error cases, by doing a mass subtraction of the refcount, surrounded > by get_page()/put_page(). >=20 > Also, further simplify (slightly), by waiting until the the successful > end of each routine, to increment *nr. >=20 > Cc: Ira Weiny > Cc: Christoph Hellwig > Cc: Aneesh Kumar K.V > Signed-off-by: John Hubbard Good cleanup. Reviewed-by: J=E9r=F4me Glisse > --- > mm/gup.c | 104 ++++++++++++++++++++++++------------------------------- > 1 file changed, 45 insertions(+), 59 deletions(-) >=20 > diff --git a/mm/gup.c b/mm/gup.c > index 85caf76b3012..199da99e8ffc 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1969,6 +1969,34 @@ static int __gup_device_huge_pud(pud_t pud, pud_t = *pudp, unsigned long addr, > } > #endif > =20 > +static int __record_subpages(struct page *page, unsigned long addr, > +=09=09=09 unsigned long end, struct page **pages, int nr) > +{ > +=09int nr_recorded_pages =3D 0; > + > +=09do { > +=09=09pages[nr] =3D page; > +=09=09nr++; > +=09=09page++; > +=09=09nr_recorded_pages++; > +=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09return nr_recorded_pages; > +} > + > +static void put_compound_head(struct page *page, int refs) > +{ > +=09/* Do a get_page() first, in case refs =3D=3D page->_refcount */ > +=09get_page(page); > +=09page_ref_sub(page, refs); > +=09put_page(page); > +} > + > +static void __huge_pt_done(struct page *head, int nr_recorded_pages, int= *nr) > +{ > +=09*nr +=3D nr_recorded_pages; > +=09SetPageReferenced(head); > +} > + > #ifdef CONFIG_ARCH_HAS_HUGEPD > static unsigned long hugepte_addr_end(unsigned long addr, unsigned long = end, > =09=09=09=09 unsigned long sz) > @@ -1998,33 +2026,20 @@ static int gup_hugepte(pte_t *ptep, unsigned long= sz, unsigned long addr, > =09/* hugepages are never "special" */ > =09VM_BUG_ON(!pfn_valid(pte_pfn(pte))); > =20 > -=09refs =3D 0; > =09head =3D pte_page(pte); > - > =09page =3D head + ((addr & (sz-1)) >> PAGE_SHIFT); > -=09do { > -=09=09VM_BUG_ON(compound_head(page) !=3D head); > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(head, refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pte_val(pte) !=3D pte_val(*ptep))) { > -=09=09/* Could be optimized better */ > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2071,29 +2086,19 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pmd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pmd_val(orig) !=3D pmd_val(*pmdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2114,29 +2119,19 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pud_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pud_val(orig) !=3D pud_val(*pudp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2151,29 +2146,20 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, = unsigned long addr, > =09=09return 0; > =20 > =09BUILD_BUG_ON(pgd_devmap(orig)); > -=09refs =3D 0; > + > =09page =3D pgd_page(orig) + ((addr & ~PGDIR_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pgd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pgd_val(orig) !=3D pgd_val(*pgdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > --=20 > 2.23.0 >=20 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=-8.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 D1FBECA9EB5 for ; Mon, 4 Nov 2019 16:53:48 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81C74214B2 for ; Mon, 4 Nov 2019 16:53:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FA5pznYb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81C74214B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 476Jlt1nhBzF3rl for ; Tue, 5 Nov 2019 03:53:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=205.139.110.61; helo=us-smtp-delivery-1.mimecast.com; envelope-from=jglisse@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="FA5pznYb"; dkim-atps=neutral Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 476JjP3YD6zDrDT for ; Tue, 5 Nov 2019 03:51:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572886294; h=from:from: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=TXrEUfVJUcd1erXFQw9FjfdFZzoYFLyJ24kgJsiz4yg=; b=FA5pznYbTukMnXNxUYEsr2a+sllUt2kUWtAghROFSu5I3R1caZebkFMC7bhvO3LvtAkDE/ Q+vG1DDObqg4RQRmF1Ui4k8QwslEzxZl3u5pAyodA4YKKyO29NUXIZJsgk++a/ZANOwxAf 057fbnJH43/COtEdZ8dXVklRKI09/xQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-zE3MYcgnMCiZjQzFEos_IQ-1; Mon, 04 Nov 2019 11:51:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AF6E8017DD; Mon, 4 Nov 2019 16:51:26 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.178]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E86D5C1B2; Mon, 4 Nov 2019 16:51:20 +0000 (UTC) Date: Mon, 4 Nov 2019 11:51:18 -0500 From: Jerome Glisse To: John Hubbard Subject: Re: [PATCH v2 02/18] mm/gup: factor out duplicate code from four routines Message-ID: <20191104165118.GB5134@redhat.com> References: <20191103211813.213227-1-jhubbard@nvidia.com> <20191103211813.213227-3-jhubbard@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20191103211813.213227-3-jhubbard@nvidia.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: zE3MYcgnMCiZjQzFEos_IQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Jan Kara , kvm@vger.kernel.org, linux-doc@vger.kernel.org, David Airlie , Dave Chinner , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Paul Mackerras , linux-kselftest@vger.kernel.org, Ira Weiny , Christoph Hellwig , Jonathan Corbet , linux-rdma@vger.kernel.org, Christoph Hellwig , Jason Gunthorpe , Vlastimil Babka , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-media@vger.kernel.org, Shuah Khan , linux-block@vger.kernel.org, Alex Williamson , Al Viro , Dan Williams , Mauro Carvalho Chehab , bpf@vger.kernel.org, Magnus Karlsson , Jens Axboe , netdev@vger.kernel.org, LKML , Daniel Vetter , "Aneesh Kumar K . V" , linux-fsdevel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S . Miller" , Mike Kravetz Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Sun, Nov 03, 2019 at 01:17:57PM -0800, John Hubbard wrote: > There are four locations in gup.c that have a fair amount of code > duplication. This means that changing one requires making the same > changes in four places, not to mention reading the same code four > times, and wondering if there are subtle differences. >=20 > Factor out the common code into static functions, thus reducing the > overall line count and the code's complexity. >=20 > Also, take the opportunity to slightly improve the efficiency of the > error cases, by doing a mass subtraction of the refcount, surrounded > by get_page()/put_page(). >=20 > Also, further simplify (slightly), by waiting until the the successful > end of each routine, to increment *nr. >=20 > Cc: Ira Weiny > Cc: Christoph Hellwig > Cc: Aneesh Kumar K.V > Signed-off-by: John Hubbard Good cleanup. Reviewed-by: J=E9r=F4me Glisse > --- > mm/gup.c | 104 ++++++++++++++++++++++++------------------------------- > 1 file changed, 45 insertions(+), 59 deletions(-) >=20 > diff --git a/mm/gup.c b/mm/gup.c > index 85caf76b3012..199da99e8ffc 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1969,6 +1969,34 @@ static int __gup_device_huge_pud(pud_t pud, pud_t = *pudp, unsigned long addr, > } > #endif > =20 > +static int __record_subpages(struct page *page, unsigned long addr, > +=09=09=09 unsigned long end, struct page **pages, int nr) > +{ > +=09int nr_recorded_pages =3D 0; > + > +=09do { > +=09=09pages[nr] =3D page; > +=09=09nr++; > +=09=09page++; > +=09=09nr_recorded_pages++; > +=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09return nr_recorded_pages; > +} > + > +static void put_compound_head(struct page *page, int refs) > +{ > +=09/* Do a get_page() first, in case refs =3D=3D page->_refcount */ > +=09get_page(page); > +=09page_ref_sub(page, refs); > +=09put_page(page); > +} > + > +static void __huge_pt_done(struct page *head, int nr_recorded_pages, int= *nr) > +{ > +=09*nr +=3D nr_recorded_pages; > +=09SetPageReferenced(head); > +} > + > #ifdef CONFIG_ARCH_HAS_HUGEPD > static unsigned long hugepte_addr_end(unsigned long addr, unsigned long = end, > =09=09=09=09 unsigned long sz) > @@ -1998,33 +2026,20 @@ static int gup_hugepte(pte_t *ptep, unsigned long= sz, unsigned long addr, > =09/* hugepages are never "special" */ > =09VM_BUG_ON(!pfn_valid(pte_pfn(pte))); > =20 > -=09refs =3D 0; > =09head =3D pte_page(pte); > - > =09page =3D head + ((addr & (sz-1)) >> PAGE_SHIFT); > -=09do { > -=09=09VM_BUG_ON(compound_head(page) !=3D head); > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(head, refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pte_val(pte) !=3D pte_val(*ptep))) { > -=09=09/* Could be optimized better */ > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2071,29 +2086,19 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pmd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pmd_val(orig) !=3D pmd_val(*pmdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2114,29 +2119,19 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pud_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pud_val(orig) !=3D pud_val(*pudp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2151,29 +2146,20 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, = unsigned long addr, > =09=09return 0; > =20 > =09BUILD_BUG_ON(pgd_devmap(orig)); > -=09refs =3D 0; > + > =09page =3D pgd_page(orig) + ((addr & ~PGDIR_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pgd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pgd_val(orig) !=3D pgd_val(*pgdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > --=20 > 2.23.0 >=20 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerome Glisse Subject: Re: [PATCH v2 02/18] mm/gup: factor out duplicate code from four routines Date: Mon, 4 Nov 2019 11:51:18 -0500 Message-ID: <20191104165118.GB5134@redhat.com> References: <20191103211813.213227-1-jhubbard@nvidia.com> <20191103211813.213227-3-jhubbard@nvidia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20191103211813.213227-3-jhubbard@nvidia.com> Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org To: John Hubbard Cc: Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jonathan Corbet , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko List-Id: dri-devel@lists.freedesktop.org On Sun, Nov 03, 2019 at 01:17:57PM -0800, John Hubbard wrote: > There are four locations in gup.c that have a fair amount of code > duplication. This means that changing one requires making the same > changes in four places, not to mention reading the same code four > times, and wondering if there are subtle differences. >=20 > Factor out the common code into static functions, thus reducing the > overall line count and the code's complexity. >=20 > Also, take the opportunity to slightly improve the efficiency of the > error cases, by doing a mass subtraction of the refcount, surrounded > by get_page()/put_page(). >=20 > Also, further simplify (slightly), by waiting until the the successful > end of each routine, to increment *nr. >=20 > Cc: Ira Weiny > Cc: Christoph Hellwig > Cc: Aneesh Kumar K.V > Signed-off-by: John Hubbard Good cleanup. Reviewed-by: J=E9r=F4me Glisse > --- > mm/gup.c | 104 ++++++++++++++++++++++++------------------------------- > 1 file changed, 45 insertions(+), 59 deletions(-) >=20 > diff --git a/mm/gup.c b/mm/gup.c > index 85caf76b3012..199da99e8ffc 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1969,6 +1969,34 @@ static int __gup_device_huge_pud(pud_t pud, pud_t = *pudp, unsigned long addr, > } > #endif > =20 > +static int __record_subpages(struct page *page, unsigned long addr, > +=09=09=09 unsigned long end, struct page **pages, int nr) > +{ > +=09int nr_recorded_pages =3D 0; > + > +=09do { > +=09=09pages[nr] =3D page; > +=09=09nr++; > +=09=09page++; > +=09=09nr_recorded_pages++; > +=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09return nr_recorded_pages; > +} > + > +static void put_compound_head(struct page *page, int refs) > +{ > +=09/* Do a get_page() first, in case refs =3D=3D page->_refcount */ > +=09get_page(page); > +=09page_ref_sub(page, refs); > +=09put_page(page); > +} > + > +static void __huge_pt_done(struct page *head, int nr_recorded_pages, int= *nr) > +{ > +=09*nr +=3D nr_recorded_pages; > +=09SetPageReferenced(head); > +} > + > #ifdef CONFIG_ARCH_HAS_HUGEPD > static unsigned long hugepte_addr_end(unsigned long addr, unsigned long = end, > =09=09=09=09 unsigned long sz) > @@ -1998,33 +2026,20 @@ static int gup_hugepte(pte_t *ptep, unsigned long= sz, unsigned long addr, > =09/* hugepages are never "special" */ > =09VM_BUG_ON(!pfn_valid(pte_pfn(pte))); > =20 > -=09refs =3D 0; > =09head =3D pte_page(pte); > - > =09page =3D head + ((addr & (sz-1)) >> PAGE_SHIFT); > -=09do { > -=09=09VM_BUG_ON(compound_head(page) !=3D head); > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(head, refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pte_val(pte) !=3D pte_val(*ptep))) { > -=09=09/* Could be optimized better */ > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2071,29 +2086,19 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pmd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pmd_val(orig) !=3D pmd_val(*pmdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2114,29 +2119,19 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, = unsigned long addr, > =09=09=09=09=09 pages, nr); > =09} > =20 > -=09refs =3D 0; > =09page =3D pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pud_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pud_val(orig) !=3D pud_val(*pudp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > @@ -2151,29 +2146,20 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, = unsigned long addr, > =09=09return 0; > =20 > =09BUILD_BUG_ON(pgd_devmap(orig)); > -=09refs =3D 0; > + > =09page =3D pgd_page(orig) + ((addr & ~PGDIR_MASK) >> PAGE_SHIFT); > -=09do { > -=09=09pages[*nr] =3D page; > -=09=09(*nr)++; > -=09=09page++; > -=09=09refs++; > -=09} while (addr +=3D PAGE_SIZE, addr !=3D end); > +=09refs =3D __record_subpages(page, addr, end, pages, *nr); > =20 > =09head =3D try_get_compound_head(pgd_page(orig), refs); > -=09if (!head) { > -=09=09*nr -=3D refs; > +=09if (!head) > =09=09return 0; > -=09} > =20 > =09if (unlikely(pgd_val(orig) !=3D pgd_val(*pgdp))) { > -=09=09*nr -=3D refs; > -=09=09while (refs--) > -=09=09=09put_page(head); > +=09=09put_compound_head(head, refs); > =09=09return 0; > =09} > =20 > -=09SetPageReferenced(head); > +=09__huge_pt_done(head, refs, nr); > =09return 1; > } > =20 > --=20 > 2.23.0 >=20 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, 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 7F0D7CA9ED3 for ; Mon, 4 Nov 2019 16:51:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D5C9214D8 for ; Mon, 4 Nov 2019 16:51:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D5C9214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BA83A89203; Mon, 4 Nov 2019 16:51:37 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA69C89203 for ; Mon, 4 Nov 2019 16:51:35 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-zE3MYcgnMCiZjQzFEos_IQ-1; Mon, 04 Nov 2019 11:51:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AF6E8017DD; Mon, 4 Nov 2019 16:51:26 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.178]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E86D5C1B2; Mon, 4 Nov 2019 16:51:20 +0000 (UTC) Date: Mon, 4 Nov 2019 11:51:18 -0500 From: Jerome Glisse To: John Hubbard Subject: Re: [PATCH v2 02/18] mm/gup: factor out duplicate code from four routines Message-ID: <20191104165118.GB5134@redhat.com> References: <20191103211813.213227-1-jhubbard@nvidia.com> <20191103211813.213227-3-jhubbard@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20191103211813.213227-3-jhubbard@nvidia.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: zE3MYcgnMCiZjQzFEos_IQ-1 X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572886294; h=from:from: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=TXrEUfVJUcd1erXFQw9FjfdFZzoYFLyJ24kgJsiz4yg=; b=FA5pznYbTukMnXNxUYEsr2a+sllUt2kUWtAghROFSu5I3R1caZebkFMC7bhvO3LvtAkDE/ Q+vG1DDObqg4RQRmF1Ui4k8QwslEzxZl3u5pAyodA4YKKyO29NUXIZJsgk++a/ZANOwxAf 057fbnJH43/COtEdZ8dXVklRKI09/xQ= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , Jan Kara , kvm@vger.kernel.org, linux-doc@vger.kernel.org, David Airlie , Dave Chinner , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Paul Mackerras , linux-kselftest@vger.kernel.org, Ira Weiny , Christoph Hellwig , Jonathan Corbet , linux-rdma@vger.kernel.org, Michael Ellerman , Christoph Hellwig , Jason Gunthorpe , Vlastimil Babka , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-media@vger.kernel.org, Shuah Khan , linux-block@vger.kernel.org, Alex Williamson , Al Viro , Dan Williams , Mauro Carvalho Chehab , bpf@vger.kernel.org, Magnus Karlsson , Jens Axboe , netdev@vger.kernel.org, LKML , "Aneesh Kumar K . V" , linux-fsdevel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S . Miller" , Mike Kravetz Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Message-ID: <20191104165118.GzlY75R1L2ovYoNvLn2Quu8eh0dagIH9bHn46Hq_Z-w@z> T24gU3VuLCBOb3YgMDMsIDIwMTkgYXQgMDE6MTc6NTdQTSAtMDgwMCwgSm9obiBIdWJiYXJkIHdy b3RlOgo+IFRoZXJlIGFyZSBmb3VyIGxvY2F0aW9ucyBpbiBndXAuYyB0aGF0IGhhdmUgYSBmYWly IGFtb3VudCBvZiBjb2RlCj4gZHVwbGljYXRpb24uIFRoaXMgbWVhbnMgdGhhdCBjaGFuZ2luZyBv bmUgcmVxdWlyZXMgbWFraW5nIHRoZSBzYW1lCj4gY2hhbmdlcyBpbiBmb3VyIHBsYWNlcywgbm90 IHRvIG1lbnRpb24gcmVhZGluZyB0aGUgc2FtZSBjb2RlIGZvdXIKPiB0aW1lcywgYW5kIHdvbmRl cmluZyBpZiB0aGVyZSBhcmUgc3VidGxlIGRpZmZlcmVuY2VzLgo+IAo+IEZhY3RvciBvdXQgdGhl IGNvbW1vbiBjb2RlIGludG8gc3RhdGljIGZ1bmN0aW9ucywgdGh1cyByZWR1Y2luZyB0aGUKPiBv dmVyYWxsIGxpbmUgY291bnQgYW5kIHRoZSBjb2RlJ3MgY29tcGxleGl0eS4KPiAKPiBBbHNvLCB0 YWtlIHRoZSBvcHBvcnR1bml0eSB0byBzbGlnaHRseSBpb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