From patchwork Sun Jan 10 00:59:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 565296 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6063C1402A1 for ; Sun, 10 Jan 2016 12:01:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=UXdPnIuI; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 35E8B1A0CFD for ; Sun, 10 Jan 2016 12:01:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=UXdPnIuI; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com [IPv6:2607:f8b0:400e:c03::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 51DBA1A0908 for ; Sun, 10 Jan 2016 11:59:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=UXdPnIuI; dkim-atps=neutral Received: by mail-pa0-x22d.google.com with SMTP id yy13so209749568pab.3 for ; Sat, 09 Jan 2016 16:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version:content-type; bh=i7/KrQW3ynwFOjndK3kcSb8HO/iO/po7r5O5Jj9BkdM=; b=UXdPnIuIimBDUTauJ/uKPr3HSgM8sYKSi3VHUe7V/+awZ3ABPPx46mRa1uddCFnGOx l8VbJk7RaCE4z4zSrO6/gyZcG3mq0H3OQFy+iHWXD6AEKXq9+bh72wRwl75S0+d2yRxD bPMbFmGWSD9YEK4vdgT+HSAQF1jqyDMejjP50kyuXaTxkIrS9K/Qy2Rtp50C72CIirLi mcjGqHF8F1xsh40Yj7aCzKgF1lhwlq0wLSOB8zUyLAEqBUtvHU9jz5TBx2wQl4E0CZEw P0hkYQV83l2o1atppD4NRB952dlANaE7jz0WppcTV+SYSbbtnvLv1b+Uka5xjP9d7vLl gxIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=i7/KrQW3ynwFOjndK3kcSb8HO/iO/po7r5O5Jj9BkdM=; b=E7fh/6fVQhi67DRSABJps+l3+M8YoL7/E+6Vb3G3KU4kyPRPNN2xdpmisReMwkW4dI XrIWS+YarC/eE59RnXZXDH0ImgZGmYVlwfsdhOsHzl2/wOfY7I2GnJsV/N62nRDCxp0O 3gQg/8X/JtdAwhaEW0h1kvEpdp5ytby5kp0EtXEwVrHf47DyIawpp6FoPxfdi76Wp7wx tboNAVs6qGbNQ8yU2XIPGC7Bf1a/SDJTgDvUWxQtHycrkeGk+ekkm0Zux4/9R4Hp1i4a 5lt+UEN8LQH0eR9HtKq+7hfJFf7XkKf3NbOwn8O8NmPFAee3SsxKighOCMi70o1i7gdY xHDg== X-Gm-Message-State: ALoCoQl31iz2ds0QXlayNuYpaQB6CidyrKq2Rf0Ha5GvVYuJ/FTbhr4+rSr37bKcxhQwZT8OjAVNoyiSC5+jDNwnaJNxHCic9g== X-Received: by 10.66.100.198 with SMTP id fa6mr129716344pab.123.1452387586236; Sat, 09 Jan 2016 16:59:46 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id l75sm13760310pfj.7.2016.01.09.16.59.43 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 09 Jan 2016 16:59:44 -0800 (PST) Date: Sat, 9 Jan 2016 16:59:42 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton Subject: [PATCH next] mm: make swapoff more robust against soft dirty In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cyrill Gorcunov , linux-mm@kvack.org, "Aneesh Kumar K.V" , Martin Schwidefsky , Laurent Dufour , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Both s390 and powerpc have hit the issue of swapoff hanging, when CONFIG_HAVE_ARCH_SOFT_DIRTY and CONFIG_MEM_SOFT_DIRTY ifdefs were not quite as x86_64 had them. I think it would be much clearer if HAVE_ARCH_SOFT_DIRTY was just a Kconfig option set by architectures to determine whether the MEM_SOFT_DIRTY option should be offered, and the actual code depend upon CONFIG_MEM_SOFT_DIRTY alone. But won't embark on that change myself: instead make swapoff more robust, by using pte_swp_clear_soft_dirty() on each pte it encounters, without an explicit #ifdef CONFIG_MEM_SOFT_DIRTY. That being a no-op, whether the bit in question is defined as 0 or the asm-generic fallback is used, unless soft dirty is fully turned on. Why "maybe" in maybe_same_pte()? Rename it pte_same_as_swp(). Signed-off-by: Hugh Dickins Acked-by: Cyrill Gorcunov Reviewed-by: Aneesh Kumar K.V --- mm/swapfile.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) --- 4.4-next/mm/swapfile.c 2016-01-06 11:54:46.327006983 -0800 +++ linux/mm/swapfile.c 2016-01-09 13:39:19.632872694 -0800 @@ -1109,19 +1109,9 @@ unsigned int count_swap_pages(int type, } #endif /* CONFIG_HIBERNATION */ -static inline int maybe_same_pte(pte_t pte, pte_t swp_pte) +static inline int pte_same_as_swp(pte_t pte, pte_t swp_pte) { -#ifdef CONFIG_MEM_SOFT_DIRTY - /* - * When pte keeps soft dirty bit the pte generated - * from swap entry does not has it, still it's same - * pte from logical point of view. - */ - pte_t swp_pte_dirty = pte_swp_mksoft_dirty(swp_pte); - return pte_same(pte, swp_pte) || pte_same(pte, swp_pte_dirty); -#else - return pte_same(pte, swp_pte); -#endif + return pte_same(pte_swp_clear_soft_dirty(pte), swp_pte); } /* @@ -1150,7 +1140,7 @@ static int unuse_pte(struct vm_area_stru } pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); - if (unlikely(!maybe_same_pte(*pte, swp_entry_to_pte(entry)))) { + if (unlikely(!pte_same_as_swp(*pte, swp_entry_to_pte(entry)))) { mem_cgroup_cancel_charge(page, memcg, false); ret = 0; goto out; @@ -1208,7 +1198,7 @@ static int unuse_pte_range(struct vm_are * swapoff spends a _lot_ of time in this loop! * Test inline before going to call unuse_pte. */ - if (unlikely(maybe_same_pte(*pte, swp_pte))) { + if (unlikely(pte_same_as_swp(*pte, swp_pte))) { pte_unmap(pte); ret = unuse_pte(vma, pmd, addr, entry, page); if (ret)