Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp244756ybv; Wed, 5 Feb 2020 04:55:43 -0800 (PST) X-Google-Smtp-Source: APXvYqw5HErJSXlgwEA3uBAULo5+rsCd8F/REbXdwY2v4RsdQeGhrvLrWA2/gP2hsNeRn4F4mT/s X-Received: by 2002:a05:6808:b13:: with SMTP id s19mr2570286oij.119.1580907342830; Wed, 05 Feb 2020 04:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580907342; cv=none; d=google.com; s=arc-20160816; b=RItYZsjFtfEYFCV0FG1ITxKLuFh/MzAOctYixC6HC7qQsUjSphn3puXWu/sV0gyUzJ U1KXVpC88YwSBAw9EGL3tRUQz+VeN/jlH3IpKzhKKVbNZQGb9uWFyp7Dp8Jl6xcgovrY 4hw6IEAQvXrf9ibs5Itkv8SwuuMSTKefTbjZNveSO3Tpevh7OgTrr/JzlbkbslxwL+7G juw3PDurSsfJ9fZJx5kx7JsB/IB0GheFnjNCNbLcDlot11aIp8bOgXIe3ku0vKX8JhNB 2jxvuWcGyYi6ndpE9joi/nCcck3N9Autvug/1SZjDv5MHlnJHm9e3Cd2zDPVIzGmchb5 vn/g== 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; bh=MWViY/Ws0Hn5PlzK3hdhovXV1UrdnFPQ/D5Qdp/aD94=; b=xFNusUYJkKHoAD+05y3Qr5zvA+xKF2iLNuwOnHlfL6Hq4Yw1Vpe1S+XaYg9h0LKGi1 YlIJAOd6jvb2E+ZuAGK9i4ooePAkbRa7F9I+gGbHsYyB5uFp2G3jnOjCOgE+GMvZ9E5c ToaFt/HzPA/1haSfnNL1DL0R0zhmurdwwv9TU3sRA7af2B8wPCpTGt8iP3rCwdZEjtHS kjC4kceqlzavV+9TKAOG/TAxrsmIYIwNjx/tZ5osq0HvghpvQXbRFJHxOjLTWsrxpV0y a2T9YWH/jgrIT7zhv3p3nKEgm4uPn1SN3qWln7pl4rkKAqx7aqtOelszRIWh7QqGIzCM ONRA== 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 n7si12665627otk.277.2020.02.05.04.55.30; Wed, 05 Feb 2020 04:55:42 -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 S1727991AbgBEMxW (ORCPT + 99 others); Wed, 5 Feb 2020 07:53:22 -0500 Received: from gate.crashing.org ([63.228.1.57]:42729 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgBEMxV (ORCPT ); Wed, 5 Feb 2020 07:53:21 -0500 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 015CppFf030570; Wed, 5 Feb 2020 06:51:51 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 015Cpn3x030569; Wed, 5 Feb 2020 06:51:49 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 5 Feb 2020 06:51:49 -0600 From: Segher Boessenkool To: David Hildenbrand Cc: Oscar Salvador , linux-s390@vger.kernel.org, Michal Hocko , linux-ia64@vger.kernel.org, Pavel Tatashin , linux-sh@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Wei Yang , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Dan Williams , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v6 10/10] mm/memory_hotplug: Cleanup __remove_pages() Message-ID: <20200205125149.GS22482@gate.crashing.org> References: <20191006085646.5768-1-david@redhat.com> <20191006085646.5768-11-david@redhat.com> <20200204094652.GE6494@linux> <5d698f94-af18-0714-bc97-14b6c520572c@redhat.com> <20200204131353.GJ22482@gate.crashing.org> <0e2f700c-b01b-8c16-99c2-2648967fc203@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0e2f700c-b01b-8c16-99c2-2648967fc203@redhat.com> User-Agent: Mutt/1.4.2.3i Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 04, 2020 at 02:38:51PM +0100, David Hildenbrand wrote: > On 04.02.20 14:13, Segher Boessenkool wrote: > > On Tue, Feb 04, 2020 at 01:41:06PM +0100, David Hildenbrand wrote: > >> It's a pattern commonly used in compilers and emulators to calculate the > >> number of bytes to the next block/alignment. (we're missing a macro > >> (like we have ALIGN_UP/IS_ALIGNED) for that - but it's hard to come up > >> with a good name (e.g., SIZE_TO_NEXT_ALIGN) . > > You can just write the easy to understand > > > > ... ALIGN_UP(x) - x ... > > you mean > > ALIGN_UP(x, PAGES_PER_SECTION) - x > > but ... > > > which is better *without* having a separate name. Does that not > > generate good machine code for you? > > 1. There is no ALIGN_UP. "SECTION_ALIGN_UP(x) - x" would be possible Erm, you started it ;-) > 2. It would be wrong if x is already aligned. > > e.g., let's use 4096 for simplicity as we all know that value by heart > (for both x and the block size). > > a) -(4096 | -4096) -> 4096 > > b) #define ALIGN_UP(x, a) ((x + a - 1) & -(a)) > > ALIGN_UP(4096, 4096) - 4096 -> 0 > > Not as easy as it seems ... If you always want to return a number >= 1, it it simply ALIGN_UP(x + 1) - x (and replace 1 by any other minimum size required). This *also* is easy to read, without having to have any details (and quirks :-/ ) of those utility functions memorised. Segher