linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	Michal Hocko <mhocko@suse.com>, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 20/20] jbd2: get rid of superfluous __GFP_REPEAT
Date: Thu, 28 Apr 2016 15:24:06 +0200	[thread overview]
Message-ID: <1461849846-27209-21-git-send-email-mhocko@kernel.org> (raw)
In-Reply-To: <1461849846-27209-1-git-send-email-mhocko@kernel.org>

From: Michal Hocko <mhocko@suse.com>

jbd2_alloc is explicit about its allocation preferences wrt. the
allocation size. Sub page allocations go to the slab allocator
and larger are using either the page allocator or vmalloc. This
is all good but the logic is unnecessarily complex.
1) as per Ted, the vmalloc fallback is a left-over:
: jbd2_alloc is only passed in the bh->b_size, which can't be >
: PAGE_SIZE, so the code path that calls vmalloc() should never get
: called.  When we conveted jbd2_alloc() to suppor sub-page size
: allocations in commit d2eecb039368, there was an assumption that it
: could be called with a size greater than PAGE_SIZE, but that's
: certaily not true today.
Moreover vmalloc allocation might even lead to a deadlock because
the callers expect GFP_NOFS context while vmalloc is GFP_KERNEL.

2) __GFP_REPEAT for requests <= PAGE_ALLOC_COSTLY_ORDER is ignored
since the flag was introduced.

Let's simplify the code flow and use the slab allocator for sub-page
requests and the page allocator for others. Even though order > 0 is
not currently used as per above leave that option open.

Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/jbd2/journal.c | 32 +++++++-------------------------
 1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b31852f76f46..e3ca4b4cac84 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2329,18 +2329,10 @@ void *jbd2_alloc(size_t size, gfp_t flags)
 
 	BUG_ON(size & (size-1)); /* Must be a power of 2 */
 
-	flags |= __GFP_REPEAT;
-	if (size == PAGE_SIZE)
-		ptr = (void *)__get_free_pages(flags, 0);
-	else if (size > PAGE_SIZE) {
-		int order = get_order(size);
-
-		if (order < 3)
-			ptr = (void *)__get_free_pages(flags, order);
-		else
-			ptr = vmalloc(size);
-	} else
+	if (size < PAGE_SIZE)
 		ptr = kmem_cache_alloc(get_slab(size), flags);
+	else
+		ptr = (void *)__get_free_pages(flags, get_order(size));
 
 	/* Check alignment; SLUB has gotten this wrong in the past,
 	 * and this can lead to user data corruption! */
@@ -2351,20 +2343,10 @@ void *jbd2_alloc(size_t size, gfp_t flags)
 
 void jbd2_free(void *ptr, size_t size)
 {
-	if (size == PAGE_SIZE) {
-		free_pages((unsigned long)ptr, 0);
-		return;
-	}
-	if (size > PAGE_SIZE) {
-		int order = get_order(size);
-
-		if (order < 3)
-			free_pages((unsigned long)ptr, order);
-		else
-			vfree(ptr);
-		return;
-	}
-	kmem_cache_free(get_slab(size), ptr);
+	if (size < PAGE_SIZE)
+		kmem_cache_free(get_slab(size), ptr);
+	else
+		free_pages((unsigned long)ptr, get_order(size));
 };
 
 /*
-- 
2.8.0.rc3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2016-04-28 13:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-28 13:23 [PATCH 0/19] get rid of superfluous __GFP_REPEAT Michal Hocko
2016-04-28 13:23 ` [PATCH 01/20] tree wide: get rid of __GFP_REPEAT for order-0 allocations part I Michal Hocko
2016-04-28 13:23 ` [PATCH 02/20] x86: get rid of superfluous __GFP_REPEAT Michal Hocko
2016-04-28 13:23 ` [PATCH 03/20] x86/efi: " Michal Hocko
2016-04-28 13:23 ` [PATCH 04/20] arm: " Michal Hocko
2016-04-28 14:55   ` Russell King - ARM Linux
2016-04-28 15:08     ` Michal Hocko
2016-04-29  9:41       ` Michal Hocko
2016-04-28 13:23 ` [PATCH 05/20] arm64: " Michal Hocko
2016-04-28 13:23 ` [PATCH 06/20] arc: " Michal Hocko
2016-04-28 13:23 ` [PATCH 07/20] mips: " Michal Hocko
2016-04-28 13:23 ` [PATCH 08/20] nios2: " Michal Hocko
2016-04-28 13:23 ` [PATCH 09/20] parisc: " Michal Hocko
2016-04-28 13:23 ` [PATCH 10/20] score: " Michal Hocko
2016-04-28 13:23 ` [PATCH 11/20] powerpc: " Michal Hocko
2016-04-28 13:23 ` [PATCH 12/20] sparc: " Michal Hocko
2016-04-28 13:23 ` [PATCH 13/20] s390: " Michal Hocko
2016-04-28 13:24 ` [PATCH 14/20] sh: " Michal Hocko
2016-04-28 13:24 ` [PATCH 15/20] tile: " Michal Hocko
2016-04-28 16:21   ` Chris Metcalf
2016-04-28 13:24 ` [PATCH 16/20] unicore32: " Michal Hocko
2016-04-28 13:24 ` [PATCH 17/20] dm: get rid of superfluous gfp flags Michal Hocko
2016-04-29 18:54   ` Mike Snitzer
2016-05-02  7:31     ` Michal Hocko
2016-04-28 13:24 ` [PATCH 18/20] dm: clean up GFP_NIO usage Michal Hocko
2016-04-28 14:20   ` Mikulas Patocka
2016-04-28 14:41     ` Michal Hocko
2016-04-28 13:24 ` [PATCH 19/20] md: simplify free_params for kmalloc vs vmalloc fallback Michal Hocko
2016-04-28 14:51   ` [PATCH] " Michal Hocko
2016-04-28 15:04     ` Mikulas Patocka
2016-04-28 15:28       ` Michal Hocko
2016-04-28 15:40         ` Mikulas Patocka
2016-04-28 16:59           ` Michal Hocko
2016-04-28 15:37   ` [PATCH 19/20] " Mike Snitzer
2016-04-28 16:00     ` Michal Hocko
2016-04-28 13:24 ` Michal Hocko [this message]
2016-05-12 16:53 ` [PATCH 0/19] get rid of superfluous __GFP_REPEAT Michal Hocko
2016-05-12 20:13   ` Andrew Morton
2016-05-13  6:58     ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461849846-27209-21-git-send-email-mhocko@kernel.org \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).