[RFC PATCH 3/7] lmb: Rename free_mem to available_mem

Ilias Apalodimas ilias.apalodimas at linaro.org
Sun Dec 8 15:30:18 CET 2024


On Sun, 8 Dec 2024 at 13:53, Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> Am 8. Dezember 2024 11:52:06 MEZ schrieb Ilias Apalodimas <ilias.apalodimas at linaro.org>:
> >free_mem is a misnomer. We never update that with the actual free
> >memory. Instead this field describes all available memory and it's
> >checked against used_mem to decide if a memory area is free or not.
> >So rename it to something that better describes its usage.
> >
> >Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> >---
> > include/lmb.h     |  4 ++--
> > lib/lmb.c         | 34 +++++++++++++++++-----------------
> > test/cmd/bdinfo.c |  2 +-
> > test/lib/lmb.c    |  2 +-
> > 4 files changed, 21 insertions(+), 21 deletions(-)
> >
> >diff --git a/include/lmb.h b/include/lmb.h
> >index 62882464f866..54af5b0e4b44 100644
> >--- a/include/lmb.h
> >+++ b/include/lmb.h
> >@@ -47,12 +47,12 @@ struct lmb_region {
> > /**
> >  * struct lmb - The LMB structure
> >  *
> >- * @free_mem: List of free memory regions
> >+ * @free_mem: List of all available memory
>
> %s/free/available/

Sure, did you find anything else wrong with this patch?

Thanks
/Ilias
>
> >  * @used_mem: List of used/reserved memory regions
> >  * @test:     Is structure being used for LMB tests
> >  */
> > struct lmb {
> >-      struct alist free_mem;
> >+      struct alist available_mem;
> >       struct alist used_mem;
> >       bool test;
> > };
> >diff --git a/lib/lmb.c b/lib/lmb.c
> >index c7bf5120696f..ffdd23d87b9b 100644
> >--- a/lib/lmb.c
> >+++ b/lib/lmb.c
> >@@ -350,7 +350,7 @@ int io_lmb_setup(struct lmb *io_lmb)
> > {
> >       int ret;
> >
> >-      ret = alist_init(&io_lmb->free_mem, sizeof(struct lmb_region),
> >+      ret = alist_init(&io_lmb->available_mem, sizeof(struct lmb_region),
> >                        (uint)LMB_ALIST_INITIAL_SIZE);
> >       if (!ret) {
> >               log_debug("Unable to initialise the list for LMB free IOVA\n");
> >@@ -371,13 +371,13 @@ int io_lmb_setup(struct lmb *io_lmb)
> >
> > void io_lmb_teardown(struct lmb *io_lmb)
> > {
> >-      alist_uninit(&io_lmb->free_mem);
> >+      alist_uninit(&io_lmb->available_mem);
> >       alist_uninit(&io_lmb->used_mem);
> > }
> >
> > long io_lmb_add(struct lmb *io_lmb, phys_addr_t base, phys_size_t size)
> > {
> >-      return lmb_add_region_flags(&io_lmb->free_mem, base, size, LMB_NONE);
> >+      return lmb_add_region_flags(&io_lmb->available_mem, base, size, LMB_NONE);
> > }
> >
> > /* derived and simplified from _lmb_alloc_base() */
> >@@ -387,9 +387,9 @@ phys_addr_t io_lmb_alloc(struct lmb *io_lmb, phys_size_t size, ulong align)
> >       phys_addr_t base = 0;
> >       phys_addr_t res_base;
> >       struct lmb_region *lmb_used = io_lmb->used_mem.data;
> >-      struct lmb_region *lmb_memory = io_lmb->free_mem.data;
> >+      struct lmb_region *lmb_memory = io_lmb->available_mem.data;
> >
> >-      for (i = io_lmb->free_mem.count - 1; i >= 0; i--) {
> >+      for (i = io_lmb->available_mem.count - 1; i >= 0; i--) {
> >               phys_addr_t lmbbase = lmb_memory[i].base;
> >               phys_size_t lmbsize = lmb_memory[i].size;
> >
> >@@ -514,7 +514,7 @@ static void lmb_dump_region(struct alist *lmb_rgn_lst, char *name)
> > void lmb_dump_all_force(void)
> > {
> >       printf("lmb_dump_all:\n");
> >-      lmb_dump_region(&lmb.free_mem, "memory");
> >+      lmb_dump_region(&lmb.available_mem, "memory");
> >       lmb_dump_region(&lmb.used_mem, "reserved");
> > }
> >
> >@@ -650,7 +650,7 @@ static long lmb_add_region(struct alist *lmb_rgn_lst, phys_addr_t base,
> > long lmb_add(phys_addr_t base, phys_size_t size)
> > {
> >       long ret;
> >-      struct alist *lmb_rgn_lst = &lmb.free_mem;
> >+      struct alist *lmb_rgn_lst = &lmb.available_mem;
> >
> >       ret = lmb_add_region(lmb_rgn_lst, base, size);
> >       if (ret)
> >@@ -706,9 +706,9 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align,
> >       phys_addr_t base = 0;
> >       phys_addr_t res_base;
> >       struct lmb_region *lmb_used = lmb.used_mem.data;
> >-      struct lmb_region *lmb_memory = lmb.free_mem.data;
> >+      struct lmb_region *lmb_memory = lmb.available_mem.data;
> >
> >-      for (i = lmb.free_mem.count - 1; i >= 0; i--) {
> >+      for (i = lmb.available_mem.count - 1; i >= 0; i--) {
> >               phys_addr_t lmbbase = lmb_memory[i].base;
> >               phys_size_t lmbsize = lmb_memory[i].size;
> >
> >@@ -800,10 +800,10 @@ static phys_addr_t _lmb_alloc_addr(phys_addr_t base, phys_size_t size,
> >                                   enum lmb_flags flags)
> > {
> >       long rgn;
> >-      struct lmb_region *lmb_memory = lmb.free_mem.data;
> >+      struct lmb_region *lmb_memory = lmb.available_mem.data;
> >
> >       /* Check if the requested address is in one of the memory regions */
> >-      rgn = lmb_overlaps_region(&lmb.free_mem, base, size);
> >+      rgn = lmb_overlaps_region(&lmb.available_mem, base, size);
> >       if (rgn >= 0) {
> >               /*
> >                * Check if the requested end address is in the same memory
> >@@ -854,10 +854,10 @@ phys_size_t lmb_get_free_size(phys_addr_t addr)
> >       int i;
> >       long rgn;
> >       struct lmb_region *lmb_used = lmb.used_mem.data;
> >-      struct lmb_region *lmb_memory = lmb.free_mem.data;
> >+      struct lmb_region *lmb_memory = lmb.available_mem.data;
> >
> >       /* check if the requested address is in the memory regions */
> >-      rgn = lmb_overlaps_region(&lmb.free_mem, addr, 1);
> >+      rgn = lmb_overlaps_region(&lmb.available_mem, addr, 1);
> >       if (rgn >= 0) {
> >               for (i = 0; i < lmb.used_mem.count; i++) {
> >                       if (addr < lmb_used[i].base) {
> >@@ -871,8 +871,8 @@ phys_size_t lmb_get_free_size(phys_addr_t addr)
> >                       }
> >               }
> >               /* if we come here: no reserved ranges above requested addr */
> >-              return lmb_memory[lmb.free_mem.count - 1].base +
> >-                     lmb_memory[lmb.free_mem.count - 1].size - addr;
> >+              return lmb_memory[lmb.available_mem.count - 1].base +
> >+                     lmb_memory[lmb.available_mem.count - 1].size - addr;
> >       }
> >       return 0;
> > }
> >@@ -895,7 +895,7 @@ static int lmb_setup(bool test)
> > {
> >       bool ret;
> >
> >-      ret = alist_init(&lmb.free_mem, sizeof(struct lmb_region),
> >+      ret = alist_init(&lmb.available_mem, sizeof(struct lmb_region),
> >                        (uint)LMB_ALIST_INITIAL_SIZE);
> >       if (!ret) {
> >               log_debug("Unable to initialise the list for LMB free memory\n");
> >@@ -967,7 +967,7 @@ int lmb_push(struct lmb *store)
> >
> > void lmb_pop(struct lmb *store)
> > {
> >-      alist_uninit(&lmb.free_mem);
> >+      alist_uninit(&lmb.available_mem);
> >       alist_uninit(&lmb.used_mem);
> >       lmb = *store;
> > }
> >diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
> >index bb419ab2394e..e5b422ab2ba8 100644
> >--- a/test/cmd/bdinfo.c
> >+++ b/test/cmd/bdinfo.c
> >@@ -131,7 +131,7 @@ static int lmb_test_dump_all(struct unit_test_state *uts)
> >       struct lmb *lmb = lmb_get();
> >
> >       ut_assert_nextline("lmb_dump_all:");
> >-      ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory"));
> >+      ut_assertok(lmb_test_dump_region(uts, &lmb->available_mem, "memory"));
> >       ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved"));
> >
> >       return 0;
> >diff --git a/test/lib/lmb.c b/test/lib/lmb.c
> >index 8af5dcad2ecc..0f7052224c10 100644
> >--- a/test/lib/lmb.c
> >+++ b/test/lib/lmb.c
> >@@ -65,7 +65,7 @@ static int setup_lmb_test(struct unit_test_state *uts, struct lmb *store,
> >
> >       ut_assertok(lmb_push(store));
> >       lmb = lmb_get();
> >-      *mem_lstp = &lmb->free_mem;
> >+      *mem_lstp = &lmb->available_mem;
> >       *used_lstp = &lmb->used_mem;
> >
> >       return 0;
> >--
> >2.45.2
> >
>


More information about the U-Boot mailing list