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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 C2EF3C433DF for ; Tue, 2 Jun 2020 20:12:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 842A9207DA for ; Tue, 2 Jun 2020 20:12:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="o5nsWsbi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 842A9207DA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 25A8D8002A; Tue, 2 Jun 2020 16:12:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20B4280007; Tue, 2 Jun 2020 16:12:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 120078002A; Tue, 2 Jun 2020 16:12:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id EB6F080007 for ; Tue, 2 Jun 2020 16:12:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AD4BCEB0C5 for ; Tue, 2 Jun 2020 20:12:20 +0000 (UTC) X-FDA: 76885368840.22.doll37_6bb6f90c85d16 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 8BD3A1801201B for ; Tue, 2 Jun 2020 20:12:20 +0000 (UTC) X-HE-Tag: doll37_6bb6f90c85d16 X-Filterd-Recvd-Size: 5721 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Jun 2020 20:12:20 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6431E207FB; Tue, 2 Jun 2020 20:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591128739; bh=jNLTf8OxCeHSCWxrwDIqOBl6BzoN37shS/FVfT9TISA=; h=Date:From:To:Subject:In-Reply-To:From; b=o5nsWsbio9SBn4S1UmVEAY9IrFZYidVCVzgWJoT60yNk1NYoCnBq4mKPT7Rl7q58F AeAFcTByzENyjfwC1EJbOx1hHrWtxhxOXmL0+Xsie9dQHxm7MxIlkFianFwavfRJjc 9LGUUbMsBWrrMIPUKPIUWAUwcUmqTLQxRVwcd5Fg= Date: Tue, 02 Jun 2020 13:12:17 -0700 From: Andrew Morton To: adilger@dilger.ca, agruenba@redhat.com, akpm@linux-foundation.org, anton@tuxera.com, bigeasy@linutronix.de, chao@kernel.org, clm@fb.com, darrick.wong@oracle.com, david@fromorbit.com, dsterba@suse.com, guoqing.jiang@cloud.ionos.com, guro@fb.com, hch@infradead.org, hubcap@omnibond.com, jaegeuk@kernel.org, josef@toxicpanda.com, kirill.shutemov@linux.intel.com, laoar.shao@gmail.com, linux-mm@kvack.org, martin@omnibond.com, mm-commits@vger.kernel.org, song@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, william.kucharski@oracle.com, willy@infradead.org, yang.shi@linux.alibaba.com, yuchao0@huawei.com Subject: [patch 039/128] include/linux/pagemap.h: introduce attach/detach_page_private Message-ID: <20200602201217.1mLrItv6z%akpm@linux-foundation.org> In-Reply-To: <20200602130930.8e8f10fa6f19e3766e70921f@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 8BD3A1801201B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: =46rom: Guoqing Jiang Subject: include/linux/pagemap.h: introduce attach/detach_page_private Patch series "Introduce attach/detach_page_private to cleanup code". This patch (of 10): 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=C3=BCnbacher, Christoph Hellwig and Matthew Wilcox. Link: http://lkml.kernel.org/r/20200517214718.468-1-guoqing.jiang@cloud.ion= os.com Link: http://lkml.kernel.org/r/20200517214718.468-2-guoqing.jiang@cloud.ion= os.com Signed-off-by: Guoqing Jiang Suggested-by: Matthew Wilcox Reviewed-by: 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: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: Alexander Viro Cc: Jaegeuk Kim Cc: Chao Yu Cc: Christoph Hellwig Cc: Anton Altaparmakov Cc: Mike Marshall Cc: Martin Brandenburg Cc: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: Roman Gushchin Cc: Andreas Dilger Cc: Chao Yu Cc: Dave Chinner Signed-off-by: Andrew Morton --- include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) --- a/include/linux/pagemap.h~include-linux-pagemaph-introduce-attach-detac= h_page_private +++ a/include/linux/pagemap.h @@ -208,6 +208,43 @@ static inline int page_cache_add_specula return __page_cache_add_speculative(page, count); } =20 +/** + * 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 =3D (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 _