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,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 BCEB9C432C3 for ; Wed, 13 Nov 2019 23:14:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 64E06206EC for ; Wed, 13 Nov 2019 23:14:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="A51eKIWP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64E06206EC 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 02E936B0003; Wed, 13 Nov 2019 18:14:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1FEC6B0005; Wed, 13 Nov 2019 18:14:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E18286B0006; Wed, 13 Nov 2019 18:14:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id CC1EE6B0003 for ; Wed, 13 Nov 2019 18:14:51 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 9B53A8249980 for ; Wed, 13 Nov 2019 23:14:51 +0000 (UTC) X-FDA: 76152811182.28.anger16_81ab4d3079536 X-HE-Tag: anger16_81ab4d3079536 X-Filterd-Recvd-Size: 6237 Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com [216.228.121.143]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Nov 2019 23:14:50 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 13 Nov 2019 15:14:51 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 13 Nov 2019 15:14:48 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 13 Nov 2019 15:14:48 -0800 Received: from [10.2.160.107] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 13 Nov 2019 23:14:47 +0000 Subject: Re: [PATCH v4 02/23] 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: <20191113042710.3997854-1-jhubbard@nvidia.com> <20191113042710.3997854-3-jhubbard@nvidia.com> <20191113111521.GI6367@quack2.suse.cz> From: John Hubbard X-Nvconfidentiality: public Message-ID: <56a575ac-c090-4063-67fc-c6cb24109442@nvidia.com> Date: Wed, 13 Nov 2019 15:12:02 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191113111521.GI6367@quack2.suse.cz> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed 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=1573686891; bh=9LRqaiCXGyssScdgi2q8tAszCMUWmamss75JnSCD7Rw=; h=X-PGP-Universal:Subject:To:CC:References:From:X-Nvconfidentiality: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=A51eKIWPld+4B5s2mm0c+AftPX6dpBjqpWkYujEzQW8kVLlFqmGjocd27BfsONHAP mmPJsbiq51gzeODte2X2C/uPkzYNTjtPJH03F4HVdvsPm9WWyPO3mCuFy2qZ+53ojk w6MdkTLmNoJEsvjJ1mHPlZG7UOzdlPWuN7wE/1LLT4AJNdQe+bbFVcAcD30SjuESOC HMOwl+XnOLJvxdKZ8WjJigzroAhsM6sSwkk0PcI+BOHfFZzPS0NsqTuAU0nk8z5SAy WgcifEMQlIH1QeCvlXON5hCNNd97lHyEHTXJRg5VuAfoyXIGForJZxdZ7GM5/XPnDu zIFH0GBGYNRaQ== 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/13/19 3:15 AM, Jan Kara wrote: > On Tue 12-11-19 20:26:49, 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: Ira Weiny >> Cc: Christoph Hellwig >> Cc: Aneesh Kumar K.V >> Signed-off-by: John Hubbard >=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, >> + unsigned long end, struct page **pages, int nr) >> +{ >> + 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 > Why don't you pass in already pages + nr? Aha, that does save a function argument. Will do. ... >> +static void __huge_pt_done(struct page *head, int nr_recorded_pages, in= t *nr) >> +{ >> + *nr +=3D nr_recorded_pages; >> + SetPageReferenced(head); >> +} >=20 > I don't find this last helper very useful. It seems to muddy water more > than necessary... Yes, I suspect it's rather unloved, and the fact that it was hard to accura= tely name should have been a big hint to not do it. I'll remove the helper and put the lines back in directly. thanks, --=20 John Hubbard NVIDIA >=20 > Other than that the cleanup looks nice to me. >=20 > Honza >=20