From patchwork Thu Jun 11 22:28:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11600961 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 572B590 for ; Thu, 11 Jun 2020 22:29:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 240FE2075F for ; Thu, 11 Jun 2020 22:29:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="C9efrmYg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 240FE2075F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3EB838D00A9; Thu, 11 Jun 2020 18:28:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 39B0B8D00A0; Thu, 11 Jun 2020 18:28:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D81F8D00A9; Thu, 11 Jun 2020 18:28:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 16D2C8D00A0 for ; Thu, 11 Jun 2020 18:28:59 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C235F180AD82F for ; Thu, 11 Jun 2020 22:28:58 +0000 (UTC) X-FDA: 76918372356.15.crate64_4b0521c26dd7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 94EAA1814B0C1 for ; Thu, 11 Jun 2020 22:28:58 +0000 (UTC) X-Spam-Summary: 2,0,0,9ca55b1361c31eef,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:966:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2553:2559:2562:2693:2895:2898:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3872:4321:4385:5007:6119:6261:6653:6742:7875:7903:8957:10004:10400:11026:11232:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12740:12895:12986:13153:13161:13228:13229:13439:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:30054:30070:30090,0,RBL:209.85.210.42:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: crate64_4b0521c26dd7 X-Filterd-Recvd-Size: 5512 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Thu, 11 Jun 2020 22:28:58 +0000 (UTC) Received: by mail-ot1-f42.google.com with SMTP id k15so5850037otp.8 for ; Thu, 11 Jun 2020 15:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=yQuXdwOztfCCh1OM0Y/znnoWVtA42w245nppjLu++SM=; b=C9efrmYgO5lfHiPabO9leNQkZRsdhlwEQGAWMA52SmmHSpafgnK+/l847DiwWOyBpj BAeGvslbj7wElzHda4DwvXS0ku8R79Ov2+bHCOh/Wc5QGdmv0su6wFBq2OfvGk2eaTGq u9MFt68ahkxY0WjRh3nuhhBOlrOW1MnYy8G6VghffVY4IdRBNay/7mj7FCjMHKTJv2ht GYwLGmvsv2JG78AtNqL4aAn4TX+q6VYmWxN1EECEZxgW8vMb3YpE6BvTsBs1SmWoAXbN k7edAcL63vK2Ld9noBiS6oSmq4WzbzSYWD0olZCdndrD21tLhFkspBj4YJEgjnw+feF7 tXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=yQuXdwOztfCCh1OM0Y/znnoWVtA42w245nppjLu++SM=; b=U15PrqrzboxTaSFqGzDFnBq9LK76trahoI4483a/skob3d4pqz5bD6dGPBNfoLrV+p eAUTWLpMrPgLs8wDTnqbs+XtBmm0DUwKnw8kP7PY+aRWvYEqIpyerM8QQKaMIY40o7X7 sbpY+C6axA9GT7selFf21em3mnccvQmvs4NrK86DDCmIHiiIbl15QziydEUECUlbaPu/ EK86Y2NRnBMXTMIOGc5uV+S0dsN3YF3Yxt+dW3TPLVPkqT7SSI7EfzgFJ2qjVVR68J1q ocrdTM0hMdQ2cYkNis23TnA+nqjWNz+VQ7Y3FoXuQmYNwKoVAGcDpO+kaxLj6BhVZ39U 2KLQ== X-Gm-Message-State: AOAM530oM/ZroSlYa8gK9sqHSdbISn09JH7peaKZZEiUp4nhKzpeTC72 Hvm7wOnoLtgsHQ4g7SSSTlCeRQ== X-Google-Smtp-Source: ABdhPJwC0cSrxAVd/oScf78OXudE/J7qH0OBFpxhpmCCenQEqZL2QUwwdccMsG0/Q/aHQLe+aN7Mmg== X-Received: by 2002:a9d:1c9b:: with SMTP id l27mr9063837ota.22.1591914537191; Thu, 11 Jun 2020 15:28:57 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 126sm974999oii.39.2020.06.11.15.28.54 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 11 Jun 2020 15:28:56 -0700 (PDT) Date: Thu, 11 Jun 2020 15:28:54 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Alex Shi cc: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com Subject: [PATCH alexv12 1/2] mm/compaction: fix isolate_migratepages_block() fails Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 94EAA1814B0C1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fix lots of crashes under compaction load: isolate_migratepages_block() must clean up appropriately when rejecting a page, setting PageLRU again if it had been cleared; and a put_page() after get_page_unless_zero() cannot safely be done while holding locked_lruvec - it may turn out to be the final put_page(), which will take an lruvec lock when PageLRU. Signed-off-by: Hugh Dickins --- These fixes should be folded into 10/16 and 12/16, I have not tried to figure out what belongs in which. mm/compaction.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- alexv12/mm/compaction.c 2020-06-11 13:24:52.037154793 -0700 +++ hughd/mm/compaction.c 2020-06-11 13:48:10.437046025 -0700 @@ -879,6 +879,7 @@ isolate_migratepages_block(struct compac if (!valid_page && IS_ALIGNED(low_pfn, pageblock_nr_pages)) { if (!cc->ignore_skip_hint && get_pageblock_skip(page)) { low_pfn = end_pfn; + page = NULL; goto isolate_abort; } valid_page = page; @@ -971,10 +972,8 @@ isolate_migratepages_block(struct compac goto isolate_fail; /* Try isolate the page */ - if (!TestClearPageLRU(page)) { - put_page(page); - goto isolate_fail; - } + if (!TestClearPageLRU(page)) + goto isolate_fail_put; rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); @@ -1005,7 +1004,8 @@ isolate_migratepages_block(struct compac */ if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; - goto isolate_fail; + SetPageLRU(page); + goto isolate_fail_put; } } else rcu_read_unlock(); @@ -1038,6 +1038,15 @@ isolate_success: } continue; + +isolate_fail_put: + /* Avoid potential deadlock in freeing page under lru_lock */ + if (locked_lruvec) { + unlock_page_lruvec_irqrestore(locked_lruvec, flags); + locked_lruvec = NULL; + } + put_page(page); + isolate_fail: if (!skip_on_failure) continue; @@ -1074,10 +1083,15 @@ isolate_fail: */ if (unlikely(low_pfn > end_pfn)) low_pfn = end_pfn; + page = NULL; isolate_abort: if (locked_lruvec) unlock_page_lruvec_irqrestore(locked_lruvec, flags); + if (page) { + SetPageLRU(page); + put_page(page); + } /* * Updated the cached scanner pfn once the pageblock has been scanned