From patchwork Wed Sep 12 00:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10596527 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 D76F3109C for ; Wed, 12 Sep 2018 00:44:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C736B29AC1 for ; Wed, 12 Sep 2018 00:44:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAEC629AD2; Wed, 12 Sep 2018 00:44: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 2C96429AC1 for ; Wed, 12 Sep 2018 00:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04B218E0006; Tue, 11 Sep 2018 20:44:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F12A08E0001; Tue, 11 Sep 2018 20:44:21 -0400 (EDT) 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 D8F048E0006; Tue, 11 Sep 2018 20:44:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 9611B8E0001 for ; Tue, 11 Sep 2018 20:44:21 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id d40-v6so106855pla.14 for ; Tue, 11 Sep 2018 17:44:21 -0700 (PDT) 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=CaCWWMD2A4Bim+4Yv358LYKJOc7V1EosNUqm3zG4Vmk=; b=OaibVg7iwQvtzcYlbshzcBIalOzn7yoO/8cx/qpcUr8vL++FdGV1810x7WocnQ5Yev EoK6mlZLc1m3lTDfGhUS4xxx2rl5iFjIHc3TJ14BBd7G3BrmDYGBRkAzj4+l/KwkqPkP 8dz2tVXynga6iNqodxuVX6HBxAmFB6XflLEjnqOobXufZBHHa2L8lbZQ9pznt7i9V3YJ ltZDoVFxAcTIo+VIBFiMNPyvHrNwEvBZm07q7sdKM2Vij/1BQLaKBWFq52lx57wOw8sM Do5pmYmUdCMxAklTinFVjKyshT3WcZkcdm72/760SxKrsevxzmAsgZONhPeZRzAZsYhb noPA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 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: APzg51BWKCFKM0Th9WtGX+MxdUDEw3iuTnNAhoEpwvVH7vSS9GEz6T7w +YiKww71r5JV0cYf2WwPrcLaNGeEmnIve1VnNbZ8EE38YmAlaANfV3tirjbPchDpgbXmtQR0ywh bs0OcplMvH1vpobbcmeaSxje6C+Ef7UlIwH542nh/KpBM3GTdYyo0A5hsoZg9Py2mwA== X-Received: by 2002:a63:1125:: with SMTP id g37-v6mr30871989pgl.187.1536713061284; Tue, 11 Sep 2018 17:44:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbAJqqSobhT9K+5qZiimeo0VKbuN4LUCdyQvJJE5fzk7K5bIWOqcs0ZMrCaaBSm8vVDHP6l X-Received: by 2002:a63:1125:: with SMTP id g37-v6mr30871961pgl.187.1536713060640; Tue, 11 Sep 2018 17:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536713060; cv=none; d=google.com; s=arc-20160816; b=s3/fREV5s72B6ug1fXTCLWZKEZyiPll0esJHDyf77Ur7VC0PXTQ8RCOIsfgzk+tlJo fMSby6Y4ndedOAJgCXE0WhbXKUKa0LSPKT5BggtTgaB72qXr+frFEf7HL3ifUQ76G+tM 8ek5soUQWR5PXOEm48AyVZFelEh2BPUt8NHbMYfJoiUAJvsM3/VHM1z9AhKky/3Hyjad ks61pF5KuHhfVWuvrRMjTDlH1xlgGnIE78Ic7I3l4aNcU1d3nO94ESRwkpkxzcoeMgze yjv3JHdUHCqQ7FLZilEFWFd2kgrUCEdgIgS1jEPpNvMS1SPDfrDft73w0+F2EH7HMlrC +Ysg== 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=CaCWWMD2A4Bim+4Yv358LYKJOc7V1EosNUqm3zG4Vmk=; b=jWyeedUc0BbfMQQ3+FpsbtPGVA7eAMIijBjI1YRqmhihNTgKu7hqYg43oDYyOcYxaP iFax+vY2Tf1NqiIeRb5hrymm2Z6I//12PKlP35FzCdaBJDmDeoN7tTrDjrW0x9ihmIr1 IDfF95xcGy6G4BD1rkjwv6x0LorwcS0ejW4Qrt9MbMJzb6RASunOeywMIi9QGtJYiQnH 0qSI58LPJ19IFA65l352GWLaV8C8H3sOwpFHNfq+CXsn2P6Mvbr/glCHvQLWAgIicjQs GE2G4yfyl1WYhBXEDqZRdD5xOdRcJT0DaIydF/7R219NXU2kNLBicFPDc0aYuG8p/AGk 5VYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id p21-v6si20648717plq.338.2018.09.11.17.44.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 17:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 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 orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2018 17:44:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,362,1531810800"; d="scan'208";a="69283822" Received: from unknown (HELO yhuang-mobile.sh.intel.com) ([10.239.198.87]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2018 17:44:15 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , "Kirill A. Shutemov" , Andrea Arcangeli , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dave Hansen , Naoya Horiguchi , Zi Yan , Daniel Jordan Subject: [PATCH -V5 RESEND 04/21] swap: Support PMD swap mapping in put_swap_page() Date: Wed, 12 Sep 2018 08:43:57 +0800 Message-Id: <20180912004414.22583-5-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180912004414.22583-1-ying.huang@intel.com> References: <20180912004414.22583-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 Previously, during swapout, all PMD page mapping will be split and replaced with PTE swap mapping. And when clearing the SWAP_HAS_CACHE flag for the huge swap cluster in put_swap_page(), the huge swap cluster will be split. Now, during swapout, the PMD page mappings to the THP will be changed to PMD swap mappings to the corresponding swap cluster. So when clearing the SWAP_HAS_CACHE flag, the huge swap cluster will only be split if the PMD swap mapping count is 0. Otherwise, we will keep it as the huge swap cluster. So that we can swapin a THP in one piece later. Signed-off-by: "Huang, Ying" Cc: "Kirill A. Shutemov" Cc: Andrea Arcangeli Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dave Hansen Cc: Naoya Horiguchi Cc: Zi Yan Cc: Daniel Jordan --- mm/swapfile.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 138968b79de5..553d2551b35a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1314,6 +1314,15 @@ void swap_free(swp_entry_t entry) /* * Called after dropping swapcache to decrease refcnt to swap entries. + * + * When a THP is added into swap cache, the SWAP_HAS_CACHE flag will + * be set in the swap_map[] of all swap entries in the huge swap + * cluster backing the THP. This huge swap cluster will not be split + * unless the THP is split even if its PMD swap mapping count dropped + * to 0. Later, when the THP is removed from swap cache, the + * SWAP_HAS_CACHE flag will be cleared in the swap_map[] of all swap + * entries in the huge swap cluster. And this huge swap cluster will + * be split if its PMD swap mapping count is 0. */ void put_swap_page(struct page *page, swp_entry_t entry) { @@ -1332,15 +1341,23 @@ void put_swap_page(struct page *page, swp_entry_t entry) ci = lock_cluster_or_swap_info(si, offset); if (size == SWAPFILE_CLUSTER) { - VM_BUG_ON(!cluster_is_huge(ci)); + VM_BUG_ON(!IS_ALIGNED(offset, size)); map = si->swap_map + offset; - for (i = 0; i < SWAPFILE_CLUSTER; i++) { - val = map[i]; - VM_BUG_ON(!(val & SWAP_HAS_CACHE)); - if (val == SWAP_HAS_CACHE) - free_entries++; + /* + * No PMD swap mapping, the swap cluster will be freed + * if all swap entries becoming free, otherwise the + * huge swap cluster will be split. + */ + if (!cluster_swapcount(ci)) { + for (i = 0; i < SWAPFILE_CLUSTER; i++) { + val = map[i]; + VM_BUG_ON(!(val & SWAP_HAS_CACHE)); + if (val == SWAP_HAS_CACHE) + free_entries++; + } + if (free_entries != SWAPFILE_CLUSTER) + cluster_clear_huge(ci); } - cluster_clear_huge(ci); if (free_entries == SWAPFILE_CLUSTER) { unlock_cluster_or_swap_info(si, ci); spin_lock(&si->lock);