General-purpose operating systems such as Linux are increasingly replacing custom embedded counterparts on a wide variety of devices. Despite their convenience and flexibility, however, such operating systems may be overly general and thus incur unnecessary performance overheads in these contexts. This paper describes a new approach to mitigating these overheads by automatically specializing the OS kernel for particular execution environments. We use value profiling to identify targets for specialization such as frequent system call parameters. A novel profiling technique is used to identify frequently invoked procedure call sequences within the kernel. This information is used to sidestep the problems arising from indirect function calls when carrying out interprocedural compiler optimization. It drives a variety of compiler optimizations such as function inlining and code specialization that reduce the execution overheads along frequent paths. A prototype implementation that uses the PLTO binary rewriting system to specialize the Linux kernel is described. While overall performance data are mixed, the improvements we see argue for the potential of this approach.