Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2950955imm; Thu, 24 May 2018 19:44:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrODpWL25W/7KyExkismyfwFF1LjdXzmpo3uVQA8r2q9TbXfildLbpa9bnEVC4i44BYN6KJ X-Received: by 2002:a62:9c0d:: with SMTP id f13-v6mr589116pfe.15.1527216294941; Thu, 24 May 2018 19:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216294; cv=none; d=google.com; s=arc-20160816; b=NW3bBP2+6VaNXwon4WrpjQ9bSKrHV8ysjiLuNrrAFs8+KJpTUwil+V77y2SezlISSW Riw1GxdSNsKdB1yuHzR3rlOdUhPCz8HBo50vSfZ/gJiNBu/5qBB7X6IaRyc/0vdxfo5M BdKlWj9T8T/w/KBNenw9f8j1R2VtV42dgN2PKQ3k26mwM8R/yA4fbrShXhCNtijoFPhE v0/lnnvQC8ZBzFRpTgteb0yubu/mUwOwVe9N0keoav9kGViwFOHWzIvy1SXmgc75ku8V bIWun/5sOXiY4r1qGfCJwO1RmmfvBCM46It5Lgxjaz5WxnE7Vayuh9iArXLZYHYU2bxp ts6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=oIQC3NPJ2Gd5Ju92EL4HbYM7f9T1BtofDHC0/tyGAEs=; b=kvZLwpmFr7b2sBeLSvzerXKqkJ6RzdJfDlh7KpfdJzmhybStL4EtUZfS1VnM0N0vE2 UO3ZWjA7heCmxZbY4qkebOMdD9U8KLmtJNFsUegilK1fl4gfZNXsiWiaf97eldiz9mhL 7B6LgPCGe+E8jatFtN31iDMNiDpsr6LE+j0PULE2aM5DsTFxwoM6SCn7SPd98mKn9U9K 7snx3YuLXCNF+hzTS1qJbVbKZLU7DTIWNVOxeI/XPinPORyvChIUeqXCHie+eY5beHYO y9Q2DvgdrzyTYRDvOu8XhEIJrJoIBQbdfuaZHaXT20bBKzHSw/Hc++2z04QuK034aUUs lIng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=dnow6fRq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7-v6si21568993plo.47.2018.05.24.19.44.40; Thu, 24 May 2018 19:44:54 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=dnow6fRq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034652AbeEXV0l (ORCPT + 99 others); Thu, 24 May 2018 17:26:41 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:54430 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033204AbeEXV0j (ORCPT ); Thu, 24 May 2018 17:26:39 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4OLKePb124060; Thu, 24 May 2018 21:25:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=oIQC3NPJ2Gd5Ju92EL4HbYM7f9T1BtofDHC0/tyGAEs=; b=dnow6fRqS/H9wl+egT2S0qRBdqND7C7Be2G5V0iZ1No+2MwaLfUHHvD9Azacpd3Lokin 9QnEhGoFNrBuaivUfyeMNC3uIau9KkZ0HVLhPUB3sIAXf8u8xdJdF6Pc8bOxt3OT2a1n eVSlM+JebXq6fzKWPJztUJQdiyfLEkIqvoSEp+Jxf4+Mvj7fL5GL3dk0uTcXv4XV6POY pUYDXXD9BjBAZXxU3/06CM348RT5SK1ojaD2DWYwXUuOUKd2kZ3RxVaTLaYhmNiagO6D AZ1qQGa4eAG4/CtsX0z1HWAac3tuR1xo9eQhgZ8eWYT47RB3oUbwoTOe/oqDOEOkCuQY CA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2j62sw8qc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 May 2018 21:25:08 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4OLP6Vp028868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 May 2018 21:25:06 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4OLP48J021408; Thu, 24 May 2018 21:25:05 GMT Received: from [192.168.1.164] (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 May 2018 14:25:04 -0700 Subject: Re: [PATCH -V2 -mm 2/4] mm, huge page: Copy target sub-page last when copy huge page To: "Huang, Ying" , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andi Kleen , Jan Kara , Michal Hocko , Andrea Arcangeli , "Kirill A. Shutemov" , Matthew Wilcox , Hugh Dickins , Minchan Kim , Shaohua Li , Christopher Lameter References: <20180524005851.4079-1-ying.huang@intel.com> <20180524005851.4079-3-ying.huang@intel.com> From: Mike Kravetz Message-ID: Date: Thu, 24 May 2018 14:25:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180524005851.4079-3-ying.huang@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8903 signatures=668700 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805240241 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/23/2018 05:58 PM, Huang, Ying wrote: > From: Huang Ying > > Huge page helps to reduce TLB miss rate, but it has higher cache > footprint, sometimes this may cause some issue. For example, when > copying huge page on x86_64 platform, the cache footprint is 4M. But > on a Xeon E5 v3 2699 CPU, there are 18 cores, 36 threads, and only 45M > LLC (last level cache). That is, in average, there are 2.5M LLC for > each core and 1.25M LLC for each thread. > > If the cache contention is heavy when copying the huge page, and we > copy the huge page from the begin to the end, it is possible that the > begin of huge page is evicted from the cache after we finishing > copying the end of the huge page. And it is possible for the > application to access the begin of the huge page after copying the > huge page. > > In commit c79b57e462b5d ("mm: hugetlb: clear target sub-page last when > clearing huge page"), to keep the cache lines of the target subpage > hot, the order to clear the subpages in the huge page in > clear_huge_page() is changed to clearing the subpage which is furthest > from the target subpage firstly, and the target subpage last. The > similar order changing helps huge page copying too. That is > implemented in this patch. Because we have put the order algorithm > into a separate function, the implementation is quite simple. > > The patch is a generic optimization which should benefit quite some > workloads, not for a specific use case. To demonstrate the performance > benefit of the patch, we tested it with vm-scalability run on > transparent huge page. > > With this patch, the throughput increases ~16.6% in vm-scalability > anon-cow-seq test case with 36 processes on a 2 socket Xeon E5 v3 2699 > system (36 cores, 72 threads). The test case set > /sys/kernel/mm/transparent_hugepage/enabled to be always, mmap() a big > anonymous memory area and populate it, then forked 36 child processes, > each writes to the anonymous memory area from the begin to the end, so > cause copy on write. For each child process, other child processes > could be seen as other workloads which generate heavy cache pressure. > At the same time, the IPC (instruction per cycle) increased from 0.63 > to 0.78, and the time spent in user space is reduced ~7.2%. > > Signed-off-by: "Huang, Ying" Reviewed-by: Mike Kravetz -- Mike Kravetz > Cc: Andi Kleen > Cc: Jan Kara > Cc: Michal Hocko > Cc: Andrea Arcangeli > Cc: "Kirill A. Shutemov" > Cc: Matthew Wilcox > Cc: Hugh Dickins > Cc: Minchan Kim > Cc: Shaohua Li > Cc: Christopher Lameter > Cc: Mike Kravetz > --- > include/linux/mm.h | 3 ++- > mm/huge_memory.c | 3 ++- > mm/memory.c | 30 +++++++++++++++++++++++------- > 3 files changed, 27 insertions(+), 9 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 7cdd8b7f62e5..d227aadaa964 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2734,7 +2734,8 @@ extern void clear_huge_page(struct page *page, > unsigned long addr_hint, > unsigned int pages_per_huge_page); > extern void copy_user_huge_page(struct page *dst, struct page *src, > - unsigned long addr, struct vm_area_struct *vma, > + unsigned long addr_hint, > + struct vm_area_struct *vma, > unsigned int pages_per_huge_page); > extern long copy_huge_page_from_user(struct page *dst_page, > const void __user *usr_src, > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index e9177363fe2e..1b7fd9bda1dc 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1328,7 +1328,8 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd) > if (!page) > clear_huge_page(new_page, vmf->address, HPAGE_PMD_NR); > else > - copy_user_huge_page(new_page, page, haddr, vma, HPAGE_PMD_NR); > + copy_user_huge_page(new_page, page, vmf->address, > + vma, HPAGE_PMD_NR); > __SetPageUptodate(new_page); > > mmun_start = haddr; > diff --git a/mm/memory.c b/mm/memory.c > index b9f573a81bbd..5d432f833d19 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4675,11 +4675,31 @@ static void copy_user_gigantic_page(struct page *dst, struct page *src, > } > } > > +struct copy_subpage_arg { > + struct page *dst; > + struct page *src; > + struct vm_area_struct *vma; > +}; > + > +static void copy_subpage(unsigned long addr, int idx, void *arg) > +{ > + struct copy_subpage_arg *copy_arg = arg; > + > + copy_user_highpage(copy_arg->dst + idx, copy_arg->src + idx, > + addr, copy_arg->vma); > +} > + > void copy_user_huge_page(struct page *dst, struct page *src, > - unsigned long addr, struct vm_area_struct *vma, > + unsigned long addr_hint, struct vm_area_struct *vma, > unsigned int pages_per_huge_page) > { > - int i; > + unsigned long addr = addr_hint & > + ~(((unsigned long)pages_per_huge_page << PAGE_SHIFT) - 1); > + struct copy_subpage_arg arg = { > + .dst = dst, > + .src = src, > + .vma = vma, > + }; > > if (unlikely(pages_per_huge_page > MAX_ORDER_NR_PAGES)) { > copy_user_gigantic_page(dst, src, addr, vma, > @@ -4687,11 +4707,7 @@ void copy_user_huge_page(struct page *dst, struct page *src, > return; > } > > - might_sleep(); > - for (i = 0; i < pages_per_huge_page; i++) { > - cond_resched(); > - copy_user_highpage(dst + i, src + i, addr + i*PAGE_SIZE, vma); > - } > + process_huge_page(addr_hint, pages_per_huge_page, copy_subpage, &arg); > } > > long copy_huge_page_from_user(struct page *dst_page, >