Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1503601imm; Wed, 23 May 2018 18:01:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqqhL3SZd6qdxuhjJ8lobluM1E1JkExjFhNiT6PyyMYxyQAiyUtZTk/KXxRSkONT0K1NflR X-Received: by 2002:a62:9696:: with SMTP id s22-v6mr4967087pfk.191.1527123686820; Wed, 23 May 2018 18:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527123686; cv=none; d=google.com; s=arc-20160816; b=pCzYa3bRmWLJBZmBheOCTNdgCve5R9PmvJQyiKS7Sld3ZPueTXSYQgxa5jnWWZGeeJ ujtb4JgVAbgU8faxAqzvKSM9LFKV+jEq0U6+KBRdqaKH/Hu12Ctj1gRu2y2ExCBDz/CG 4l5CtViYeT+4rKgkRXI5gpsUHglqVqjPdXQ4019mkpFxbc5hU+mKAkUdk8tJnGDCIcJE kGPy/83BsNpBk8iutMUkxcgwmZsjMMiHt2Xwpo88hN3X2Rr2OVnStxn2pb+3nyhG3pKQ 3WYkVzGx8T40bGdtpfwAUs4FgAdOPGi5LBy7Zm0pkY/Rpq60PAUfcCqnuoZrT0GFKRMw fj5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=y9KJcXxv1uiT8FNG4pi9wPWcvlBsW239KbT00nSccw0=; b=IJ95PttV5bnTT248dKf/9mx/ZwNlnV3ryVmnFYQ9hwwIJTpSzzjn8ipHp0z7gUxWnW Ek0xn6FNlrd+M/Re2copNMuiV4dka2HOk6UqxGUhAUhJFFWGCmvNnLiHsPTBdsB6mg1Y xDIf9oTVpYo21rzquSiJqwD1Na3cW7JQNdiuRje2qRwK/jqg9AXqQ/MJstjhN0Nh2rWQ 96rGOeYmoYcjouo05WT5D8TTQ7TJVygCzHZunu+wg87/t4Rmrsf4nE9QsEwvbgM8ZtCg w2HP+nrlQsk2eLS9x4v0YXRMP7Pd0/9aa/63M2jRkJ/RZK1nZDt0BUNwjM4p+yzfzD4X 88AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k128-v6si16316225pgc.321.2018.05.23.18.01.12; Wed, 23 May 2018 18:01:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935399AbeEXBAo (ORCPT + 99 others); Wed, 23 May 2018 21:00:44 -0400 Received: from mga07.intel.com ([134.134.136.100]:34349 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935386AbeEXBAj (ORCPT ); Wed, 23 May 2018 21:00:39 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 18:00:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,435,1520924400"; d="scan'208";a="42362576" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga008.fm.intel.com with ESMTP; 23 May 2018 18:00:36 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Mike Kravetz , Michal Hocko , David Rientjes , Andrea Arcangeli , "Kirill A. Shutemov" , Andi Kleen , Jan Kara , Matthew Wilcox , Hugh Dickins , Minchan Kim , Shaohua Li , Christopher Lameter , "Aneesh Kumar K.V" , Punit Agrawal , Anshuman Khandual Subject: [PATCH -V2 -mm 4/4] mm, hugetlbfs: Pass fault address to cow handler Date: Thu, 24 May 2018 08:58:51 +0800 Message-Id: <20180524005851.4079-5-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180524005851.4079-1-ying.huang@intel.com> References: <20180524005851.4079-1-ying.huang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huang Ying This is to take better advantage of the general huge page copying optimization. Where, the target subpage will be copied last to avoid the cache lines of target subpage to be evicted when copying other subpages. This works better if the address of the target subpage is available when copying huge page. So hugetlbfs page fault handlers are changed to pass that information to hugetlb_cow(). This will benefit workloads which don't access the begin of the hugetlbfs huge page after the page fault under heavy cache contention. Signed-off-by: "Huang, Ying" Cc: Mike Kravetz Cc: Michal Hocko Cc: David Rientjes Cc: Andrea Arcangeli Cc: "Kirill A. Shutemov" Cc: Andi Kleen Cc: Jan Kara Cc: Matthew Wilcox Cc: Hugh Dickins Cc: Minchan Kim Cc: Shaohua Li Cc: Christopher Lameter Cc: "Aneesh Kumar K.V" Cc: Punit Agrawal Cc: Anshuman Khandual --- mm/hugetlb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ad3bec2ed269..1df974af34c1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3500,7 +3500,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma, * Keep the pte_same checks anyway to make transition from the mutex easier. */ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long haddr, pte_t *ptep, + unsigned long address, pte_t *ptep, struct page *pagecache_page, spinlock_t *ptl) { pte_t pte; @@ -3509,6 +3509,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, int ret = 0, outside_reserve = 0; unsigned long mmun_start; /* For mmu_notifiers */ unsigned long mmun_end; /* For mmu_notifiers */ + unsigned long haddr = address & huge_page_mask(h); pte = huge_ptep_get(ptep); old_page = pte_page(pte); @@ -3583,7 +3584,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, goto out_release_all; } - copy_user_huge_page(new_page, old_page, haddr, vma, + copy_user_huge_page(new_page, old_page, address, vma, pages_per_huge_page(h)); __SetPageUptodate(new_page); set_page_huge_active(new_page); @@ -3817,7 +3818,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, hugetlb_count_add(pages_per_huge_page(h), mm); if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) { /* Optimization, do the COW without a second fault */ - ret = hugetlb_cow(mm, vma, haddr, ptep, page, ptl); + ret = hugetlb_cow(mm, vma, address, ptep, page, ptl); } spin_unlock(ptl); @@ -3971,7 +3972,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, if (flags & FAULT_FLAG_WRITE) { if (!huge_pte_write(entry)) { - ret = hugetlb_cow(mm, vma, haddr, ptep, + ret = hugetlb_cow(mm, vma, address, ptep, pagecache_page, ptl); goto out_put_page; } -- 2.16.1