From patchwork Wed Jul 22 17:44:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 11679043 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 751A8138A for ; Wed, 22 Jul 2020 17:45:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 489A8207BB for ; Wed, 22 Jul 2020 17:45:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 489A8207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 300DA6B0002; Wed, 22 Jul 2020 13:45:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 289C16B0005; Wed, 22 Jul 2020 13:45:06 -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 151D66B0006; Wed, 22 Jul 2020 13:45:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id F07456B0002 for ; Wed, 22 Jul 2020 13:45:05 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 841141C8939F8 for ; Wed, 22 Jul 2020 17:45:05 +0000 (UTC) X-FDA: 77066437770.21.dust79_5b0406f26f37 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 7C45318017BEF for ; Wed, 22 Jul 2020 17:44:41 +0000 (UTC) X-Spam-Summary: 20,1.5,0,b111619ac5b128f0,d41d8cd98f00b204,andrea.righi@canonical.com,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1312:1313:1314:1345:1431:1437:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:5007:6119:6261:6630:7903:10009:10400:11026:11658:11914:12296:12297:12438:12517:12519:12555:12895:13069:13161:13229:13311:13357:13439:13869:13895:14096:14097:14181:14394:14721:21060:21080:21324:21444:21451:21627:21987:21990:30054:30070:30091,0,RBL:91.189.89.112:@canonical.com:.lbl8.mailshell.net-62.8.15.100 64.201.201.201;04y8texmppj3ckqeskya3p56eo77cycncd5j8gp6yg33bi791os1npimhpx9ah3.6qgsy8zzfhtw5w5mexp5fmuw6eoh5tsd34z5ptbzczn3sduhe9tg68c8a3susb9.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: dust79_5b0406f26f37 X-Filterd-Recvd-Size: 4372 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Jul 2020 17:44:40 +0000 (UTC) Received: from mail-wm1-f70.google.com ([209.85.128.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jyInH-0007OS-Ia for linux-mm@kvack.org; Wed, 22 Jul 2020 17:44:39 +0000 Received: by mail-wm1-f70.google.com with SMTP id b13so1320998wme.9 for ; Wed, 22 Jul 2020 10:44:39 -0700 (PDT) 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:mime-version :content-disposition; bh=wIK2o+UarAf7XWWj0TPiEcgHlsE+IXk4111M8CYmrKA=; b=l/XuyQL5aOzUJmZ4XsFqQXzic84WXM5FJcPiF1dp4GSqRT3iPwAMQwrggFwADeIbES 7Js+nT04OWP8Cf1tyR9aRzfbDqrlUQqX8ooecIHXsbWaV4qwiXZ9oixzbJtWo9fsB8+9 FAenf5l6cmZVpfzxpHL6vTatdzZrcW9kEz0E3WvRHY0uxKOv9jb7zf4SjCKE2Qg00Fxk YxEjDxBA87xg6tFm4vJQ41wSozYnYNYe2CJ9AC2N9enwFO0Se5xVfEqzZ0inKNF5ThFS gAV2vb310195LoUAoSs/rcQp9dYeEb/hImRg/h126mfeI1IMae5TUdS4EkhTOi2f0hqc Thqg== X-Gm-Message-State: AOAM532ILyxWAwyWJI7AGp6l61yVHydyXO7+l6I7aq2MT9rmW3UY6NfH 9s13pDVs8WHNejtrUXIcesUVw5VDDacae2oPYX8C6dozGrzkR2jnJVJ06ULaV+XPw0dp8pdm9yb NLD9qNRg1gl0Bhvd5gI+WLNotnNJx X-Received: by 2002:adf:a11d:: with SMTP id o29mr566751wro.421.1595439879197; Wed, 22 Jul 2020 10:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0/LB1ytnXv/m4kbvp81Q9qHxXu3ShznEJiuSAv0FpH67DPWIZLP0LDSqSiuObHQl6NsjEPQ== X-Received: by 2002:adf:a11d:: with SMTP id o29mr566735wro.421.1595439878868; Wed, 22 Jul 2020 10:44:38 -0700 (PDT) Received: from localhost (host-87-11-131-192.retail.telecomitalia.it. [87.11.131.192]) by smtp.gmail.com with ESMTPSA id 12sm430632wmg.6.2020.07.22.10.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 10:44:38 -0700 (PDT) Date: Wed, 22 Jul 2020 19:44:36 +0200 From: Andrea Righi To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: swap: do not wait for lock_page() in unuse_pte_range() Message-ID: <20200722174436.GB841369@xps-13> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: 7C45318017BEF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Waiting for lock_page() with mm->mmap_sem held in unuse_pte_range() can lead to stalls while running swapoff (i.e., not being able to ssh into the system, inability to execute simple commands like 'ps', etc.). Replace lock_page() with trylock_page() and release mm->mmap_sem if we fail to lock it, giving other tasks a chance to continue and prevent the stall. This issue can be easily reproduced running swapoff in systems with a large amount of RAM (>=100GB) and a lot of pages swapped out to disk. A specific use case is to run swapoff immediately after resuming from hibernation. Under these conditions and without this patch applied the system can be stalled even for 15min, with this patch applied the system is always responsive. Signed-off-by: Andrea Righi --- mm/swapfile.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 987276c557d1..794935ecf82a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1977,7 +1977,11 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, return -ENOMEM; } - lock_page(page); + if (!trylock_page(page)) { + ret = -EAGAIN; + put_page(page); + goto out; + } wait_on_page_writeback(page); ret = unuse_pte(vma, pmd, addr, entry, page); if (ret < 0) { @@ -2100,11 +2104,17 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type, struct vm_area_struct *vma; int ret = 0; +retry: mmap_read_lock(mm); for (vma = mm->mmap; vma; vma = vma->vm_next) { if (vma->anon_vma) { ret = unuse_vma(vma, type, frontswap, fs_pages_to_unuse); + if (ret == -EAGAIN) { + mmap_read_unlock(mm); + cond_resched(); + goto retry; + } if (ret) break; }