From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE8BEEB64D8 for ; Wed, 14 Jun 2023 20:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236943AbjFNUdy (ORCPT ); Wed, 14 Jun 2023 16:33:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236396AbjFNUdv (ORCPT ); Wed, 14 Jun 2023 16:33:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1386226BA for ; Wed, 14 Jun 2023 13:33:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8FA906184D for ; Wed, 14 Jun 2023 20:33:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85DBC433C0; Wed, 14 Jun 2023 20:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1686774819; bh=Iu93SuweVrRX7FVAD9kDUf9pdECryvqWZ90NRtl/CPM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pSwEuI0aIqzS/2+x/BhbgWOiPFgdB3tHAXo9/s4EEeQpUBC6DL34uboA1uV9fel// tmwtpHlh9olp17mtfnOvFdKh/SZJsYxpZEZJJ7bTf8mz1FSNkjAHrQm0Y16fIoU0dv KR9VvyNtVnVajWAOyJ6WJ+MtyO71bVnyYORfmY/U= Date: Wed, 14 Jun 2023 13:33:37 -0700 From: Andrew Morton To: Matthew Wilcox Cc: "Vishal Moola (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/5] mmzone: Introduce folio_migratetype() Message-Id: <20230614133337.f5eb6ef530d7d6cb1edbcf0d@linux-foundation.org> In-Reply-To: References: <20230614021312.34085-1-vishal.moola@gmail.com> <20230614021312.34085-3-vishal.moola@gmail.com> <20230614131305.2939f29e4372c94a8c6a56a8@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 14 Jun 2023 21:17:34 +0100 Matthew Wilcox wrote: > On Wed, Jun 14, 2023 at 01:13:05PM -0700, Andrew Morton wrote: > > On Tue, 13 Jun 2023 19:13:09 -0700 "Vishal Moola (Oracle)" wrote: > > > > > Introduce folio_migratetype() as a folio equivalent for > > > get_pageblock_migratetype(). This function intends to return the > > > migratetype the folio is located in, hence the name choice. > > > > > > ... > > > > > > --- a/include/linux/mmzone.h > > > +++ b/include/linux/mmzone.h > > > @@ -105,6 +105,9 @@ extern int page_group_by_mobility_disabled; > > > #define get_pageblock_migratetype(page) \ > > > get_pfnblock_flags_mask(page, page_to_pfn(page), MIGRATETYPE_MASK) > > > > > > +#define folio_migratetype(folio) \ > > > + get_pfnblock_flags_mask(&folio->page, folio_pfn(folio), \ > > > + MIGRATETYPE_MASK) > > > > Theoretically this is risky because it evaluates its argument more than > > once. Although folio_migratetype(folio++) seems an unlikely thing to do. > > folio++ is always an unsafe thing to do. folios are not consecutive > in memory (unless we know they're order-0). OK, folio_migratetype(expensive_function_which_returns_a_folio()) or folio_migratetype(function_with_side_effects_which_returns_a_folio()). There are many failure modes. > > An inlined C function is always preferable. My quick attempt at that > > reveals that the header files are All Messed Up As Usual. > > The page-equivalent of this also evaluates its arguments more than once, > so it doesn't see too risky for now? We got lucky. It's just bad practice.