Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp572190pxb; Thu, 31 Mar 2022 11:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBmbdff9POlzzwNzihqW6EknzMjbJfFTBg34SPyaB/dPPuxEhFe/fKxkYgyAIfDbeD626k X-Received: by 2002:a63:3d0b:0:b0:37f:ef34:1431 with SMTP id k11-20020a633d0b000000b0037fef341431mr11812584pga.547.1648752853059; Thu, 31 Mar 2022 11:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648752853; cv=none; d=google.com; s=arc-20160816; b=xXRLuAAzEZghzZg7VtuN42crD+O3HqV6SlK/dolfI7bbdthmcrKmAhMVbokweH73yt HVcYqSgO+fLALBWAnrfPa9ZX0BwnVu1ufwQ6OVen0aH87VDQl42FzV+0BNCtUo2MvW5H 8pIrC9JOpmysy6mbkH1TlgNcLu8yRmm0o8dup9VN6cD9RGgZlLyGSJHJNbb+EO790im4 BDIOZMFZE+gO5ZuTXYmEA+GKI+xOLJXVj6zJmwXlWzCJZXSO9+T8ueIvFigBIalx0+aP 1GK0KOT+sxO78LEB3RYdC4Oih9y1IWobxo9XMzWkVjIyTjv9ZdoS69fz7AMAJp4MS9Xh t11w== 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 :message-id:date:subject:cc:to:from; bh=4azr41PMS6ixPlSn0ze+kzwsmMMBXY5PmFqQmkb/uVI=; b=YHHISjeC9GOX08tk9HfLqh06tPMDGjK6gLekxCSeTPRWgW3nQ+FfJQwceyiKG6glkw g0/QKuJZIkdyZfZTpX5zPrr+j27f8kfBwfKkD2FZ72HR+VE2m1mgwp6gLVGmlAumZ6VB OsolGdO2f2uWCOJr/PPD4v16BkjpH2lEWEBtI73gS4uM91x5XGsbPwRtoOf8I4F2TjvZ GTs+E+DD0M6p7/4OHO7sOjfdhVnpHX2fPajMq+jIKjnvdeL3e3anhVFe9LHEzmJ0jobu Z99BpmSP2ERSAUVINo5IW0frPnXR6HG2gfwI9kKAOIA/24pkr5Gdc4rpkJsFx23niutd ujjw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu11-20020a17090b1b0b00b001befa3ba5ebsi418606pjb.17.2022.03.31.11.53.58; Thu, 31 Mar 2022 11:54:13 -0700 (PDT) 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 S235367AbiCaL7s (ORCPT + 99 others); Thu, 31 Mar 2022 07:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231668AbiCaL7r (ORCPT ); Thu, 31 Mar 2022 07:59:47 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52490208C12; Thu, 31 Mar 2022 04:57:58 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0V8iqyCU_1648727873; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V8iqyCU_1648727873) by smtp.aliyun-inc.com(127.0.0.1); Thu, 31 Mar 2022 19:57:54 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com, tianzichen@kuaishou.com, fannaihao@baidu.com Subject: [PATCH v7 00/19] fscache,erofs: fscache-based on-demand read semantics Date: Thu, 31 Mar 2022 19:57:34 +0800 Message-Id: <20220331115753.89431-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 changes since v6: - rebased to latest upstream branch - cachefiles: move calling of cachefiles_ondemand_clean_object() into cachefiles_withdraw_cookie() (it is called in cachefiles_clean_up_object() previously), so that the previously anon_fd could be withdrawed if the looking up phase failed ( object->file is still NULL while a previous OPEN request has been sent to user daemon) (patch 3) - cachefiles: rename "cinit" (response of OPEN request) to "copen" (patch 2) - cachefiles: "fscache: export fscache_end_operation()" is still needed. Since it has been pull requested for 5.18 (not merged yet), it's not included in this patchset. - erofs: register fscache volume for each erofs filesystem (patch 9) - erofs: rename erofs_is_nodev_mode() to erofs_is_fscache_mode (patch 8) - erofs: remove erofs_fscache_read_folio() helper (patch 12) - erofs: remove erofs_fscache_get_map() helper, and no new field is needed in "struct erofs_map_blocks" now (patch 16) - erofs: fold several helper functions, and other miscellaneous fixes regarding to comments from Gao Xiang Kernel Patchset --------------- Git tree: https://github.com/lostjeffle/linux.git jingbo/dev-erofs-fscache-v7 Gitweb: https://github.com/lostjeffle/linux/commits/jingbo/dev-erofs-fscache-v7 User Daemon for Quick Test -------------------------- Git tree: https://github.com/lostjeffle/demand-read-cachefilesd.git main Gitweb: https://github.com/lostjeffle/demand-read-cachefilesd RFC: https://lore.kernel.org/all/YbRL2glGzjfZkVbH@B-P7TQMD6M-0146.local/t/ v1: https://lore.kernel.org/lkml/47831875-4bdd-8398-9f2d-0466b31a4382@linux.alibaba.com/T/ v2: https://lore.kernel.org/all/2946d871-b9e1-cf29-6d39-bcab30f2854f@linux.alibaba.com/t/ v3: https://lore.kernel.org/lkml/20220209060108.43051-1-jefflexu@linux.alibaba.com/T/ v4: https://lore.kernel.org/lkml/20220307123305.79520-1-jefflexu@linux.alibaba.com/T/#t v5: https://lore.kernel.org/lkml/202203170912.gk2sqkaK-lkp@intel.com/T/ v6: https://lore.kernel.org/lkml/202203260720.uA5o7k5w-lkp@intel.com/T/ [Background] ============ Nydus [1] is an image distribution service especially optimized for distribution over network. Nydus is an excellent container image acceleration solution, since it only pulls data from remote when needed, a.k.a. on-demand reading and it also supports chunk-based deduplication, compression, etc. erofs (Enhanced Read-Only File System) is a filesystem designed for read-only scenarios. (Documentation/filesystem/erofs.rst) Over the past months we've been focusing on supporting Nydus image service with in-kernel erofs format[2]. In that case, each container image will be organized in one bootstrap (metadata) and (optional) multiple data blobs in erofs format. Massive container images will be stored on one machine. To accelerate the container startup (fetching container images from remote and then start the container), we do hope that the bootstrap & blob files could support on-demand read. That is, erofs can be mounted and accessed even when the bootstrap/data blob files have not been fully downloaded. Then it'll have native performance after data is available locally. That means we have to manage the cache state of the bootstrap/data blob files (if cache hit, read directly from the local cache; if cache miss, fetch the data somehow). It would be painful and may be dumb for erofs to implement the cache management itself. Thus we prefer fscache/cachefiles to do the cache management instead. The fscache on-demand read feature aims to be implemented in a generic way so that it can benefit other use cases and/or filesystems if it's implemented in the fscache subsystem. [1] https://nydus.dev [2] https://sched.co/pcdL [Overall Design] ================ Please refer to patch 7 ("cachefiles: document on-demand read mode") for more details. When working in the original mode, cachefiles mainly serves as a local cache for remote networking fs, while in on-demand read mode, cachefiles can work in the scenario where on-demand read semantics is needed, e.g. container image distribution. The essential difference between these two modes is that, in original mode, when cache miss, netfs itself will fetch data from remote, and then write the fetched data into cache file. While in on-demand read mode, a user daemon is responsible for fetching data and then feeds to the kernel fscache side. The on-demand read mode relies on a simple protocol used for communication between kernel and user daemon. The proposed implementation relies on the anonymous fd mechanism to avoid the dependence on the format of cache file. When a fscache cachefile is opened for the first time, an anon_fd associated with the cache file is sent to the user daemon. With the given anon_fd, user daemon could fetch and write data into the cache file in the background, even when kernel has not triggered the cache miss. Besides, the write() syscall to the anon_fd will finally call cachefiles kernel module, which will write data to cache file in the latest format of cache file. 1. cache miss When cache miss, cachefiles kernel module will notify user daemon with the anon_fd, along with the requested file range. When notified, user daemon needs to fetch data of the requested file range, and then write the fetched data into cache file with the given anonymous fd. When finished processing the request, user daemon needs to notify the kernel. After notifying the user daemon, the kernel read routine will hang there, until the request is handled by user daemon. When it's awaken by the notification from user daemon, i.e. the corresponding hole has been filled by the user daemon, it will retry to read from the same file range. 2. cache hit Once data is already ready in cache file, netfs will read from cache file directly. [Advantage of fscache-based on-demand read] ======================================== 1. Asynchronous Prefetch In current mechanism, fscache is responsible for cache state management, while the data plane (fetch data from local/remote on cache miss) is done on the user daemon side. If data has already been ready in the backing file, netfs (e.g. erofs) will read from the backing file directly and won't be trapped to user space anymore. Thus the user daemon could fetch data (from remote) asynchronously on the background, and thus accelerate the backing file accessing in some degree. 2. Support massive blob files Besides this mechanism supports a large amount of backing files, and thus can benefit the densely employed scenario. In our using scenario, one container image can correspond to one bootstrap file (required) and multiple data blob files (optional). For example, one container image for node.js will corresponds to ~20 files in total. In densely employed environment, there could be as many as hundreds of containers and thus thousands of backing files on one machine. Jeffle Xu (19): cachefiles: extract write routine cachefiles: notify user daemon with anon_fd when looking up cookie cachefiles: notify user daemon when withdrawing cookie cachefiles: implement on-demand read cachefiles: enable on-demand read mode cachefiles: document on-demand read mode erofs: make erofs_map_blocks() generally available erofs: add mode checking helper erofs: register fscache volume erofs: add fscache context helper functions erofs: add anonymous inode managing page cache for data blob erofs: add erofs_fscache_read_folios() helper erofs: register fscache context for primary data blob erofs: register fscache context for extra data blobs erofs: implement fscache-based metadata read erofs: implement fscache-based data read for non-inline layout erofs: implement fscache-based data read for inline layout erofs: implement fscache-based data readahead erofs: add 'fsid' mount option .../filesystems/caching/cachefiles.rst | 166 ++++++ fs/cachefiles/Kconfig | 11 + fs/cachefiles/Makefile | 1 + fs/cachefiles/daemon.c | 90 +++- fs/cachefiles/interface.c | 2 + fs/cachefiles/internal.h | 67 +++ fs/cachefiles/io.c | 72 ++- fs/cachefiles/namei.c | 16 +- fs/cachefiles/ondemand.c | 473 ++++++++++++++++++ fs/erofs/Kconfig | 10 + fs/erofs/Makefile | 1 + fs/erofs/data.c | 27 +- fs/erofs/fscache.c | 369 ++++++++++++++ fs/erofs/inode.c | 5 + fs/erofs/internal.h | 55 ++ fs/erofs/super.c | 99 +++- include/linux/fscache.h | 1 + include/linux/netfs.h | 1 + include/trace/events/cachefiles.h | 2 + include/uapi/linux/cachefiles.h | 57 +++ 20 files changed, 1457 insertions(+), 68 deletions(-) create mode 100644 fs/cachefiles/ondemand.c create mode 100644 fs/erofs/fscache.c create mode 100644 include/uapi/linux/cachefiles.h -- 2.27.0