From patchwork Mon Sep 3 07:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10585583 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 AF2F413AC for ; Mon, 3 Sep 2018 07:23:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97A5D291E4 for ; Mon, 3 Sep 2018 07:23:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B8B329203; Mon, 3 Sep 2018 07:23:28 +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 04D7E291E4 for ; Mon, 3 Sep 2018 07:23:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 057656B66C2; Mon, 3 Sep 2018 03:23:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F22586B66C3; Mon, 3 Sep 2018 03:23:05 -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 DC1306B66C4; Mon, 3 Sep 2018 03:23:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 9BDBA6B66C2 for ; Mon, 3 Sep 2018 03:23:05 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id 3-v6so2633011plq.6 for ; Mon, 03 Sep 2018 00:23:05 -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=sSuHAxdJw5wR/53zP7teoEH2FB0eMG7Or719zFrThv8=; b=uNQm3LGHXxVwWx3dGPoSFpOZDQnjVO0kvo/nSDOwDjDVIacPjAQ/9BAYDhKo5ncwTh nuxTKemFA2jgAkFymrixT44gk6B4q6Ir6Dg38h3FP2XuOccXcrrui96QH9qQ7fUrfd/9 8KZr/A+WCh2MnPW0Q+t2EttTzoXomaGpfJ1znEngk3mBcI73I2wuS4e/w8Yo14OiikKG hBXkdqQ+Zqeh59/Ymrbz/A9aCZdU7f2QiNoWwUncTHIFjcp/InmMYlJYFfEI1uvoD84q qakJE4Zwv2UE1PatF7VRwLnzFnYM/DYLr/59uXyj25gdloZ4ZC2tj3uw4Q/aC3CR9xGu kSuw== 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: APzg51Bz79FnK0IsPe/xKfwdncTJftiorsk3717nyGqAJsOx3Jhyryvc J37m1quhy+7V41pm4Klnp6bpvFo5WKWjWjHeTt5Kyy5ARTxaaMPN/smJUGP0mRhHD1TGfWnIRGt GIvDQcznX9OWtf2vFEh5qLNtiISZ8NDwgZskX3Qy9pC8jCpTruB1aE8Zm4bI8jdB/NQ== X-Received: by 2002:a62:7088:: with SMTP id l130-v6mr20147947pfc.84.1535959385341; Mon, 03 Sep 2018 00:23:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdblIQHYoP74VfI2NYHRpaoet91EctEDAu6izR/iq4a6UcZxjD/4seUpnkuUF5TwEFN+BU/p X-Received: by 2002:a62:7088:: with SMTP id l130-v6mr20147909pfc.84.1535959384695; Mon, 03 Sep 2018 00:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535959384; cv=none; d=google.com; s=arc-20160816; b=zpFerLnvbVFYpz9fPhCODLaQSmZT9f49BeN2eFem+4D6CMn84A2504H7N1ufFPkD1a b5n2XOG5sjVHaaCoZvShc5uROZeGlRllaJcy0FA35xZUs4LKDZKbhjFLgtjKdjumiGOt qPOS1XJvoOOiHnFiYCiCIuSGzdpYzLSbG8AGkIsbSbPPk6d6GoWBuk8q7z3vgEVnjcAn XPpLbZZQP3bDyaRZ4/QQTTfBJWlcJVic0LCzruIlKPCX7NAGH8LkS13fwi+jv9CUkaum XSV/cG6EXF21cbnhrhGkATDeNPw0ZJg1nAvfEJZoiyIsQjtSzdrn9gXXA36aENi2yF/8 Q5bQ== 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 :arc-authentication-results; bh=sSuHAxdJw5wR/53zP7teoEH2FB0eMG7Or719zFrThv8=; b=ttCMsnhWqyBQ1lhToI9oyYz7j5m31DfSdxXbt2MyJM1lLAj/Z1lCrPWqAhoxfxhTdr OPBpr9Wv0HvdjOx0QoXKWttMrz2p8Je2GzI+yWyWKLjWO8B8MIKjaWkERVecNt1GhYEN tJyz8axtxIVPC20lRRGedDvXT/GX8MlXZy71jRiaOg2kUcp/TtouP4Jjtb71BLBDn1GT hI0alvHwRSuUx3w2dVZ9dJU0UX7p2LZz90d+5Cub+cEG7hjgeEXwkzsUi2VzuQGLKCF+ e/UuFPCe6a/myK5K2H1tAAjmEeWCMoytaOpvmMkdcmvXQNBoVOLoLLRHdEc86xLlkxF9 7E2g== 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 az1-v6si9327648plb.513.2018.09.03.00.23.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 00:23:04 -0700 (PDT) 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 orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Sep 2018 00:23:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,324,1531810800"; d="scan'208";a="70146978" Received: from yhuang-mobile.sh.intel.com ([10.239.196.86]) by orsmga008.jf.intel.com with ESMTP; 03 Sep 2018 00:23:01 -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 17/21] swap: Support PMD swap mapping for MADV_WILLNEED Date: Mon, 3 Sep 2018 15:22:10 +0800 Message-Id: <20180903072214.24602-18-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180903072214.24602-1-ying.huang@intel.com> References: <20180903072214.24602-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 During MADV_WILLNEED, for a PMD swap mapping, if THP swapin is enabled for the VMA, the whole swap cluster will be swapin. Otherwise, the huge swap cluster and the PMD swap mapping will be split and fallback to PTE swap mapping. 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/madvise.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 20101ff125d0..0413659ff6ba 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -196,14 +196,36 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, pte_t *orig_pte; struct vm_area_struct *vma = walk->private; unsigned long index; + swp_entry_t entry; + struct page *page; + pmd_t pmdval; + + pmdval = *pmd; + if (IS_ENABLED(CONFIG_THP_SWAP) && is_swap_pmd(pmdval) && + !is_pmd_migration_entry(pmdval)) { + entry = pmd_to_swp_entry(pmdval); + if (!transparent_hugepage_swapin_enabled(vma)) { + if (!split_swap_cluster(entry, 0)) + split_huge_swap_pmd(vma, pmd, start, pmdval); + } else { + page = read_swap_cache_async(entry, + GFP_HIGHUSER_MOVABLE, + vma, start, false); + if (page) { + /* The swap cluster has been split under us */ + if (!PageTransHuge(page)) + split_huge_swap_pmd(vma, pmd, start, + pmdval); + put_page(page); + } + } + } if (pmd_none_or_trans_huge_or_clear_bad(pmd)) return 0; for (index = start; index != end; index += PAGE_SIZE) { pte_t pte; - swp_entry_t entry; - struct page *page; spinlock_t *ptl; orig_pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl);