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=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 67591C38A2A for ; Thu, 7 May 2020 21:44:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0ED8F208E4 for ; Thu, 7 May 2020 21:44:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="NAbAsbcC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0ED8F208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cloud.ionos.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 63BAD900003; Thu, 7 May 2020 17:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ED11900002; Thu, 7 May 2020 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DBD9900003; Thu, 7 May 2020 17:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id 36F40900002 for ; Thu, 7 May 2020 17:44:20 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E672C99BD for ; Thu, 7 May 2020 21:44:19 +0000 (UTC) X-FDA: 76791251838.20.balls71_7d0f8a16d170b X-HE-Tag: balls71_7d0f8a16d170b X-Filterd-Recvd-Size: 7997 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 May 2020 21:44:19 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id y24so6893110edo.0 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=ocjbJU120CYH54BXY6Ppp+af+ZYjbm7q8hlfjyN0R4xkd/H1W2uGv1xrVOMhhGGk6t 0PEvb+YnWjuRP/JPvs2+Jlf8SBA9g/J2Q2rArGf1GBThzH1SoaoFaU+nOn7CPSjWw7+d gBt/iDfEZnYdjIjeOMgr48Rjo8hESqSydLaVFZqZTQDVKEl1MQV4/N9iDWJxWe2MnJ+P eSbY++x/r9ahy8KR74uVmQk9OveE+fgbb8zROK1X9Fka/hG1o5TXfLHGmkYgqvcsuDZV l0oXdquHH/0dALmUWhvKeflRDmkuGNxIcelK4Sl6B/6pgOL4D/1w0hChBcbxhMfgLrT1 8cRw== X-Gm-Message-State: AGi0PubBrk+57I3bTt+5TgsUZTmoSdSZnEvyR+WZ86txjHUifksbio94 Jf0da/0cZ0e3DIWR+Z+UHHmpRg== X-Google-Smtp-Source: APiQypLmX8YHBXb7kua9dEsVAJulVEp2exuqcsxlWLEdtzHF8lGn1ZzGxVKJFdK6oe8J4dems5+T3w== 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: quoted-printable 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: 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. 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); } =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 coun= t. + * 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 decreme= nts + * 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 --=20 2.17.1