Skip to contentSkip to conversation

Crashes/hung tasks with z3pool under memory pressure

DISCUSSION Vitaly Wool 2 participants 5 messages Apr 17, 2018 – Apr 27, 2018 1 message not in the archive Memory management

lore
Share & tools
lore
#0 lore raw

Hi Guenter,

Quoted 19 lines

[ ... ]

Quoted 7 lines

Ugh. Could you please keep that patch and apply this on top:

mm/z3fold.c +0 -0
index c0bca6153b95..e8a80d044d9e 100644

mm/z3fold.c static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) · line 846

Quoted 7 lines
mm/z3fold.c +1 -0
@@ -840,6 +840,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
                      kref_get(&zhdr->refcount);
                      list_del_init(&zhdr->buddy);
                      zhdr->cpu = -1;
+                     break;
              }
              list_del_init(&page->lru);
 

Much better, in a way. The system now takes much longer to crash, and the crash reason is a bit different. The log is too long to attach, so I copied it to [1].

Quoted 2 lines

crashdump.0002 Latest log
000[12]-Fix-attempt-[12].patch Patches applied on top of v4.17.0-rc1.

thanks for the update. Let's start from a clean sheet. I believe this patch has to be applied anyway so could you please check if it solves the problem.

mm/z3fold.c +10 -1
index c0bca6153b95..059fb3d5ca86 100644
@@ -144,7 +144,8 @@ enum z3fold_page_flags {
 	PAGE_HEADLESS = 0,
 	MIDDLE_CHUNK_MAPPED,
 	NEEDS_COMPACTING,
-	PAGE_STALE
+	PAGE_STALE,
+	UNDER_RECLAIM
 };
 
 /*****************
@@ -173,6 +174,7 @@ static struct z3fold_header *init_z3fold_page(struct page *page,
 	clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
 	clear_bit(NEEDS_COMPACTING, &page->private);
 	clear_bit(PAGE_STALE, &page->private);
+	clear_bit(UNDER_RECLAIM, &page->private);
 
 	spin_lock_init(&zhdr->page_lock);
 	kref_init(&zhdr->refcount);
@@ -756,6 +758,10 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		atomic64_dec(&pool->pages_nr);
 		return;
 	}
+	if (test_bit(UNDER_RECLAIM, &page->private)) {
+		z3fold_page_unlock(zhdr);
+		return;
+	}
 	if (test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
 		z3fold_page_unlock(zhdr);
 		return;
@@ -840,6 +846,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 			kref_get(&zhdr->refcount);
 			list_del_init(&zhdr->buddy);
 			zhdr->cpu = -1;
+			set_bit(UNDER_RECLAIM, &page->private);
+			break;
 		}
 
 		list_del_init(&page->lru);
@@ -888,6 +896,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 		}
 next:
 		spin_lock(&pool->lock);
+		clear_bit(UNDER_RECLAIM, &page->private);
 		if (test_bit(PAGE_HEADLESS, &page->private)) {
 			if (ret == 0) {
 				spin_unlock(&pool->lock);
#1 lore raw
Quoted 21 lines · Vitaly Wool

Hi Guenter,

Quoted 19 lines

[ ... ]

Quoted 7 lines

Ugh. Could you please keep that patch and apply this on top:

mm/z3fold.c +0 -0
index c0bca6153b95..e8a80d044d9e 100644

mm/z3fold.c static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) · line 846

Quoted 7 lines
mm/z3fold.c +1 -0
@@ -840,6 +840,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
                      kref_get(&zhdr->refcount);
                      list_del_init(&zhdr->buddy);
                      zhdr->cpu = -1;
+                     break;
              }
              list_del_init(&page->lru);
 

Much better, in a way. The system now takes much longer to crash, and the crash reason is a bit different. The log is too long to attach, so I copied it to [1].

Quoted 5 lines
Quoted 2 lines

crashdump.0002 Latest log
000[12]-Fix-attempt-[12].patch Patches applied on top of v4.17.0-rc1.

thanks for the update. Let's start from a clean sheet. I believe this patch has to be applied anyway so could you please check if it solves the problem.

Getting better; the log is much less noisy. Unfortunately, there are still locking problems, resulting in a hung task. I copied the log message to [1]. This is with [2] applied on top of v4.17-rc1.

Guenter

---
[1] http://server.roeck-us.net/qemu/z3pool/crashdump.0003
[2] http://server.roeck-us.net/qemu/z3pool/0001-Fix-attempt-3.patch

#2 lore raw
In reply to Vitaly Wool

Den tis 17 apr. 2018 kl 18:35 skrev Guenter Roeck <[email protected]>:

<snip>

Quoted 3 lines

Getting better; the log is much less noisy. Unfortunately, there are still locking problems, resulting in a hung task. I copied the log message to [1]. This is with [2] applied on top of v4.17-rc1.

Now this version (this is a full patch to be applied instead of the previous one) should have the above problem resolved too:

mm/z3fold.c +30 -12
index c0bca6153b95..901c0b07cbda 100644
@@ -144,7 +144,8 @@ enum z3fold_page_flags {
 	PAGE_HEADLESS = 0,
 	MIDDLE_CHUNK_MAPPED,
 	NEEDS_COMPACTING,
-	PAGE_STALE
+	PAGE_STALE,
+	UNDER_RECLAIM
 };
 
 /*****************
@@ -173,6 +174,7 @@ static struct z3fold_header *init_z3fold_page(struct page *page,
 	clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
 	clear_bit(NEEDS_COMPACTING, &page->private);
 	clear_bit(PAGE_STALE, &page->private);
+	clear_bit(UNDER_RECLAIM, &page->private);
 
 	spin_lock_init(&zhdr->page_lock);
 	kref_init(&zhdr->refcount);
@@ -756,6 +758,10 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		atomic64_dec(&pool->pages_nr);
 		return;
 	}
+	if (test_bit(UNDER_RECLAIM, &page->private)) {
+		z3fold_page_unlock(zhdr);
+		return;
+	}
 	if (test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
 		z3fold_page_unlock(zhdr);
 		return;
@@ -840,6 +846,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 			kref_get(&zhdr->refcount);
 			list_del_init(&zhdr->buddy);
 			zhdr->cpu = -1;
+			set_bit(UNDER_RECLAIM, &page->private);
+			break;
 		}
 
 		list_del_init(&page->lru);
@@ -887,25 +895,35 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 				goto next;
 		}
 next:
-		spin_lock(&pool->lock);
 		if (test_bit(PAGE_HEADLESS, &page->private)) {
 			if (ret == 0) {
-				spin_unlock(&pool->lock);
 				free_z3fold_page(page);
 				return 0;
 			}
-		} else if (kref_put(&zhdr->refcount, release_z3fold_page)) {
-			atomic64_dec(&pool->pages_nr);
+			spin_lock(&pool->lock);
+			list_add(&page->lru, &pool->lru);
+			spin_unlock(&pool->lock);
+		} else {
+			z3fold_page_lock(zhdr);
+			clear_bit(UNDER_RECLAIM, &page->private);
+			 if (kref_put(&zhdr->refcount,
+					release_z3fold_page_locked)) {
+				atomic64_dec(&pool->pages_nr);
+				return 0;
+			}
+			/*
+			 * if we are here, the page is still not completely
+			 * free. Take the global pool lock then to be able
+			 * to add it back to the lru list
+			 */
+			spin_lock(&pool->lock);
+			list_add(&page->lru, &pool->lru);
 			spin_unlock(&pool->lock);
-			return 0;
+			z3fold_page_unlock(zhdr);
 		}
 
-		/*
-		 * Add to the beginning of LRU.
-		 * Pool lock has to be kept here to ensure the page has
-		 * not already been released
-		 */
-		list_add(&page->lru, &pool->lru);
+		/* We started off locked to we need to lock the pool back */
+		spin_lock(&pool->lock);
 	}
 	spin_unlock(&pool->lock);
 	return -EAGAIN;
#3 lore raw
Quoted 10 lines · Vitaly Wool

Den tis 17 apr. 2018 kl 18:35 skrev Guenter Roeck <[email protected]>:

<snip>

Quoted 3 lines

Getting better; the log is much less noisy. Unfortunately, there are still locking problems, resulting in a hung task. I copied the log message to [1]. This is with [2] applied on top of v4.17-rc1.

Now this version (this is a full patch to be applied instead of the previous one) should have the above problem resolved too:

Excellent - I can not reproduce the problem with this patch applied.

Guenter

Quoted 59 lines
mm/z3fold.c +13 -5
index c0bca6153b95..901c0b07cbda 100644
@@ -144,7 +144,8 @@ enum z3fold_page_flags {
 	PAGE_HEADLESS = 0,
 	MIDDLE_CHUNK_MAPPED,
 	NEEDS_COMPACTING,
-	PAGE_STALE
+	PAGE_STALE,
+	UNDER_RECLAIM
 };
 
 /*****************
@@ -173,6 +174,7 @@ static struct z3fold_header *init_z3fold_page(struct page *page,
 	clear_bit(MIDDLE_CHUNK_MAPPED, &page->private);
 	clear_bit(NEEDS_COMPACTING, &page->private);
 	clear_bit(PAGE_STALE, &page->private);
+	clear_bit(UNDER_RECLAIM, &page->private);
 
 	spin_lock_init(&zhdr->page_lock);
 	kref_init(&zhdr->refcount);
@@ -756,6 +758,10 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle)
 		atomic64_dec(&pool->pages_nr);
 		return;
 	}
+	if (test_bit(UNDER_RECLAIM, &page->private)) {
+		z3fold_page_unlock(zhdr);
+		return;
+	}
 	if (test_and_set_bit(NEEDS_COMPACTING, &page->private)) {
 		z3fold_page_unlock(zhdr);
 		return;
@@ -840,6 +846,8 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 			kref_get(&zhdr->refcount);
 			list_del_init(&zhdr->buddy);
 			zhdr->cpu = -1;
+			set_bit(UNDER_RECLAIM, &page->private);
+			break;
 		}
 
 		list_del_init(&page->lru);
@@ -887,25 +895,35 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries)
 				goto next;
 		}
 next:
-		spin_lock(&pool->lock);
 		if (test_bit(PAGE_HEADLESS, &page->private)) {
 			if (ret == 0) {
-				spin_unlock(&pool->lock);
 				free_z3fold_page(page);
 				return 0;
 			}
-		} else if (kref_put(&zhdr->refcount, release_z3fold_page)) {
-			atomic64_dec(&pool->pages_nr);
+			spin_lock(&pool->lock);
+			list_add(&page->lru, &pool->lru);
+			spin_unlock(&pool->lock);
+		} else {

mm/z3fold.c static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) · line 916

Quoted 10 lines
mm/z3fold.c +10 -0
+			z3fold_page_lock(zhdr);
+			clear_bit(UNDER_RECLAIM, &page->private);
+			 if (kref_put(&zhdr->refcount,
+					release_z3fold_page_locked)) {
+				atomic64_dec(&pool->pages_nr);
+				return 0;
+			}
+			/*
+			 * if we are here, the page is still not completely
+			 * free. Take the global pool lock then to be able

extra then ?

Quoted 20 lines
mm/z3fold.c +7 -7
+			 * to add it back to the lru list
+			 */
+			spin_lock(&pool->lock);
+			list_add(&page->lru, &pool->lru);
 			spin_unlock(&pool->lock);
-			return 0;
+			z3fold_page_unlock(zhdr);
 		}
 
-		/*
-		 * Add to the beginning of LRU.
-		 * Pool lock has to be kept here to ensure the page has
-		 * not already been released
-		 */
-		list_add(&page->lru, &pool->lru);
+		/* We started off locked to we need to lock the pool back */
+		spin_lock(&pool->lock);
 	}
 	spin_unlock(&pool->lock);
 	return -EAGAIN;

A message that is not in the archive (sent off-list or not yet received): CAMJBoFO9ktEHK=e=Dkq99tNNKHM1iPuxUJ5bmyoX_bzjGwOmig@mail.gmail.com

#5 lore raw

Hi Vitaly,

Quoted 16 lines · Vitaly Wool

Hi Guenter,

Den ons 18 apr. 2018 kl 18:07 skrev Guenter Roeck <[email protected]>:

Quoted 12 lines · Vitaly Wool
Quoted 5 lines

Den tis 17 apr. 2018 kl 18:35 skrev Guenter Roeck <[email protected]>:

<snip>

Quoted 1 line

Getting better; the log is much less noisy. Unfortunately, there are

still

Quoted 1 line
Quoted 1 line

locking problems, resulting in a hung task. I copied the log message

to [1].

Quoted 3 lines
Quoted 1 line

This is with [2] applied on top of v4.17-rc1.

Now this version (this is a full patch to be applied instead of the

Quoted 9 lines
Quoted 7 lines

previous one) should have the above problem resolved too:

Quoted 1 line

Excellent - I can not reproduce the problem with this patch applied.

thank you very much for testing and prompt feedback. I'll come up shortly

with the final patch.

Any updates ?

Thanks,
Guenter