Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2311868ybz; Thu, 30 Apr 2020 14:56:27 -0700 (PDT) X-Google-Smtp-Source: APiQypIUOp+JvUaRDVHYdW0beDtQPSAOWcSBM2Yn/IuAWbS5DwqrEc5Y3pAX0tFU3aHLwIWEH8MX X-Received: by 2002:a50:ea87:: with SMTP id d7mr1046385edo.48.1588283787641; Thu, 30 Apr 2020 14:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588283787; cv=none; d=google.com; s=arc-20160816; b=qvT2Z+QayxzSk/CFtdXwwm19Zqb9ouDA0AyzT/BjboyOc/f+rZL1sSh4TIFGVUJFmA etSCuuaU22qLox3YKpsKahFOwEFcF6GTmBqxKth/z29tTUH4viBc2e9yYDoflL4AatXT FlkCLZvwg5SZYAF4K/a4tFjbU9Z4rVJVn1mTfYQjWZYcP0K865DfdUoQU9Ud5tw1+ErS TwpL3WfTj/IO/t3bkPZecb9OB+pruGKB3pHuZWbsuO9NO5ocpplVy/B4dPBstjRBornp nIzWqzCw9K/Fn1rxW26j1tzQgZuzPLwg775aEMu1auvP2MR8+Kp6e5f1eYoa2pxLcjlR Lj0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=md/K4aJ3DJ3NearZBqaJ0p50C7eWTdgYeQjfAkdJDw6SoJIdYNJYvHMKxG2oYRGDIm Rm/kWp4ba8E+uEWyq6fjeqGwPcYoSOzhGuSbbKUcXBNGdwoigNu2T5kG40dAuKazhwsb ONcXRglQKSYs2uxHBfIrehacktyjta+HHKU32MjID4MCGnyM3nn90ws4nx95ufLSO1pY 7WuJmXUgaAAzwnYzbkdiUgE/gOZeuVHaQT/HBa5QT229DMw8J67Zmm7p22lJo5x6EP06 Qvn2Y6HwKGe4aeNtUPItG0gCAjSZdJyGqm+MHxlDv4IcuttUg9HtXIuZE0k3oV2xHHCc DBpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=NGAEKGru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si555897edq.329.2020.04.30.14.56.04; Thu, 30 Apr 2020 14:56:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=NGAEKGru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbgD3VxT (ORCPT + 99 others); Thu, 30 Apr 2020 17:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgD3Vwj (ORCPT ); Thu, 30 Apr 2020 17:52:39 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C815CC035494 for ; Thu, 30 Apr 2020 14:52:38 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id x1so5967944ejd.8 for ; Thu, 30 Apr 2020 14:52:38 -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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=NGAEKGruhKtx7ZWTrFdEqTmqAVl/YDbNX5SVHiheCt5mgGQXMvPqVsB2mWj4W+6TZx avj1y2aqFM2fM4mYbpeY1mNHjz5L5wFBJHZ7nqGDO/UfrsVe7K3fK+19Qz0xhaRBCJF8 cnG9jsv0Y3cuCHExnrUC59PgGg5ldN6zReZ4l/MkqDih/pWf2Qq5leOqyJa1Ea1uUvqL KSJUgjKhSgiIMTbhcESV0rK/2/wlrqs0rRp/j53oVanG3NSXpHazoglUXFC2CIoq8QGs T0RBK7fYVyj0odwSJ7t5g5PDfIz9c6vhMkT7fz1ruAgadlRAj8EWlz0SjkauUs46ppHW r7PQ== 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=2Cwm7q37wd5a49T4hM9tpsz7D3qzUxu8CT8JBwv0w4c=; b=H16hrr6qFDxbuEyzVYBxSv7tPu0Wy/xg+A+7j2q1idHuDvgEkGHHyJSoRx420pDYP2 cNoXHSigGojfW1ag0C8nvN2ReNYpBA+Ig0Qsr3jCDc/wY0ObFZ/U5ObF0BCL4sD+1saB h21DYF4EcQb6NfWugFDwO8FX8WxvqMfBqSsWeADgVRPn+3ecYfRVDwBlAg9QRlKiUfHa 2EXq+73FDJJK/3P7kpjHKelyBtVXoUjxHcmLOpxsO7CgUfvuze9Lid70l839nitx1AGR NJL71iY23W1H1oUthPYkWGwmoQFDSjpZgrV0r7kfL1jnYXYHqPl5evBWYHMRMwermKES /0Kw== X-Gm-Message-State: AGi0PuYaUuBAMNFLXXw56eVa9BBi2EAdl09Wt81hv1XQa2IZX36oFeuJ 8M8B4fXkwlM9WKjV7E+IhPiEoQ== X-Received: by 2002:a17:906:b2c4:: with SMTP id cf4mr538626ejb.340.1588283557346; Thu, 30 Apr 2020 14:52:37 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:b82f:dfc:5e2a:e7cc]) by smtp.gmail.com with ESMTPSA id f13sm92022ejd.2.2020.04.30.14.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 14:52:36 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: hch@infradead.org, david@fromorbit.com, willy@infradead.org, Guoqing Jiang , Andrew Morton , "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, Alexander Viro , 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: [RFC PATCH V2 1/9] include/linux/pagemap.h: introduce attach/clear_page_private Date: Thu, 30 Apr 2020 23:44:42 +0200 Message-Id: <20200430214450.10662-2-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> References: <20200430214450.10662-1-guoqing.jiang@cloud.ionos.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/clear_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 the new names from Christoph Hellwig. 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 --- 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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..2e515f210b18 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,41 @@ static inline int page_cache_add_speculative(struct page *page, int count) return __page_cache_add_speculative(page, count); } +/** + * attach_page_private - attach data to page's private field and set PG_private. + * @page: page to be attached and set flag. + * @data: data to attach to page's private field. + * + * Need to take reference as mm.h said "Setting PG_private should also increment + * the refcount". + */ +static inline void attach_page_private(struct page *page, void *data) +{ + get_page(page); + set_page_private(page, (unsigned long)data); + SetPagePrivate(page); +} + +/** + * clear_page_private - clear page's private field and PG_private. + * @page: page to be cleared. + * + * The counterpart function of attach_page_private. + * Return: private data of page or NULL if page doesn't have private data. + */ +static inline void *clear_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 -- 2.17.1