From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751142AbdALQVx (ORCPT ); Thu, 12 Jan 2017 11:21:53 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45999 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751051AbdALQVv (ORCPT ); Thu, 12 Jan 2017 11:21:51 -0500 Subject: Re: [PATCH v1 1/1] mm/ksm: improve deduplication of zero pages with colouring To: Claudio Imbrenda , linux-mm@kvack.org References: <1484237834-15803-1-git-send-email-imbrenda@linux.vnet.ibm.com> Cc: hughd@google.com, izik.eidus@ravellosystems.com, aarcange@redhat.com, chrisw@sous-sol.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org From: Christian Borntraeger Date: Thu, 12 Jan 2017 17:21:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <1484237834-15803-1-git-send-email-imbrenda@linux.vnet.ibm.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17011216-0020-0000-0000-00000AB727CE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006420; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000199; SDB=6.00806685; UDB=6.00392590; IPR=6.00584015; BA=6.00005051; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013903; XFM=3.00000011; UTC=2017-01-12 16:21:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011216-0021-0000-0000-000058D01D26 Message-Id: <1ba9984d-aef5-0d49-4a9b-28e38a9a84de@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-12_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701120225 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/12/2017 05:17 PM, Claudio Imbrenda wrote: > Some architectures have a set of zero pages (coloured zero pages) > instead of only one zero page, in order to improve the cache > performance. In those cases, the kernel samepage merger (KSM) would > merge all the allocated pages that happen to be filled with zeroes to > the same deduplicated page, thus losing all the advantages of coloured > zero pages. > > This patch fixes this behaviour. When coloured zero pages are present, > the checksum of a zero page is calculated during initialisation, and > compared with the checksum of the current canditate during merging. In > case of a match, the normal merging routine is used to merge the page > with the correct coloured zero page, which ensures the candidate page > is checked to be equal to the target zero page. > > This behaviour is noticeable when a process accesses large arrays of > allocated pages containing zeroes. A test I conducted on s390 shows > that there is a speed penalty when KSM merges such pages, compared to > not merging them or using actual zero pages from the start without > breaking the COW. > > With this patch, the performance with KSM is the same as with non > COW-broken actual zero pages, which is also the same as without KSM. > > Signed-off-by: Claudio Imbrenda FWIW, I cannot say if the memory management part is correct and sane. (the patch below). But this issue (loosing the cache colouring for the zero page) is certainly a reason to not use KSM on s390 for specific workloads (large sparsely matrixes backed by the guest empty zero page). This patch will fix that. > --- > mm/ksm.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/mm/ksm.c b/mm/ksm.c > index 9ae6011..b0cfc30 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -223,6 +223,11 @@ struct rmap_item { > /* Milliseconds ksmd should sleep between batches */ > static unsigned int ksm_thread_sleep_millisecs = 20; > > +#ifdef __HAVE_COLOR_ZERO_PAGE > +/* Checksum of an empty (zeroed) page */ > +static unsigned int zero_checksum; > +#endif > + > #ifdef CONFIG_NUMA > /* Zeroed when merging across nodes is not allowed */ > static unsigned int ksm_merge_across_nodes = 1; > @@ -1467,6 +1472,25 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > return; > } > > +#ifdef __HAVE_COLOR_ZERO_PAGE > + /* > + * Same checksum as an empty page. We attempt to merge it with the > + * appropriate zero page. > + */ > + if (checksum == zero_checksum) { > + struct vm_area_struct *vma; > + > + vma = find_mergeable_vma(rmap_item->mm, rmap_item->address); > + err = try_to_merge_one_page(vma, page, > + ZERO_PAGE(rmap_item->address)); > + /* > + * In case of failure, the page was not really empty, so we > + * need to continue. Otherwise we're done. > + */ > + if (!err) > + return; > + } > +#endif > tree_rmap_item = > unstable_tree_search_insert(rmap_item, page, &tree_page); > if (tree_rmap_item) { > @@ -2304,6 +2328,11 @@ static int __init ksm_init(void) > struct task_struct *ksm_thread; > int err; > > +#ifdef __HAVE_COLOR_ZERO_PAGE > + /* The correct value depends on page size and endianness */ > + zero_checksum = calc_checksum(ZERO_PAGE(0)); > +#endif > + > err = ksm_slab_init(); > if (err) > goto out; >