Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp987783imu; Fri, 11 Jan 2019 12:47:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN7omk60JhsM85uV07K8pTqtxSo2seFIdCmrNfrd4tQTmlIzaObDNYB+B1z1mJh0eATDMj+O X-Received: by 2002:a17:902:690c:: with SMTP id j12mr15974534plk.206.1547239631681; Fri, 11 Jan 2019 12:47:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547239631; cv=none; d=google.com; s=arc-20160816; b=jFDGdyaKp37zHA8ym46o6w4NEEenDkaoEGOOWIUz5PWAx08Ko7eVGUEvcGwnomVqcF HZZMsBx7TnjgbCFOILCmcUXIbHXLnjgFMxZSuYdHe2TvtLodkfN0fkESvPYsCNpw+E7S iphRO4Bdn8b9XkQznv4vg8tk5senV/sC53Fvd5azSis6qK+muEEIBqOeoR4FpTStWeHH asEb/d7aMG5uYYqs1LKrMYQUCNrMnjc8st4/tXTKGTsGkExGpvwwmqYg0s2IQqMslNaw rrZzfq5Y3s/qm1PDqs2CS/T4SpgrCFbgGJSQ4HeZi4fcnkYqibWgJo0NjDxrQQl1Z/Tr uRbA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W7FRzTt12GzdYk8NGBYS6WSjh08axG0iO5RuZd1D7Do=; b=Ayi7WXoZ3dluX+QR2TyGjgwmZqLNFzrRgXD8KSIbQUb6d9g2mH57c3VYVYe3cCSHc5 /YvL7CAPio3x7Znotbf4GPudPpdFMN2bzvqiE9nIKnbRTxWOLXLzIZZCl6B6zIVhBv40 UscIRgY8NtTtVyBeOhlBhpnxx6AGJZvflWLYf1wosDEDnhXK3giFwtoAL2PxTQszqVQz fUSA+nSeeDlR+JHu3GGgrzeObzNLXXb3lzf8RbQmXxnqjLgayBjnj7AwxMBn2IIV2NWT J5JAEFgsQpweZcsVeospKcs9I+Bt4gsoecdLEL7Ni6Wu8KjeWIkueR6NgAcnVZoAMnfB E2JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RiSB4YN7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si76623716plh.245.2019.01.11.12.46.56; Fri, 11 Jan 2019 12:47:11 -0800 (PST) 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=@kernel.org header.s=default header.b=RiSB4YN7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391443AbfAKOsR (ORCPT + 99 others); Fri, 11 Jan 2019 09:48:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:34746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404064AbfAKOl5 (ORCPT ); Fri, 11 Jan 2019 09:41:57 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 DC4F321848; Fri, 11 Jan 2019 14:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217716; bh=HOLC/3FweLdsxKq+BpJ2jNWoLIb8DRAdjZw1tizChgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RiSB4YN73/qHSCgkJYwlUH2x/EPp3M4bGwhhw77TIjuTN9msJKZBP7Qm4s32N73GI 5gzZey3AjGTuR1T5Ek++CFFYrgNT2D7/7fNHlus+qSYalyz4lwPHbbi+4YVYSSdDGl hI5GKSYrTIual9Cgv2tKdbzNW1o12iWCQNbHt6fo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Huang, Ying" , Hugh Dickins , Rik van Riel , Johannes Weiner , Minchan Kim , Shaohua Li , Daniel Jordan , Andrew Morton , Linus Torvalds Subject: [PATCH 4.20 16/65] mm, swap: fix swapoff with KSM pages Date: Fri, 11 Jan 2019 15:15:02 +0100 Message-Id: <20190111131058.625053244@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huang Ying commit 7af7a8e19f0c5425ff639b0f0d2d244c2a647724 upstream. KSM pages may be mapped to the multiple VMAs that cannot be reached from one anon_vma. So during swapin, a new copy of the page need to be generated if a different anon_vma is needed, please refer to comments of ksm_might_need_to_copy() for details. During swapoff, unuse_vma() uses anon_vma (if available) to locate VMA and virtual address mapped to the page, so not all mappings to a swapped out KSM page could be found. So in try_to_unuse(), even if the swap count of a swap entry isn't zero, the page needs to be deleted from swap cache, so that, in the next round a new page could be allocated and swapin for the other mappings of the swapped out KSM page. But this contradicts with the THP swap support. Where the THP could be deleted from swap cache only after the swap count of every swap entry in the huge swap cluster backing the THP has reach 0. So try_to_unuse() is changed in commit e07098294adf ("mm, THP, swap: support to reclaim swap space for THP swapped out") to check that before delete a page from swap cache, but this has broken KSM swapoff too. Fortunately, KSM is for the normal pages only, so the original behavior for KSM pages could be restored easily via checking PageTransCompound(). That is how this patch works. The bug is introduced by e07098294adf ("mm, THP, swap: support to reclaim swap space for THP swapped out"), which is merged by v4.14-rc1. So I think we should backport the fix to from 4.14 on. But Hugh thinks it may be rare for the KSM pages being in the swap device when swapoff, so nobody reports the bug so far. Link: http://lkml.kernel.org/r/20181226051522.28442-1-ying.huang@intel.com Fixes: e07098294adf ("mm, THP, swap: support to reclaim swap space for THP swapped out") Signed-off-by: "Huang, Ying" Reported-by: Hugh Dickins Tested-by: Hugh Dickins Acked-by: Hugh Dickins Cc: Rik van Riel Cc: Johannes Weiner Cc: Minchan Kim Cc: Shaohua Li Cc: Daniel Jordan Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/swapfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2197,7 +2197,8 @@ int try_to_unuse(unsigned int type, bool */ if (PageSwapCache(page) && likely(page_private(page) == entry.val) && - !page_swapped(page)) + (!PageTransCompound(page) || + !swap_page_trans_huge_swapped(si, entry))) delete_from_swap_cache(compound_head(page)); /*