add patch improve-warning-directory-handling-messages
[ext4-patch-queue.git] / revert-must-not-fail-allocation-loops-back-to-GFP_NOFAIL
blob7beec8498daa19b0d49aabeef4b4c166c9a2e550
1 jbd2: revert must-not-fail allocation loops back to GFP_NOFAIL
3 From: Michal Hocko <mhocko@suse.cz>
5 This basically reverts 47def82672b3 (jbd2: Remove __GFP_NOFAIL from jbd2
6 layer). The deprecation of __GFP_NOFAIL was a bad choice because it led
7 to open coding the endless loop around the allocator rather than
8 removing the dependency on the non failing allocation. So the
9 deprecation was a clear failure and the reality tells us that
10 __GFP_NOFAIL is not even close to go away.
12 It is still true that __GFP_NOFAIL allocations are generally discouraged
13 and new uses should be evaluated and an alternative (pre-allocations or
14 reservations) should be considered but it doesn't make any sense to lie
15 the allocator about the requirements. Allocator can take steps to help
16 making a progress if it knows the requirements.
18 Signed-off-by: Michal Hocko <mhocko@suse.cz>
19 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 Acked-by: David Rientjes <rientjes@google.com>
21 ---
23 Hi, 
24 this has been posted few months ago
25 (http://marc.info/?l=linux-mm&m=142530454419654&w=2) but it hasn't
26 gone anywhere so I am reposting. I've just rebased it on top of the
27 ext4/for-linus tree. It wasn't clear to me which branch should I use so
28 I've just picked this one as it was one of the most recently updated.
30  fs/jbd2/journal.c     | 11 +----------
31  fs/jbd2/transaction.c | 20 +++++++-------------
32  2 files changed, 8 insertions(+), 23 deletions(-)
34 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
35 index b96bd8076b70..0bc333b4a594 100644
36 --- a/fs/jbd2/journal.c
37 +++ b/fs/jbd2/journal.c
38 @@ -371,16 +371,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
39          */
40         J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
42 -retry_alloc:
43 -       new_bh = alloc_buffer_head(GFP_NOFS);
44 -       if (!new_bh) {
45 -               /*
46 -                * Failure is not an option, but __GFP_NOFAIL is going
47 -                * away; so we retry ourselves here.
48 -                */
49 -               congestion_wait(BLK_RW_ASYNC, HZ/50);
50 -               goto retry_alloc;
51 -       }
52 +       new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL);
54         /* keep subsequent assertions sane */
55         atomic_set(&new_bh->b_count, 1);
56 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
57 index ff2f2e6ad311..799242cecffb 100644
58 --- a/fs/jbd2/transaction.c
59 +++ b/fs/jbd2/transaction.c
60 @@ -278,22 +278,16 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
62  alloc_transaction:
63         if (!journal->j_running_transaction) {
64 +               /*
65 +                * If __GFP_FS is not present, then we may be being called from
66 +                * inside the fs writeback layer, so we MUST NOT fail.
67 +                */
68 +               if ((gfp_mask & __GFP_FS) == 0)
69 +                       gfp_mask |= __GFP_NOFAIL;
70                 new_transaction = kmem_cache_zalloc(transaction_cache,
71                                                     gfp_mask);
72 -               if (!new_transaction) {
73 -                       /*
74 -                        * If __GFP_FS is not present, then we may be
75 -                        * being called from inside the fs writeback
76 -                        * layer, so we MUST NOT fail.  Since
77 -                        * __GFP_NOFAIL is going away, we will arrange
78 -                        * to retry the allocation ourselves.
79 -                        */
80 -                       if ((gfp_mask & __GFP_FS) == 0) {
81 -                               congestion_wait(BLK_RW_ASYNC, HZ/50);
82 -                               goto alloc_transaction;
83 -                       }
84 +               if (!new_transaction)
85                         return -ENOMEM;
86 -               }
87         }
89         jbd_debug(3, "New handle %p going live.\n", handle);
90 -- 
91 2.1.4
94 To unsubscribe, send a message with 'unsubscribe linux-mm' in
95 the body to majordomo@kvack.org.  For more info on Linux MM,
96 see: http://www.linux-mm.org/ .
97 Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>