Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1093580ybj; Thu, 7 May 2020 14:48:16 -0700 (PDT) X-Google-Smtp-Source: APiQypI0EDaEGAY9U6VnlSTkqJMwBhqisL9iSgEvv1xfeTsPIhPTYTC84f12d/cl4JBApfruUDOH X-Received: by 2002:a17:907:2098:: with SMTP id pv24mr14492149ejb.22.1588888096133; Thu, 07 May 2020 14:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588888096; cv=none; d=google.com; s=arc-20160816; b=PL6IHHPLQ82UfKkaIAJXrePNX4rySmaYMxD+KzG0ULpd+XFv5IVsvsIdm32Bqv6oyX tMHVI/YB0mXdK4r6tAITE/2XUrLkT78BWPnTIATpzEwEseAgdOZIddUyPs231r3iY1Br ENVc4bGpuTcFNJagSSftdywahg/jffkNh2pl3ARsYPcd9DdzEj+AOFuf4ruqbkb6Y/Xm +tBKI/TzTe5fswgBl2OViiVDGPnrm8U8gRjN0S7jPH8IFf8+A6pRS48swW72FJdg4WBt XDwWpRRrZ0gP2RN+5+FvV8fbrtr/4g8wJf0w5QqPoDKZpEhF3OKRtVkB5WgXGNPhuHJJ XZyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mR5KN3Pz1n6bpXv2DNeSraShlVTsxJWNxOu3C85SoMg=; b=XZaHEeTxz4vs61rxTRZ2i+rEWNiza5Owz/dRVmVTUN+cIs22iMvv9A9GgliznnI1vj lMNNl7NI0zz2VD+hhiwDosPz5oyhSg8x//5ROhtS0BEt1DRTXfn7JFw1Dgsbh6Q1W4q3 isat62CetMW69rKmjt4b+G4rUHOG/HyWgnCp9tvgaA8XBR8NEaS6Ye6Uk48cEqQWvzU3 dp7vbDej78/iiTfD2qWm6Zj0IodQNDCevjnxDI1uza6KkBU2DpRsd0GqXoPe9xzZ2M88 akocHionZJOwucEL+jiXPtQMYwqxUsEmcUyW/mnoUDayWuGrD3HiWmzFNXKDWHSh3qCy iYVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=NAbAsbcC; 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 dn17si5383328ejc.311.2020.05.07.14.47.53; Thu, 07 May 2020 14:48:16 -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=NAbAsbcC; 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 S1726751AbgEGVoU (ORCPT + 99 others); Thu, 7 May 2020 17:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbgEGVoT (ORCPT ); Thu, 7 May 2020 17:44:19 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6667FC05BD0A for ; Thu, 7 May 2020 14:44:19 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id d16so6739240edv.8 for ; Thu, 07 May 2020 14:44:19 -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=mR5KN3Pz1n6bpXv2DNeSraShlVTsxJWNxOu3C85SoMg=; b=NAbAsbcCbcOXGfgGm7ahZi0o5gzd0TsLfygSJrNrVrw5vLmqVRWfCI3isz5iFR5mbA STvZy0Ini+hckNV2WvZupD+LtTplGUSiOCIH9BQ4aOETcgeCdIpI3Mj4WzqQem9CXLDe qYqvI/C+O08KvR+8KRty0U7zvjbl56T9lDhJogFf/OcHKnQJ9/6T7DcnRmFb0xuydSVo OCcwBscdI31qgR35JMlzx4rHo/+NUlCVj0gEvFfy2Ss+woreUw2pfXnuKNU5iEfww/Em QGboLZniwFBp/2tvxFy9cYEauvwdXj+tBAzwiJzCfCEprECi1B8+ab9SEyFXMnVToH+E +Dmg== 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=mR5KN3Pz1n6bpXv2DNeSraShlVTsxJWNxOu3C85SoMg=; b=rosGg23KCod9i4mnPStzcN7u3V4LlMdLGF5c0+Tgy+51mY/Y0YBABlrE1F5fN4HvhG tb3ssIwxNWm93Spgr+Y5+LoblIXxxcnh1HWgxZLR7Uo+X00sAg8zeoHomt5+jo3x1zBC EbuY8T24+b2FpFtXcm/MTUCfZ++Wy+oS2WKsCWRRDZMrbpRtqeT7YU2a1BVS+oSgKrhV jstY7UXgkAOhXhYvwSrEo4XkAJceUQ/lNf10IECUl5RTLAjlTSv0flMvo3+aAPC5DYAp LrPwQxYhY1sGhV2xMi2N5ahs4nJg3/vZqmpWrAySgbo7knflBPX4Lzk/YmedhuCd+d6f 1d5g== X-Gm-Message-State: AGi0PubiayLrQVYwRmpyGSoukR5I7WiZAX4A7maIMyTGYU/7369oD5Lz gl7I44MSAuBazXGDO1MEv1ZgGw== X-Received: by 2002:a05:6402:221c:: with SMTP id cq28mr13246566edb.50.1588887857976; Thu, 07 May 2020 14:44:17 -0700 (PDT) Received: from ls00508.pb.local ([2001:1438:4010:2540:a1ee:a39a:b93a:c084]) by smtp.gmail.com with ESMTPSA id k3sm613530edi.60.2020.05.07.14.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 14:44:17 -0700 (PDT) From: Guoqing Jiang To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: david@fromorbit.com, hch@infradead.org, willy@infradead.org, Guoqing Jiang , Andrew Morton , linux-mm@kvack.org, "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 V3 01/10] include/linux/pagemap.h: introduce attach/detach_page_private Date: Thu, 7 May 2020 23:43:51 +0200 Message-Id: <20200507214400.15785-2-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com> References: <20200507214400.15785-1-guoqing.jiang@cloud.ionos.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/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: linux-mm@kvack.org 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 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 a8f7bd8ea1c6..99dd93188a5e 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,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 -- 2.17.1