Received: by 10.223.176.46 with SMTP id f43csp701485wra; Wed, 24 Jan 2018 04:45:22 -0800 (PST) X-Google-Smtp-Source: AH8x22791p5YZ1EsJcpgHoYHQHNMm0ai3BnGd6V+xDfpU/xmyhZ1yveupB9mxzE/JvpuDXmrKhbu X-Received: by 2002:a17:902:102:: with SMTP id 2-v6mr8077565plb.178.1516797921906; Wed, 24 Jan 2018 04:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516797921; cv=none; d=google.com; s=arc-20160816; b=MnuaH/QX8iUfncW67t0ZsfJA45SHMfw7PbY3ftiFdsUvdR5xZJff2g+8xL+xv3/YAT bG3MmMpA5AGkfU3KpsOt6aJ6f9D9uCDdy21wpAuQErhGeQ8V2uq+l4LYYKBvgNn4PEDi qo6hHe8v/YmaJabYqwc9PQIGYgaR4a4hBYnkZjYgcOD3pDyvS00eHUGuMSDfISJuD1/X JTTmGNHadfpw5bYfa7mAlRuPuOCdFGREoPoynato4dP8WmYxmaqsUiyug5tFfA6TBR+m V9YU8ezf5xY58OapUAcXyeZmDL8XcByqdwBzROG50K892OFHeagZkgpJNbZ587PkfNnm m0kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=qM+FSsn+V7h+119sD/UbpO+D8ZCYKaRlTNiYMlQMO7g=; b=DSbfMW0w7IW0ObxueAWQZsVgtpKNKtJs07o3SnPeyVZkpcRIynMAmPrQ9QOtLPhmNH lhdNwgXaRn7Jby4r/9lH0JrM2t8dae8fyX8+D0RUwYVAZzm2lOSC3TRNshEGcKjKMFxS GdFshI8u15WWZLzqGAolIwkdxbNbhWNZ5N8AabYbw3OR6LRxKBrEJhgvFkFkBkyWv7+a IEhB9+2wnse4B3XZBeCZXQMSK1aInO9ShzPoplDl0IVIvjlCWpfhd/rxX7tnqttghbHw K+Q4NN3P3blrGGiuhbqFt+Y0U08JnOPKj3hldWEsv52CFaByvFIbh4nU20DSnlVYMQxe iyNA== 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 p1si2878060pfp.12.2018.01.24.04.44.52; Wed, 24 Jan 2018 04:45:21 -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 S933589AbeAXMn5 (ORCPT + 99 others); Wed, 24 Jan 2018 07:43:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:59185 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933386AbeAXMn4 (ORCPT ); Wed, 24 Jan 2018 07:43:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 14BBBAD34; Wed, 24 Jan 2018 12:43:55 +0000 (UTC) Date: Wed, 24 Jan 2018 13:43:53 +0100 From: Michal Hocko To: Petr Tesarik 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: <20180124124353.GE28465@dhcp22.suse.cz> References: <20180119080908.3a662e6f@ezekiel.suse.cz> <20180119123956.GZ6584@dhcp22.suse.cz> <20180119142133.379d5145@ezekiel.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180119142133.379d5145@ezekiel.suse.cz> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 19-01-18 14:21:33, Petr Tesarik wrote: > 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. Yeah, it is a mess. So I will leave it up to you. I do not want to block your comment update which is a nice improvement. So with or without the runtime check feel free to add Acked-by: Michal Hocko -- Michal Hocko SUSE Labs