* [PATCH] mm/mempool: Add 'else' to split mutually exclusive case
@ 2020-08-24 11:53 Miaohe Lin
2020-08-24 19:18 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Miaohe Lin @ 2020-08-24 11:53 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe
Add else to split mutually exclusive case and avoid some unnecessary check.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/mempool.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/mm/mempool.c b/mm/mempool.c
index 79bff63ecf27..73fb2e548b43 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
/* Mempools backed by slab allocator */
if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
__check_element(pool, element, ksize(element));
-
/* Mempools backed by page allocator */
- if (pool->free == mempool_free_pages) {
+ else if (pool->free == mempool_free_pages) {
int order = (int)(long)pool->pool_data;
void *addr = kmap_atomic((struct page *)element);
@@ -84,9 +83,8 @@ static void poison_element(mempool_t *pool, void *element)
/* Mempools backed by slab allocator */
if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc)
__poison_element(element, ksize(element));
-
/* Mempools backed by page allocator */
- if (pool->alloc == mempool_alloc_pages) {
+ else if (pool->alloc == mempool_alloc_pages) {
int order = (int)(long)pool->pool_data;
void *addr = kmap_atomic((struct page *)element);
@@ -107,7 +105,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element)
{
if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc)
kasan_poison_kfree(element, _RET_IP_);
- if (pool->alloc == mempool_alloc_pages)
+ else if (pool->alloc == mempool_alloc_pages)
kasan_free_pages(element, (unsigned long)pool->pool_data);
}
@@ -115,7 +113,7 @@ static void kasan_unpoison_element(mempool_t *pool, void *element)
{
if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc)
kasan_unpoison_slab(element);
- if (pool->alloc == mempool_alloc_pages)
+ else if (pool->alloc == mempool_alloc_pages)
kasan_alloc_pages(element, (unsigned long)pool->pool_data);
}
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempool: Add 'else' to split mutually exclusive case
2020-08-24 11:53 [PATCH] mm/mempool: Add 'else' to split mutually exclusive case Miaohe Lin
@ 2020-08-24 19:18 ` Andrew Morton
2020-08-24 19:22 ` Matthew Wilcox
2020-08-24 19:27 ` Joe Perches
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2020-08-24 19:18 UTC (permalink / raw)
To: Miaohe Lin; +Cc: linux-mm, linux-kernel
On Mon, 24 Aug 2020 07:53:54 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
> Add else to split mutually exclusive case and avoid some unnecessary check.
>
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
> /* Mempools backed by slab allocator */
> if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
> __check_element(pool, element, ksize(element));
> -
> /* Mempools backed by page allocator */
> - if (pool->free == mempool_free_pages) {
> + else if (pool->free == mempool_free_pages) {
> int order = (int)(long)pool->pool_data;
> void *addr = kmap_atomic((struct page *)element);
>
It doesn't seem to change code generation (compiler is smart), but I
think it helps readability.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempool: Add 'else' to split mutually exclusive case
2020-08-24 19:18 ` Andrew Morton
@ 2020-08-24 19:22 ` Matthew Wilcox
2020-08-24 19:27 ` Joe Perches
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2020-08-24 19:22 UTC (permalink / raw)
To: Andrew Morton; +Cc: Miaohe Lin, linux-mm, linux-kernel
On Mon, Aug 24, 2020 at 12:18:40PM -0700, Andrew Morton wrote:
> On Mon, 24 Aug 2020 07:53:54 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> > Add else to split mutually exclusive case and avoid some unnecessary check.
> >
> > --- a/mm/mempool.c
> > +++ b/mm/mempool.c
> > @@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
> > /* Mempools backed by slab allocator */
> > if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
> > __check_element(pool, element, ksize(element));
> > -
> > /* Mempools backed by page allocator */
> > - if (pool->free == mempool_free_pages) {
> > + else if (pool->free == mempool_free_pages) {
> > int order = (int)(long)pool->pool_data;
> > void *addr = kmap_atomic((struct page *)element);
> >
>
> It doesn't seem to change code generation (compiler is smart), but I
> think it helps readability.
Not with the comments where they are
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempool: Add 'else' to split mutually exclusive case
2020-08-24 19:18 ` Andrew Morton
2020-08-24 19:22 ` Matthew Wilcox
@ 2020-08-24 19:27 ` Joe Perches
1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2020-08-24 19:27 UTC (permalink / raw)
To: Andrew Morton, Miaohe Lin; +Cc: linux-mm, linux-kernel
On Mon, 2020-08-24 at 12:18 -0700, Andrew Morton wrote:
> On Mon, 24 Aug 2020 07:53:54 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> > Add else to split mutually exclusive case and avoid some unnecessary check.
> >
> > --- a/mm/mempool.c
> > +++ b/mm/mempool.c
> > @@ -60,9 +60,8 @@ static void check_element(mempool_t *pool, void *element)
> > /* Mempools backed by slab allocator */
> > if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
> > __check_element(pool, element, ksize(element));
> > -
> > /* Mempools backed by page allocator */
> > - if (pool->free == mempool_free_pages) {
> > + else if (pool->free == mempool_free_pages) {
> > int order = (int)(long)pool->pool_data;
> > void *addr = kmap_atomic((struct page *)element);
> >
>
> It doesn't seem to change code generation (compiler is smart), but I
> think it helps readability.
style: braces should be added to the first test.
Perhaps better as:
---
mm/mempool.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/mempool.c b/mm/mempool.c
index 79bff63ecf27..d0206eab86a4 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -57,12 +57,12 @@ static void __check_element(mempool_t *pool, void *element, size_t size)
static void check_element(mempool_t *pool, void *element)
{
- /* Mempools backed by slab allocator */
- if (pool->free == mempool_free_slab || pool->free == mempool_kfree)
+ if (pool->free == mempool_free_slab ||
+ pool->free == mempool_kfree) {
+ /* Mempools backed by slab allocator */
__check_element(pool, element, ksize(element));
-
- /* Mempools backed by page allocator */
- if (pool->free == mempool_free_pages) {
+ } else if (pool->free == mempool_free_pages) {
+ /* Mempools backed by page allocator */
int order = (int)(long)pool->pool_data;
void *addr = kmap_atomic((struct page *)element);
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-24 19:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 11:53 [PATCH] mm/mempool: Add 'else' to split mutually exclusive case Miaohe Lin
2020-08-24 19:18 ` Andrew Morton
2020-08-24 19:22 ` Matthew Wilcox
2020-08-24 19:27 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).