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.4 required=3.0 tests=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,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 57B06C432C3 for ; Tue, 19 Nov 2019 07:00:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B9E822309 for ; Tue, 19 Nov 2019 07:00:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="OHB+eUp2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B9E822309 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 AAE946B000E; Tue, 19 Nov 2019 02:00:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A67616B0010; Tue, 19 Nov 2019 02:00:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94D376B0266; Tue, 19 Nov 2019 02:00:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 7EDB26B000E for ; Tue, 19 Nov 2019 02:00:42 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 294468249980 for ; Tue, 19 Nov 2019 07:00:42 +0000 (UTC) X-FDA: 76172129124.03.land42_7a2b4ca8ea959 X-HE-Tag: land42_7a2b4ca8ea959 X-Filterd-Recvd-Size: 6104 Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com [216.228.121.64]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Nov 2019 07:00:39 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 18 Nov 2019 23:00:32 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 18 Nov 2019 23:00:34 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 18 Nov 2019 23:00:34 -0800 Received: from [10.110.48.28] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 19 Nov 2019 07:00:34 +0000 Subject: Re: [PATCH v5 02/24] mm/gup: factor out duplicate code from four routines To: Jan Kara CC: Andrew Morton , Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jason Gunthorpe , Jens Axboe , Jonathan Corbet , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Magnus Karlsson , Mauro Carvalho Chehab , Michael Ellerman , Michal Hocko , Mike Kravetz , Paul Mackerras , Shuah Khan , Vlastimil Babka , , , , , , , , , , , , , LKML , Christoph Hellwig , "Aneesh Kumar K . V" References: <20191115055340.1825745-1-jhubbard@nvidia.com> <20191115055340.1825745-3-jhubbard@nvidia.com> <20191118094604.GC17319@quack2.suse.cz> X-Nvconfidentiality: public From: John Hubbard Message-ID: <152e2ea9-edd9-f868-7731-ff467d692f5f@nvidia.com> Date: Mon, 18 Nov 2019 23:00:33 -0800 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: <20191118094604.GC17319@quack2.suse.cz> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1574146832; bh=u3YCRE77HsuXbqK9BxFmzDLl8JhQHMG9gXXaYRfagTQ=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=OHB+eUp2jQQmHLrGYBTtAkydhQax1jgPbRIdqXv/zT7mJheOoxm2jC/o00J+31bDd psR1uWZTYTlZpkmYbJIlMzoHbpxnwxoe7ZrZ8UMQNDddfR1HU1k+hUj3JCOx3ZRd5b XT8Ag7PAkGX6G4pIQ7geJmQblkDOtgu1RTN+An2f8z0fTBevVuF5GINewI0N+iPfcv YgagSYh5LQVW6KL8izWZSAMBRDSFlAEl3uHonusWk1CkuRAUgvh73saFcEMPgIKbUo 7msrJOumHG3EP3Mzt2Z3Dov3XH2Wq2MWpaj0JPNxYk4UIQaUft9LMOT0FAc0/WGi6i OtciRBna4adWA== 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 11/18/19 1:46 AM, Jan Kara wrote: > On Thu 14-11-19 21:53:18, 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. >> >> Factor out the common code into static functions, thus reducing the >> overall line count and the code's complexity. >> >> 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(). >> >> Also, further simplify (slightly), by waiting until the the successful >> end of each routine, to increment *nr. >> >> Reviewed-by: J=C3=A9r=C3=B4me Glisse >> Cc: Jan Kara >> Cc: Ira Weiny >> Cc: Christoph Hellwig >> Cc: Aneesh Kumar K.V >> Signed-off-by: John Hubbard >> --- >> mm/gup.c | 95 ++++++++++++++++++++++++-------------------------------- >> 1 file changed, 40 insertions(+), 55 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index 85caf76b3012..858541ea30ce 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -1969,6 +1969,29 @@ 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, >> + unsigned long end, struct page **pages) >> +{ >> + int nr =3D 0; >> + int nr_recorded_pages =3D 0; >> + >> + do { >> + pages[nr] =3D page; >> + nr++; >> + page++; >> + nr_recorded_pages++; >> + } while (addr +=3D PAGE_SIZE, addr !=3D end); >> + return nr_recorded_pages; >=20 > nr =3D=3D nr_recorded_pages so no need for both... BTW, structuring this = as a > for loop would be probably more logical and shorter now: >=20 > for (nr =3D 0; addr !=3D end; addr +=3D PAGE_SIZE) > pages[nr++] =3D page++; > return nr; >=20 Nice touch, I've applied it. thanks, --=20 John Hubbard NVIDIA > The rest of the patch looks good to me. >=20 > Honza >=20