Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3553882pxp; Tue, 8 Mar 2022 17:18:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFBc9HUVLoEQBAjFOKYU+poZ4u4Jo+jt2KZTK3iHjfvTKWTSiVxThaTyXHHimtC8JHOSA5 X-Received: by 2002:a63:f055:0:b0:362:d557:2ccb with SMTP id s21-20020a63f055000000b00362d5572ccbmr15957370pgj.377.1646788727675; Tue, 08 Mar 2022 17:18:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646788727; cv=none; d=google.com; s=arc-20160816; b=xovItWiuuvDSIx/EBmxUV9hOm7lNDKinAvwLe+4WUCjqTppaONmjY5jaTKBmVaAZka zTa9SFRJqNv0YrC8Uj53pvZW9PQX1SykB6uBQcrsUpCZeC9LVlAxPnFjfjHPDI/IyKwE aW3+pGCQ4RlQAQ1na5EbRp35VA1UE/jyFatJsE/mo88jhMlmtxmezp6UiO5Sp9iqxBQ3 kMlLlhc0nbw3HFOlCZaqVPF3U72E9h79kayz1Hw66fHZ9Z7VZcgYjrpW7wRDlq70ylhh RyFBIZWsZUHH5KX16bmytmlZ/zj3Ef+fvjWTzQHfq8YF9bQ1eEcDbrNTrgVjO9yD1Bpb NWvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PtUIO+KlIHnuwZcxB8rQEEiVqAu06QZDgLrU97vhKCg=; b=bKUnZlYa1/vGQZL65N2IJcko2WzTiTy0zZJAL6Tvsb3eaLnQ2v1uqfflppLYAG1Fui LYNdYsPjiKbYsotimcIb50U6Qw8BTr3v9Pa0nxZ1HfYFvANGpFJQUON5MpUMUszgsBYE Ad6XI6YUlzCwuyJKksoU6WZ9/1kxzRUHSvmh7OZ1VsJGp3PlYOnHcPKzx9tL4cEbswyT vzgiHjgYkENLMGos9ynx7cqtryFx1lBltoPGa56PJxsK/Fe99PeKcTbqwlo5YgCUDpcD in0SuZ7Lg8KJC/dFy012Mz+ETJ7YLDSUNEimlzL5tp1wAhAwHJ6087sgJqVHqt3wqubx Ih2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=cgcY5LKW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m4-20020a6545c4000000b003804722678asi466731pgr.286.2022.03.08.17.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:18:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=cgcY5LKW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A7479184634; Tue, 8 Mar 2022 16:13:32 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233651AbiCHSvL (ORCPT + 99 others); Tue, 8 Mar 2022 13:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349726AbiCHSvJ (ORCPT ); Tue, 8 Mar 2022 13:51:09 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DAA753E34 for ; Tue, 8 Mar 2022 10:50:08 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id bn33so26312208ljb.6 for ; Tue, 08 Mar 2022 10:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=PtUIO+KlIHnuwZcxB8rQEEiVqAu06QZDgLrU97vhKCg=; b=cgcY5LKW2TzJAfELjjvu0YRJX0cVXNV6yOUNqzYRkaYtWQEF1q1FXcSpdlHjJbunMR 0IbdURZXDS7gbD0Dqozrcw4EE0wCiRe7NhG/aY7qMDiLpEncbBRE3msFVv86nACqBYIf Xv2BbgPMeS5GkaXhGA6UU/fXBTXoXyHyEm648= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=PtUIO+KlIHnuwZcxB8rQEEiVqAu06QZDgLrU97vhKCg=; b=N1DwgSWY3ryqcnV1Z5r+o90IGVlEcT2F7CPmQV+eiIDUIIGoIdLF3XMsQA/++P27p3 V4xpPvz1PC0tWY5BEX9Jd9J8Gm0FjcDaui2lO6ZQf7gG4IjC0old+XzCo6Tj7RrvQ+B+ fX7Qz/5yg2ajCdE+uUamAjfzcTS38tmutNvBtWlchq4G/2bCQPWPJhIjB1Q9gEu7Quml iY6fIfkDbrRa8ufGdkjlKSvrTO7DxGRaRd0X4exuc5NjvVwemblr+yfxRgsgoxPVdnJt 2HLqRmnJrt89y/1XN9n9CZcLUY2aSWCA2SS/hLPV589Y9uC6ZJK01KTC8TdmHBb6NbZc IejQ== X-Gm-Message-State: AOAM533cINj8Y2xLohNJQYwgylMmY6iH5zpSN+4yM/XNb7W1JO40ySSM /caF85znJ73fggwVJowED6PryRFiV0cfFsVPEr0= X-Received: by 2002:a2e:a586:0:b0:247:e785:49cd with SMTP id m6-20020a2ea586000000b00247e78549cdmr6522247ljp.503.1646765406111; Tue, 08 Mar 2022 10:50:06 -0800 (PST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id y16-20020a2e9d50000000b00247b105c11dsm4015282ljj.34.2022.03.08.10.50.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Mar 2022 10:50:05 -0800 (PST) Received: by mail-lj1-f178.google.com with SMTP id v28so26295111ljv.9 for ; Tue, 08 Mar 2022 10:50:05 -0800 (PST) X-Received: by 2002:a2e:924d:0:b0:246:370c:5618 with SMTP id v13-20020a2e924d000000b00246370c5618mr11487227ljg.358.1646764958731; Tue, 08 Mar 2022 10:42:38 -0800 (PST) MIME-Version: 1.0 References: <20220308141437.144919-1-david@redhat.com> <20220308141437.144919-6-david@redhat.com> <0FFA6BBC-766F-4ABC-821A-062632632475@vmware.com> In-Reply-To: <0FFA6BBC-766F-4ABC-821A-062632632475@vmware.com> From: Linus Torvalds Date: Tue, 8 Mar 2022 10:42:22 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 05/15] mm/rmap: convert RMAP flags to a proper distinct rmap_t type To: Nadav Amit Cc: David Hildenbrand , Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Pedro Gomes , Oded Gabbay , "linux-mm@kvack.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 8, 2022 at 10:24 AM Nadav Amit wrote: > > I see your point regarding passing an arg. The or=E2=80=99ing of bitfield= s > can easily be resolved, unless I am missing something, with a union > that holds the aggregate value and an anonymous struct that holds > the individual flags. I think that falls under the same heading as passing them as arguments: it's certainly doable, but it requires special work that is hidden by helper macros/functions/types. I mean, even the "pass as arguments" can certainly work. It's not impossible to hide the odd syntax behind a macro, particularly if you only ever have a couple of specific cases. So you can do typedef struct rmap_flags { unsigned int exclusive:1, compound:1; } rmap_t; #define RMAP_EXCLUSIVE (rmap_t) { .exclusive =3D 1 } #define RMAP_COMPOUND (rmap_t) { .compound =3D 1 } and now you can use RMAP_EXCLUSIVE when you pass it as an argument, and in the functions themselves you can use if (flags.exclusive) {... which is certainly not unreadable. But it does mean that you basically have one syntax for testing "is this exclusive" and another for passing that value in. And you can't do RMAP_EXCLUSIVE | RMAP_COMPOUND to say "I want to pass in both exclusive and compound", but you *can* do flags.exclusive =3D 1; to set the exclusive bit. Again - that is certainly not unreadable on its own, but it's an example of how inconsistent and inconvenient the interface gets once you do anything outside of some very specific cases. And yes, you can solve these cases by simply always limiting yourself to specific syntax (in particular, just make the rule be that you can never create values out of thin air, you always have a variable that gets set. The bitfield thing does have the advantage that it ends up having very strict type checking. But in general, I'd say that the disadvantages are huge enough that you should never use a bitfield "on its own". Once it's part of a structure that you have to pass around and initialize as a structure *anyway*, then most of the problems go away. So bitfields as part of structures are fine - and we obviously use them extensively in that form. Even then they can have problems if there are any kinds of atomicity issues (ie think "page flags" or anything like that) but that's obviously a different thing, and using a union to get both ways to access things isn't out of the question. Of course, if you use unions to get "both as a bitfield and as a value" things working, you suddenly have "bit order issues", so that can be really problematic too. Bit endianness doesn't even have to follow byte endianness. End result: bitfields are actually often more complex than you think they a= re. Linus