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.3 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 D39D9C433E0 for ; Fri, 15 May 2020 06:29:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7730820728 for ; Fri, 15 May 2020 06:29:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7730820728 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 DC5D790000C; Fri, 15 May 2020 02:29:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D51048E0005; Fri, 15 May 2020 02:29:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C191790000C; Fri, 15 May 2020 02:29:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id A58418E0005 for ; Fri, 15 May 2020 02:29:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5BF2D2C0C for ; Fri, 15 May 2020 06:29:02 +0000 (UTC) X-FDA: 76817975724.27.swim56_1478d7a08b803 X-HE-Tag: swim56_1478d7a08b803 X-Filterd-Recvd-Size: 3005 Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 06:29:00 +0000 (UTC) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D74529857C06E2477F6F; Fri, 15 May 2020 14:28:56 +0800 (CST) Received: from [127.0.0.1] (10.166.215.55) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Fri, 15 May 2020 14:28:54 +0800 Subject: Re: [PATCH v2 06/10] mm/swap: use npage_to_sectors() and PAGE_SECTORS to clean up code To: Matthew Wilcox CC: Minchan Kim , Nitin Gupta , "Sergey Senozhatsky" , Jens Axboe , Coly Li , Kent Overstreet , Alasdair Kergon , Mike Snitzer , linux-block , "Andrew Morton" , linux-mm , dm-devel , Song Liu , linux-raid , linux-kernel References: <20200507075100.1779-1-thunder.leizhen@huawei.com> <20200507075100.1779-7-thunder.leizhen@huawei.com> <20200515040647.GC16070@bombadil.infradead.org> From: "Leizhen (ThunderTown)" Message-ID: <766da107-bc67-ff99-a8c8-87f8f98c7cf6@huawei.com> Date: Fri, 15 May 2020 14:28:53 +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: <20200515040647.GC16070@bombadil.infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.166.215.55] X-CFilter-Loop: Reflected 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/15 12:06, Matthew Wilcox wrote: > On Thu, May 07, 2020 at 03:50:56PM +0800, Zhen Lei wrote: >> @@ -266,7 +266,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc) >> >> static sector_t swap_page_sector(struct page *page) >> { >> - return (sector_t)__page_file_index(page) << (PAGE_SHIFT - 9); >> + return npage_to_sectors((sector_t)__page_file_index(page)); > > If you make npage_to_sectors() a proper function instead of a macro, > you can do the casting inside the function instead of in the callers > (which is prone to bugs). Oh, yes. __page_file_index(page) maybe called many times in marco, althouth currently it is not. So that, not all are suitable for page_to_sector(). And for this example, still need to use "<< PAGE_SECTORS_SHIFT". > > Also, this is a great example of why page_to_sector() was a better name > than npage_to_sectors(). This function doesn't return a count of sectors, > it returns a sector number within the swap device. OK, so I will change to page_to_sector()/sector_to_page(). > > > . >