Message ID | 20250224-page-alloc-kunit-v1-0-d337bb440889@google.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96D8BC19776 for <linux-mm@archiver.kernel.org>; Mon, 24 Feb 2025 14:47:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15C766B009D; Mon, 24 Feb 2025 09:47:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10CF06B009E; Mon, 24 Feb 2025 09:47:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F16406B009F; Mon, 24 Feb 2025 09:47:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D44D56B009D for <linux-mm@kvack.org>; Mon, 24 Feb 2025 09:47:31 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CF31815CD for <linux-mm@kvack.org>; Mon, 24 Feb 2025 14:47:31 +0000 (UTC) X-FDA: 83155116702.21.38BF61D Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf27.hostedemail.com (Postfix) with ESMTP id 2E0AD4000A for <linux-mm@kvack.org>; Mon, 24 Feb 2025 14:47:28 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UxtTCzIY; spf=pass (imf27.hostedemail.com: domain of 3f4a8ZwgKCMIriksuivjowwotm.kwutqv25-uus3iks.wzo@flex--jackmanb.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3f4a8ZwgKCMIriksuivjowwotm.kwutqv25-uus3iks.wzo@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740408449; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=lY/f60hP8VWKJvO3bIE0M//2ttPDqncPJc81wpWwDM0=; b=I7L7LtKl0E598oiX2sOn79NncB80bfBsWsXYydIcjc8DooM+b+7b3cWJVNccJpEpP7JAvs /NzBtjsO7vpzDzqWZJcDEGOeOt/GYZ4jyJe8yf64rrHOG5R4SovK+AsG7IILbWbf5UeuHl +uDLUQbLWS56TJ8ePYaofOmH2Zmo8Hg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UxtTCzIY; spf=pass (imf27.hostedemail.com: domain of 3f4a8ZwgKCMIriksuivjowwotm.kwutqv25-uus3iks.wzo@flex--jackmanb.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3f4a8ZwgKCMIriksuivjowwotm.kwutqv25-uus3iks.wzo@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740408449; a=rsa-sha256; cv=none; b=PjIOn55ec+Zr2JYRKlpIhLS+onh08A6xNZhzpq0bfjPs4LiJihqlo4wJe2jC2wtiwqEqQR 5hypSXvlvMVuzcNwoANaJvNjGrwuDonjJLuNnWtDKLz6FUOU5f5MpRG1BFcE37n7e47SQ6 YEZ5ZRmEItbgT5tYb2nAf1unOFXa5uA= Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38f44be93a8so2399656f8f.1 for <linux-mm@kvack.org>; Mon, 24 Feb 2025 06:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740408447; x=1741013247; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lY/f60hP8VWKJvO3bIE0M//2ttPDqncPJc81wpWwDM0=; b=UxtTCzIYNJDv21Q7YPO/Arnj+g1fFiQjMHIHNfefi53YS0A3itEwBSUtjXCx3rSi/k VPqbZpzpHzer/Jm5ZtMCJqeRNkfXK+12ZQ9Vy5HYPeHvrC6P7tE+vlIuFrQ1rvZebAWE TAXf97how0I1ZDwc29WvQZKzbhnzhY9JkS0u9kHjViV6v2ZjXgorBF5xbvHfZ7ZDexut kCfYWLvar8OGzG0dEUgI9IYZKU7s90E/1axgQjvx4p7H8RjVoFh6brQ76dXNqbZGdccA SRGswXQ35QEkyO0+PreySD2WiUIo1OwGgrkhu/wSATG3cfBDdij7xKV490d+CgGnLyXY gQYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740408447; x=1741013247; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lY/f60hP8VWKJvO3bIE0M//2ttPDqncPJc81wpWwDM0=; b=tQ9I/EdyLh9IalhqDkmUsCHCpcO69gE6gnGKFnEsgQ9rpjKDWkkTKHCkYHthfUvXlj /SeFOhIEH5J3XH8e4BCrL5HPpsLShEGgItjtsB56BpXoOQ8Bfix6LbErXq96TnwRsJtG uheYo66zDGsTy6ldResFQ5f91tDJcMObllL66xozNjX6hv6sZCimvhYMC3G1rq+erM1e Au9J9erxERE3z8vDRBGvHyaGNCc2gUMj3JhCZrh04PPGHidQEkQdwzjWr7E5a9ORD+Ec /fN0yjqHukvfTc5slQ3JbXdDeIz2MCRlQJh4xS0BTx6ni8OXnb+QcA3sJZ4J3uUIqiFJ 7PLw== X-Forwarded-Encrypted: i=1; AJvYcCWvCNp3NKlEIstN+VqdT1fIUQAduM/i8fXr/2C28ZztePOhFJfhoI03I6kSQ8pmll/XzLTmMjYgbQ==@kvack.org X-Gm-Message-State: AOJu0YyGUdyF03jZffLqUlwnJzrPMkh9sPZHks0/ErCm4m+8FPpTDzkJ nWnsCLbeF9JvjNL1gIX8oxQ3mXAMuqF/IcT59oJrtGChNLURaVccCvWUOiRoLlqzPPTylTxjYRl 5s2B1XY7aUw== X-Google-Smtp-Source: AGHT+IENgoTDlWe0ZNnHReuth/Sr7TVUqQE1u7CvzpuJvSEXob7jKOT1xXN1OI0qw1ZLFVKDzieKdDescRaUUQ== X-Received: from wmbec10.prod.google.com ([2002:a05:600c:610a:b0:439:98ca:e39d]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:598d:0:b0:38f:3c8a:4c0a with SMTP id ffacd0b85a97d-38f6e7539b7mr7384989f8f.7.1740408447541; Mon, 24 Feb 2025 06:47:27 -0800 (PST) Date: Mon, 24 Feb 2025 14:47:10 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAG6GvGcC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1MDI0NL3YJEoFhiTk5+sm52aV5miW5KmrlZappFikVqkqUSUFtBUWpaZgX YyGilIDdnpdjaWgA2v9x7ZwAAAA== X-Change-Id: 20250219-page-alloc-kunit-df76ef8d8eb9 X-Mailer: b4 0.15-dev Message-ID: <20250224-page-alloc-kunit-v1-0-d337bb440889@google.com> Subject: [PATCH RFC 0/4] mm: KUnit tests for the page allocator From: Brendan Jackman <jackmanb@google.com> To: Brendan Higgins <brendan.higgins@linux.dev>, David Gow <davidgow@google.com>, Rae Moar <rmoar@google.com>, Andrew Morton <akpm@linux-foundation.org>, David Hildenbrand <david@redhat.com>, Oscar Salvador <osalvador@suse.de> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>, Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@kernel.org>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Brendan Jackman <jackmanb@google.com>, Yosry Ahmed <yosry.ahmed@linux.dev> Content-Type: text/plain; charset="utf-8" X-Rspam-User: X-Stat-Signature: uqemtjoca7ie8tf7rka88fe871qbd4sa X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2E0AD4000A X-HE-Tag: 1740408448-521014 X-HE-Meta: U2FsdGVkX1+P2sAc3ixTjqCGJwOHDAzC6hFsHsVVapdZrN+/Qxv6z3xVNG89qKmtchUBgMK+PEp72iegPNqbjqvHLf+Y/ympSxKTeRlmeifvG733okC8QcRsfDBocmR24sMcXfbaRXFO43hcTum39FtRgRNe0IjT060XrNIoMnDOodhJucSstaJmYFxBjC3kQOmpYtOgpQDcb36qokElytw15Mfb5Y0TpjTaPJJicwmDVyuEdtCqteLNut9fotmvGfTJephAajeiiD5UfgPsy9bCAEYJEybmPv6iiMPyeDuh7RjbwgBTX4hmT8LoHaDADWQunk0LaCCGoKygo46rNMOKkNU0O+JyyWBm4d0rx7NNP4/GQK9GuAlOw00eHlDcIWqj34ldG/IAqzPei6bqnpSxrFMmw+RVhAPQ9d6VVn8Bi8WWE51uvcXPExfw5dEaWP335hak/kKAi8nb6TLbl1xn6L+3CSUpKnBOVUeXwpJ56EH6z95IcyiZ6StY3fKPv2pzHCexU2YYtNtE/754GTlsuP86OjjPEY4OO2efDTyA2Awf+TyATXRCdCdHu+NinGdHYoj1Am9tkvYTeOKo3YS2B0VVhAStYucwe+r7sn0bg5uZkLd/zjBd2K2N/QbWbg2tuVDUMXZKuy9iquyVw5PIsbDUoGFYAEw4xRo0jwjTf+ZzcLzTrm9tR7NHHsMWKchNSEMT/f3fMV5tRKmPGEMsk0tpytwdkTZURt5P9Zc/khaH8jSiDAW2GkGHGP1xjvWWTf9n+iQ+mYPmK4jqvasyEsnT4RSnFq3iUFNnsIykGIroc7SCUi9y5NhsW8QRR+UqBAgS5JD/buDnqLO4nRauAETLUM+YcGt3R1WNdWbRMg0dxQZbdA9TudOvdL9qaPYUUPeFD9ONZjxvckm3yxKKIolNAzttpMjzhNMAXW1eg9gOTNiy4LMKn9iwpmkr88XIMJoOI+O5ga6gD6S f6G2qM9O YfMba0pAsHUgRuR1U3KC2nsF6FmLsG7Ho/liRD4VT+m0lZR49XYG/kmuV9nh7S68Ftwm555wZP5wxAy94LbuVNR5lpUFKL3Id+RvM94Er+jlzCfjVut9catAaHOuOSBJSGTcaEGd26gMTAIbwahLl2fJ4YihTesoPz907ykgu07W3CI0QDcAApNAANEQj8q2mR3GZMPnpyhwhWwdLMhkXcHil2qT8noPGkXHuvPOJNcw9mSVTQl7OoYI253Aei1kHm+hq4/Z90dpiJsdJaq5w9JjHDYqzwRmhbjZPvFDMEEtYcuK83rAPFUuePsI1sB6bJvS24MtBfbE5SJm2ZkXwCqGOc8Xq8uG7eiDb69V3dYyYfc7P/uYr66J1NV7f3ySigfqYUpkod6+hJED5aGzyDpFbDO9pF/WJqm0INwdC/uPeso5VVB/Gr417XJ4ArmmpFchU7JiOqO3cr7LIkxQH0jYDV1GbX/LaQnNDsqXyi2RQU7oh1rvlveKwGfFSa8SOFi6ysh2sETJw0OBK+Oz/mxW1Xdca+A1v5ZGAYQAwC+n1elkuTDYJ8nvUzYxE+zXKU1pIlVUmxCEnU28= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series | mm: KUnit tests for the page allocator | expand |
The page allocator does a lot of stuff that is not visible to the user in any deterministic way. But this stuff is still important and it would be nice to test that behaviour. KUnit is a tool for unit-testing kernel-internal APIs. This is an attempt to adopt it the page allocator. I have been hacking on this as a way to try and test the code I'm writing for my ASI page_alloc integration proposal [0]. It's been extremely useful to be able to "just call it and see what it does". So I wanna gather some feedback on whether this basic idea is of interest before I invest too much more time in it. You can run these tests like this: tools/testing/kunit/kunit.py run \ --arch=x86_64 --kernel_args="movablecore=2G" \ --qemu_args="-m 4G" --kunitconfig mm/.kunitconfig Unit-testing code that has mutable global variables can be a pain. Unit-testing code with mutable global variables _that can change concurrently with the tests_ is basically impossible. So, we need some way to isolate an "instance" of the allocator that doesn't refer to any such concurrently-mutated state. Luckily, the allocator only has one really important global variable: node_data. So, the approach here is to carve out a subset of that variable which is as isolated as possible from the rest of rthe system, which can be used for deterministic testing. This is achieved by crating a fake "isolated" node at boot, and plugging in memory at test init time. This is an RFC and not a PATCH because: 1. I have not taken much care to ensure the isolation is complete. There are probably sources of flakiness and nondeterminism in here. 2. I suspect the the basic idea might be over-complicated: do we really need memory hotplug here? Do we even need the instance of the allocator we're testing to actual memory behind the pages it's allocating, or could we just hallucinate a new region of vmemmap without any of that awkwardness? One significant downside of relying on memory hotplug is that the test won't run if we can't hotplug anything out. That means you have to fiddle with the platform to even run the tests - see the --kernel_args and --qemu_args I had to add to my kunit.py command above. So yeah, other suggestions welcome. 2b. I'm not very confident I'm using the hotplug API properly. 3. There's no point in merging this without actually having at least a few tests that are actually interesting! Maybe a "build it and they will come" approach can be justified to some extent, but there's a nonzero cost to the infrastructure so we should probably have some confidence that they will indeed come. [0] https://lore.kernel.org/linux-mm/20250129144320.2675822-1-jackmanb@google.com/ Signed-off-by: Brendan Jackman <jackmanb@google.com> --- Brendan Jackman (4): kunit: Allocate assertion data with GFP_ATOMIC mm/page_alloc_test: Add empty KUnit boilerplate mm/page_alloc_test: Add logic to isolate a node for testing mm/page_alloc_test: Add smoke-test for page allocation drivers/base/memory.c | 5 +- include/linux/memory.h | 4 + include/linux/nodemask.h | 13 +++ kernel/kthread.c | 3 + lib/kunit/assert.c | 2 +- lib/kunit/resource.c | 2 +- lib/kunit/test.c | 2 +- mm/.kunitconfig | 10 ++ mm/Kconfig | 8 ++ mm/Makefile | 2 + mm/internal.h | 11 ++ mm/memory_hotplug.c | 26 +++-- mm/numa_memblks.c | 22 ++++ mm/page_alloc.c | 37 +++++- mm/page_alloc_test.c | 296 +++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 429 insertions(+), 14 deletions(-) --- base-commit: d082ecbc71e9e0bf49883ee4afd435a77a5101b6 change-id: 20250219-page-alloc-kunit-df76ef8d8eb9 Best regards,