Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2237373ybk; Sun, 17 May 2020 14:49:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi8qque6fcTQRADZbNGyv7eF2HDbRgncSiFIJ/w9VVVcMdIz8bwYeRctYWBe9LzzPcUD6x X-Received: by 2002:a17:906:ece4:: with SMTP id qt4mr12916857ejb.162.1589752152715; Sun, 17 May 2020 14:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589752152; cv=none; d=google.com; s=arc-20160816; b=qpmkgWdRjkIXo/RTB5gEgpNkDWLpJ37ACFsZPQujZcCoRZ5DE3jkoyflMFu/ihVWV0 S2Omqa+MK8ztoAkmH99miQoxm9oMQk/OmOIPx+biC9LMmgdjPHBze1165Z2xnvkp3nxE /Nx1x7Aly5dYzCWnzkANdkoQy7b6FDLWFSvDyfJ5PI4hgAslbrAeXLMUtMqL4NbCNmSs sWNnAsKgwQqOjQftNMgO3wneHquTOVy1BIv6Vf4W4XNHyUm8xhUMQ6tvV/aRX1QtKZ0P eAAS2qC09IH185q4v4AkPrxxi+AAbQ3uOhdn9ZxY59y2iGt7VfPakXnh0Uae6PSA1XJN b7UA== 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=umFCQ4NMWCIE/enEbdR7IzBDkwF+7PPxVjQ7OU7ryME=; b=CVWwPAqvMZmzrEZcWGfF2VptA63sJ4BMZx9Ov66MJAa0hdY/VNeWX6qp8ErJYBeSsE 5MDHWgvwqDqWSlvaHQ36OHt2Lr83uByV7PEXX/5RmECvDE23di2hBI4WAk1Rx2+SAFeJ UXu7tr2V1jU9Lp3DKUQonnpFgStk4JBPIY9qXeU7QqFd80uAp/poioZisaG7GFlxgWVQ XBo+aTrgH4p+Dm4Zcz34/OKEn3YP4kkB7Q28CKBqZzbhAww+ElsQ6IH8CGqphfqlvi6j palUNaCNP3I9DaUhTT5W6TDWY6xyTVkO+lohxsfAXESd1Q27Ch3b7ipSQjBAKckNHyFl FK2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=bc9JiCyN; 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 c95si3201631edf.206.2020.05.17.14.48.49; Sun, 17 May 2020 14:49:12 -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=bc9JiCyN; 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 S1726729AbgEQVr2 (ORCPT + 99 others); Sun, 17 May 2020 17:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726671AbgEQVr0 (ORCPT ); Sun, 17 May 2020 17:47:26 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC52C05BD09 for ; Sun, 17 May 2020 14:47:25 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id n18so3929993wmj.5 for ; Sun, 17 May 2020 14:47:25 -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=Lz7/gJ26Vtppi5EY9bvGTr/2i9JxfpGkbULrnv6FQ8vFPRQyn/ZUdLAzaRiYmK7Bqc XYxZ8e84tMPiXypuPs4AVZk19V4ofitPgbCq7M0xHhczp6x6Ut1ZC11r01b6+Sley1TF IUc1PUw+KUGqTXHRUjJ+4gRRvGAtBgH+XV99NQ3ggy4vvKBp/i8+9nw5PTtV1W62lt4s nU5DWO3mqmcwNz/J4e6cKeq7JGvKOI7kFij6zImXMpQLMYuG9Be95bmHG7L1tWVJ1jgn 82iS85zgQIa7Zyw0GJzSkMuX97BXiBCmRcDksV+lwqLF/bQ6rEAllkOjcoLXcoN7UJ1Q oMug== X-Gm-Message-State: AOAM533A8G9EhhWfsiD27rfLIQdCBpwcb+6lZgtX/MTRxYcffGp2V28c DbKtDN0EjAmI2JMG/8Tt37KLfw== 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 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: "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 -- 2.17.1