Received: by 10.213.65.68 with SMTP id h4csp232505imn; Tue, 20 Mar 2018 01:58:29 -0700 (PDT) X-Google-Smtp-Source: AG47ELtoqYxEtbJ3N4rHYRaXA6fHsRqt0vpd6UIrXU+5dBCI9nqKa92+FhO3uRXS28S7otuUV0ZK X-Received: by 2002:a17:902:5a87:: with SMTP id r7-v6mr11122377pli.173.1521536309264; Tue, 20 Mar 2018 01:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521536309; cv=none; d=google.com; s=arc-20160816; b=CEVl2j/Wdl/n8BBTZY4YM9WKbVBMtgcVIo/Zdm5Hl00VRaqDzX25r6vFg79mNHbm1W I1hkaRVd+CsBsDpno6HysuyM15aNI0cx4UhMxG7AEn0pMXZLN4kVC+9z36vJU2oCtxpk xeXnMDZIbZfvcBOCpjfyS1O0qw6jWG3JCM+bQ0wNqe2di1BxWqmuDKKSm6e75aMe63gO HCDAjnqXFs3gcUW/kJAwlscWlpJ5nIepm7XiL1aX8Eqk+KSPkxCHpNTaSSwAFSI3cljW qnXXs/5Tye+8+rsHPSnPCdQPsLRntDD3gludMd69lvuJ8ZuzGV0UEdXhgYh+ep4RM1f7 DjfQ== 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=rigBp7waRZYfiwxeGFyqdGD+NI/YkhYX1zSZYo5JFtw=; b=1J92kCXk0FKQHx59W5pBMOVBva+bAh7NhxNGcZl5lROsZtyfzH/oZ50mSsIAhA5Ecc 1TrmPVykaQ4BH6P7iApqi2i1toKiuovgs1smvfRzJwhjijMU1uHEJk/18ofCLHQNVlyz mov68R2vKDBmUY9wxNQW2ciAjrF7q7xqLAQ2rymjOiC5/+WAKOXE3zhvm3x4XwBn5xXG o6PIYzd0+xO1eWOfir7iXh3rn5+3osa61cEF9/S50GAmLmULppD2BvtaTiaVlD/w1kdX 5BZl6PlnFedj3+6A4pP93piLVDLwo2bUWGxOBHlgMUr6Vy0awxLUgBFhFGqEVfU9KaLS OT/w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si853117pgf.530.2018.03.20.01.58.12; Tue, 20 Mar 2018 01:58:29 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752338AbeCTIxs (ORCPT + 99 others); Tue, 20 Mar 2018 04:53:48 -0400 Received: from mga14.intel.com ([192.55.52.115]:51134 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751988AbeCTIxq (ORCPT ); Tue, 20 Mar 2018 04:53:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2018 01:53:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,334,1517904000"; d="scan'208";a="184360742" Received: from aaronlu.sh.intel.com ([10.239.159.135]) by orsmga004.jf.intel.com with ESMTP; 20 Mar 2018 01:53:43 -0700 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Huang Ying , Dave Hansen , Kemi Wang , Tim Chen , Andi Kleen , Michal Hocko , Vlastimil Babka , Mel Gorman , Matthew Wilcox , Daniel Jordan Subject: [RFC PATCH v2 0/4] Eliminate zone->lock contention for will-it-scale/page_fault1 and parallel free Date: Tue, 20 Mar 2018 16:54:48 +0800 Message-Id: <20180320085452.24641-1-aaron.lu@intel.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series is meant to improve zone->lock scalability for order 0 pages. With will-it-scale/page_fault1 workload, on a 2 sockets Intel Skylake server with 112 CPUs, CPU spend 80% of its time spinning on zone->lock. Perf profile shows the most time consuming part under zone->lock is the cache miss on "struct page", so here I'm trying to avoid those cache misses. Patch 1/4 adds some wrapper functions for page to be added/removed into/from buddy and doesn't have functionality changes. Patch 2/4 skip doing merge for order 0 pages to avoid cache misses on buddy's "struct page". On a 2 sockets Intel Skylake, this has very good effect on free path for will-it-scale/page_fault1 full load in that it reduced zone->lock contention on free path from 35% to 1.1%. Also, it shows good result on parallel free(*) workload by reducing zone->lock contention from 90% to almost zero(lru lock increased from almost 0 to 90% though). Patch 3/4 deals with allocation path zone->lock contention by not touching pages on free_list one by one inside zone->lock. Together with patch 2/4, zone->lock contention is entirely eliminated for will-it-scale/page_fault1 full load, though this patch adds some overhead to manage cluster on free path and it has some bad effects on parallel free workload in that it increased zone->lock contention from almost 0 to 25%. Patch 4/4 is an optimization in free path due to cluster operation. It decreased the number of times add_to_cluster() has to be called and restored performance for parallel free workload by reducing zone->lock's contention to almost 0% again. The good thing about this patchset is, it eliminated zone->lock contention for will-it-scale/page_fault1 and parallel free on big servers(contention shifted to lru_lock). The bad thing are: - it added some overhead in compaction path where it will do merging for those merge-skipped order 0 pages; - it is unfriendly to high order page allocation since we do not do merging for order 0 pages now. To see how much effect it has on compaction, mmtests/stress-highalloc is used on a Desktop machine with 8 CPUs and 4G memory. (mmtests/stress-highalloc: make N copies of kernel tree and start building them to consume almost all memory with reclaimable file page cache. These file page cache will not be returned to buddy so effectively makes it a worst case for high order page workload. Then after 5 minutes, start allocating X order-9 pages to see how well compaction works). With a delay of 100ms between allocations: kernel success_rate average_time_of_alloc_one_hugepage base 58% 3.95927e+06 ns patch2/4 58% 5.45935e+06 ns patch4/4 57% 6.59174e+06 ns With a delay of 1ms between allocations: kernel success_rate average_time_of_alloc_one_hugepage base 53% 3.17362e+06 ns patch2/4 44% 2.31637e+06 ns patch4/4 59% 2.73029e+06 ns If we compare patch4/4's result with base, it performed OK I think. This is probably due to compaction is a heavy job so the added overhead doesn't affect much. To see how much effect it has on workload that uses hugepage, I did the following test on a 2 sockets Intel Skylake with 112 CPUs/64G memory: 1 Break all high order pages by starting a program that consumes almost all memory with anonymous pages and then exit. This is used to create an extreme bad case for this patchset compared to vanilla that always does merging; 2 Start 56 processes of will-it-scale/page_fault1 that use hugepages through calling madvise(MADV_HUGEPAGE). To make things worse for this patchset, start another 56 processes of will-it-scale/page_fault1 that uses order 0 pages to continually cause trouble for the 56 THP users. Let them run for 5 minutes. Score result(higher is better): kernel order0 THP base 1522246 10540254 patch2/4 5266247 +246% 3309816 -69% patch4/4 2234073 +47% 9610295 -8.8% TBH, I'm not sure if the way I tried above is good enough to expose the problem of this patchset. So if you have any thoughts on this patchset, please feel free to let me know, thanks. (*) Parallel free is a workload that I used to see how well parallel freeing a large VMA can be. I tested this on a 4 sockets Intel Skylake machine with 768G memory. The test program starts by doing a 512G anon memory allocation with mmap() and then exit to see how fast it can exit. The parallel is implemented inside kernel and has been posted before: http://lkml.kernel.org/r/1489568404-7817-1-git-send-email-aaron.lu@intel.com A branch is maintained here in case someone wants to give it a try: https://github.com/aaronlu/linux zone_lock_rfc_v2 v2: Rewrote allocation path optimization, compaction could happen now and no crashes that I'm aware of. v1 is here: https://lkml.kernel.org/r/20180205053013.GB16980@intel.com Aaron Lu (4): mm/page_alloc: use helper functions to add/remove a page to/from buddy mm/__free_one_page: skip merge for order-0 page unless compaction failed mm/rmqueue_bulk: alloc without touching individual page structure mm/free_pcppages_bulk: reduce overhead of cluster operation on free path Documentation/vm/struct_page_field | 10 + include/linux/mm_types.h | 3 + include/linux/mmzone.h | 35 +++ mm/compaction.c | 17 +- mm/internal.h | 61 +++++ mm/page_alloc.c | 488 +++++++++++++++++++++++++++++++++---- 6 files changed, 563 insertions(+), 51 deletions(-) create mode 100644 Documentation/vm/struct_page_field -- 2.14.3