From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 900EEC433EF for ; Mon, 28 Feb 2022 14:47:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 347068D000C; Mon, 28 Feb 2022 09:47:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CE198D0001; Mon, 28 Feb 2022 09:47:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BD778D000C; Mon, 28 Feb 2022 09:47:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 0C6778D0001 for ; Mon, 28 Feb 2022 09:47:36 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BED1E8249980 for ; Mon, 28 Feb 2022 14:47:35 +0000 (UTC) X-FDA: 79192467270.19.32E0ACC Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf20.hostedemail.com (Postfix) with ESMTP id 558601C0002 for ; Mon, 28 Feb 2022 14:47:35 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id i11so21799169lfu.3 for ; Mon, 28 Feb 2022 06:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lhOyf5GwOxdKBxOHGEH+WB1RGf3JKbPOT7zY+wvKvpo=; b=S+RYY8RZ9EY5+hvJbl5XGbgTDwm4dDMevg8gng2DAjAhl+hzUfE5UpuJSqCdFVEj6S 1NTKYB/mBo70ZGoXWtvtyiM9JUFXiNDPjC15lzvTfVKFbE5L80OlYxlhfNBuerMl5G+n ui/eQHpHBct16ZEW+G8lmCPtNEM1H+hW3N+RF+/RaN8wopIAT19HIxjs9I0BRL6QrZ++ R7L4VouiGAzcat4lhiB5eD4VzqEAFfMNMhp1JdxXgVlfJUcDnRk9ytRH1dbF0G9qaBh3 2fGj7gsDXPyuxL7Kq+mujwCFhBMaxOsEGU21ox6+WMSjuDLRfWScfZE44aYCLm442trM IXrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lhOyf5GwOxdKBxOHGEH+WB1RGf3JKbPOT7zY+wvKvpo=; b=IRhTZ3q3eWvuWqjeDqtLJxxkBMhhF7hOAL5UNKTzafocW3atWTDqbY10L7X4bbrM1g gL72TWat1Fp253axUnYUL6/14JlErXGbj9YvDBLsEbmSFr78OIuV9nxdEuHCWvM410Yr rIRYcfXjxuCPv8K2KvGM1RXNVmOK2DXMOz6WYNjuSuJyWbMwi5Wf0Wqw3qV0xcm7Z6Iz kft5WN2RpHzRBtuZVy5ND/A58WOC9+jU4WrUVdSuoB92mm8NjvXOelIW58hwO0CCWj+U v4QBl1SyRlTnIkdlqiAkIAlVI7pbCS65IJ0POjMsZehrXS2wvy9B8nI968MC0UkEW7oB us5A== X-Gm-Message-State: AOAM532jLoTFiJioApPdcY8cUWQrQPVhSNh2SQGyzKnNC75p+3QJGvWf qjuoZW8tIZd6Y3C45enKeJxF5B/6nR4= X-Google-Smtp-Source: ABdhPJyEeKoOELU4Hs0AN+LD8C7bjctTAL8b1xrVTD9IoYA74oJXqlKROxJpkA1Hu5bWjLvvy2pu4w== X-Received: by 2002:a05:6512:34d4:b0:442:a9c5:8e37 with SMTP id w20-20020a05651234d400b00442a9c58e37mr13051807lfr.362.1646059653785; Mon, 28 Feb 2022 06:47:33 -0800 (PST) Received: from elysium.toya.net.pl (staticline-31-183-165-244.toya.net.pl. [31.183.165.244]) by smtp.gmail.com with ESMTPSA id r14-20020ac252ae000000b00443f3cbc03asm993996lfm.6.2022.02.28.06.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 06:47:33 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: rppt@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH 9/9] memblock tests: Add TODO and README files Date: Mon, 28 Feb 2022 15:46:51 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: cr9m78ihtrwwwfgkdtztyyqgppt6biy4 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=S+RYY8RZ; spf=pass (imf20.hostedemail.com: domain of karolinadrobnik@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=karolinadrobnik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: 558601C0002 X-HE-Tag: 1646059655-527301 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add description of the project, its structure and how to run it. List what is left to implement and what the known issues are. Signed-off-by: Karolina Drobnik --- tools/testing/memblock/README | 114 ++++++++++++++++++++++++++++++++++ tools/testing/memblock/TODO | 28 +++++++++ 2 files changed, 142 insertions(+) create mode 100644 tools/testing/memblock/README create mode 100644 tools/testing/memblock/TODO diff --git a/tools/testing/memblock/README b/tools/testing/memblock/READM= E new file mode 100644 index 000000000000..40c0ce50e7c2 --- /dev/null +++ b/tools/testing/memblock/README @@ -0,0 +1,114 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + Memblock simulator +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + + +Introduction +--------------------- + +Memblock is a boot time memory allocator[1] that manages memory regions = before +the actual memory management is initialized. Its APIs allow to register = physical +memory regions, mark them as available or reserved, allocate a block of = memory +within the requested range and/or in specific NUMA node, and many more. + +Because it is used so early in the booting process, testing and debuggin= g it is +difficult. This test suite, usually referred as memblock simulator, is +an attempt at testing the memblock mechanism. It runs one monolithic tes= t that +consist of a series of checks that exercise both the basic operations an= d +allocation functionalities of memblock. The main data structure of the b= oot time +memory allocator is initialized at the build time, so the checks here re= use its +instance throughout the duration of the test. To ensure that tests don't= affect +each other, region arrays are reset in between. + +As this project uses the actual memblock code and has to run in user spa= ce, some +of the kernel definitions were stubbed in the introductory patch[2]. Mos= t of +them don't match the kernel implementation, so one should consult them f= irst +before making any significant changes to the project. + + +Usage +--------------------- + +To run the tests, build the main target and run it: + +$ make; ./main + +A successful run produces no output. It is also possible to override dif= ferent +configuration parameters. For example, to simulate enabled NUMA, use: + +$ make NUMA=3D1 + +For the full list of options, see `make help`. + + +Project structure +--------------------- + +The project has one target, main, which calls a group of checks for basi= c and +allocation functions. Tests for each group are defined in dedicated file= s, as it +can be seen here: + +memblock +|-- asm ------------------, +|-- lib |-- implement function and struct stubs +|-- linux ------------------' +|-- scripts +| |-- Makefile.include -- handles `make` parameters +|-- tests +| |-- alloc_api.(c|h) -- memblock_alloc tests +| |-- alloc_helpers_api.(c|h) -- memblock_alloc_from tests +| |-- alloc_nid_api.(c|h) -- memblock_alloc_try_nid tests +| |-- basic_api.(c|h) -- memblock_add/memblock_reserve/... te= sts +| |-- common.(c|h) -- helper functions for resetting membl= ock; +|-- main.c --------------. dummy physical memory definition +|-- Makefile `- test runner +|-- README +|-- TODO +|-- .gitignore + + +Simulating physical memory +-------------------------- + +Some allocation functions clear the memory in the process, so it is requ= ired for +memblock to track valid memory ranges. To achieve this, the test suite r= egisters +with memblock memory stored by test_memory struct. It is a small wrapper= that +points to a block of memory allocated via malloc. For each group of allo= cation +tests, dummy physical memory is allocated, added to memblock, and then r= eleased +at the end of the test run. The structure of a test runner checking allo= cation +functions is as follows: + +int memblock_alloc_foo_checks(void) +{ + reset_memblock_attributes(); /* data structure reset */ + dummy_physical_memory_init(); /* allocate and register memory */ + + (...allocation checks...) + + dummy_physical_memory_cleanup(); /* free the memory */ +} + +There's no need to explicitly free the dummy memory from memblock via +memblock_free() call. The entry will be erased by reset_memblock_regions= (), +called at the beginning of each test. + + +Known issues +--------------------- + +1. Requesting a specific NUMA node via memblock_alloc_node() does not wo= rk as + intended. Once the fix is in place, tests for this function can be ad= ded. + +2. Tests for memblock_alloc_low() can't be easily implemented. The funct= ion uses + ARCH_LOW_ADDRESS_LIMIT marco, which can't be changed to point at the = low + memory of the memory_block. + + +References +--------------------- + +1. Boot time memory management documentation page: + https://www.kernel.org/doc/html/latest/core-api/boot-time-mm.html + +2. Introduce memblock simulator, lore link: +https://lore.kernel.org/linux-mm/cover.1643796665.git.karolinadrobnik@gm= ail.com/ diff --git a/tools/testing/memblock/TODO b/tools/testing/memblock/TODO new file mode 100644 index 000000000000..c25b2fdec45e --- /dev/null +++ b/tools/testing/memblock/TODO @@ -0,0 +1,28 @@ +TODO +=3D=3D=3D=3D=3D + +1. Add verbose output (e.g., what is being tested and how many tests cas= es are + passing) + +2. Add flags to Makefile: + + verbosity level + + enable memblock_dbg() messages (i.e. pass "-D CONFIG_DEBUG_MEMORY_I= NIT" + flag) + +3. Add tests trying to memblock_add() or memblock_reserve() 129th region= . + This will trigger memblock_double_array(), make sure it succeeds. + *Important:* These tests require valid memory ranges, use dummy physi= cal + memory block from common.c to implement them. It is also= very + likely that the current MEM_SIZE won't be enough for the= se + test cases. Use realloc to adjust the size accordingly. + +4. Add test cases using this functions (implement them for both directio= ns): + + memblock_alloc_raw() + + memblock_alloc_exact_nid_raw() + + memblock_alloc_try_nid_raw() + +5. Add tests for memblock_alloc_node() to check if the correct NUMA node= is set + for the new region + +6. Update comments in tests/basic_api.c to match the style used in + tests/alloc_*.c -- 2.30.2