Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3184892yba; Mon, 8 Apr 2019 13:00:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxfnP6WMDCZP0L67f7CUaMtGgWTqxWqO6KWfiVF+E39iBcYCKObGfR4f3p+whmz63YC+AK X-Received: by 2002:a62:f20e:: with SMTP id m14mr32127458pfh.228.1554753647343; Mon, 08 Apr 2019 13:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554753647; cv=none; d=google.com; s=arc-20160816; b=SnxsQgca5g35TjxCYM67iktfGO1ihEO/h1rhYXln2mLFhYufzD8Plxkamppok7r9Kj yHJ+W+roC9IVca+y29z9qv0MtsDZuieloDIJEiL4U2x5vdvtcxR63qmNxQa72ZItVCsU Lk/XGkC7FtwJdXdtx865dK4ZIPL4rfVBoFdORG3YOQBTC6Z4K/Mko1Eb08UuwcJEYCUP xgQywtsxtBzA7bSPYSK6LvbJwPbK+ovb/xTnrOagE3q3H4qSGPX2HO0wwfZx+MoVlOAK NIrXK2B43KPy7jd6m+Fh+JL1E2dN8Ze20p0/RTRv0j/QrFYLscZEts6PvCe1W1rHWj4d jYKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=RSStTgCMJwvCqECwFlnDBhxtF8I569p9e6PuxiQP1oM=; b=k1oxHV49/p9YBT5M3agCylcfjiW4K9RxuRncZzmbW3kqP9j7DSML/p80grRF9Q+UtW Cu2umYqA/MagbIC1jO+ubGUpBfFqrK85ozviRyEIZbj2qgEn5mFirvG+1TuOwn8Qjx1H rK4pHaZVhoqS5NQ1UeYRgJ/i9RliDYS8vOa0pFTWHUcBj1odknUR7MAcdsZy58TzsRmD 8h8gvc+Bitet4tWwVIYrRJc/a5+n4S9FrKT3jHNdae9QhbPusuZNWOc8NFxr6O6O3SZX WdfOs97cth8Skb6npvWxkXc0VEH1DtluLMu56075R14SSkoRgjFmdVTHv19RrVjNBYhN xGkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="IaVs/v49"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r133si27295013pgr.175.2019.04.08.13.00.31; Mon, 08 Apr 2019 13:00:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="IaVs/v49"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbfDHT7g (ORCPT + 99 others); Mon, 8 Apr 2019 15:59:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42699 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726220AbfDHT7g (ORCPT ); Mon, 8 Apr 2019 15:59:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id w25so6792168pfi.9 for ; Mon, 08 Apr 2019 12:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=RSStTgCMJwvCqECwFlnDBhxtF8I569p9e6PuxiQP1oM=; b=IaVs/v49W9F4RB08+llfR3LzCZzsnZdb9KI01bTePyyBQrFAkbpQgsu5FDJDr4nZ/m YA6tTLHgZuvBGyWo/ywVHmrLflS/IVvDlnqE04G9JZQ6H5X7Xn+Co+j/3YHc5dB4U07s hbx3CzJxJZajypW7gQfNirQWke+RqbuAZFyNwtCXf8XQqi4eOU+ydwDNX5yNZ0pO+7N5 GmmBYlJvxnFG59cHiMFKUAf6KwMbkN173hB3GNxcqSoZtnqFuDaGFZTSblrnWbNsLT/W kMw1dwylomWuocQ2hW4ZhH1yohtb86UkZvXeLQtvEK96NHD+YFp2Wh06ZkCcU3MSMPt2 H3pQ== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=RSStTgCMJwvCqECwFlnDBhxtF8I569p9e6PuxiQP1oM=; b=f/UU+1pXBr8t88+seRcgkVV4DQu/IP7AGVEFYKwrHPMH6I8TFR7mF8ndbGzivhB2Ug 0r75RHqag8VsgeLofoOY/JDROShTjKJ3txPpV9RkgciA0ZNGeqtSiKG3PX0yOpfIwe/j O2IJLdxNEh6q+B5fohkuwnYJUCWy/dG4Ll6bDUrOdjEvmP/fyIhFOFUGjeXkj7NkwDcL mh1qr/oYZ5oZk64HVdNvQG8yIWAkrBKEt+EaJ5lNQGdKcnLl3ujphTjCKU6OmW72X849 HiybvmoIlpJMIWBrJ29jnKrnqBy0rH+Ze5Yfeykm1DtVHKvFyGPXXvaQl3GBht6reEyb GGiQ== X-Gm-Message-State: APjAAAX4HmFIFPgZTcyHtORzewdqEUALTHGBGM3ftlS+pvIsMO9MxwXs FCqRYj8nF2TfCI0LHKlAIIowdw== X-Received: by 2002:a65:5383:: with SMTP id x3mr12785290pgq.60.1554753574808; Mon, 08 Apr 2019 12:59:34 -0700 (PDT) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id j16sm41059643pfi.58.2019.04.08.12.59.33 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Apr 2019 12:59:33 -0700 (PDT) Date: Mon, 8 Apr 2019 12:59:32 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Konstantin Khlebnikov , "Alex Xu (Hello71)" , Vineeth Pillai , Kelley Nielsen , Rik van Riel , Huang Ying , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] mm: swapoff: take notice of completion sooner In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The old try_to_unuse() implementation was driven by find_next_to_unuse(), which terminated as soon as all the swap had been freed. Add inuse_pages checks now (alongside signal_pending()) to stop scanning mms and swap_map once finished. The same ought to be done in shmem_unuse() too, but never was before, and needs a different interface: so leave it as is for now. Fixes: b56a2d8af914 ("mm: rid swapoff of quadratic complexity") Signed-off-by: Hugh Dickins --- mm/swapfile.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- 5.1-rc4/mm/swapfile.c 2019-04-07 19:15:01.269054187 -0700 +++ linux/mm/swapfile.c 2019-04-07 19:17:13.291957539 -0700 @@ -2051,11 +2051,9 @@ retry: spin_lock(&mmlist_lock); p = &init_mm.mmlist; - while ((p = p->next) != &init_mm.mmlist) { - if (signal_pending(current)) { - retval = -EINTR; - break; - } + while (si->inuse_pages && + !signal_pending(current) && + (p = p->next) != &init_mm.mmlist) { mm = list_entry(p, struct mm_struct, mmlist); if (!mmget_not_zero(mm)) @@ -2082,7 +2080,9 @@ retry: mmput(prev_mm); i = 0; - while ((i = find_next_to_unuse(si, i, frontswap)) != 0) { + while (si->inuse_pages && + !signal_pending(current) && + (i = find_next_to_unuse(si, i, frontswap)) != 0) { entry = swp_entry(type, i); page = find_get_page(swap_address_space(entry), i); @@ -2123,8 +2123,11 @@ retry: * separate lists, and wait for those lists to be emptied; but it's * easier and more robust (though cpu-intensive) just to keep retrying. */ - if (si->inuse_pages) - goto retry; + if (si->inuse_pages) { + if (!signal_pending(current)) + goto retry; + retval = -EINTR; + } out: return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; }