From: Matthew Wilcox <willy@infradead.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: snitzer@kernel.org, Yang Shi <shy828301@gmail.com>,
mgorman@techsingularity.net, agk@redhat.com, dm-devel@redhat.com,
akpm@linux-foundation.org, linux-block@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dm-crypt: allocate compound pages if possible
Date: Thu, 16 Feb 2023 19:04:24 +0000 [thread overview]
Message-ID: <Y+5+OKbeTO2d9TsH@casper.infradead.org> (raw)
In-Reply-To: <alpine.LRH.2.21.2302161245210.18393@file01.intranet.prod.int.rdu2.redhat.com>
On Thu, Feb 16, 2023 at 12:47:08PM -0500, Mikulas Patocka wrote:
> + while (order > 0) {
> + page = alloc_pages(gfp_mask
> + | __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN, order);
... | __GFP_COMP
> page = mempool_alloc(&cc->page_pool, gfp_mask);
> if (!page) {
> crypt_free_buffer_pages(cc, clone);
> bio_put(clone);
> gfp_mask |= __GFP_DIRECT_RECLAIM;
> + order = 0;
> goto retry;
> }
>
> - len = (remaining_size > PAGE_SIZE) ? PAGE_SIZE : remaining_size;
> -
> - bio_add_page(clone, page, len, 0);
> +have_pages:
> + page->compound_order = order;
No. You'll corrupt the next page if page is order-0, which it is if it
came from the mempool. Also we've deleted page->compound_order in -next
so you can't make this mistake. Using __GFP_COMP will set this field
for you, so you can just drop this line.
> - remaining_size -= len;
> + for (o = 0; o < 1U << order; o++) {
> + unsigned len = min((unsigned)PAGE_SIZE, remaining_size);
> + bio_add_page(clone, page, len, 0);
> + remaining_size -= len;
> + page++;
You can add multiple pages at once, whether they're compound or not. So
replace this entire loop with:
bio_add_page(clone, page, remaining_size, 0);
> @@ -1711,10 +1732,23 @@ static void crypt_free_buffer_pages(stru
> {
> struct bio_vec *bv;
> struct bvec_iter_all iter_all;
> + unsigned skip_entries = 0;
>
> bio_for_each_segment_all(bv, clone, iter_all) {
> - BUG_ON(!bv->bv_page);
> - mempool_free(bv->bv_page, &cc->page_pool);
> + unsigned order;
> + struct page *page = bv->bv_page;
> + BUG_ON(!page);
> + if (skip_entries) {
> + skip_entries--;
> + continue;
> + }
> + order = page->compound_order;
> + if (order) {
> + __free_pages(page, order);
> + skip_entries = (1U << order) - 1;
> + } else {
> + mempool_free(page, &cc->page_pool);
> + }
You can simplify this by using the folio code.
struct folio_iter fi;
bio_for_each_folio_all(fi, bio) {
if (folio_test_large(folio))
folio_put(folio);
else
mempool_free(&folio->page, &cc->page_pool);
}
(further work would actually convert this driver to use folios instead
of pages)
next prev parent reply other threads:[~2023-02-16 19:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 17:47 Mikulas Patocka
2023-02-16 19:04 ` Matthew Wilcox [this message]
2023-02-16 21:19 ` Mikulas Patocka
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=Y+5+OKbeTO2d9TsH@casper.infradead.org \
--to=willy@infradead.org \
--cc=agk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dm-devel@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mpatocka@redhat.com \
--cc=shy828301@gmail.com \
--cc=snitzer@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