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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 7BD09C433E0 for ; Fri, 15 May 2020 04:07:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26BB0206DA for ; Fri, 15 May 2020 04:07:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="uP0kdW5N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26BB0206DA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D1E4890000C; Fri, 15 May 2020 00:07:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCF958E0005; Fri, 15 May 2020 00:07:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE45D90000C; Fri, 15 May 2020 00:07:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id A47028E0005 for ; Fri, 15 May 2020 00:07:06 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 62741181AC9CB for ; Fri, 15 May 2020 04:07:06 +0000 (UTC) X-FDA: 76817618052.08.burn50_5b1734bd67234 X-HE-Tag: burn50_5b1734bd67234 X-Filterd-Recvd-Size: 2893 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 04:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5PwB/9JSdMfY5nBxzWW07ajXI/9xxScbdH3I41S0bUQ=; b=uP0kdW5N0sgVFf0t9LYyPg7+md SebAjT9iphzheJMd77jFgS5a6+kfWSVXR0scfu2ahFIsIDrf8ysSznN/jH6WpEvk21W2p2kNEzkY1 D1fvCfaB8yehGnBKN9c46Y96JKkxI8F0KQGtGnit3fYaaeXAuN2PvTr+WUd5Tk/He+gqAr4ypsrV5 Oh8GFCWYk6Hfl831KzJU3VBKjavRxxbCEWsfW2pMkN8wAoiI1plB/WYtyVtDinwDJT8T6U78d9cz9 aLAyOSxU9vlMhqWOAwnfSz1Hzw36/gUEbutRc11m99ZvOeuQOiKLJ+yc4JAqR0hA/X1Xs2MDVML+/ If4Hvqjg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZRcV-0008AQ-A6; Fri, 15 May 2020 04:06:47 +0000 Date: Thu, 14 May 2020 21:06:47 -0700 From: Matthew Wilcox To: Zhen Lei 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 Subject: Re: [PATCH v2 06/10] mm/swap: use npage_to_sectors() and PAGE_SECTORS to clean up code Message-ID: <20200515040647.GC16070@bombadil.infradead.org> References: <20200507075100.1779-1-thunder.leizhen@huawei.com> <20200507075100.1779-7-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507075100.1779-7-thunder.leizhen@huawei.com> 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 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). 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.