From patchwork Fri Dec 14 06:27:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Ying X-Patchwork-Id: 10730613 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 A920791E for ; Fri, 14 Dec 2018 06:28:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98DAD2CC8C for ; Fri, 14 Dec 2018 06:28:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A0692CC99; Fri, 14 Dec 2018 06:28:02 +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 7F11D2CC8C for ; Fri, 14 Dec 2018 06:28:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFEC28E01AE; Fri, 14 Dec 2018 01:28:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD3468E0014; Fri, 14 Dec 2018 01:28:00 -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 9C39E8E01AE; Fri, 14 Dec 2018 01:28:00 -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 58D7A8E0014 for ; Fri, 14 Dec 2018 01:28:00 -0500 (EST) Received: by mail-pg1-f199.google.com with SMTP id s27so3162424pgm.4 for ; Thu, 13 Dec 2018 22:28:00 -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=+YFKEG//rlf0/GQhw6vBmeocw65fCmDEJxyZLgC78fk=; b=UUouF3CSWidJuk2B6mSSENWkCGh9FE50WDfks4xbQow8GN0Lhjj+GN13EM6oxJgVoh KF3SZS0HdmG/p+VyEN7Sok3mNuvnJ94xCCtI3TkTO1u3dNI7okts/6JvjkAEo1nJYDm6 f0xaT5TYwW0PdpwVFxWrcqURrynKA7qYSkwD4ZehcUjsW82W0e55y182mUgWzCIsv5Lv 6/KcLD4sOLygTF4mQNHpXRtSBE3UBOvRZSiw470LTOq2btnsjVZGkiSYimBGrcPdEp4j bqcN+Mt8yoav2sxInPjIzEx0F0hxSNzqNfkGCJC3RCW4UzLoPwC6iTjm4LZZFPwRaqyh SQBA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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+aEWYfUUcmz566JtrV0uMjRZ88kSX07L+p+VIiFTK2hM/OdxKEdqHN oZ35Eqz67DGcxW3qf4lXh1n1e1ddmJOs5q0GGMRaMN27xYywsDzJoKX/TDQgBiqL3/j8QIcsh5m WeNvqRd1QILGvSi96eMbN/Af0jaIaHTnmR+dFu1UUyzaGehiQml9wxGJPx+b6x/e+Tw== X-Received: by 2002:a17:902:3124:: with SMTP id w33mr1752467plb.241.1544768880031; Thu, 13 Dec 2018 22:28:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmuL3c1VyXk7SXlJE6VTQg0giZIlTSziXWAlsSIhUCZjE5QQmctSoIoYOKXT8cffGxMQ4X X-Received: by 2002:a17:902:3124:: with SMTP id w33mr1752432plb.241.1544768879342; Thu, 13 Dec 2018 22:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544768879; cv=none; d=google.com; s=arc-20160816; b=IdvHEz0XEJRkKUnUBoDEw3QNi4ontCbF9Xey+jgGfLngk597VDab07DfhqjjFP9O+u mGLQgqexs+r8JvdAgGE3cRdHklQ5oWGac/LprM53TZ0YR+flrgMjv86peOlDj0znagWG sVJmdLYR57amq1j1QjtLD9oA0tRHNbOsXvpIrbRRv/rDlBPaZUaMXtuXbvDQ/BXlIqTG 6YMozX/Yeu79ZljM3tLM7r+/rCbkGnAYTRPQmYnQmhY080JvCowzbeE8s+ukdvGZQ8DI 1vTXc9bD3wiK0lxlvQYf1LDFo7tVr8TDwd48u3mMzUOdhyVxGJMZT6yf2wiHugE5WbDx ihsg== 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=+YFKEG//rlf0/GQhw6vBmeocw65fCmDEJxyZLgC78fk=; b=v7CWOXtqZWjWvILaG7ns2E2tlZqiJVjq4910AxkeEXTzVmCmu+sRChffOUv7s2uz0L ajF9JGRGSRUb2fItfFWu9GbytorRzl95QBtZxvQwA811nRhmt6MoMBLJkLJOpgcI3ImP UoDbqpn05t1d5VvhVrLl3PueEJMipbQV3hLLYtwG3X6UjDGgheSHo2/aSxRXDKud+XN5 1rjLIjJYWks0HUmGzdAyTyzltDw1z9dTUYIhITQy/sS8vGarN+mek8mRW4bmCdOuzcr5 oPxVTP1kBuTtLuvG8UI0XXHbK0jMHkkvi1+5Wz9iAzvEGEPF+J900byqGqCn9+m+w8yq +KGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id v19si3555849pfa.80.2018.12.13.22.27.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 22:27:59 -0800 (PST) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Dec 2018 22:27:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,351,1539673200"; d="scan'208";a="125840848" Received: from yhuang-mobile.sh.intel.com ([10.239.197.226]) by fmsmga002.fm.intel.com with ESMTP; 13 Dec 2018 22:27:52 -0800 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 -V9 05/21] swap: Support PMD swap mapping in put_swap_page() Date: Fri, 14 Dec 2018 14:27:38 +0800 Message-Id: <20181214062754.13723-6-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181214062754.13723-1-ying.huang@intel.com> References: <20181214062754.13723-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 bd8756ac3bcc..04cf6b95cae0 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);