Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp698830ybr; Fri, 22 May 2020 17:26:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznOk1zGU6LV18JgS+5eSCsOc2W6SM9AgQjHfIMAm+qfR6nC/EYhRqnBZW5tKqR0oTpPhVE X-Received: by 2002:a50:8165:: with SMTP id 92mr5167867edc.263.1590193602234; Fri, 22 May 2020 17:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590193602; cv=none; d=google.com; s=arc-20160816; b=w7GP3HUWTnkIDRbAdSqLXH8JoQbgjIRbqkW8Q+OiyBAanA7Al+mShnC7/HdqCO15k1 +wXrcCyFJNxBT/PGTL7UQbU5y/2yKBQnpo1m3Wqm1dhHkxBHnUHDTdYbKOO35DYzCc0u aXUiJOk8tf/pLiGLNCkSJu/QnZgs+KG9HY+9fvovQzSU0zS/4CsJvQcDdvGhZ+hJtjM1 G0vnWjgcZ8wEMxiSQ5gvdppwdN5HV9OpXC3rtKDXWXR2c80fXdXHTTONw8TtzyDWrxYz /K1QnA0ukKeYW5y7RSapkZ5NqOpQuX7r7RnWf9ht7PhRtfXgdQsQYXWKlbc2WwGIy1aZ NACA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9VtAOlBK9KfcZ9PUvgPzNlrZbINRni1ImSMy32Ul7eA=; b=BgfQl98V6NK985Y6cR1BsHtQS/sB8k8TA88pgSJQ+nv/r/7v8dlB3CAJh06v6K9nnG jX4hKmUvCoKrONg/MAIa44pfHp63pVHsISBheDf0wItFJwsLsDX65G9ZlKXsYHlHOq+L 9FAw+03GDZ63LfICObxc5ZebU+Y/jMPt+fr8U5LesAihvM4dhmwW7Ikms+VLTRYVTtIZ AXcnR2sAdLJHbknWt+pb8QjH3+RCi1Ie+PumWVItT2eXPVWiwTFWtHMiustUFwONQy7A Rkp4K1zYthGB7XFhIwe0KZdPCRkIEPeplgZcCIAYzhyhb9ff+OHHYpU7kSw2EB+dn2Zv r22Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1bkaaMvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si127192edn.148.2020.05.22.17.26.16; Fri, 22 May 2020 17:26:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1bkaaMvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387413AbgEWAYP (ORCPT + 99 others); Fri, 22 May 2020 20:24:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:40886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731169AbgEWAYO (ORCPT ); Fri, 22 May 2020 20:24:14 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F161C206B6; Sat, 23 May 2020 00:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590193454; bh=Ltqk5S7sTe6qhzTsLX+lmDJTePgoj+yWfBQOSW1e5F8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=1bkaaMvhTxF5JMHQIXeMj1VUx4IxQzKJsYnk9y9BesD/kJ1NP93vE9yr7FoNNbDBS GeeUnYVf9sO7wwe+wmjsUDnFf3KF0cV1FwI/fT1mKecJ3TmJeSLozYUh1+u751XCA/ 7ihIEaQJI1cwlxIqd2N87NnqyzPwHpOeX5nIo0NI= Date: Fri, 22 May 2020 17:24:13 -0700 From: Andrew Morton To: Hugh Dickins Cc: Johannes Weiner , Alex Shi , Joonsoo Kim , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH mmotm] mm/swap: fix livelock in __read_swap_cache_async() Message-Id: <20200522172413.19c1d45848b4f3db1015a534@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 May 2020 22:56:20 -0700 (PDT) Hugh Dickins wrote: > I've only seen this livelock on one machine (repeatably, but not to > order), and not fully analyzed it - two processes seen looping around > getting -EEXIST from swapcache_prepare(), I guess a third (at lower > priority? but wanting the same cpu as one of the loopers? preemption > or cond_resched() not enough to let it back in?) set SWAP_HAS_CACHE, > then went off into direct reclaim, scheduled away, and somehow could > not get back to add the page to swap cache and let them all complete. > > Restore the page allocation in __read_swap_cache_async() to before > the swapcache_prepare() call: "mm: memcontrol: charge swapin pages > on instantiation" moved it outside the loop, which indeed looks much > nicer, but exposed this weakness. We used to allocate new_page once > and then keep it across all iterations of the loop: but I think that > just optimizes for a rare case, and complicates the flow, so go with > the new simpler structure, with allocate+free each time around (which > is more considerate use of the memory too). > > Fix the comment on the looping case, which has long been inaccurate: > it's not a racing get_swap_page() that's the problem here. > > Fix the add_to_swap_cache() and mem_cgroup_charge() error recovery: > not swap_free(), but put_swap_page() to undo SWAP_HAS_CACHE, as was > done before; but delete_from_swap_cache() already includes it. > > And one more nit: I don't think it makes any difference in practice, > but remove the "& GFP_KERNEL" mask from the mem_cgroup_charge() call: > add_to_swap_cache() needs that, to convert gfp_mask from user and page > cache allocation (e.g. highmem) to radix node allocation (lowmem), but > we don't need or usually apply that mask when charging mem_cgroup. > > Signed-off-by: Hugh Dickins > --- > Mostly fixing mm-memcontrol-charge-swapin-pages-on-instantiation.patch > but now I see that mm-memcontrol-delete-unused-lrucare-handling.patch > made a further change here (took an arg off the mem_cgroup_charge call): > as is, this patch is diffed to go on top of both of them, and better > that I get it out now for Johannes look at; but could be rediffed for > folding into blah-instantiation.patch later. Thanks - I did the necessary jiggery-pokery to get this into the right place.