From patchwork Tue Sep 25 07:13:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10613495 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 DCC17161F for ; Tue, 25 Sep 2018 07:13:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD7DE29B12 for ; Tue, 25 Sep 2018 07:13:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1CA129B18; Tue, 25 Sep 2018 07:13:43 +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 46D7A29B12 for ; Tue, 25 Sep 2018 07:13:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE78A8E006E; Tue, 25 Sep 2018 03:13:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CD2518E0041; Tue, 25 Sep 2018 03:13:40 -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 B741D8E006E; Tue, 25 Sep 2018 03:13:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 6C76D8E0041 for ; Tue, 25 Sep 2018 03:13:40 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id 77-v6so5159110pgg.0 for ; Tue, 25 Sep 2018 00:13:40 -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=dYOkjphR0ossIWa2x1mV+b4/IsZ0pfzTF0gCiNecG//UMF9p+eRMfeZ1YkvdZduca3 4c3kDVrdXBHIxR6QaZ0k22baohBml+vOif9VSRVTI8pID4hpFNcyM3H7iURLUHWrye9p 9KjGanm/ypoolV9Flf5TxpSxT+w31bVqsnY/7EEtwX7HM3yuYxTDAWUdaLKFuoFHjapq Hlo8cjennon6mwMGY3LV2EBfuICENNQkK8xuMeFKHN8DsE/EZL1TSZ28vxW59MU6j5ya Q+Fe1Jfm9wlE4UXcdRHrYD5X1nesBoA5CkZixnWsn1xSjH/aPDSV/KrpJSrcMupHQXh0 Z33A== 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: ABuFfojgb/jr43EZoSV9t5hcRSRh25X9lWrjt9LRzuMBfofyOw2Wz36A O5hqkGgEUi+hC4sv/3uljPDj498VOXSnMtsOeiOU1BkCNVKmqyXpR8SJpQX2yhvFiXH8irzUXv3 5UVsxXjzc0yIbmnZw4QOUsqaqck20XRMXhAzKEpZA6RO8Nn96pYukpTz8ImMbXrM+EQ== X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr2091272plb.245.1537859620130; Tue, 25 Sep 2018 00:13:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV60nZWqnpWrgFHc4/r+dwD13I937I3b1P9Weo4GRPO0HEtP9ygEIycOh6y2m02vIazl3tLvF X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr2091229plb.245.1537859619409; Tue, 25 Sep 2018 00:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537859619; cv=none; d=google.com; s=arc-20160816; b=vEnmZtAEskJ3IhiIyD9dI7n+rer5qIzqeqZpa/Jx8Cnr7ltIk04bPGbjppF7apr1XK xzwWPA0Y2fXPbyuryDkdsgGJwFOEnvLt3EdJiGpal/vsxbtqY1v0hEK+6uyVHFlz6KvQ Ker/H3YHjCQwkVpPeVf/VlV75k39GQ3mBrTWFmYG34ZE0pEtGvfktOinrnSSHL4XQVml gViFK8XteEepQS8aIj7UKqhrvpVtr9IA1j/DI1lWgScUr6Ug3CWS19g6XLIUkaprTpM4 1mRcM0v8e4WQ3u/HZQY1vqPl9G39qi0ObHa30JDTnUqPqWby+ki0u2HFhIBkZSQBk8mR bnmw== 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=M10nHGOxDlFwvemXbWKaObeD0g2dzCmP89eM5XWf6Mi6DvDMT/pU6MZutS/cPOOBUh xzBzE5iMyY7rsPy8ef9LHlq4zp45pyza+gVhjeOsuajnE+Glt5WIuwnw5VzEQ19yY6/q AJC/MwyO8MVEpKXhbJSjppBhR8Z7dKb8tRyoHuAY8csFMMqZni+W90G6kDKhpkfEIo0t F04dLg3oevEQOyBU5czjQa2GvANBOFsEjdAFN/b27mMeapXWUkl9TBbMs9b3TlpVTSM4 SVIOiCtDHOG8LO41TXfYyAaWn7Zf8uC+z4g5fQGqFmZlAW+MQMjaaNOG9r+O+1pE3Ari aPGw== 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 h18-v6si1501855pgl.398.2018.09.25.00.13.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 00:13:39 -0700 (PDT) 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 fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 00:13:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,301,1534834800"; d="scan'208";a="89093516" Received: from yhuang-mobile.sh.intel.com ([10.239.198.87]) by fmsmga002.fm.intel.com with ESMTP; 25 Sep 2018 00:13:35 -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: Tue, 25 Sep 2018 15:13:31 +0800 Message-Id: <20180925071348.31458-5-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180925071348.31458-1-ying.huang@intel.com> References: <20180925071348.31458-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);