Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1505482imm; Wed, 23 May 2018 18:03:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqVViaJKmcJC0pDIgahvJvNX+7mwGTcjj61oUo+VlhJ2pPdKuigM9MvAeXTRCKe1RzUoWfY X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr5015126plt.378.1527123829627; Wed, 23 May 2018 18:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527123829; cv=none; d=google.com; s=arc-20160816; b=MxSH+C0YDaKS6Q8Ebxetg6R3LalVYGsMyCqt3utXh+3KUXFvuXx87pPwRfj/g2ke4G ffbqFQ7d5N4s23Wcd0yVvEqwVFDkClVCf+bKUYLHCaOLTma+d/V5tJck84H4ek4bApBG 57McwkUwQDxZKDA9EGy5bVNP9w74Rv33ZLIqSv0iSGL5/z6szeUWK5waRVw/TWR83hg2 Z3MIhDKwlMf91soWR0UUSp3QmdpQ9qVRSgdmwEEjd5wl09pEw/kFfRmPydAqML1ZbgF2 BomEOSyK5ydpHrEtF7mEr4xK7CfgjJJ9An/V/XIdCRQIG9gG7p1qgPS1M4XjKiWBaf9o a3bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=PzxrcgebtXyExzfokpiPZPj20fuRLMmQxFQGvPycMAY=; b=nxwXXA/1Yg5MkjFdxflgQPs9e8S8U2kAofYQhBIVahTsRIdnh1yap0/ME0vUyXscF3 AZVliGCLsG5skHgt8GZblsyVeVRe1OpKrjalibtO5IlpFn+D7YtVktnNW8wv9ZohtXqZ 1Kj6ZuYOO/VuViWhZLuhfynvQWqyNxPyiaCEBnu2bW6AeG4ldt1N7YuM6okNZppKh8ot bKmDvczNiKXKaJjv49HzTHvhPdljKI/9AfyaRPW6duVt+bI3if4FRaCc1xzC+C3bY3XH eF8DIotXzjv+G5PGhlEOEZABnRDFiQvzAkjuQkR0yWB0utDJOTp5imI90LgX9YMi1fwh UcKA== 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 v190-v6si19847435pfb.324.2018.05.23.18.03.34; Wed, 23 May 2018 18:03:49 -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 S935359AbeEXBAa (ORCPT + 99 others); Wed, 23 May 2018 21:00:30 -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 S935196AbeEXBA2 (ORCPT ); Wed, 23 May 2018 21:00:28 -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:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,435,1520924400"; d="scan'208";a="42362508" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga008.fm.intel.com with ESMTP; 23 May 2018 18:00:25 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Andi Kleen , Jan Kara , Michal Hocko , Andrea Arcangeli , "Kirill A. Shutemov" , Matthew Wilcox , Hugh Dickins , Minchan Kim , Shaohua Li , Christopher Lameter , Mike Kravetz Subject: [PATCH -V2 -mm 0/4] mm, huge page: Copy target sub-page last when copy huge page Date: Thu, 24 May 2018 08:58:47 +0800 Message-Id: <20180524005851.4079-1-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 patchset. The patchset is a generic optimization which should benefit quite some workloads, not for a specific use case. To demonstrate the performance benefit of the patchset, we have tested it with vm-scalability run on transparent huge page. With this patchset, 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%. Changelog: V2: - As suggested by Mike Kravetz, put subpage order algorithm into a separate patch to avoid code duplication and reduce maintenance overhead. - Add hugetlbfs support Best Regards, Huang, Ying