From: Yufen Yu <yuyufen@huawei.com>
To: song@kernel.org
Cc: linux-raid@vger.kernel.org, neilb@suse.com,
guoqing.jiang@cloud.ionos.com, houtao1@huawei.com,
yuyufen@huawei.com
Subject: [PATCH v4 05/15] md/raid5: allocate and free shared pages of r5pages
Date: Fri, 12 Jun 2020 19:42:10 +0800 [thread overview]
Message-ID: <20200612114220.13126-6-yuyufen@huawei.com> (raw)
In-Reply-To: <20200612114220.13126-1-yuyufen@huawei.com>
When PAGE_SIZE is bigger than stripe_size, try to allocate pages of
r5pages in grow_buffres() and free these pages in shrink_buffers().
Then, set sh->dev[i].page and sh->dev[i].offset as the page in
array. Without enable shared page, we just set offset as value of '0'.
Signed-off-by: Yufen Yu <yuyufen@huawei.com>
---
drivers/md/raid5.c | 113 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 106 insertions(+), 7 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 2f04fd13768b..3ae2cc8cd1ea 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -448,15 +448,72 @@ static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
return sh;
}
+/*
+ * Try to free all pages in r5pages array.
+ */
+static void free_stripe_pages(struct stripe_head *sh)
+{
+ int i;
+ struct page *p;
+
+ /* Have not allocate page pool */
+ if (!sh->pages.page)
+ return;
+
+ for (i = 0; i < sh->pages.size; i++) {
+ p = sh->pages.page[i];
+ if (p)
+ put_page(p);
+ sh->pages.page[i] = NULL;
+ }
+}
+
+/*
+ * Allocate pages for r5pages.
+ */
+static int alloc_stripe_pages(struct stripe_head *sh, gfp_t gfp)
+{
+ int i;
+ struct page *p;
+
+ for (i = 0; i < sh->pages.size; i++) {
+ /* The page have allocated. */
+ if (sh->pages.page[i])
+ continue;
+
+ p = alloc_page(gfp);
+ if (!p) {
+ free_stripe_pages(sh);
+ return -ENOMEM;
+ }
+ sh->pages.page[i] = p;
+ }
+ return 0;
+}
+
static void shrink_buffers(struct stripe_head *sh)
{
struct page *p;
int i;
int num = sh->raid_conf->pool_size;
- for (i = 0; i < num ; i++) {
+ if (raid5_stripe_pages_shared(sh->raid_conf))
+ free_stripe_pages(sh); /* Free pages in r5pages */
+
+ for (i = 0; i < num; i++) {
WARN_ON(sh->dev[i].page != sh->dev[i].orig_page);
p = sh->dev[i].page;
+
+ /*
+ * If we use pages in r5pages, these pages have been
+ * freed in free_stripe_pages().
+ */
+ if (raid5_stripe_pages_shared(sh->raid_conf)) {
+ if (p)
+ sh->dev[i].page = NULL;
+ continue;
+ }
+
if (!p)
continue;
sh->dev[i].page = NULL;
@@ -469,14 +526,26 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
int i;
int num = sh->raid_conf->pool_size;
+ if (raid5_stripe_pages_shared(sh->raid_conf) &&
+ alloc_stripe_pages(sh, gfp))
+ return -ENOMEM;
+
for (i = 0; i < num; i++) {
struct page *page;
+ unsigned int offset;
- if (!(page = alloc_page(gfp))) {
- return 1;
+ if (raid5_stripe_pages_shared(sh->raid_conf)) {
+ page = raid5_get_dev_page(sh, i);
+ offset = raid5_get_page_offset(sh, i);
+ } else {
+ page = alloc_page(gfp);
+ if (!page)
+ return -ENOMEM;
+ offset = 0;
}
sh->dev[i].page = page;
sh->dev[i].orig_page = page;
+ sh->dev[i].offset = offset;
}
return 0;
@@ -2146,11 +2215,35 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh)
{
+ kfree(sh->pages.page);
+
if (sh->ppl_page)
__free_page(sh->ppl_page);
kmem_cache_free(sc, sh);
}
+static int
+init_stripe_shared_pages(struct stripe_head *sh, struct r5conf *conf)
+{
+ int nr_page;
+ int cnt;
+
+ BUG_ON(conf->stripe_size > PAGE_SIZE);
+ if (!raid5_stripe_pages_shared(conf) || sh->pages.page)
+ return 0;
+
+ /* Each of the sh->dev[i] need one conf->stripe_size */
+ cnt = PAGE_SIZE / conf->stripe_size;
+ nr_page = (conf->raid_disks + cnt - 1) / cnt;
+
+ sh->pages.page = kcalloc(nr_page, sizeof(struct page *), GFP_KERNEL);
+ if (!sh->pages.page)
+ return -ENOMEM;
+ sh->pages.size = nr_page;
+
+ return 0;
+}
+
static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
int disks, struct r5conf *conf)
{
@@ -2177,14 +2270,20 @@ static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
if (raid5_has_ppl(conf)) {
sh->ppl_page = alloc_page(gfp);
- if (!sh->ppl_page) {
- free_stripe(sc, sh);
- sh = NULL;
- }
+ if (!sh->ppl_page)
+ goto fail;
}
+
+ if (init_stripe_shared_pages(sh, conf))
+ goto fail;
}
return sh;
+
+fail:
+ free_stripe(sc, sh);
+ return NULL;
}
+
static int grow_one_stripe(struct r5conf *conf, gfp_t gfp)
{
struct stripe_head *sh;
--
2.21.3
next prev parent reply other threads:[~2020-06-12 11:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 11:42 [PATCH v4 00/15] md/raid5: set STRIPE_SIZE as a configurable value Yufen Yu
2020-06-12 11:42 ` [PATCH v4 01/15] md/raid456: covert macro define of STRIPE_* as members of struct r5conf Yufen Yu
2020-06-14 2:28 ` Xiao Ni
2020-06-15 7:17 ` Yufen Yu
2020-06-12 11:42 ` [PATCH v4 02/15] md/raid5: add sysfs entry to set and show stripe_size Yufen Yu
2020-06-12 11:42 ` [PATCH v4 03/15] md/raid5: set default stripe_size as 4096 Yufen Yu
2020-06-12 11:42 ` [PATCH v4 04/15] md/raid5: add a member of r5pages for struct stripe_head Yufen Yu
2020-06-12 11:42 ` Yufen Yu [this message]
2020-06-12 11:42 ` [PATCH v4 06/15] md/raid5: set correct page offset for bi_io_vec in ops_run_io() Yufen Yu
2020-06-12 11:42 ` [PATCH v4 07/15] md/raid5: set correct page offset for async_copy_data() Yufen Yu
2020-06-12 11:42 ` [PATCH v4 08/15] md/raid5: resize stripes and set correct offset when reshape array Yufen Yu
2020-06-12 11:42 ` [PATCH v4 09/15] md/raid5: add new xor function to support different page offset Yufen Yu
2020-06-12 11:42 ` [PATCH v4 10/15] md/raid5: add offset array in scribble buffer Yufen Yu
2020-06-12 11:42 ` [PATCH v4 11/15] md/raid5: compute xor with correct page offset Yufen Yu
2020-06-12 11:42 ` [PATCH v4 12/15] md/raid5: support config stripe_size by sysfs entry Yufen Yu
2020-06-12 11:42 ` [PATCH v4 13/15] md/raid6: let syndrome computor support different page offset Yufen Yu
2020-06-12 11:42 ` [PATCH v4 14/15] md/raid6: compute syndrome with correct " Yufen Yu
2020-06-12 11:42 ` [PATCH v4 15/15] raid6test: adaptation with syndrome function Yufen Yu
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=20200612114220.13126-6-yuyufen@huawei.com \
--to=yuyufen@huawei.com \
--cc=guoqing.jiang@cloud.ionos.com \
--cc=houtao1@huawei.com \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.com \
--cc=song@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