Received: by 10.223.176.46 with SMTP id f43csp993356wra; Fri, 19 Jan 2018 05:24:01 -0800 (PST) X-Google-Smtp-Source: ACJfBouIooOjJNkv/zEbBnHq3Sc1phs3G61yJYZzv6/z6Ggpqv0mjOOjx+0idGeAo5sb+tZ8FRuL X-Received: by 10.99.185.74 with SMTP id v10mr40185324pgo.361.1516368241222; Fri, 19 Jan 2018 05:24:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516368241; cv=none; d=google.com; s=arc-20160816; b=j3vSfXXiwMyapioVn0Q9nY19umMqA7W2EAc2nTpW+Lg3uLwCrjKQ9BitsLO1rv7/tO 63G5D5kCRgFQAfVGGmN6x+WiXhHIEie8Izkn3sXt75IdftPrYgxBLN6fP6usDvJ3qYbP ysu8xnZri1976qO5alWuEd1sY2SfSKG8EE5RR6ECBrxm61Q/D7IkcADv05gktspadcoN InqoFnq2ZKmtR4NALsMIzyF35eniHMz4+nN1/kGmJKYpzyA1Qx8i1Oi0NagIcvB7N6R2 9R9g8Yp9In0kAtI6TpeGo4UG+jGktiYOjJLVSoPsIa6kgYmepjFDiby8ZJYRe+IwTRbg r9+w== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=fdfVZrl1B8BDpGU6QhSE8LEpK2+Gs3Mgm+P08hzgeJc=; b=Rsh6m51CDxqFCH7meBcixLciB3lyKrmjD4kBKaXZwy3l3e8taZbBBs91fn/mVMMq7/ d0UkMDQodeCohUra9nE9P75SaGTeRv/Z4RagOcL63nGaK0pVheEZ0kmqBJ04HqhYywt6 xu0DI9g9FL1et7XcdKMjY3FIE2YczCGB/D/vZi0JqBEcx/6IWECEPnTPSH2XmHNo1j2R WxUwZfGopN7WHUsZlP2SYF6mu9S+y1bT9GzkyVGKq/DxWCLLP1X++04TEEfSWP2nt3W+ 1L9nGPbfspskDTLFc/+FaoO1ACQYJ28IJM06bG+8e3WjmddD4ELuEKwqdqfkGk/wWCK4 xDkw== 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 p3si4028058pgf.710.2018.01.19.05.23.46; Fri, 19 Jan 2018 05:24:01 -0800 (PST) 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 S1755398AbeASNVs (ORCPT + 99 others); Fri, 19 Jan 2018 08:21:48 -0500 Received: from smtp2.provo.novell.com ([137.65.250.81]:46446 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755172AbeASNVm (ORCPT ); Fri, 19 Jan 2018 08:21:42 -0500 Received: from ezekiel.suse.cz (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Fri, 19 Jan 2018 06:21:38 -0700 Date: Fri, 19 Jan 2018 14:21:33 +0100 From: Petr Tesarik To: Michal Hocko Cc: linux-mm@kvack.org, Andrew Morton , Vlastimil Babka , linux-kernel@vger.kernel.org, Mel Gorman , Johannes Weiner , Kemi Wang , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov Subject: Re: [PATCH] Fix explanation of lower bits in the SPARSEMEM mem_map pointer Message-ID: <20180119142133.379d5145@ezekiel.suse.cz> In-Reply-To: <20180119123956.GZ6584@dhcp22.suse.cz> References: <20180119080908.3a662e6f@ezekiel.suse.cz> <20180119123956.GZ6584@dhcp22.suse.cz> Organization: SUSE Linux X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 19 Jan 2018 13:39:56 +0100 Michal Hocko wrote: > On Fri 19-01-18 08:09:08, Petr Tesarik wrote: > [...] > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > > index 67f2e3c38939..7522a6987595 100644 > > --- a/include/linux/mmzone.h > > +++ b/include/linux/mmzone.h > > @@ -1166,8 +1166,16 @@ extern unsigned long usemap_size(void); > > > > /* > > * We use the lower bits of the mem_map pointer to store > > - * a little bit of information. There should be at least > > - * 3 bits here due to 32-bit alignment. > > + * a little bit of information. The pointer is calculated > > + * as mem_map - section_nr_to_pfn(pnum). The result is > > + * aligned to the minimum alignment of the two values: > > + * 1. All mem_map arrays are page-aligned. > > + * 2. section_nr_to_pfn() always clears PFN_SECTION_SHIFT > > + * lowest bits. PFN_SECTION_SHIFT is arch-specific > > + * (equal SECTION_SIZE_BITS - PAGE_SHIFT), and the > > + * worst combination is powerpc with 256k pages, > > + * which results in PFN_SECTION_SHIFT equal 6. > > + * To sum it up, at least 6 bits are available. > > */ > > This is _much_ better indeed. Do you think we can go one step further > and add BUG_ON into the sparse code to guarantee that every mmemap > is indeed aligned properly so that SECTION_MAP_LAST_BIT-1 bits are never > used? This is easy for the section_nr_to_pfn() part. I'd just add: BUILD_BUG_ON(PFN_SECTION_SHIFT < SECTION_MAP_LAST_BIT); But for the mem_map arrays... Do you mean adding a run-time BUG_ON into all allocation paths? Note that mem_map arrays can be allocated by: a) __earlyonly_bootmem_alloc b) memblock_virt_alloc_try_nid c) memblock_virt_alloc_try_nid_raw d) alloc_remap (only arch/tile still has it) Some allocation paths are in mm/sparse.c, others are mm/sparse-vmemmap.c, so it becomes a bit messy, but since it's a single line in each, it may work. Petr T