From patchwork Sun May 17 21:47:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 11554391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1120138A for ; Sun, 17 May 2020 21:48:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82240207E8 for ; Sun, 17 May 2020 21:48:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="bc9JiCyN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726700AbgEQVr1 (ORCPT ); Sun, 17 May 2020 17:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbgEQVr1 (ORCPT ); Sun, 17 May 2020 17:47:27 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02FDC05BD0D for ; Sun, 17 May 2020 14:47:26 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id g14so20994625wme.1 for ; Sun, 17 May 2020 14:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=umFCQ4NMWCIE/enEbdR7IzBDkwF+7PPxVjQ7OU7ryME=; b=bc9JiCyNi2SaYl+btE6yrujudYyNLl78V5XpCyZ9/4KEKAxZRAkGj+1u6RtqkAg8km AqFdngrJgZ/406TlWA1lT6giJ9khHuUW7QONSzFjqtf58qeWHJGMxhP3aPHFDtf+2zaQ mydxAV6NRzV2r1+bfnNomk9OOUhPLAlSKRxC16WEBfx4jes9GyHem4xpgvJTiW5lWMUw vhTlktN5Wp5bdjPQy+ibqrcIY+uBMIk5JRsyjeodQ5f5J23sr5oITBr9zBlowO7pPGPZ VRPpox3R7Qe8bogft+q4bqukDp6Glyy0BZW8Wg4rtv5njYWjLb6gNugwrmJhNroIrloy qcIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=umFCQ4NMWCIE/enEbdR7IzBDkwF+7PPxVjQ7OU7ryME=; b=oevgGxspWUmcbR4zZUZyIUQZMfqloWLNkOmL6ywqi4Vdu8cjReO+AvUqbyRpBMPzYf 4se5N5zDnGxPcQDSB2CO28MKD3A4Dc9+9E/cu2yztpvWxtg5wW4MNTjTmGssmmzFLTRl o4hDRifxEcLXDzpwtMC6YgnhLg+7a9JW9WTvFE70WO1YrxVeZB7Iy4Y46uEGWXz1KHXL IQLayMlzeCqzCuWSMgS/93qx6UlD5q6Pvwdx+q5gBFvej770X/E1DcrBIIdf9/LJEV/M CEHi5G9SyHRPTSyoDCmrtGuQs6XhuZh/LXVF4IvQtE5dWdPZYGTilH41s8CDND/Yvv4c PFCg== X-Gm-Message-State: AOAM533/rlkkxvVCyFo3UeIQLqbJGrMccX7+zI5r2BX/KbG7wEfn4ONW YmEmPTGPwbfMA0aN97ZEEAqheg== X-Google-Smtp-Source: ABdhPJw4f9DasVjg3UWnPvpGkYC6F50+B/J+YVBxdXzbXqEpee6TDkiCS9KiwItSk/Fp8hTBso6ChQ== X-Received: by 2002:a1c:545e:: with SMTP id p30mr15205009wmi.20.1589752043827; Sun, 17 May 2020 14:47:23 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:bc3e:92a1:7010:2763]) by smtp.gmail.com with ESMTPSA id v126sm14441244wmb.4.2020.05.17.14.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 14:47:23 -0700 (PDT) From: Guoqing Jiang To: akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, david@fromorbit.com, hch@infradead.org, willy@infradead.org, Guoqing Jiang , "Darrick J. Wong" , William Kucharski , "Kirill A. Shutemov" , Andreas Gruenbacher , Yang Shi , Yafang Shao , Song Liu , linux-raid@vger.kernel.org, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Anton Altaparmakov , linux-ntfs-dev@lists.sourceforge.net, Mike Marshall , Martin Brandenburg , devel@lists.orangefs.org, Thomas Gleixner , Sebastian Andrzej Siewior , Roman Gushchin , Andreas Dilger Subject: [PATCH 01/10] include/linux/pagemap.h: introduce attach/detach_page_private Date: Sun, 17 May 2020 23:47:09 +0200 Message-Id: <20200517214718.468-2-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200517214718.468-1-guoqing.jiang@cloud.ionos.com> References: <20200517214718.468-1-guoqing.jiang@cloud.ionos.com> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The logic in attach_page_buffers and __clear_page_buffers are quite paired, but 1. they are located in different files. 2. attach_page_buffers is implemented in buffer_head.h, so it could be used by other files. But __clear_page_buffers is static function in buffer.c and other potential users can't call the function, md-bitmap even copied the function. So, introduce the new attach/detach_page_private to replace them. With the new pair of function, we will remove the usage of attach_page_buffers and __clear_page_buffers in next patches. Thanks for suggestions about the function name from Alexander Viro, Andreas Grünbacher, Christoph Hellwig and Matthew Wilcox. Suggested-by: Matthew Wilcox Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: William Kucharski Cc: "Kirill A. Shutemov" Cc: Andreas Gruenbacher Cc: Yang Shi Cc: Yafang Shao Cc: Song Liu Cc: linux-raid@vger.kernel.org Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Alexander Viro Cc: Jaegeuk Kim Cc: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Cc: Christoph Hellwig Cc: linux-xfs@vger.kernel.org Cc: Anton Altaparmakov Cc: linux-ntfs-dev@lists.sourceforge.net Cc: Mike Marshall Cc: Martin Brandenburg Cc: devel@lists.orangefs.org Cc: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: Roman Gushchin Cc: Andreas Dilger Signed-off-by: Guoqing Jiang --- No change since RFC V3. RFC V2 -> RFC V3: 1. rename clear_page_private to detach_page_private. 2. updated the comments for the two functions. RFC -> RFC V2: Address the comments from Christoph Hellwig 1. change function names to attach/clear_page_private and add comments. 2. change the return type of attach_page_private. include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index c6348c50136f..8e085713150c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -208,6 +208,43 @@ static inline int page_cache_add_speculative(struct page *page, int count) return __page_cache_add_speculative(page, count); } +/** + * attach_page_private - Attach private data to a page. + * @page: Page to attach data to. + * @data: Data to attach to page. + * + * Attaching private data to a page increments the page's reference count. + * The data must be detached before the page will be freed. + */ +static inline void attach_page_private(struct page *page, void *data) +{ + get_page(page); + set_page_private(page, (unsigned long)data); + SetPagePrivate(page); +} + +/** + * detach_page_private - Detach private data from a page. + * @page: Page to detach data from. + * + * Removes the data that was previously attached to the page and decrements + * the refcount on the page. + * + * Return: Data that was attached to the page. + */ +static inline void *detach_page_private(struct page *page) +{ + void *data = (void *)page_private(page); + + if (!PagePrivate(page)) + return NULL; + ClearPagePrivate(page); + set_page_private(page, 0); + put_page(page); + + return data; +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else From patchwork Sun May 17 21:47:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 11554381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBA41618 for ; Sun, 17 May 2020 21:48:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B426A20820 for ; Sun, 17 May 2020 21:48:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="OnCwteZT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726823AbgEQVsD (ORCPT ); Sun, 17 May 2020 17:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbgEQVra (ORCPT ); Sun, 17 May 2020 17:47:30 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E159C05BD0D for ; Sun, 17 May 2020 14:47:30 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id e16so9562774wra.7 for ; Sun, 17 May 2020 14:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KhLF+EAo4dGVe9BW/cZoXpOODpgV89tLSnKlct0jr14=; b=OnCwteZT1cB8ocCGH1aeVFrR4EgF5VX00CwdKk8KWUvXv5ftfo0fsjEkaKXrYyqAko mv8QW8YvOau+ddNZijQJPWJlc875CMZRCq5jPs47LtKcK0iAs7w4XKAdfWadVkwF5yh0 vbZ8lxoep7MmAuEH6k47PeqCAdK68/ugEpDe30/qtwZ9iClzkmuyh8DAmed8tdkPBipP jtwANFKLPWtFlbDtTJ0ozTDQyrJ/8MF+yVMxoywDnUPV0eAnzFwGIvF1UFAWTh1jfkPy frPno0kwJWfIWzY+KzjmatENTMD8D9ajyV22QBav5R+pK9+lpGb7JXY4w7s1coccPTEN Jq9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KhLF+EAo4dGVe9BW/cZoXpOODpgV89tLSnKlct0jr14=; b=Pvt3yMCi0mxXe2PiaI2jxIt3awmx1bTzFZ+8EqjmVErbiniC0fGqw+fKPXF5IIs8oj 01uMlDOWlkWZwxPTMGDVrsoSpWkXMH0Qu1HI7eUvJLG5XROCvp1xdl30rFsTEbnTJEuZ NEA0+XsTBsVmZAjLOdzTpDcIW9aoGn4xS4TIuBalqLaVsJOKMegKV8L3+pKgWxudDgHM pLdOic/POFBEFQsSylQTzTiXu6lC755fjN6Bkm8lwY/LQN7b2dxOIUcv4Uj8ebRnps0J vC3vq5fkb6HPr9qFKB7zPXV5+1WV7CnKYjWlfCIKK+0LVgbhHJMGPYyT0Oa0BW+6LKNU 4JeA== X-Gm-Message-State: AOAM5320ktomhBrS71VnrbpK6N2TOQSk6/egE5WJ2WXeeoYFELu39Xc7 NL3Uc7XuX7jv6hlnWScvOjVyzw== X-Google-Smtp-Source: ABdhPJxxkRT4OGk3cy6v3FeXQDoR5/LNYOrP29Np5Cq4jtgQoATViCQkp2walv4nqYI4LHoZCE16MQ== X-Received: by 2002:a5d:5228:: with SMTP id i8mr16279223wra.359.1589752049269; Sun, 17 May 2020 14:47:29 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:bc3e:92a1:7010:2763]) by smtp.gmail.com with ESMTPSA id v126sm14441244wmb.4.2020.05.17.14.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 14:47:28 -0700 (PDT) From: Guoqing Jiang To: akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, david@fromorbit.com, hch@infradead.org, willy@infradead.org, Guoqing Jiang , "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 06/10] iomap: use attach/detach_page_private Date: Sun, 17 May 2020 23:47:14 +0200 Message-Id: <20200517214718.468-7-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200517214718.468-1-guoqing.jiang@cloud.ionos.com> References: <20200517214718.468-1-guoqing.jiang@cloud.ionos.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Since the new pair function is introduced, we can call them to clean the code in iomap. Cc: Christoph Hellwig Cc: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Signed-off-by: Guoqing Jiang --- No change since RFC V3. RFC V2 -> RFC V3 1. rename clear_page_private to detach_page_private. RFC -> RFC V2 1. change the name of new functions to attach/clear_page_private. 2. call attach_page_private(newpage, clear_page_private(page)) to cleanup code further as suggested by Matthew Wilcox. 3. don't return attach_page_private in iomap_page_create per the comment from Christoph Hellwig. fs/iomap/buffered-io.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 890c8fcda4f3..a1ed7620fbac 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -59,24 +59,19 @@ iomap_page_create(struct inode *inode, struct page *page) * migrate_page_move_mapping() assumes that pages with private data have * their count elevated by 1. */ - get_page(page); - set_page_private(page, (unsigned long)iop); - SetPagePrivate(page); + attach_page_private(page, iop); return iop; } static void iomap_page_release(struct page *page) { - struct iomap_page *iop = to_iomap_page(page); + struct iomap_page *iop = detach_page_private(page); if (!iop) return; WARN_ON_ONCE(atomic_read(&iop->read_count)); WARN_ON_ONCE(atomic_read(&iop->write_count)); - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); kfree(iop); } @@ -526,14 +521,8 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage, if (ret != MIGRATEPAGE_SUCCESS) return ret; - if (page_has_private(page)) { - ClearPagePrivate(page); - get_page(newpage); - set_page_private(newpage, page_private(page)); - set_page_private(page, 0); - put_page(page); - SetPagePrivate(newpage); - } + if (page_has_private(page)) + attach_page_private(newpage, detach_page_private(page)); if (mode != MIGRATE_SYNC_NO_COPY) migrate_page_copy(newpage, page);