From: Jingbo Xu <jefflexu@linux.alibaba.com>
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 [thread overview]
Message-ID: <20220802030342.46302-9-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20220802030342.46302-1-jefflexu@linux.alibaba.com>
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 <jefflexu@linux.alibaba.com>
---
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
next prev parent reply other threads:[~2022-08-02 3:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 3:03 [RFC PATCH 0/9] cachefiles: content map Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 1/9] cachefiles: improve FSCACHE_COOKIE_NO_DATA_TO_READ optimization Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 2/9] cachefiles: add content map file helpers Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 3/9] cachefiles: allocate per-subdir content map files Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 4/9] cachefiles: alloc/load/save content map Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 5/9] cachefiles: mark content map on write to the backing file Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 6/9] cachefiles: check content map on read/write Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 7/9] cachefiles: free content map on invalidate Jingbo Xu
2022-08-02 3:03 ` Jingbo Xu [this message]
2022-08-02 3:03 ` [PATCH RFC 9/9] cachefiles: cull content map file on cull Jingbo Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220802030342.46302-9-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=dhowells@redhat.com \
--cc=linux-cachefs@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®