Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3184384yba; Mon, 8 Apr 2019 13:00:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxE6SYmXFn58YzTsVHWoJF4S4K6JBzKv9FcFt+7XGuA364Pq77Bvlw1kfmxuLmSYVa8E1I X-Received: by 2002:a63:e70c:: with SMTP id b12mr29122803pgi.399.1554753615976; Mon, 08 Apr 2019 13:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554753615; cv=none; d=google.com; s=arc-20160816; b=iaIc3t14UJSGIMqTYgutvdinwXW4S3e5twWSO3qvDenenOMYY2MkklYdApfZyk+DBD 4ASSjuxwiqlDJfQSJVf4YnIyIXtwzRKbSTY9chFZNznYxMTIlDQmspASzK0PeJgCXamY Bmjgn+nE4OlehTpmqUgWez7vMheep6kXu4J8MCOIdM3JJKYCIDUcgQklOZikqnfghXMe xFWxZhSRTpa+uODsJ0pcb3l+yoW04HltWBqVgFoC7qd9NSuTwatMjJFzxMuJMLh7ZhdE xk/JkYpbgkx1DFNazWca3FNZxufdcBjTbfbTQ6P8hoi6xHwYdOQL592tsKfJYgXq3Knl K2Bw== 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=29W9ucIOqItYnzmL2gQIQ5ExGyQgwi2PVG1yglWaKBM=; b=kpXWcRQQTaz7L8zQRd672ln8rw2uVNi+mI3gRDqMJ+eWK7SVr1JTaHFadQ4gHPyzkC uaD9ADxX0+8wz00b4EqIQVxm4fZYTgxvG+726UliPSUXkpQa615RCYQm69iw0w0dhNeV +Ej7Rf7V6QhSYEiU+Tg5sysLwdgAOaAkCmy39jKksD8Adx9HEvWjd7pRP9zaDE9FykKO 5EX5h6CLdbdL3vj6S6ZbxHsLM+qffPfIisFdrLm2Mp5E5BuKtya9GMH+AeQ6xY+gg42T KcVyTc1IwH+AnXVoN0GaovK7V9QBPcSId/XG2SWttjAtDrBkFCNfqOGTvCyrbdsi3sdA ExDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Fy4t1CyU; 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 d23si26560143pls.151.2019.04.08.13.00.00; Mon, 08 Apr 2019 13:00:15 -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=Fy4t1CyU; 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 S1726994AbfDHT6S (ORCPT + 99 others); Mon, 8 Apr 2019 15:58:18 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33775 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbfDHT6S (ORCPT ); Mon, 8 Apr 2019 15:58:18 -0400 Received: by mail-pg1-f195.google.com with SMTP id k19so7920889pgh.0 for ; Mon, 08 Apr 2019 12:58:17 -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=29W9ucIOqItYnzmL2gQIQ5ExGyQgwi2PVG1yglWaKBM=; b=Fy4t1CyUr8Vd/Tq1kRsSKxv77weNKQj5DhgPy9nD2bCEsiBn3FEGyA8sZ83Fpwo6bW tRb1hXjVG3V8vMhxBjeLI6C1RvZMzNOtU33E4GDSDs0Ps0T0NgRjLBkn9n5ALGsshrwb Oxspjm1t7dapzNkUm1UBxH7cqGC7RV4j4v9uZukrNkd09KxA+zKmao0FCp1YBCvYdbAN 76r1I75mjP8bgo4nUEuuqhIjwkoGsrIzEzuTrPl0JUP+dwFcE0tW06qlb0KlIOOev7tg 5f+JD1JqYlb1nfbuCaPOdDZFwIKIgmIe2jO8gc4TX04rNrLUFEsId6g6YZYGYoCqlm2Z r0zA== 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=29W9ucIOqItYnzmL2gQIQ5ExGyQgwi2PVG1yglWaKBM=; b=eJBI8TPFs1aTbOWfB/YuJqm66XS/2OA34OLlJ/0GrN9AgakOWt3Cqn2WeVMtcU7nXx rDLhyjpCi4UkS/brAPr6d4hayO4MsqastyrWk2Rs0mB4nKtPc4TQ1qjQDyB3SQQAxebW pYwt+f9QTBat7/dgo/S+z+bgCD90WbxSkWrIqYBZn2LGsBgDcdVQZ61+ecrlTeyZm8Hn VBisOyv+IgoiXh3oo/2jxaRmClV3wWklyDm+h4oI5EYsCWFDjloHTgYPKAYc4K+26Trf XWgH/DPHEfyjv6GGK5JN3nDjhsDNgX5+ZZF2svFKTOdE937d4TpmrjWkPQ1Btvx5YU6C OdzQ== X-Gm-Message-State: APjAAAWUEm5KEhMrRuXtkyrxxmnkbrbRGKEFzP9B6b4zKDk4WqMZ30yI zB82G2P1fJ+CKOnfGEPgOTfdWQ== X-Received: by 2002:a62:209c:: with SMTP id m28mr31113893pfj.233.1554753496623; Mon, 08 Apr 2019 12:58:16 -0700 (PDT) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id l5sm55488310pfi.97.2019.04.08.12.58.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Apr 2019 12:58:15 -0700 (PDT) Date: Mon, 8 Apr 2019 12:58:14 -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 2/4] mm: swapoff: remove too limiting SWAP_UNUSE_MAX_TRIES 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 SWAP_UNUSE_MAX_TRIES 3 appeared to work well in earlier testing, but further testing has proved it to be a source of unnecessary swapoff EBUSY failures (which can then be followed by unmount EBUSY failures). When mmget_not_zero() or shmem's igrab() fails, there is an mm exiting or inode being evicted, freeing up swap independent of try_to_unuse(). Those typically completed much sooner than the old quadratic swapoff, but now it's more common that swapoff may need to wait for them. It's possible to move those cases from init_mm.mmlist and shmem_swaplist to separate "exiting" swaplists, and try_to_unuse() then wait for those lists to be emptied; but we've not bothered with that in the past, and don't want to risk missing some other forgotten case. So just revert to cycling around until the swap is gone, without any retries limit. Fixes: b56a2d8af914 ("mm: rid swapoff of quadratic complexity") Signed-off-by: Hugh Dickins --- mm/swapfile.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- 5.1-rc4/mm/swapfile.c 2019-03-17 16:18:15.713823942 -0700 +++ linux/mm/swapfile.c 2019-04-07 19:15:01.269054187 -0700 @@ -2023,7 +2023,6 @@ static unsigned int find_next_to_unuse(s * If the boolean frontswap is true, only unuse pages_to_unuse pages; * pages_to_unuse==0 means all pages; ignored if frontswap is false */ -#define SWAP_UNUSE_MAX_TRIES 3 int try_to_unuse(unsigned int type, bool frontswap, unsigned long pages_to_unuse) { @@ -2035,7 +2034,6 @@ int try_to_unuse(unsigned int type, bool struct page *page; swp_entry_t entry; unsigned int i; - int retries = 0; if (!si->inuse_pages) return 0; @@ -2117,14 +2115,16 @@ retry: * If yes, we would need to do retry the unuse logic again. * Under global memory pressure, swap entries can be reinserted back * into process space after the mmlist loop above passes over them. - * Its not worth continuosuly retrying to unuse the swap in this case. - * So we try SWAP_UNUSE_MAX_TRIES times. + * + * Limit the number of retries? No: when shmem_unuse()'s igrab() fails, + * a shmem inode using swap is being evicted; and when mmget_not_zero() + * above fails, that mm is likely to be freeing swap from exit_mmap(). + * Both proceed at their own independent pace: we could move them to + * 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 (++retries >= SWAP_UNUSE_MAX_TRIES) - retval = -EBUSY; - else if (si->inuse_pages) + if (si->inuse_pages) goto retry; - out: return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; }