2018-12-24 07:25:49

by Huang Shijie

[permalink] [raw]
Subject: [PATCH 1/2] lib/genalloc.c: Use the vzalloc_node to allocate the bitmap.

Some devices may have over 1G memory on chip.
In some cases, the nbytes may big then 4M which is the bounday of
the memory buddy system. So use vzalloc_node() to allocate the bitmap.

Signed-off-by: Huang Shijie <[email protected]>
---
lib/genalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 5deb25c40a5a..0d0ff9f0483f 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -187,7 +187,7 @@ int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phy
int nbytes = sizeof(struct gen_pool_chunk) +
BITS_TO_LONGS(nbits) * sizeof(long);

- chunk = kzalloc_node(nbytes, GFP_KERNEL, nid);
+ chunk = vzalloc_node(nbytes, nid);
if (unlikely(chunk == NULL))
return -ENOMEM;

--
2.17.1



2018-12-24 07:24:02

by Huang Shijie

[permalink] [raw]
Subject: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

We may use the addr_in_gen_pool() in the driver module.
So export the addr_in_gen_pool for the compiling.

Signed-off-by: Huang Shijie <[email protected]>
---
lib/genalloc.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 0d0ff9f0483f..9da91a16046f 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -450,6 +450,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
rcu_read_unlock();
return found;
}
+EXPORT_SYMBOL(addr_in_gen_pool);

/**
* gen_pool_avail - get available free space of the pool
--
2.17.1


2018-12-25 02:00:38

by Huang Shijie

[permalink] [raw]
Subject: [PATCH 1/2 fix] lib/genalloc.c: Use the vzalloc_node to allocate the bitmap.

Some devices may have big memory on chip, such as over 1G.
In some cases, the nbytes maybe bigger then 4M which is the bounday of
the memory buddy system (4K default).

So use vzalloc_node() to allocate the bitmap.
Also use vfree to free the it.

Signed-off-by: Huang Shijie <[email protected]>
---
The v1 did not free the memory with vfree.
This patch fixes it.

---
lib/genalloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 5deb25c40a5a..f365d71cdc77 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -187,7 +187,7 @@ int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phy
int nbytes = sizeof(struct gen_pool_chunk) +
BITS_TO_LONGS(nbits) * sizeof(long);

- chunk = kzalloc_node(nbytes, GFP_KERNEL, nid);
+ chunk = vzalloc_node(nbytes, nid);
if (unlikely(chunk == NULL))
return -ENOMEM;

@@ -251,7 +251,7 @@ void gen_pool_destroy(struct gen_pool *pool)
bit = find_next_bit(chunk->bits, end_bit, 0);
BUG_ON(bit < end_bit);

- kfree(chunk);
+ vfree(chunk);
}
kfree_const(pool->name);
kfree(pool);
--
2.17.1


2018-12-28 16:09:17

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

On Mon, 24 Dec 2018 15:06:22 +0800 Huang Shijie <[email protected]> wrote:

> We may use the addr_in_gen_pool() in the driver module.
> So export the addr_in_gen_pool for the compiling.
>
> ...
>
> --- a/lib/genalloc.c
> +++ b/lib/genalloc.c
> @@ -450,6 +450,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
> rcu_read_unlock();
> return found;
> }
> +EXPORT_SYMBOL(addr_in_gen_pool);
>
> /**
> * gen_pool_avail - get available free space of the pool

OK, but... The name is poor.

q:/usr/src/25> grep EXPORT_SYMBOL lib/genalloc.c
EXPORT_SYMBOL(gen_pool_create);
EXPORT_SYMBOL(gen_pool_add_virt);
EXPORT_SYMBOL(gen_pool_virt_to_phys);
EXPORT_SYMBOL(gen_pool_destroy);
EXPORT_SYMBOL(gen_pool_alloc);
EXPORT_SYMBOL(gen_pool_alloc_algo);
EXPORT_SYMBOL(gen_pool_dma_alloc);
EXPORT_SYMBOL(gen_pool_free);
EXPORT_SYMBOL(gen_pool_for_each_chunk);
EXPORT_SYMBOL_GPL(gen_pool_avail);
EXPORT_SYMBOL_GPL(gen_pool_size);
EXPORT_SYMBOL(gen_pool_set_algo);
EXPORT_SYMBOL(gen_pool_first_fit);
EXPORT_SYMBOL(gen_pool_first_fit_align);
EXPORT_SYMBOL(gen_pool_fixed_alloc);
EXPORT_SYMBOL(gen_pool_first_fit_order_align);
EXPORT_SYMBOL(gen_pool_best_fit);
EXPORT_SYMBOL_GPL(gen_pool_get);
EXPORT_SYMBOL(devm_gen_pool_create);
EXPORT_SYMBOL_GPL(of_gen_pool_get);

See? Almost everything is called gen_pool_foo. Which is correct as
per kernel conventions. We should globally rename this to
gen_pool_has_addr or similar.

2018-12-28 16:22:33

by Huang Shijie

[permalink] [raw]
Subject: Re: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

On Thu, Dec 27, 2018 at 09:49:29PM -0800, Andrew Morton wrote:
> On Mon, 24 Dec 2018 15:06:22 +0800 Huang Shijie <[email protected]> wrote:
>
> > We may use the addr_in_gen_pool() in the driver module.
> > So export the addr_in_gen_pool for the compiling.
> >
> > ...
> >
> > --- a/lib/genalloc.c
> > +++ b/lib/genalloc.c
> > @@ -450,6 +450,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
> > rcu_read_unlock();
> > return found;
> > }
> > +EXPORT_SYMBOL(addr_in_gen_pool);
> >
> > /**
> > * gen_pool_avail - get available free space of the pool
>
> OK, but... The name is poor.
>
> q:/usr/src/25> grep EXPORT_SYMBOL lib/genalloc.c
> EXPORT_SYMBOL(gen_pool_create);
> EXPORT_SYMBOL(gen_pool_add_virt);
> EXPORT_SYMBOL(gen_pool_virt_to_phys);
> EXPORT_SYMBOL(gen_pool_destroy);
> EXPORT_SYMBOL(gen_pool_alloc);
> EXPORT_SYMBOL(gen_pool_alloc_algo);
> EXPORT_SYMBOL(gen_pool_dma_alloc);
> EXPORT_SYMBOL(gen_pool_free);
> EXPORT_SYMBOL(gen_pool_for_each_chunk);
> EXPORT_SYMBOL_GPL(gen_pool_avail);
> EXPORT_SYMBOL_GPL(gen_pool_size);
> EXPORT_SYMBOL(gen_pool_set_algo);
> EXPORT_SYMBOL(gen_pool_first_fit);
> EXPORT_SYMBOL(gen_pool_first_fit_align);
> EXPORT_SYMBOL(gen_pool_fixed_alloc);
> EXPORT_SYMBOL(gen_pool_first_fit_order_align);
> EXPORT_SYMBOL(gen_pool_best_fit);
> EXPORT_SYMBOL_GPL(gen_pool_get);
> EXPORT_SYMBOL(devm_gen_pool_create);
> EXPORT_SYMBOL_GPL(of_gen_pool_get);
>
> See? Almost everything is called gen_pool_foo. Which is correct as
> per kernel conventions. We should globally rename this to
> gen_pool_has_addr or similar.
okay, I will do it right now..

Thanks
Huang Shijie

2019-01-03 10:58:37

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

On Mon, Dec 24, 2018 at 03:06:22PM +0800, Huang Shijie wrote:
> We may use the addr_in_gen_pool() in the driver module.
> So export the addr_in_gen_pool for the compiling.

Please send this along with the driver that plans to use it.

2019-01-03 14:17:44

by Huang Shijie

[permalink] [raw]
Subject: Re: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

On Wed, Jan 02, 2019 at 11:55:50PM -0800, Christoph Hellwig wrote:
> On Mon, Dec 24, 2018 at 03:06:22PM +0800, Huang Shijie wrote:
> > We may use the addr_in_gen_pool() in the driver module.
> > So export the addr_in_gen_pool for the compiling.
>
> Please send this along with the driver that plans to use it.
The driver is still under develop with the FPGA, and our hardware chip maybe
tape out at next year.

Thanks
Huang Shijie



2019-01-03 22:06:34

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 2/2] lib/genalloc.c: export symbol addr_in_gen_pool

On Thu, Jan 03, 2019 at 06:11:59PM +0800, Huang Shijie wrote:
> On Wed, Jan 02, 2019 at 11:55:50PM -0800, Christoph Hellwig wrote:
> > On Mon, Dec 24, 2018 at 03:06:22PM +0800, Huang Shijie wrote:
> > > We may use the addr_in_gen_pool() in the driver module.
> > > So export the addr_in_gen_pool for the compiling.
> >
> > Please send this along with the driver that plans to use it.
> The driver is still under develop with the FPGA, and our hardware chip maybe
> tape out at next year.

So lets wait for the driver submission or another user before we
export the symbol.