f2fs crypto: remove alloc_page for bounce_page
We don't need to call alloc_page() prior to mempool_alloc(), since the mempool_alloc() calls alloc_page() internally. And, if __GFP_WAIT is set, it never fails on page allocation, so let's give GFP_NOWAIT and handle ENOMEM by writepage(). Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
9236cac566
commit
4683ff837c
fs/f2fs
|
@ -83,10 +83,7 @@ void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *ctx)
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) {
|
if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) {
|
||||||
if (ctx->flags & F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL)
|
mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool);
|
||||||
__free_page(ctx->w.bounce_page);
|
|
||||||
else
|
|
||||||
mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool);
|
|
||||||
ctx->w.bounce_page = NULL;
|
ctx->w.bounce_page = NULL;
|
||||||
}
|
}
|
||||||
ctx->w.control_page = NULL;
|
ctx->w.control_page = NULL;
|
||||||
|
@ -408,34 +405,28 @@ struct page *f2fs_encrypt(struct inode *inode,
|
||||||
return (struct page *)ctx;
|
return (struct page *)ctx;
|
||||||
|
|
||||||
/* The encryption operation will require a bounce page. */
|
/* The encryption operation will require a bounce page. */
|
||||||
ciphertext_page = alloc_page(GFP_NOFS);
|
ciphertext_page = mempool_alloc(f2fs_bounce_page_pool, GFP_NOWAIT);
|
||||||
if (!ciphertext_page) {
|
if (!ciphertext_page) {
|
||||||
/*
|
err = -ENOMEM;
|
||||||
* This is a potential bottleneck, but at least we'll have
|
goto err_out;
|
||||||
* forward progress.
|
|
||||||
*/
|
|
||||||
ciphertext_page = mempool_alloc(f2fs_bounce_page_pool,
|
|
||||||
GFP_NOFS);
|
|
||||||
if (WARN_ON_ONCE(!ciphertext_page))
|
|
||||||
ciphertext_page = mempool_alloc(f2fs_bounce_page_pool,
|
|
||||||
GFP_NOFS | __GFP_WAIT);
|
|
||||||
ctx->flags &= ~F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL;
|
|
||||||
} else {
|
|
||||||
ctx->flags |= F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->flags |= F2FS_WRITE_PATH_FL;
|
ctx->flags |= F2FS_WRITE_PATH_FL;
|
||||||
ctx->w.bounce_page = ciphertext_page;
|
ctx->w.bounce_page = ciphertext_page;
|
||||||
ctx->w.control_page = plaintext_page;
|
ctx->w.control_page = plaintext_page;
|
||||||
err = f2fs_page_crypto(ctx, inode, F2FS_ENCRYPT, plaintext_page->index,
|
err = f2fs_page_crypto(ctx, inode, F2FS_ENCRYPT, plaintext_page->index,
|
||||||
plaintext_page, ciphertext_page);
|
plaintext_page, ciphertext_page);
|
||||||
if (err) {
|
if (err)
|
||||||
f2fs_release_crypto_ctx(ctx);
|
goto err_out;
|
||||||
return ERR_PTR(err);
|
|
||||||
}
|
|
||||||
SetPagePrivate(ciphertext_page);
|
SetPagePrivate(ciphertext_page);
|
||||||
set_page_private(ciphertext_page, (unsigned long)ctx);
|
set_page_private(ciphertext_page, (unsigned long)ctx);
|
||||||
lock_page(ciphertext_page);
|
lock_page(ciphertext_page);
|
||||||
return ciphertext_page;
|
return ciphertext_page;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
f2fs_release_crypto_ctx(ctx);
|
||||||
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -84,8 +84,7 @@ struct f2fs_crypt_info {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001
|
#define F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001
|
||||||
#define F2FS_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL 0x00000002
|
#define F2FS_WRITE_PATH_FL 0x00000002
|
||||||
#define F2FS_WRITE_PATH_FL 0x00000004
|
|
||||||
|
|
||||||
struct f2fs_crypto_ctx {
|
struct f2fs_crypto_ctx {
|
||||||
union {
|
union {
|
||||||
|
|
Loading…
Reference in New Issue