Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3628221imm; Mon, 10 Sep 2018 22:37:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZsqkq0403vuyOes0pFbLpuSQVwd6opgEXxEF4bfdS1ARh3JRSS0qnsCDvKLTBTuiHMBCPg X-Received: by 2002:a17:902:145:: with SMTP id 63-v6mr24715289plb.329.1536644230268; Mon, 10 Sep 2018 22:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536644230; cv=none; d=google.com; s=arc-20160816; b=0wtfE/jQf/Wa3ymhRVrRBl+I6rDKR0MDeOtwpi++qSDK258fQ+NByX/yVwami0fUGp 4fxbS40bKZnZdo+y7P9OI71Ujp/Kv7oS5MBzffERd+2/tQk0c+dzkznli/xtGDWvGxz3 wYxNaacJDokc7ZHJj+k2mBimFVFhY4ynfmuY3AmkkixZtUWLwsM6/CcCEFl4GVEQptoY tuJf7eRj13aTy9vDvhlSJfo/qayDU2cYM+ytdlhAhlhkhNZbSnjTr+W+MY/wEwvs+jaP KSH9xuF2tAsx5tf7Coke9AW9hytnTzMOQb2M/G1ZA09wCGuzgAuyQG/Sa+4/foWWkRBb HE6w== 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; bh=XjJ52xEqFESi+s+KBkxlZtbm6DermFAY+MomtCT5gNo=; b=C00fh7Ml/yI2Fbm1cawQY3YKJqnIkdPU0zAw1/RFGAMq9wCXymwxRy4HDKzqgHjae2 /1NGGz3xoyOyMZ5HkZS1e6TZ80UW4QkywX9NJqcwJio9a+osFo7l/Nftquu/CrFAYQ/p DXxVW3z71HO/6G5R3h8NbG9zrp9u8zwFYL8Wvm2EbcXUBw0SlkcWMKoSePqAMrV9xn4U 41IlgIpcOt/CJDwZk7hAMx2jtNE2hdQFO82oVLqQkC1UWO9ECd9gIBBF1Q3S08pb04fC GZgtKYg8/JiZQbz1MgScVRv+tmLetISiB+sn8Dj/cLxTpWH3WmWck33mRIhUrVds2cri iIIQ== 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 m10-v6si20954332pgc.105.2018.09.10.22.36.55; Mon, 10 Sep 2018 22:37:10 -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 S1727183AbeIKKeC (ORCPT + 99 others); Tue, 11 Sep 2018 06:34:02 -0400 Received: from mga17.intel.com ([192.55.52.151]:62510 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbeIKKeB (ORCPT ); Tue, 11 Sep 2018 06:34:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 22:36:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,359,1531810800"; d="scan'208";a="262426310" Received: from aaronlu.sh.intel.com ([10.239.159.44]) by fmsmga006.fm.intel.com with ESMTP; 10 Sep 2018 22:36:16 -0700 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Dave Hansen , Michal Hocko , Vlastimil Babka , Mel Gorman , Matthew Wilcox , Daniel Jordan , Tariq Toukan , Yosef Lev , Jesper Dangaard Brouer Subject: [RFC PATCH 0/9] Improve zone lock scalability using Daniel Jordan's list work Date: Tue, 11 Sep 2018 13:36:07 +0800 Message-Id: <20180911053616.6894-1-aaron.lu@intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Jordan and others proposed an innovative technique to make multiple threads concurrently use list_del() at any position of the list and list_add() at head position of the list without taking a lock in this year's MM summit[0]. People think this technique may be useful to improve zone lock scalability so here is my try. This series is based on Daniel Jordan's most recent patchset[1]. To make this series self contained, 2 of his patches are extracted here. Scalability comes best when multiple threads are operating at different positions of the list. Since free path will access (buddy) pages randomly on free list during merging, it is a good fit to make use of this technique. This patchset makes free path run concurrently. Patch 1 is for testing purpose only, it removes LRU lock from the picture so we can get a better understanding of how much improvement this patchset has on zone lock. Patch 2-3 are Daniel's work to realize concurrent list_del() and list_add(), these new APIs are called smp_list_del() and smp_list_splice(). Patch 4-7 makes free path run concurrently by converting the zone lock from spinlock to rwlock and has free path taking the zone lock in read mode. To avoid complexity and problems, all other code paths take zone lock in write mode. Patch 8 is an optimization that reduces free list head access to avoid severe cache bouncing. It also comes with a side effect: with this patch, there will be mergable pages unmerged in Buddy. Patch 9 improves fragmentation issues introduced in patch 8 by doing pre-merges before pages are sent to merge under zone lock. This patchset is based on v4.19-rc2. Performance wise on 56 cores/112 threads Intel Skylake 2 sockets server using will-it-scale/page_fault1 process mode(higher is better): kernel performance zone lock contention patch1 9219349 76.99% patch7 2461133 -73.3% 54.46%(another 34.66% on smp_list_add()) patch8 11712766 +27.0% 68.14% patch9 11386980 +23.5% 67.18% Though lock contention reduced a lot for patch7, the performance dropped considerably due to severe cache bouncing on free list head among multiple threads doing page free at the same time, because every page free will need to add the page to the free list head. Patch8 is meant to solve this cache bouncing problem and has good result, except the above mentioned side effect of having mergable pages unmerged in Buddy. Patch9 reduced the fragmentation problem to some extent while caused slightly performance drop. As a comparison to the no_merge+cluster_alloc approach I posted before[2]: kernel performance zone lock contention patch1 9219349 76.99% no_merge 11733153 +27.3% 69.18% no_merge+cluster_alloc 12094893 +31.2% 0.73% no_merge(skip merging for order0 page on free path) has similar performance and zone lock contention as patch8/9, while with cluster_alloc that also improves allocation side, zone lock contention for this workload is almost gone. To get an idea of how fragmentation are affected by patch8 and how much improvement patch9 has, this is the result of /proc/buddyinfo after running will-it-scale/page_fault1 for 3 minutes: With patch7: Node 0, zone DMA 0 2 1 1 3 2 2 1 0 1 3 Node 0, zone DMA32 7 3 6 5 5 10 6 7 6 10 410 Node 0, zone Normal 17820 16819 14645 12969 11367 9229 6365 3062 756 69 5646 Node 1, zone Normal 44789 60354 52331 37532 22071 9604 2750 241 32 11 6378 With patch8: Node 0, zone DMA 0 2 1 1 3 2 2 1 0 1 3 Node 0, zone DMA32 7 9 5 4 5 10 6 7 6 10 410 Node 0, zone Normal 404917 119614 79446 58303 20679 3106 222 89 28 9 5615 Node 1, zone Normal 507659 127355 64470 53549 14104 1288 30 4 1 1 6078 With patch9: Node 0, zone DMA 0 3 0 1 3 0 1 0 1 1 3 Node 0, zone DMA32 11 423 621 705 726 702 60 14 5 6 296 Node 0, zone Normal 20407 21016 18731 16195 13697 10483 6873 3148 735 39 5637 Node 1, zone Normal 79738 76963 59313 35996 18626 9743 3947 750 21 2 6080 A lot more pages stayed in order0 in patch8 than patch7, consequently, for order5 and above pages, there are fewer with patch8 than patch7, suggesting that some pages are not properly merged into high order pages with patch8 applied. Patch9 has far fewer pages stayed in order0 than patch8, which is a good sign but still not as good as patch7. As a comparison, this is the result of no_merge(think of it as a worst case result regarding fragmentation): With no_merge: Node 0, zone DMA 0 2 1 1 3 2 2 1 0 1 3 Node 0, zone DMA32 7 3 6 5 5 10 6 7 6 10 410 Node 0, zone Normal 1895199 5 1 1 4 2 2 1 1 1 5614 Node 1, zone Normal 1718733 4 1 13 10 3 2 0 1 1 6008 Conclusion: The approach I proposed here caused performance drop due to free list head cache bouncing. If we can bear the result of some mergable pages becoming unmerged in Buddy, zone lock scalability can be improved: performance increase 20%+, lock contention drop 8%. no_merge+cluster_alloc on the other hand, can eiminate zone lock contention entirely, but has worse fragmentation issue. [0] https://lwn.net/Articles/753058/ [1] https://lkml.kernel.org/r/20180911004240.4758-1-daniel.m.jordan@oracle.com [2] https://lkml.kernel.org/r/20180509085450.3524-1-aaron.lu@intel.com Aaron Lu (7): mm: do not add anon pages to LRU mm: convert zone lock from spinlock to rwlock mm/page_alloc: use helper functions to add/remove a page to/from buddy use atomic for free_area[order].nr_free mm: use read_lock for free path mm: use smp_list_splice() on free path mm: page_alloc: merge before sending pages to global pool Daniel Jordan (2): mm: introduce smp_list_del for concurrent list entry removals mm: introduce smp_list_splice to prepare for concurrent LRU adds include/linux/list.h | 4 + include/linux/mm.h | 1 + include/linux/mmzone.h | 4 +- init/main.c | 1 + lib/Makefile | 2 +- lib/list.c | 227 ++++++++++++++++++++++++++++ mm/compaction.c | 90 +++++------ mm/hugetlb.c | 8 +- mm/memory.c | 2 +- mm/page_alloc.c | 332 ++++++++++++++++++++++++++++------------- mm/page_isolation.c | 12 +- mm/vmstat.c | 8 +- 12 files changed, 526 insertions(+), 165 deletions(-) create mode 100644 lib/list.c -- 2.17.1