From patchwork Tue Dec 11 08:46:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10723203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB5E391E for ; Tue, 11 Dec 2018 08:46:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F152A51C for ; Tue, 11 Dec 2018 08:46:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97AD92A52A; Tue, 11 Dec 2018 08:46:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F9002A51C for ; Tue, 11 Dec 2018 08:46:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C6CE8E005D; Tue, 11 Dec 2018 03:46:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6748B8E004D; Tue, 11 Dec 2018 03:46:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5193D8E005D; Tue, 11 Dec 2018 03:46:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id F2F238E004D for ; Tue, 11 Dec 2018 03:46:20 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id o9so9363699pgv.19 for ; Tue, 11 Dec 2018 00:46:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=gvo2LxMZWkljyIAiEOEqg7/axz2AQWt5UQMad2uBvgg=; b=AX8UdMAyBbBbCWWiaqrKA7M6Q8j5I5ZDTPIa8Vcubfj0OGj9bfvdxuXP/qW2IPzbKg MH7YM6YnJhJKhcczBKVawY334PvOypTvsORkKmJZXp8DDPfZ+7zjIMcSNMjPahA3kssG NcZT5NYnAX0CBnucma0GmIyluzzcpjHlsyRBM7CMh8tXT80b4bZspxHdqX0D1xefTa8H yi5pWFr8RJT5vQ7kXBpyG2izYI7YXWr+mesLW+/CPK6MXEGQv7jhWDtIrqNcoxG6Oi3J O00dPrKBF8h8ZpEwwrAnB0shT0mJ6JRyTySn6Fxuc+0G1yUSKgitCni+yprDfPgjeoKe Vq/A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWaJebOXi/k8wC/1FJshIxsTZZsrph0zOZlexeG0hn4n5t3qLDy9 xBX6oRUSGd2hyx1q16TDFyw2UZcsxg2MxWOJTyOzS0oSCivIYnwLmqo9d/aBO9FrQW9vbUSPh9M 4G/EDTew0rT9NdeSYBOQDdLq7lTV3IAY2Z0IO2qb49/sTBN5GAZiUQHiEb4QkJ+Xa5w== X-Received: by 2002:a63:580a:: with SMTP id m10mr13660034pgb.332.1544517980504; Tue, 11 Dec 2018 00:46:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/VPxnEAZ46xWB0JHI9DM5wKWDDt7VLbaXcyW682mnR9IbXhniNlpjzQI9tL0mxHvk8LJvtB X-Received: by 2002:a63:580a:: with SMTP id m10mr13659983pgb.332.1544517979126; Tue, 11 Dec 2018 00:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544517979; cv=none; d=google.com; s=arc-20160816; b=PYvBS0JJdTf/atl13KjLQxB4B7g1KVrK6UIteyhiOT1mGLWdOVuVEGzvvwTAHc1p4w wOwIMDOsknTDFCNyPnqukTmSdjQNoOozVLUb1Y+CEwVhNNkjgJcFarSKnYb2jOlqCHbu Bigsiv8AIW2uXqkaCtGD0t7qjN0mCDoPNj9zVpagizgCc46Rwox7Z1gJfnLyfDcRgJrN g38wEOnMieAc5daNLuLXNUyr+g0gXT2WMvzi8QZYCGjJbvyTEuCJX5xU4bf5UccBQxqG ugE4VjYFcIuD7ZjfUxECeQ4bPiNqyL1t615BCxltHaUdz6iMGqccQdUAVXhtPTwSWF5m L9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=gvo2LxMZWkljyIAiEOEqg7/axz2AQWt5UQMad2uBvgg=; b=DPKTtRgY69sEi7V8QHD9hXEDPye/luNSvTWwivu/1+su98ZOnTlhfA9ptnnk/9A3PN SO5KpzisXHpUqADwJMxYG4/N8gYhwDl2J1QWddii2Oef+yWYRqf6XHecvrx3Cc0Ad1iF 18VGrxQK6rl1TWUScgQ0iNNTE3zSKJAYBqzGuiEkq0iaZFNaAJCR93Xd9cqLAqICOuaV lRGG7Uqp25q8+6Q+e7XMlRacVscElnZ6FUscd+fq9tCWiy70yNTstXQpnDiBteD5yqxq NnrDsxjS2HPCIchmHAPuX3GpYaPVg9GRHwuZ4CxIkW8W8WEIb4oWUAs0dLgXPHXMoX8r Tc9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id d2si12797074pfe.159.2018.12.11.00.46.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 00:46:19 -0800 (PST) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 00:46:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,341,1539673200"; d="scan'208";a="106520746" Received: from yhuang-mobile.sh.intel.com ([10.239.192.61]) by fmsmga007.fm.intel.com with ESMTP; 11 Dec 2018 00:46:16 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Vineeth Remanan Pillai , Kelley Nielsen , Rik van Riel , Matthew Wilcox , Hugh Dickins Subject: [PATCH 1/2] swap: Fix general protection fault when swapoff Date: Tue, 11 Dec 2018 16:46:08 +0800 Message-Id: <20181211084609.19553-1-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When VMA based swap readahead is used, which is default if all swap devices are SSD, swapoff will trigger general protection fault as follow, because vmf->pmd isn't initialized when calling swapin_readahead(). This fix could be folded into the patch: mm, swap: rid swapoff of quadratic complexity in -mm patchset. general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC CPU: 3 PID: 352 Comm: swapoff Not tainted 4.20.0-rc5-mm1-kvm+ #535 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-1.fc28 04/01/2014 RIP: 0010:swapin_readahead+0xb7/0x39b Code: ff 01 00 00 40 f6 c7 80 49 0f 45 d0 48 21 d7 48 ba 00 00 00 00 80 88 ff ff 48 8d 14 f2 48 01 d7 48 ba ff ff ff ff ff ff ff ef <48> 39 17 0f 87 5d 01 00 00 49 8b 95 b0 00 00 00 48 85 d2 75 05 ba RSP: 0018:ffffc900004c3ca0 EFLAGS: 00010207 RAX: 000055de5d252000 RBX: 000000055de5d252 RCX: 0000000000000003 RDX: efffffffffffffff RSI: 0000000000000052 RDI: 000f0bc11c600290 RBP: ffffc900004c3d30 R08: 000fffffffe00000 R09: ffffc900004c3ea0 R10: ffffc900004c3d50 R11: 0000000000000002 R12: ffffc900004c3da8 R13: ffff88803b71d780 R14: 0000000000000001 R15: ffff88803b71d780 FS: 00007f87c20e02c0(0000) GS:ffff88803e800000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055a439825398 CR3: 000000003b49a004 CR4: 0000000000360ea0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: ? list_add_tail_rcu+0x19/0x31 ? __lock_acquire+0xd61/0xe1c ? find_held_lock+0x2b/0x6e ? unuse_pte_range+0xe9/0x429 unuse_pte_range+0xe9/0x429 ? find_held_lock+0x2b/0x6e ? __lock_is_held+0x40/0x71 try_to_unuse+0x311/0x54b __do_sys_swapoff+0x254/0x625 ? lockdep_hardirqs_off+0x29/0x86 ? do_syscall_64+0x12/0x65 do_syscall_64+0x57/0x65 entry_SYSCALL_64_after_hwframe+0x49/0xbe Signed-off-by: "Huang, Ying" Cc: Vineeth Remanan Pillai Cc: Kelley Nielsen Cc: Rik van Riel Cc: Matthew Wilcox Cc: Hugh Dickins --- mm/swapfile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 9ca162cc45dc..7464d0a92869 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1904,6 +1904,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, swap_map = &si->swap_map[offset]; vmf.vma = vma; vmf.address = addr; + vmf.pmd = pmd; page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, &vmf); if (!page) { if (*swap_map == 0 || *swap_map == SWAP_MAP_BAD) From patchwork Tue Dec 11 08:46:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10723205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5594A91E for ; Tue, 11 Dec 2018 08:46:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 452162A51C for ; Tue, 11 Dec 2018 08:46:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38E232A52A; Tue, 11 Dec 2018 08:46:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD33D2A51C for ; Tue, 11 Dec 2018 08:46:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 802428E005E; Tue, 11 Dec 2018 03:46:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 787CC8E004D; Tue, 11 Dec 2018 03:46:22 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58E428E005E; Tue, 11 Dec 2018 03:46:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 092078E004D for ; Tue, 11 Dec 2018 03:46:22 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id 202so9375806pgb.6 for ; Tue, 11 Dec 2018 00:46:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=rcmn20os+/K4CyfpYFSW3FtZWFvbwNieX5oLi+pnIY4=; b=FroZFTjEaF3qBI3NCXdpGpUe9CB01KYC4sS0t8TE4w22NtDSf4omFW6YT/XlgQdXXk +GTFivimWrCZAJsXg2s+ekaVvsUkqpDakg5ducTUp27mZo3/SOOCf5iMwAqGSxLqixNl rh4D/KnBR5kg54RZZvudmuNIflWsVARtgAbKFo4FjFaKRhnww5wxnO3pEfp5PPyN1eRa eqh607mW7uW62HHjRvs6VwJwEyeuuQA+oJsR5Ou47su/N+1XXXhw6EyHTJSddbDQCu1q zzz4Q3S1/UQlpsvgVA64O4HNUktd31S/y87TljpSyyWzfYNfIyYrs37IzmTPxZiPqjLl gJog== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWaqkKu5+iicpoaEJI1i6jn5SPFJb3LHesmP7y1d1GtxA++2u9JX TH1pjDaXcN8UVoLirYb+O+BFrtdy8y0GCA3mFKnJ8s1cFGijt1kUxA0nbWFycJ1VYUYOh14lwNp FI35ziSuLBNRZFV0aJ6PfgVNq2d5eoG9lUgHpTJxXHyRBgUHuyQ3rNsh70ieMNkcxRA== X-Received: by 2002:a17:902:bd0b:: with SMTP id p11mr15363793pls.259.1544517981652; Tue, 11 Dec 2018 00:46:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/WVuE5aVlhQGXvLv7uVJZVtV0SCAFccKDBz6pEWnSddyuGalWApr0ipIwRPi3L3vfO6+Z11 X-Received: by 2002:a17:902:bd0b:: with SMTP id p11mr15363735pls.259.1544517980352; Tue, 11 Dec 2018 00:46:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544517980; cv=none; d=google.com; s=arc-20160816; b=M4ZpoQfciHVUap1APiUVtCixtAMvSt1uOPehEf4Q5u1BgjCDc6YvtF4/uI6Szo12W2 aZmXkrjAX8yvHWoKACuCjqmF45V5elIXkKxcPHIcqO7QR05++hEsY0bnYFcLH5Xbw9pL mt2Vyz34Ym3r+Wg1OvpzFUCJZiSse5+wFySCFdxmoicz8Dsqe6qPJU4sf5JCAST2m3uK VFf7+79goDjLCgmA4AgqhTVoK0cwyJLA8TblaFwfprHt+nSKQNJB3gwe8hjcFoBHxyD4 i8rC/0K1bjH2o7sdGw++2NPuzEgQxLl9uwkZbKEG25LPzNGwR/HP5xqMgRqX5tUUspmO oUtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=rcmn20os+/K4CyfpYFSW3FtZWFvbwNieX5oLi+pnIY4=; b=ZfyZMZEHMwFsM4qdv9dnvugx/9GoQnPZEvuk8bnHCMmvDGoioE/FikRiGLDR9JlPZP vurxuQA+V5Map9g8l5odeO5fQwooUgY8sJP1XDaFoUJodQXAT3YTABwXWKxLHI08VXZY SSCYvjtEiCOHgEtNpr/cKhT2/A5G8VHvGgbgiZQ5gvNRFkn3JsKXdzmVI2PRCf2RTEjG S4KYW5qAiZxh36tRn+vM9+YWC8C+zGkCFHLrxj8VPbf6IGVA7hAt6PLBSy3ypvpO+zlR OUUPKUKzEc5pzM9Xqv8uvY7SENhwDfC+AtsL8CSqlERRDJKuPKmAqR4q0n/HWmnF3wQt hl2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id d2si12797074pfe.159.2018.12.11.00.46.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 00:46:20 -0800 (PST) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 00:46:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,341,1539673200"; d="scan'208";a="106520763" Received: from yhuang-mobile.sh.intel.com ([10.239.192.61]) by fmsmga007.fm.intel.com with ESMTP; 11 Dec 2018 00:46:18 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Vineeth Remanan Pillai , Kelley Nielsen , Rik van Riel , Matthew Wilcox , Hugh Dickins Subject: [PATCH 2/2] swap: Deal with PTE mapped THP when unuse PTE Date: Tue, 11 Dec 2018 16:46:09 +0800 Message-Id: <20181211084609.19553-2-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181211084609.19553-1-ying.huang@intel.com> References: <20181211084609.19553-1-ying.huang@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP A PTE swap entry may map to a normal swap slot inside a huge swap cluster. To free the huge swap cluster and the corresponding THP (transparent huge page), all PTE swap entry mappings need to be unmapped. The original implementation only checks current PTE swap entry mapping, this is fixed via calling try_to_free_swap() instead, which will check all PTE swap mappings inside the huge swap cluster. This fix could be folded into the patch: mm, swap: rid swapoff of quadratic complexity in -mm patchset. Signed-off-by: "Huang, Ying" Cc: Vineeth Remanan Pillai Cc: Kelley Nielsen Cc: Rik van Riel Cc: Matthew Wilcox Cc: Hugh Dickins Reviewed-by: William Kucharski --- mm/swapfile.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 7464d0a92869..9e6da494781f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1921,10 +1921,8 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, goto out; } - if (PageSwapCache(page) && (swap_count(*swap_map) == 0)) - delete_from_swap_cache(compound_head(page)); + try_to_free_swap(page); - SetPageDirty(page); unlock_page(page); put_page(page);