All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Mike Snitzer <snitzer@redhat.com>,
	Christoph Hellwig <hch@infradead.org>,
	dm-devel@redhat.com, "Alasdair G. Kergon" <agk@redhat.com>,
	linux-block@vger.kernel.org
Subject: [PATCH 3/4] brd: implement discard
Date: Wed, 26 Oct 2016 16:27:03 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.1610261626390.12287@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1610261624100.12287@file01.intranet.prod.int.rdu2.redhat.com>

Implement page discard using rcu. Each page has built-in entry rcu_head
that could be used to free the page from rcu.

Regarding the commant that "re-allocating the pages can result in
writeback deadlocks under heavy load" - if the user is in the risk of such
deadlocks, he should mount the filesystem without "-o discard".

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/block/brd.c |   30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

Index: linux-2.6/drivers/block/brd.c
===================================================================
--- linux-2.6.orig/drivers/block/brd.c
+++ linux-2.6/drivers/block/brd.c
@@ -137,6 +137,12 @@ static struct page *brd_insert_page(stru
 	return page;
 }
 
+static void brd_free_page_rcu(struct rcu_head *head)
+{
+	struct page *page = container_of(head, struct page, rcu_head);
+	__free_page(page);
+}
+
 static void brd_free_page(struct brd_device *brd, sector_t sector)
 {
 	struct page *page;
@@ -147,7 +153,7 @@ static void brd_free_page(struct brd_dev
 	page = radix_tree_delete(&brd->brd_pages, idx);
 	spin_unlock(&brd->brd_lock);
 	if (page)
-		__free_page(page);
+		call_rcu(&page->rcu_head, brd_free_page_rcu);
 }
 
 static void brd_zero_page(struct brd_device *brd, sector_t sector)
@@ -233,7 +239,7 @@ static void discard_from_brd(struct brd_
 		 * re-allocating the pages can result in writeback
 		 * deadlocks under heavy load.
 		 */
-		if (0)
+		if (1)
 			brd_free_page(brd, sector);
 		else
 			brd_zero_page(brd, sector);
@@ -257,22 +263,22 @@ static void copy_to_brd(struct brd_devic
 
 	copy = min_t(size_t, n, PAGE_SIZE - offset);
 	page = brd_lookup_page(brd, sector);
-	BUG_ON(!page);
-
-	dst = kmap_atomic(page);
-	memcpy(dst + offset, src, copy);
-	kunmap_atomic(dst);
+	if (page) {
+		dst = kmap_atomic(page);
+		memcpy(dst + offset, src, copy);
+		kunmap_atomic(dst);
+	}
 
 	if (copy < n) {
 		src += copy;
 		sector += copy >> SECTOR_SHIFT;
 		copy = n - copy;
 		page = brd_lookup_page(brd, sector);
-		BUG_ON(!page);
-
-		dst = kmap_atomic(page);
-		memcpy(dst, src, copy);
-		kunmap_atomic(dst);
+		if (page) {
+			dst = kmap_atomic(page);
+			memcpy(dst, src, copy);
+			kunmap_atomic(dst);
+		}
 	}
 
 	rcu_read_unlock();

  parent reply	other threads:[~2016-10-26 20:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21 18:33 device mapper and the BLKFLSBUF ioctl Mikulas Patocka
2016-10-21 20:00 ` Mike Snitzer
2016-10-21 20:18   ` Mikulas Patocka
2016-10-24 15:57     ` Mike Snitzer
2016-10-25 13:07       ` Christoph Hellwig
2016-10-25 14:37         ` [PATCH] brd: remove support for BLKFLSBUF Mike Snitzer
2016-10-25 14:46           ` Jens Axboe
2016-10-26 20:25             ` [PATCH 0/4] brd: support discard Mikulas Patocka
2016-10-26 20:26               ` [PATCH 1/4] brd: handle misaligned discard Mikulas Patocka
2016-10-26 20:38                 ` [dm-devel] " Bart Van Assche
2016-10-26 20:38                   ` Bart Van Assche
2016-10-26 21:46                   ` Mikulas Patocka
2016-10-26 21:50                     ` REQ_OP for zeroing, was " Christoph Hellwig
2016-10-28 11:43                       ` Mikulas Patocka
2016-10-28 13:14                         ` Christoph Hellwig
2016-10-31 16:36                           ` Mikulas Patocka
2016-10-26 21:57                     ` Bart Van Assche
2016-10-26 21:57                       ` Bart Van Assche
2016-10-28 11:39                       ` Mikulas Patocka
2016-10-28 15:55                         ` Bart Van Assche
2016-10-28 15:55                           ` Bart Van Assche
2016-10-31 16:31                           ` Mikulas Patocka
2016-10-26 20:26               ` [PATCH 2/4] brd: extend rcu read sections Mikulas Patocka
2016-10-26 20:27               ` Mikulas Patocka [this message]
2016-10-26 20:27               ` [PATCH 4/4] brd: remove unused brd_zero_page 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=alpine.LRH.2.02.1610261626390.12287@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=snitzer@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.