From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 5/6] f2fs crypto: shrink size of the f2fs_crypto_ctx structure
Date: Tue, 12 May 2015 17:40:33 -0700 [thread overview]
Message-ID: <1431477634-48111-5-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1431477634-48111-1-git-send-email-jaegeuk@kernel.org>
This patch integrates the below patch into f2fs.
"ext4 crypto: shrink size of the ext4_crypto_ctx structure
Some fields are only used when the crypto_ctx is being used on the
read path, some are only used on the write path, and some are only
used when the structure is on free list. Optimize memory use by using
a union."
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/crypto.c | 40 ++++++++++++++++++----------------------
fs/f2fs/f2fs_crypto.h | 21 ++++++++++++++-------
fs/f2fs/segment.c | 2 +-
3 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/fs/f2fs/crypto.c b/fs/f2fs/crypto.c
index c1a5c6f..e36eddd 100644
--- a/fs/f2fs/crypto.c
+++ b/fs/f2fs/crypto.c
@@ -82,14 +82,14 @@ void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *ctx)
{
unsigned long flags;
- if (ctx->bounce_page) {
+ if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) {
if (ctx->flags & F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL)
- __free_page(ctx->bounce_page);
+ __free_page(ctx->w.bounce_page);
else
- mempool_free(ctx->bounce_page, f2fs_bounce_page_pool);
- ctx->bounce_page = NULL;
+ mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool);
+ ctx->w.bounce_page = NULL;
}
- ctx->control_page = NULL;
+ ctx->w.control_page = NULL;
if (ctx->flags & F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL) {
if (ctx->tfm)
crypto_free_tfm(ctx->tfm);
@@ -146,6 +146,7 @@ struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *inode)
} else {
ctx->flags &= ~F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL;
}
+ ctx->flags &= ~F2FS_WRITE_PATH_FL;
/*
* Allocate a new Crypto API context if we don't already have
@@ -181,12 +182,6 @@ struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *inode)
}
BUG_ON(ci->ci_size != f2fs_encryption_key_size(ci->ci_data_mode));
- /*
- * There shouldn't be a bounce page attached to the crypto
- * context at this point.
- */
- BUG_ON(ctx->bounce_page);
-
out:
if (res) {
if (!IS_ERR_OR_NULL(ctx))
@@ -203,8 +198,8 @@ out:
static void completion_pages(struct work_struct *work)
{
struct f2fs_crypto_ctx *ctx =
- container_of(work, struct f2fs_crypto_ctx, work);
- struct bio *bio = ctx->bio;
+ container_of(work, struct f2fs_crypto_ctx, r.work);
+ struct bio *bio = ctx->r.bio;
struct bio_vec *bv;
int i;
@@ -225,9 +220,9 @@ static void completion_pages(struct work_struct *work)
void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *ctx, struct bio *bio)
{
- INIT_WORK(&ctx->work, completion_pages);
- ctx->bio = bio;
- queue_work(f2fs_read_workqueue, &ctx->work);
+ INIT_WORK(&ctx->r.work, completion_pages);
+ ctx->r.bio = bio;
+ queue_work(f2fs_read_workqueue, &ctx->r.work);
}
/**
@@ -238,12 +233,12 @@ void f2fs_exit_crypto(void)
struct f2fs_crypto_ctx *pos, *n;
list_for_each_entry_safe(pos, n, &f2fs_free_crypto_ctxs, free_list) {
- if (pos->bounce_page) {
+ if (pos->w.bounce_page) {
if (pos->flags &
F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL)
- __free_page(pos->bounce_page);
+ __free_page(pos->w.bounce_page);
else
- mempool_free(pos->bounce_page,
+ mempool_free(pos->w.bounce_page,
f2fs_bounce_page_pool);
}
if (pos->tfm)
@@ -335,7 +330,7 @@ void f2fs_restore_and_release_control_page(struct page **page)
ctx = (struct f2fs_crypto_ctx *)page_private(bounce_page);
/* restore control page */
- *page = ctx->control_page;
+ *page = ctx->w.control_page;
f2fs_restore_control_page(bounce_page);
}
@@ -492,8 +487,9 @@ struct page *f2fs_encrypt(struct inode *inode,
} else {
ctx->flags |= F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL;
}
- ctx->bounce_page = ciphertext_page;
- ctx->control_page = plaintext_page;
+ ctx->flags |= F2FS_WRITE_PATH_FL;
+ ctx->w.bounce_page = ciphertext_page;
+ ctx->w.control_page = plaintext_page;
err = f2fs_page_crypto(ctx, inode, F2FS_ENCRYPT, plaintext_page->index,
plaintext_page, ciphertext_page);
if (err) {
diff --git a/fs/f2fs/f2fs_crypto.h b/fs/f2fs/f2fs_crypto.h
index 58682d2..e33cec9 100644
--- a/fs/f2fs/f2fs_crypto.h
+++ b/fs/f2fs/f2fs_crypto.h
@@ -87,16 +87,23 @@ struct f2fs_crypt_info {
#define F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001
#define F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL 0x00000002
+#define F2FS_WRITE_PATH_FL 0x00000004
struct f2fs_crypto_ctx {
struct crypto_tfm *tfm; /* Crypto API context */
- struct page *bounce_page; /* Ciphertext page on write path */
- struct page *control_page; /* Original page on write path */
- struct bio *bio; /* The bio for this context */
- struct work_struct work; /* Work queue for read complete path */
- struct list_head free_list; /* Free list */
- int flags; /* Flags */
- int mode; /* Encryption mode for tfm */
+ union {
+ struct {
+ struct page *bounce_page; /* Ciphertext page */
+ struct page *control_page; /* Original page */
+ } w;
+ struct {
+ struct bio *bio;
+ struct work_struct work;
+ } r;
+ struct list_head free_list; /* Free list */
+ };
+ char flags; /* Flags */
+ char mode; /* Encryption mode for tfm */
};
struct f2fs_completion_result {
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 17e89ba..70d1ccb 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1369,7 +1369,7 @@ static inline bool is_merged_page(struct f2fs_sb_info *sbi,
/* encrypted page */
ctx = (struct f2fs_crypto_ctx *)page_private(
bvec->bv_page);
- target = ctx->control_page;
+ target = ctx->w.control_page;
}
if (page == target) {
--
2.1.1
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
next prev parent reply other threads:[~2015-05-13 0:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 0:40 [PATCH 1/6] f2fs crypto: free encryption_info at f2fs_evict_inode Jaegeuk Kim
2015-05-13 0:40 ` [PATCH 2/6] f2fs crypto: not support fcollapse for encrypted inode Jaegeuk Kim
2015-05-13 0:40 ` [PATCH 3/6] f2fs crypto: use slab caches Jaegeuk Kim
2015-05-13 0:40 ` [PATCH 4/6] f2fs crypto: get rid of ci_mode from struct f2fs_crypt_info Jaegeuk Kim
2015-05-13 0:40 ` Jaegeuk Kim [this message]
2015-05-13 0:40 ` [PATCH 6/6] f2fs crypto: require CONFIG_CRYPTO_CTR if f2fs encryption is enabled Jaegeuk Kim
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=1431477634-48111-5-git-send-email-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).