From patchwork Thu May 7 21:43:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 11534965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9806D139A 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 5B7DC208D6 for ; Thu, 7 May 2020 21:44:21 +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 5B7DC208D6 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5ED11900002; Thu, 7 May 2020 17:44:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org 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-Original-To: linux-mm@kvack.org 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-Spam-Summary: 2,0,0,3aec6fc3c6ac57df,d41d8cd98f00b204,guoqing.jiang@cloud.ionos.com,,RULES_HIT:41:152:355:379:541:800:960:966:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2895:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4118:4385:5007:6119:6120:6261:6653:6742:6743:7514:7875:7903:8660:8957:10004:10394:10400:10450:10455:11026:11232:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13148:13153:13161:13228:13229:13230:13255:13846:13894:14096:14097:14181:14659:14721:19904:19999:21060:21080:21444:21451:21627:21789:21990:30003:30029:30030:30054:30064:30070,0,RBL:209.85.208.66:@cloud.ionos.com:.lbl8.mailshell.net-66.201.201.201 62.14.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:74,LUA_SUMMARY:none 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 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ü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 From patchwork Thu May 7 21:44:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 11534973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93D0C912 for ; Thu, 7 May 2020 21:44:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6169C208E4 for ; Thu, 7 May 2020 21:44:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="dkeBq94O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6169C208E4 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 6B23A900004; Thu, 7 May 2020 17:44:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 66330900002; Thu, 7 May 2020 17:44:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A084900004; Thu, 7 May 2020 17:44:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 41E55900002 for ; Thu, 7 May 2020 17:44:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EC0DF10F23 for ; Thu, 7 May 2020 21:44:29 +0000 (UTC) X-FDA: 76791252258.10.death65_7e8dbbc584639 X-Spam-Summary: 2,0,0,a58f8f537057ebed,d41d8cd98f00b204,guoqing.jiang@cloud.ionos.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1431:1437:1534:1540:1568:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3876:3877:4321:5007:6114:6119:6120:6261:6642:6653:7903:8660:8957:10004:11026:11232:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13069:13148:13230:13311:13357:13846:14096:14181:14384:14721:21080:21212:21444:21451:21627:30012:30054,0,RBL:209.85.218.52:@cloud.ionos.com:.lbl8.mailshell.net-66.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: death65_7e8dbbc584639 X-Filterd-Recvd-Size: 3783 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 May 2020 21:44:29 +0000 (UTC) Received: by mail-ej1-f52.google.com with SMTP id q8so5911445eja.2 for ; Thu, 07 May 2020 14:44:29 -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=p3qBa9K9MbgLEfhWUqlAktM7PPXv8tgud53nGFCyYG0=; b=dkeBq94OBb3NF7kVoAbkVx2HSO3CU2chuvwHNFGEWXV0yhNdXxm/WFjxCC0MkuBwOQ ukTQVmH3uUPgYCweOd1LQwPUAiwXSwuEHHA3DGaAzdHCj7mD6A77knGTR2DbyLLaoMmr P9/xT7V4BL2slYRI2haV4GFVTBcxtTPf1JtlHWg9BSOm7kTAMgWRJ5oRuiN5qcHOOlyX BNtTA6Fe24s8s4Oa3ZVX5xjq6Kj2yZ8P5YLEXdWpAx+lfEA+3pPnLlKxThXhKsFv5fWe zkNndfIoksb9SEG4OkxblR24QSkvS1+qVaCorcEY8RlAtYD1QYFhXRzyfiZlmBPsE72S mwbg== 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=p3qBa9K9MbgLEfhWUqlAktM7PPXv8tgud53nGFCyYG0=; b=XBpqIGQ7bX8v3EMIVZRkeyVHrVbWokfNBj4uJ41LRJ8VU/OZEVEchUtKBzcwOiqRQC wmW1toONRyVT6/INK9OMCRPonDr2P8Wgh6B3EW+/C9fZ22e+698UZWuhaAJI8wVO1p2X cLFMtNLAhsdK2dUpHjQnOQnS9XMPTe6NpbFaoRyjzNkIP7Z/EwR33YT+YVwTg49cfFPe iZNhpF6QbKmUqS0PkcMmHNys1Ul7wwblk7nJXEGtXAXllERaz2kFTHk3bQzRthOF0uzj 1Zdi3xv7d7fFob8XaQlSPQIGxxki6MrGmW7KYWBGwuBcZMe4NjVEdv5sG4QAYK8m/Ip+ ngmg== X-Gm-Message-State: AGi0PuawfFzw8pVyhAmrT7W0fct7FHoKynaxQTzkZHyeYGHB4Q2wE+fJ d851Mk+TadrKMeJr1uoHoDiq6w== X-Google-Smtp-Source: APiQypIynmIlSHyf+k65C+y42oKo8PLrA1c4S7WEkoE13fKDpP+OJZwLHdb5GIwza40Y5+tp0xnxFQ== X-Received: by 2002:a17:906:a857:: with SMTP id dx23mr14469278ejb.52.1588887868069; Thu, 07 May 2020 14:44:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 14:44:27 -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 Subject: [RFC PATCH V3 10/10] mm/migrate.c: call detach_page_private to cleanup code Date: Thu, 7 May 2020 23:44:00 +0200 Message-Id: <20200507214400.15785-11-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> 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: We can cleanup code a little by call detach_page_private here. Cc: Andrew Morton Cc: linux-mm@kvack.org Signed-off-by: Guoqing Jiang --- Added since RFC V3. mm/migrate.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 7160c1556f79..f214adfb3fa4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -797,10 +797,7 @@ static int __buffer_migrate_page(struct address_space *mapping, if (rc != MIGRATEPAGE_SUCCESS) goto unlock_buffers; - ClearPagePrivate(page); - set_page_private(newpage, page_private(page)); - set_page_private(page, 0); - put_page(page); + set_page_private(newpage, detach_page_private(page)); get_page(newpage); bh = head;