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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 934ACC28CBC for ; Wed, 6 May 2020 09:16:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EC6520714 for ; Wed, 6 May 2020 09:16:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EC6520714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8AE208E0005; Wed, 6 May 2020 05:16:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8370C8E0003; Wed, 6 May 2020 05:16:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D8668E0005; Wed, 6 May 2020 05:16:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 50D148E0003 for ; Wed, 6 May 2020 05:16:18 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 134E11CB0E for ; Wed, 6 May 2020 09:16:18 +0000 (UTC) X-FDA: 76785738036.14.wool54_53e2c29d20c4b X-HE-Tag: wool54_53e2c29d20c4b X-Filterd-Recvd-Size: 3247 Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 May 2020 09:16:16 +0000 (UTC) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 49EA1F029C3B287432E4; Wed, 6 May 2020 17:16:08 +0800 (CST) Received: from [127.0.0.1] (10.166.215.55) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Wed, 6 May 2020 17:16:05 +0800 Subject: Re: [PATCH 2/4] mm/swap: use SECTORS_PER_PAGE_SHIFT to clean up code From: "Leizhen (ThunderTown)" To: Matthew Wilcox CC: Minchan Kim , Nitin Gupta , "Sergey Senozhatsky" , Jens Axboe , linux-block , Andrew Morton , linux-mm , Alasdair Kergon , Mike Snitzer , dm-devel , Song Liu , linux-raid , linux-kernel References: <20200505115543.1660-1-thunder.leizhen@huawei.com> <20200505115543.1660-3-thunder.leizhen@huawei.com> <20200505172520.GI16070@bombadil.infradead.org> <32ba9907-60ad-27c0-c565-e7b5c80ab03c@huawei.com> Message-ID: <8fefbfb2-1100-fab2-0383-e57343dc44f5@huawei.com> Date: Wed, 6 May 2020 17:16:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.166.215.55] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable 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 2020/5/6 11:47, Leizhen (ThunderTown) wrote: >=20 >=20 > On 2020/5/6 9:33, Leizhen (ThunderTown) wrote: >> >> >> On 2020/5/6 1:25, Matthew Wilcox wrote: >>> On Tue, May 05, 2020 at 07:55:41PM +0800, Zhen Lei wrote: >>>> +++ b/mm/swapfile.c >>>> @@ -177,8 +177,8 @@ static int discard_swap(struct swap_info_struct = *si) >>>> =20 >>>> /* Do not discard the swap header page! */ >>>> se =3D first_se(si); >>>> - start_block =3D (se->start_block + 1) << (PAGE_SHIFT - 9); >>>> - nr_blocks =3D ((sector_t)se->nr_pages - 1) << (PAGE_SHIFT - 9); >>>> + start_block =3D (se->start_block + 1) << SECTORS_PER_PAGE_SHIFT; >>>> + nr_blocks =3D ((sector_t)se->nr_pages - 1) << SECTORS_PER_PAGE_SHI= FT; >>> >>> Thinking about this some more, wouldn't this look better? >>> >>> start_block =3D page_sectors(se->start_block + 1); >>> nr_block =3D page_sectors(se->nr_pages - 1); >>> >> >> OK=EF=BC=8CThat's fine, it's clearer. And in this way, there won't be = more than 80 columns. >=20 > Should we rename "page_sectors" to "page_to_sectors"? Because we may ne= ed to define > "sectors_to_page" also. Change the "sectors_to_page" to "sectors_to_npage", npage means "number o= f pages" or "page number". To distinguish the use case of "pfn_to_page()" etc. The= latter returns the pointer of "struct page". >=20 >> >>> >>> . >>>