Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2311031imn; Mon, 1 Aug 2022 20:21:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vy9XhzpDgR7/WDj/xCtI0xIdJvpRoHP1YD0w18ocry0YGRY1qmSPRvbstIWUcE9RlkGgfU X-Received: by 2002:a63:b50b:0:b0:412:b42c:6940 with SMTP id y11-20020a63b50b000000b00412b42c6940mr15046170pge.460.1659410492292; Mon, 01 Aug 2022 20:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659410492; cv=none; d=google.com; s=arc-20160816; b=jlcmCv9KvcD06Unk+pKPSTi8KNrwTYlwQMrzTZL04gIs0gh2fJkD1ytNS+LySbw7EL pK6Jr6UxVNz+sOc5GISZcWriiFlDnFZm8J/uIsyjpn5teyW059nrJ9tAL9iARgGEqPcE F0k5hVBCWFkgsxeByHdPTFy5Uv7V4fIrS4br+0unoOoJf5Z+BdEXdI08BC595I/zyg5V M+ukPAjnC5zQrXY0EMdRK0+l/xfT4JVKp0gJGMhOAzWBLQ2XwfcAAvAk1JuUeKuBOOnx oUjXWL6EbQQ9xh49FBPpF7W7m5MAs46yDWmI1F0ybjKikyJkoZFex87SOzl4efqK6+z1 Dr8Q== 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=KO5fhDXgBXA5XODxG0TD7zWTlrGo/eacVFlEnZ+bB0c=; b=xyjHSNaWSV4DghPqeuWkFT/nZP6XupFhM0CBhH3FgLafhpyljCaFXTmY4BNNLjp4lR qM+f/hZdIRPqHbQFSXcJQu093qb4fRIvg5iBZyv0SU/9RlwsPaw5f+AXxP04QI1nj7L7 BafZv0OC26sYtPGhvuOWcvMrw9H0yRYL9kPFUZe+t1NZikSdilpUebwAfUVzcXV3sOn1 F77Diz4GqPVWBq56PpCEXeAu44ecbp3elvUqTY6T8r3GPA+TXt4OJwUZMahY+cdIavUG QsfFHa0tYip3u+ueyCbxWMG0PYipwibIVIByGQppaRjPrImW2tXpM9YzyEOY5H8rlqbi sXcw== 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 x11-20020a63aa4b000000b0041c11497138si5059866pgo.788.2022.08.01.20.21.18; Mon, 01 Aug 2022 20:21:32 -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 S235511AbiHBDEn (ORCPT + 99 others); Mon, 1 Aug 2022 23:04:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235603AbiHBDEE (ORCPT ); Mon, 1 Aug 2022 23:04:04 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34FDF1EC4D for ; Mon, 1 Aug 2022 20:03:53 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VL9W-Pi_1659409429; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VL9W-Pi_1659409429) by smtp.aliyun-inc.com; Tue, 02 Aug 2022 11:03:49 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org, xiang@kernel.org Subject: [PATCH RFC 8/9] cachefiles: resize content map on resize Date: Tue, 2 Aug 2022 11:03:41 +0800 Message-Id: <20220802030342.46302-9-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220802030342.46302-1-jefflexu@linux.alibaba.com> References: <20220802030342.46302-1-jefflexu@linux.alibaba.com> 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,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 Adjust the content map when we shorten a backing object. In this case, only the unused tail of the content map after shortening gets zeroed, while the size of the content map itself is not changed. Also the corresponding range in the backing content map file is not changed. Besides, the content map and the corresponding range in the backing content map file are not touched when we expand a backing object. They will be lazily expanded at runtime later. Signed-off-by: Jingbo Xu --- fs/cachefiles/content-map.c | 23 +++++++++++++++++++++++ fs/cachefiles/interface.c | 1 + fs/cachefiles/internal.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/fs/cachefiles/content-map.c b/fs/cachefiles/content-map.c index b73a109844ca..360c59b06670 100644 --- a/fs/cachefiles/content-map.c +++ b/fs/cachefiles/content-map.c @@ -271,3 +271,26 @@ void cachefiles_invalidate_content_map(struct cachefiles_object *object) } write_unlock_bh(&object->content_map_lock); } + +/* + * Adjust the content map when we shorten a backing object. + */ +void cachefiles_shorten_content_map(struct cachefiles_object *object, + loff_t new_size) +{ + if (object->content_info != CACHEFILES_CONTENT_MAP) + return; + + read_lock_bh(&object->content_map_lock); + /* + * Nothing needs to be done when content map has not been allocated yet. + */ + if (!object->content_map_size) + goto out; + + if (cachefiles_map_size(new_size) <= object->content_map_size) + cachefiles_zero_content_map(object->content_map, + object->content_map_size, new_size); +out: + read_unlock_bh(&object->content_map_lock); +} diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index f87b9a665d85..76f70a9ebe50 100644 --- a/fs/cachefiles/interface.c +++ b/fs/cachefiles/interface.c @@ -290,6 +290,7 @@ static void cachefiles_resize_cookie(struct netfs_cache_resources *cres, cachefiles_begin_secure(cache, &saved_cred); cachefiles_shorten_object(object, file, new_size); cachefiles_end_secure(cache, saved_cred); + cachefiles_shorten_content_map(object, new_size); object->cookie->object_size = new_size; return; } diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index c674c4e42529..7747f99f00c1 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -188,6 +188,8 @@ extern loff_t cachefiles_find_next_granule(struct cachefiles_object *object, extern loff_t cachefiles_find_next_hole(struct cachefiles_object *object, loff_t start); extern void cachefiles_invalidate_content_map(struct cachefiles_object *object); +extern void cachefiles_shorten_content_map(struct cachefiles_object *object, + loff_t new_size); /* * daemon.c -- 2.27.0