From patchwork Fri Feb 3 03:01:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 52270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp610340wrn; Thu, 2 Feb 2023 19:02:44 -0800 (PST) X-Google-Smtp-Source: AK7set8misdNt5dno60WRZlbm2JCR1hRfDnvkv9sUVTELJ4yCB0nGkpYGId9qfgEFVtDrUZOsuQU X-Received: by 2002:a17:903:d1:b0:192:4f32:3ba7 with SMTP id x17-20020a17090300d100b001924f323ba7mr6804914plc.18.1675393364113; Thu, 02 Feb 2023 19:02:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675393364; cv=none; d=google.com; s=arc-20160816; b=eNh95O0Ak7bF6bIjkYMV7CrDWA3BwFrd9nGtC7rz01tHljuFC2cA0+SXtK0tjUTo97 ASsKsAhBSt5vU0+sYl+QYLGfitpm6CVvJ0rUtWNqBk9nvvOPqvN2x6x1hOBolBLZSNBJ r98JSNcgnX0R2vJrKrvggOG4O2XAtqxomzhIMGLIOCDjq3JDF3gs3dvUApFTlmtE8pMG OrHBkpw/jsgvRlMlLEkq1T0cfweEHX9L7ThfaMmQAw5jQKnQDmbUfD+y39S2Vbz7I0gd pMMzBtUGQ5IxcgJqpEEc5YrcHu8IocLIShSTECTPVVr5yWmtu/K74Frsnd4yNJ94yhjR pPSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=inyrVk2Fyb+OE4Nl8GN4TeuVPjpKeWPntOEIuzM9wFg=; b=SxgRg/1rgyoVvCi2kbqfYpUOAtdCq0izlTHMTFplFZC0PfrymAYn2n/mm833rXYpGV ozdUYo9X/2YvgkLO6VOOeO3WsxSfAWVRGSt9y5ureNx9YmXMJQ3FQWF3iZytPcWL2OXN Z/8SBJQWwN2GydBxCMHv/AVf8ezCL+iL8ALalasfIPhlmGV4khWL4IydDicSARNp3wYY 2A2PXSS1g86qc0EsO4w7ulJwr+PYaq3r0I0hg6ZKt2D8v2OQ4K2F45KsnLFnxZnBpw4m WZKL18E1XKv61mXLUWrD9Bzim1Wp/DmWKVSgCmaOarLSiBcRMAPgsixb6z/PLCp0K3RX uJFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a1709026b8b00b001787f1922a7si1087923plk.19.2023.02.02.19.02.30; Thu, 02 Feb 2023 19:02:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232340AbjBCDCN (ORCPT + 99 others); Thu, 2 Feb 2023 22:02:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjBCDBv (ORCPT ); Thu, 2 Feb 2023 22:01:51 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6064610A9D; Thu, 2 Feb 2023 19:01:50 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamlQX8_1675393307; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamlQX8_1675393307) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:47 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 4/9] erofs: allocate anonymous file of blob for page cache sharing Date: Fri, 3 Feb 2023 11:01:38 +0800 Message-Id: <20230203030143.73105-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756777272142000162?= X-GMAIL-MSGID: =?utf-8?q?1756777272142000162?= In prep for the following support for page cache sharing based mmap, allocate an anonymous file of corresponding blob, so that we can link associated vma to the blob later. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 1 + 2 files changed, 76 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 7f2e2d17e8e0..bed02b21978a 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -4,6 +4,8 @@ * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include +#include +#include #include "internal.h" static DEFINE_MUTEX(erofs_domain_list_lock); @@ -22,6 +24,11 @@ struct erofs_fscache_request { refcount_t ref; }; +struct erofs_fscache_finfo { + erofs_off_t pa; + pgoff_t max_idx; +}; + static struct erofs_fscache_request *erofs_fscache_req_alloc(struct address_space *mapping, loff_t start, size_t len) { @@ -341,6 +348,74 @@ const struct address_space_operations erofs_fscache_access_aops = { .readahead = erofs_fscache_readahead, }; +static int erofs_fscache_share_meta_release(struct inode *inode, struct file *filp) +{ + kfree(filp->private_data); + filp->private_data = NULL; + return 0; +} + +static const struct file_operations erofs_fscache_share_meta_fops = { + .release = erofs_fscache_share_meta_release, +}; + +static int erofs_fscache_share_file_release(struct inode *inode, struct file *filp) +{ + fput(filp->private_data); + filp->private_data = NULL; + return 0; +} + +static int erofs_fscache_share_file_open(struct inode *inode, struct file *filp) +{ + /* since page cache sharing is enabled only when i_size <= chunk_size */ + struct erofs_map_blocks map = {}; /* .m_la = 0 */ + struct erofs_map_dev mdev; + struct erofs_fscache_finfo *finfo; + struct inode *realinode; + struct file *realfile; + int ret; + + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + return ret; + + mdev = (struct erofs_map_dev) { + .m_deviceid = map.m_deviceid, + .m_pa = map.m_pa, + }; + ret = erofs_map_dev(inode->i_sb, &mdev); + if (ret) + return ret; + + finfo = kzalloc(sizeof(struct erofs_fscache_finfo), GFP_KERNEL); + if (!finfo) + return -ENOMEM; + finfo->pa = mdev.m_pa; + finfo->max_idx = DIV_ROUND_UP(mdev.m_pa + inode->i_size, PAGE_SIZE); + + realinode = mdev.m_fscache->inode; + ihold(realinode); + realfile = alloc_file_pseudo(realinode, filp->f_path.mnt, "[erofs]", + O_RDONLY, &erofs_fscache_share_meta_fops); + if (IS_ERR(realfile)) { + iput(realinode); + kfree(finfo); + return PTR_ERR(realfile); + } + + file_ra_state_init(&realfile->f_ra, filp->f_mapping); + realfile->private_data = finfo; + filp->private_data = realfile; + return 0; +} + +const struct file_operations erofs_fscache_share_file_fops = { + .llseek = generic_file_llseek, + .open = erofs_fscache_share_file_open, + .release = erofs_fscache_share_file_release, +}; + static void erofs_fscache_domain_put(struct erofs_domain *domain) { mutex_lock(&erofs_domain_list_lock); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b3d04bc2d279..7c6a7a2d9acf 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -616,6 +616,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); extern const struct address_space_operations erofs_fscache_access_aops; +extern const struct file_operations erofs_fscache_share_file_fops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) {