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 08CF2C433F5 for ; Wed, 8 Dec 2021 16:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237338AbhLHQye (ORCPT ); Wed, 8 Dec 2021 11:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbhLHQyd (ORCPT ); Wed, 8 Dec 2021 11:54:33 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE767C061746 for ; Wed, 8 Dec 2021 08:51:01 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id e3so10529858edu.4 for ; Wed, 08 Dec 2021 08:51:01 -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; bh=7dto8X3c8dkt8cAuGIAikbVN54E5STCRsv0et+8KXh8=; b=XL0p0g2mnaxR5sNE/l+nWe28s9d3M1czmNdZvqDzJYOtI9OUtCjctzb75KHJ13Fmgf kxjEdIK6lI5Iqihs3D3DF1KbxA+pGkY3myenSVWEXzC6cVMdvOBIHdUDtJwxbbLH0hJC ZuyS2FQBQqB3Fj+cUfkE/veQZzqrEAWYRJ0AI= 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; bh=7dto8X3c8dkt8cAuGIAikbVN54E5STCRsv0et+8KXh8=; b=dBuOg7FovV4ZX+09kLUP0GKdAWpc83B24mFcsex47fhdQkIUnJeISDdYQLMmKnB93F Piapb/P+GpV+nlDM1UhWaPI2+78Iagm5ssJ1ZkuZTAkEOkmfw7Bwy6g1yYOLWMWrcDxf Su6daXECgeqAzsYDCFtU4Le9Wurt/agRoiszo38SPQ+cp3MXLdvzgvUKvnB6i040T+VM V9V1W9xbNjJXAleflfgHO/i6BFg2xjGGEz0/HjLYMdh3n8peN1hN0z45fjCgLhK6PB9b /mDB0Wd8yyTvhCGTflLHuhdYoLeXvJJz0v02qiXYyWz0HZA2EVGYwRgr63Nz1itr1J83 JCaA== X-Gm-Message-State: AOAM531Wkkqq93g7n/4SXkPQjgnBmvfbagp8GpaAeikix5PEEfNZnhJJ unl4jsfUDe5mvJY6/3foYwdS80OBBnFM3n5LG68= X-Google-Smtp-Source: ABdhPJyCRJ7aUtQK15OYnUlC6GgXn4qGhmQ62Ru8GBAvKeklY866UEJ7gw7Pic0F4kWjsGC8cK0PqA== X-Received: by 2002:aa7:c313:: with SMTP id l19mr20635705edq.209.1638982259938; Wed, 08 Dec 2021 08:50:59 -0800 (PST) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com. [209.85.128.48]) by smtp.gmail.com with ESMTPSA id hg19sm1692234ejc.1.2021.12.08.08.50.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Dec 2021 08:50:58 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id o29so2253538wms.2 for ; Wed, 08 Dec 2021 08:50:58 -0800 (PST) X-Received: by 2002:a05:600c:22ce:: with SMTP id 14mr16865226wmg.152.1638982258068; Wed, 08 Dec 2021 08:50:58 -0800 (PST) MIME-Version: 1.0 References: <20211207150927.3042197-1-arnd@kernel.org> <20211207150927.3042197-3-arnd@kernel.org> In-Reply-To: From: Linus Torvalds Date: Wed, 8 Dec 2021 08:50:42 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC 2/3] headers: introduce linux/struct_types.h To: Arnd Bergmann Cc: Linux Kernel Mailing List , Arnd Bergmann , Al Viro , Andrew Morton , Guenter Roeck , Kees Cook , Masahiro Yamada , Matthew Wilcox , Nathan Chancellor , Nick Desaulniers , Stephen Rothwell , kernel test robot , Ingo Molnar , Peter Zijlstra , Will Deacon , Waiman Long , Boqun Feng , Thomas Gleixner , Tejun Heo , kernelci@groups.io, linux-fsdevel , Linux Kbuild mailing list , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 8, 2021 at 12:56 AM Arnd Bergmann wrote: > > For the added headers, do you have a preference for whether to try grouping > them logically or not? I could either split them out individually into many new > headers (xarray_types.h, idr_types.h, percpu_rwsem_types.h, rwsem_types.h, > ...), or combine some of them when they define related types. So I'd really like to have some logical grouping. I'd rather have ten smaller headers that each have one logical grouping than one "put random core kernel structs in this one". The reason I reacted fairly strongly against this "struct_types.h" patch is that I quite often end up looking up some exact type definition and the associated initializers etc. It's admittedly seldom stuff that is this core (it tends to be some random odder type), but just to give a concrete example, that change was an example of something I really dislike. Moving just the type definition away, particularly when it then depends on various kernel config options, and having the core initializer macros and functions somewhere different from where the type is defined is really nasty when you're looking at some type definition details. (The mutex one is just an example: all the locking structures had the same pattern). I realize that the locking structs are also exactly the ones that are then often embedded in other structures, so I understand why they were so prominent in that patch. But at the same time, I think that is how C header files work - it has many upsides, but it certainly also has that problematic downside of having to get the header inclusion right without recursion etc. So instead of trying to split out things like the structures associated with locking, I'd rather aim to (a) try to make sure that the locking headers are always self-contained enough that there is never any issue with including them, and recursion isn't an issue. (b) I think it might be better to try to instead split out the more specialized and high-level structures, and try to declare _those_ separately optimally for (b) is to not declare them at all: in many situations you really just want the header file for some function pointer declaration, and doing a forward declaration with just "struct super_block;" in the generic header file might be the right thing. Then the relatively few places that actually care what 'struct super_block' looks like could include or whatever. Because a big portion of our code probably does want to include , but is not AT ALL interested in how 'struct super_block' actually is laid out. The fact that you want declarations for functions that take a pointer to it doesn't matter, for them it's enough to have that forward-declaration of "this is a valid struct, you don't care what it looks like". So I think I would be much more interested in _that_ kind of patch: instead of trying to collect truly core types in one (or a few) header files, try to see if all those random other types could not be split out into their own patches. And yes, yes, I realize that 'struct super_block' is actually actively used by inline functions in , so they actually require that declaration as it stands now. But those functions are generally fairly specialized, and they could go along with the structure definition into the header. And maybe some of them shouldn't be inline functions at all - we often end up having unnecessariyl big and complex headers just because it was easier to add an inline function (or expand a trivial one) than it was to just make a function declaration and then move the code into a separate C file. (This is also why sometimes macros are more convenient than inline functions - they don't need the context. So sometimes the answer for trivial helper functions is to just turn then into macros instead). Hmm? Linus