Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1maCFH-0006tb-K9 for mharc-grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCFA-0006r7-NL for grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:36 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:44959) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maCF6-0006Kh-SX for grub-devel@gnu.org; Tue, 12 Oct 2021 03:30:36 -0400 Received: by mail-pf1-x42c.google.com with SMTP id w6so5337070pfd.11 for ; Tue, 12 Oct 2021 00:30:32 -0700 (PDT) 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=w1J1e/cU47j94Ck5CwkSkYGWMPKptwVhKsGKWbbHjjY=; b=YnpUcVVdi+V2Z8bxS5F8FZVeBa92QleBhS/7U3KK7FbsbJ5biANJzpa0K6lxbHZTIv 5/zvh5O9OycgBg2fAwsZIS3QEiyEMmDhUBknf5RWLXS9MyVMCeocfqWeXf8Vfukm1HnM 9xPG9a00ki5qQvTk7/Gh73TCu9zgCqnYZwkHA= 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=w1J1e/cU47j94Ck5CwkSkYGWMPKptwVhKsGKWbbHjjY=; b=Ics0cSjsc9+PTeTD5nDzTv/jbwrBx0dsmsWObaQ7S8DhIT0+VbOHVylKeYBrbXJNwD ETdS6riU8wutmprntRu6xhkVGRsGU4SDd9b3x0AKpTQ4DlswG3am1lefYqCSS2G41cwF WxX4jGnLZeATpZP1barDcerip8UjQ+t5xaUv3lnGrXtX2gHX2nRv+TJ0/utdgoMny1CL /6Lm23QeJCQz9TT2qPX4xluJWx7VJADnd71i0iv1JSTTaX19Kmt7s6/Wh3bqMsQmycKm eYnPHHNQt+7E1Mwl1cEhmjGv8Fi86is/KkioZpU1z+raIMCOAPKZp3qKxN57IVhAoxwM vCwA== X-Gm-Message-State: AOAM531rwZYNoJUMlQ+EDzGj/Sv0J3V+rAx5l+0E885kVWZl1TDpFc2F cTYt+VZm0pgUZuIr0lOWbaRp6cDNaHONcw== X-Google-Smtp-Source: ABdhPJwY0sCyWj36r27o08PWh5IkjWJBV4qgjpS0qgnFpDT1oPQZnPZmugjZy3kvkHGtko5wRDY4Hw== X-Received: by 2002:a62:cd0f:0:b0:447:b8fe:d6c2 with SMTP id o15-20020a62cd0f000000b00447b8fed6c2mr29748639pfg.70.1634023831189; Tue, 12 Oct 2021 00:30:31 -0700 (PDT) Received: from localhost ([2001:4479:e300:600:41fe:d15:934f:4029]) by smtp.gmail.com with ESMTPSA id r130sm10014348pfc.89.2021.10.12.00.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 00:30:30 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl, Daniel Axtens Subject: [PATCH 03/19] mm: document grub internal memory management structures Date: Tue, 12 Oct 2021 18:29:52 +1100 Message-Id: <20211012073008.4059133-4-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211012073008.4059133-1-dja@axtens.net> References: <20211012073008.4059133-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=dja@axtens.net; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 07:30:37 -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 --- include/grub/mm_private.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h index c2c4cb1511c6..e80a059dd4e4 100644 --- a/include/grub/mm_private.h +++ b/include/grub/mm_private.h @@ -25,11 +25,18 @@ #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. A circular list. + Only meaningful if the block is free. + */ struct grub_mm_header *next; + /* The region size in cells (not 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 mm.c. */ #if GRUB_CPU_SIZEOF_VOID_P == 4 char padding[4]; #elif GRUB_CPU_SIZEOF_VOID_P == 8 @@ -48,11 +55,25 @@ 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.30.2