Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mpu7I-0005fz-UM for mharc-grub-devel@gnu.org; Wed, 24 Nov 2021 10:23:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpu79-0005eL-R6 for grub-devel@gnu.org; Wed, 24 Nov 2021 10:23:17 -0500 Received: from [2607:f8b0:4864:20::632] (port=43841 helo=mail-pl1-x632.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpu72-0000ax-3Y for grub-devel@gnu.org; Wed, 24 Nov 2021 10:23:15 -0500 Received: by mail-pl1-x632.google.com with SMTP id m24so2111835pls.10 for ; Wed, 24 Nov 2021 07:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jYxk8GJNWnFVKnE1OyyfH9V+sNMz2qI6JXT9TYgZrrg=; b=oC/NA3H0nwKfQ/4CBx0kpA7PUVOEjc5bOlE1bxfzsrucGjsyY0om9mCuqxf8MzPOAf wUIlNt1wHLoIxdIKm6Mw+HdN5UQxR4GkXFQkCe1zBNIJgZNeDgFu8tw0FUBppf0R/2+O bL+XEwDhzWM0Dciu25t04kmsVoAxqcNf26qrk= 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=jYxk8GJNWnFVKnE1OyyfH9V+sNMz2qI6JXT9TYgZrrg=; b=Kkm329qwE1/nru7whYkcKUVBDk9Z8c2eLHAjaAFm/jtnpkv+tXi0W/nPkl4w9lRzhZ rz27fbV3VUOJTndVvIqTAr0gzVm3Ckv1TvLzT7BvbECSFuSdl/3S622elEnxl9NpHPPA MAymdFCWbDFuJq0cVMKbeNfspfClgyQwZhlyHACew7azcwYxMtexEbIg4IysZFk/3Gzb xBt2pxJ8pfrt/9JEHnEjqgFTg/SgzvW1s5TNV8mFcYF8oNV2rDGpIsdJpzCYjcbinyjQ 8V5DDfSB0959wSMuS/I6sTmFEd2p+tU0uwPDlaSM5d8hUueU4OfEYZwXa7uXvkLEKv3B 8rZQ== X-Gm-Message-State: AOAM530BTlV+SOwIiODGDp5ZooN58L+pjgW8G8fEX19b0cpOMXkJnTze KbRH+WMcovLTUy2UC9i9X9eX117GGxacLA== X-Google-Smtp-Source: ABdhPJzD8GA+c8zAlpElw4hyssJNr7A+XJzcRJ5dNK1xOiNS56/taEzPE+y5QO8REjzkBEQKFZ0rZQ== X-Received: by 2002:a17:90a:6b44:: with SMTP id x4mr10030836pjl.27.1637767377881; Wed, 24 Nov 2021 07:22:57 -0800 (PST) Received: from localhost ([2001:4479:e000:e400:9826:f987:bef5:b0c4]) by smtp.gmail.com with ESMTPSA id o7sm93205pjf.33.2021.11.24.07.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 07:22:57 -0800 (PST) From: Daniel Axtens To: grub-devel@gnu.org Cc: development@efficientek.com, dkiper@net-space.pl, Daniel Axtens Subject: [PATCH 1/6] mm: document grub internal memory management structures Date: Thu, 25 Nov 2021 02:22:45 +1100 Message-Id: <20211124152250.1040794-2-dja@axtens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211124152250.1040794-1-dja@axtens.net> References: <20211124152250.1040794-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::632 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=dja@axtens.net; helo=mail-pl1-x632.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 15:23:18 -0000 I spent more than a trivial quantity of time figuring out pre_size and whether a memory region's size contains the header cell or not. Document the meanings of all the properties. Hopefully now no-one else has to figure it out! Signed-off-by: Daniel Axtens --- This version: thanks to Glenn Washburn for catching various issues. --- include/grub/mm_private.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h index c2c4cb1511c6..203533cc3d42 100644 --- a/include/grub/mm_private.h +++ b/include/grub/mm_private.h @@ -21,15 +21,27 @@ #include +/* For context, see kern/mm.c */ + /* Magic words. */ #define GRUB_MM_FREE_MAGIC 0x2d3c2808 #define GRUB_MM_ALLOC_MAGIC 0x6db08fa4 +/* A header describing a block of memory - either allocated or free */ typedef struct grub_mm_header { + /* + * The 'next' free block in this region's circular free list. + * Only meaningful if the block is free. + */ struct grub_mm_header *next; + /* The block size, not in bytes but the number of cells of + * GRUB_MM_ALIGN bytes. Includes the header cell. + */ grub_size_t size; + /* either free or alloc magic, depending on the block type. */ grub_size_t magic; + /* pad to cell size: see the top of kern/mm.c. */ #if GRUB_CPU_SIZEOF_VOID_P == 4 char padding[4]; #elif GRUB_CPU_SIZEOF_VOID_P == 8 @@ -48,11 +60,27 @@ typedef struct grub_mm_header #define GRUB_MM_ALIGN (1 << GRUB_MM_ALIGN_LOG2) +/* A region from which we can make allocations. */ typedef struct grub_mm_region { + /* The first free block in this region. */ struct grub_mm_header *first; + + /* + * The next region in the linked list of regions. Regions are initially + * sorted in order of increasing size, but can grow, in which case the + * ordering may not be preserved. + */ struct grub_mm_region *next; + + /* + * A grub_mm_region will always be aligned to cell size. The pre-size is + * the number of bytes we were given but had to skip in order to get that + * alignment. + */ grub_size_t pre_size; + + /* How many bytes are in this region? (free and allocated) */ grub_size_t size; } *grub_mm_region_t; -- 2.32.0