Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2310997imn; Mon, 1 Aug 2022 20:21:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR4l1iSk7CfJ3JUS1wIZd1dnPf2+J2x1Pj1s+UGplEcGjAolu3kXoC+F+fORtEnMM8te+uHW X-Received: by 2002:a17:902:d2c3:b0:16e:ea56:7840 with SMTP id n3-20020a170902d2c300b0016eea567840mr8023459plc.142.1659410485703; Mon, 01 Aug 2022 20:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659410485; cv=none; d=google.com; s=arc-20160816; b=yXmVnq0lAwEA7NLrh8gqyabLbcrl/Nelz182YontAxu5+UlCPD1J2rfnKXLy3QmlGC W8NVCFepRQyxeuOMf/KcT45n+4bTZEoHWYGZWTwQCH5PS6GTbeqKe9FfYgmiU2gTOx2p B/WYTdADcBJXESeBV/Cpq+Fp8VIcDPSbR0db6IdIt1HPtRaDT4gx67HTeVcnMkK0I9J7 RpbtORPVbkGjxWD+v1oIeF+JI4lfi/w/MxMtNGlf6Xoz7+36s0Ry07M+J2mt7DchA5JF yIMWvXaOM8b7Ad1NC88QyGdJWPZBZbfTuHXG794z9vVKp0xZaji6usYJU5eUJ0cGJbu+ 5iIQ== 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=KLKUIzpcTPyrw2DokJLOUb7+kzalIhREngfv7zsuCfc=; b=OG7J1w6JdwajHJdQ6jy6bQDE4V3kY1i3RCZh+9w3qOPwRwc3q5+tWqaKW2JiC3F4Lm UAMl4np0+oghfd7YkMWiv/BqzMF2r7Y9MaoGJW50kb74eUH9j8eTlYQOZ4ALjlpcjyDB flDq6Vuzjt0la/6+DYJQGMcpUnevbYMb8ThqIOeNImLx4z+6qJgwCpuRjNS5o2d7UQqj Ri0BXqBWmvUA+Rdl8eyx9dxzcHKJ6TDBeR5iY+g0MAsHRA/3Oie85VXcYfqgL02nz960 zQ9iE2TFRWh5a900X/V6XQe62O5V9qmxqxwTwdX9qDRihjCR+oIOhO2qs+aZZDDpnxcM V0OQ== 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 s12-20020a632c0c000000b0041a4d5a316dsi14655993pgs.855.2022.08.01.20.21.11; Mon, 01 Aug 2022 20:21:25 -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 S235806AbiHBDEg (ORCPT + 99 others); Mon, 1 Aug 2022 23:04:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235520AbiHBDDy (ORCPT ); Mon, 1 Aug 2022 23:03:54 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46E81DA4F for ; Mon, 1 Aug 2022 20:03:51 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R791e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VL9XpO._1659409428; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VL9XpO._1659409428) by smtp.aliyun-inc.com; Tue, 02 Aug 2022 11:03:48 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org, xiang@kernel.org Subject: [PATCH RFC 7/9] cachefiles: free content map on invalidate Date: Tue, 2 Aug 2022 11:03:40 +0800 Message-Id: <20220802030342.46302-8-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 Free the content map when the cached file is invalidated. Also hole punch the backing content map file if any. Signed-off-by: Jingbo Xu --- fs/cachefiles/content-map.c | 21 +++++++++++++++++++++ fs/cachefiles/interface.c | 1 + fs/cachefiles/internal.h | 1 + 3 files changed, 23 insertions(+) diff --git a/fs/cachefiles/content-map.c b/fs/cachefiles/content-map.c index 949ec5d9e4c9..b73a109844ca 100644 --- a/fs/cachefiles/content-map.c +++ b/fs/cachefiles/content-map.c @@ -250,3 +250,24 @@ loff_t cachefiles_find_next_hole(struct cachefiles_object *object, return min_t(loff_t, result * CACHEFILES_GRAN_SIZE, object->cookie->object_size); } + +void cachefiles_invalidate_content_map(struct cachefiles_object *object) +{ + struct file *file = object->volume->content_map[(u8)object->cookie->key_hash]; + + if (object->content_info != CACHEFILES_CONTENT_MAP) + return; + + write_lock_bh(&object->content_map_lock); + free_pages((unsigned long)object->content_map, + get_order(object->content_map_size)); + object->content_map = NULL; + object->content_map_size = 0; + + if (object->content_map_off != CACHEFILES_CONTENT_MAP_OFF_INVAL) { + vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + object->content_map_off, object->content_map_size); + object->content_map_off = CACHEFILES_CONTENT_MAP_OFF_INVAL; + } + write_unlock_bh(&object->content_map_lock); +} diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c index 4cfbdc87b635..f87b9a665d85 100644 --- a/fs/cachefiles/interface.c +++ b/fs/cachefiles/interface.c @@ -409,6 +409,7 @@ static bool cachefiles_invalidate_cookie(struct fscache_cookie *cookie) old_file = object->file; object->file = new_file; + cachefiles_invalidate_content_map(object); object->content_info = CACHEFILES_CONTENT_NO_DATA; set_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags); set_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &object->cookie->flags); diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 506700809a6d..c674c4e42529 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -187,6 +187,7 @@ extern loff_t cachefiles_find_next_granule(struct cachefiles_object *object, loff_t start); extern loff_t cachefiles_find_next_hole(struct cachefiles_object *object, loff_t start); +extern void cachefiles_invalidate_content_map(struct cachefiles_object *object); /* * daemon.c -- 2.27.0