0001 .. _development_advancedtopics:
0002
0003 Advanced topics
0004 ===============
0005
0006 At this point, hopefully, you have a handle on how the development process
0007 works. There is still more to learn, however! This section will cover a
0008 number of topics which can be helpful for developers wanting to become a
0009 regular part of the Linux kernel development process.
0010
0011 Managing patches with git
0012 -------------------------
0013
0014 The use of distributed version control for the kernel began in early 2002,
0015 when Linus first started playing with the proprietary BitKeeper
0016 application. While BitKeeper was controversial, the approach to software
0017 version management it embodied most certainly was not. Distributed version
0018 control enabled an immediate acceleration of the kernel development
0019 project. In current times, there are several free alternatives to
0020 BitKeeper. For better or for worse, the kernel project has settled on git
0021 as its tool of choice.
0022
0023 Managing patches with git can make life much easier for the developer,
0024 especially as the volume of those patches grows. Git also has its rough
0025 edges and poses certain hazards; it is a young and powerful tool which is
0026 still being civilized by its developers. This document will not attempt to
0027 teach the reader how to use git; that would be sufficient material for a
0028 long document in its own right. Instead, the focus here will be on how git
0029 fits into the kernel development process in particular. Developers who
0030 wish to come up to speed with git will find more information at:
0031
0032 https://git-scm.com/
0033
0034 https://www.kernel.org/pub/software/scm/git/docs/user-manual.html
0035
0036 and on various tutorials found on the web.
0037
0038 The first order of business is to read the above sites and get a solid
0039 understanding of how git works before trying to use it to make patches
0040 available to others. A git-using developer should be able to obtain a copy
0041 of the mainline repository, explore the revision history, commit changes to
0042 the tree, use branches, etc. An understanding of git's tools for the
0043 rewriting of history (such as rebase) is also useful. Git comes with its
0044 own terminology and concepts; a new user of git should know about refs,
0045 remote branches, the index, fast-forward merges, pushes and pulls, detached
0046 heads, etc. It can all be a little intimidating at the outset, but the
0047 concepts are not that hard to grasp with a bit of study.
0048
0049 Using git to generate patches for submission by email can be a good
0050 exercise while coming up to speed.
0051
0052 When you are ready to start putting up git trees for others to look at, you
0053 will, of course, need a server that can be pulled from. Setting up such a
0054 server with git-daemon is relatively straightforward if you have a system
0055 which is accessible to the Internet. Otherwise, free, public hosting sites
0056 (Github, for example) are starting to appear on the net. Established
0057 developers can get an account on kernel.org, but those are not easy to come
0058 by; see https://kernel.org/faq/ for more information.
0059
0060 The normal git workflow involves the use of a lot of branches. Each line
0061 of development can be separated into a separate "topic branch" and
0062 maintained independently. Branches in git are cheap, there is no reason to
0063 not make free use of them. And, in any case, you should not do your
0064 development in any branch which you intend to ask others to pull from.
0065 Publicly-available branches should be created with care; merge in patches
0066 from development branches when they are in complete form and ready to go -
0067 not before.
0068
0069 Git provides some powerful tools which can allow you to rewrite your
0070 development history. An inconvenient patch (one which breaks bisection,
0071 say, or which has some other sort of obvious bug) can be fixed in place or
0072 made to disappear from the history entirely. A patch series can be
0073 rewritten as if it had been written on top of today's mainline, even though
0074 you have been working on it for months. Changes can be transparently
0075 shifted from one branch to another. And so on. Judicious use of git's
0076 ability to revise history can help in the creation of clean patch sets with
0077 fewer problems.
0078
0079 Excessive use of this capability can lead to other problems, though, beyond
0080 a simple obsession for the creation of the perfect project history.
0081 Rewriting history will rewrite the changes contained in that history,
0082 turning a tested (hopefully) kernel tree into an untested one. But, beyond
0083 that, developers cannot easily collaborate if they do not have a shared
0084 view of the project history; if you rewrite history which other developers
0085 have pulled into their repositories, you will make life much more difficult
0086 for those developers. So a simple rule of thumb applies here: history
0087 which has been exported to others should generally be seen as immutable
0088 thereafter.
0089
0090 So, once you push a set of changes to your publicly-available server, those
0091 changes should not be rewritten. Git will attempt to enforce this rule if
0092 you try to push changes which do not result in a fast-forward merge
0093 (i.e. changes which do not share the same history). It is possible to
0094 override this check, and there may be times when it is necessary to rewrite
0095 an exported tree. Moving changesets between trees to avoid conflicts in
0096 linux-next is one example. But such actions should be rare. This is one
0097 of the reasons why development should be done in private branches (which
0098 can be rewritten if necessary) and only moved into public branches when
0099 it's in a reasonably advanced state.
0100
0101 As the mainline (or other tree upon which a set of changes is based)
0102 advances, it is tempting to merge with that tree to stay on the leading
0103 edge. For a private branch, rebasing can be an easy way to keep up with
0104 another tree, but rebasing is not an option once a tree is exported to the
0105 world. Once that happens, a full merge must be done. Merging occasionally
0106 makes good sense, but overly frequent merges can clutter the history
0107 needlessly. Suggested technique in this case is to merge infrequently, and
0108 generally only at specific release points (such as a mainline -rc
0109 release). If you are nervous about specific changes, you can always
0110 perform test merges in a private branch. The git "rerere" tool can be
0111 useful in such situations; it remembers how merge conflicts were resolved
0112 so that you don't have to do the same work twice.
0113
0114 One of the biggest recurring complaints about tools like git is this: the
0115 mass movement of patches from one repository to another makes it easy to
0116 slip in ill-advised changes which go into the mainline below the review
0117 radar. Kernel developers tend to get unhappy when they see that kind of
0118 thing happening; putting up a git tree with unreviewed or off-topic patches
0119 can affect your ability to get trees pulled in the future. Quoting Linus:
0120
0121 ::
0122
0123 You can send me patches, but for me to pull a git patch from you, I
0124 need to know that you know what you're doing, and I need to be able
0125 to trust things *without* then having to go and check every
0126 individual change by hand.
0127
0128 (https://lwn.net/Articles/224135/).
0129
0130 To avoid this kind of situation, ensure that all patches within a given
0131 branch stick closely to the associated topic; a "driver fixes" branch
0132 should not be making changes to the core memory management code. And, most
0133 importantly, do not use a git tree to bypass the review process. Post an
0134 occasional summary of the tree to the relevant list, and, when the time is
0135 right, request that the tree be included in linux-next.
0136
0137 If and when others start to send patches for inclusion into your tree,
0138 don't forget to review them. Also ensure that you maintain the correct
0139 authorship information; the git "am" tool does its best in this regard, but
0140 you may have to add a "From:" line to the patch if it has been relayed to
0141 you via a third party.
0142
0143 When requesting a pull, be sure to give all the relevant information: where
0144 your tree is, what branch to pull, and what changes will result from the
0145 pull. The git request-pull command can be helpful in this regard; it will
0146 format the request as other developers expect, and will also check to be
0147 sure that you have remembered to push those changes to the public server.
0148
0149
0150 Reviewing patches
0151 -----------------
0152
0153 Some readers will certainly object to putting this section with "advanced
0154 topics" on the grounds that even beginning kernel developers should be
0155 reviewing patches. It is certainly true that there is no better way to
0156 learn how to program in the kernel environment than by looking at code
0157 posted by others. In addition, reviewers are forever in short supply; by
0158 looking at code you can make a significant contribution to the process as a
0159 whole.
0160
0161 Reviewing code can be an intimidating prospect, especially for a new kernel
0162 developer who may well feel nervous about questioning code - in public -
0163 which has been posted by those with more experience. Even code written by
0164 the most experienced developers can be improved, though. Perhaps the best
0165 piece of advice for reviewers (all reviewers) is this: phrase review
0166 comments as questions rather than criticisms. Asking "how does the lock
0167 get released in this path?" will always work better than stating "the
0168 locking here is wrong."
0169
0170 Different developers will review code from different points of view. Some
0171 are mostly concerned with coding style and whether code lines have trailing
0172 white space. Others will focus primarily on whether the change implemented
0173 by the patch as a whole is a good thing for the kernel or not. Yet others
0174 will check for problematic locking, excessive stack usage, possible
0175 security issues, duplication of code found elsewhere, adequate
0176 documentation, adverse effects on performance, user-space ABI changes, etc.
0177 All types of review, if they lead to better code going into the kernel, are
0178 welcome and worthwhile.