From: Jan Kara <jack@suse.cz> To: David Rientjes <rientjes@google.com> Cc: Andrew Morton <akpm@linux-foundation.org>, Steven Whitehouse <swhiteho@redhat.com>, Jens Axboe <jaxboe@fusionio.com>, Jan Kara <jack@suse.cz>, cluster-devel@redhat.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [patch 3/5] fs: add nofail variant of alloc_buffer_head Date: Tue, 24 Aug 2010 14:17:03 +0200 [thread overview] Message-ID: <20100824121702.GC3713@quack.suse.cz> (raw) In-Reply-To: <alpine.DEB.2.00.1008240347070.19596@chino.kir.corp.google.com> On Tue 24-08-10 03:50:30, David Rientjes wrote: > Add alloc_buffer_head_nofail(). This function is equivalent to > alloc_buffer_head(), except that it will never return NULL and instead > loop forever trying to allocate memory. > > If the first allocation attempt fails, a warning will be emitted, > including a call trace. Subsequent failures will suppress this warning. > > This was added as a helper function for documentation and auditability. > No future callers should be added. Acked-by: Jan Kara <jack@suse.cz> for the JBD part here as well. Honza > > Signed-off-by: David Rientjes <rientjes@google.com> > --- > fs/buffer.c | 18 ++++++++++++++++++ > fs/gfs2/log.c | 2 +- > fs/jbd/journal.c | 2 +- > include/linux/buffer_head.h | 1 + > 4 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/fs/buffer.c b/fs/buffer.c > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -3238,6 +3238,24 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags) > } > EXPORT_SYMBOL(alloc_buffer_head); > > +/* > + * NOTE: no new callers of this function should be implemented! > + * All memory allocations should be failable whenever possible. > + */ > +struct buffer_head *alloc_buffer_head_nofail(gfp_t gfp_flags) > +{ > + struct buffer_head *ret; > + > + for (;;) { > + ret = alloc_buffer_head(gfp_flags); > + if (ret) > + return ret; > + WARN_ONCE(1, "Out of memory; no fallback implemented " > + "(flags=0x%x)\n", > + gfp_flags); > + } > +} > + > void free_buffer_head(struct buffer_head *bh) > { > BUG_ON(!list_empty(&bh->b_assoc_buffers)); > diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c > --- a/fs/gfs2/log.c > +++ b/fs/gfs2/log.c > @@ -523,7 +523,7 @@ struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, > u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); > struct buffer_head *bh; > > - bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); > + bh = alloc_buffer_head_nofail(GFP_NOFS); > atomic_set(&bh->b_count, 1); > bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock); > set_bh_page(bh, real->b_page, bh_offset(real)); > diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c > --- a/fs/jbd/journal.c > +++ b/fs/jbd/journal.c > @@ -301,7 +301,7 @@ int journal_write_metadata_buffer(transaction_t *transaction, > */ > J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in)); > > - new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL); > + new_bh = alloc_buffer_head_nofail(GFP_NOFS); > /* keep subsequent assertions sane */ > new_bh->b_state = 0; > init_buffer(new_bh, NULL, NULL); > diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h > --- a/include/linux/buffer_head.h > +++ b/include/linux/buffer_head.h > @@ -176,6 +176,7 @@ void __breadahead(struct block_device *, sector_t block, unsigned int size); > struct buffer_head *__bread(struct block_device *, sector_t block, unsigned size); > void invalidate_bh_lrus(void); > struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); > +struct buffer_head *alloc_buffer_head_nofail(gfp_t gfp_flags); > void free_buffer_head(struct buffer_head * bh); > void unlock_buffer(struct buffer_head *bh); > void __lock_buffer(struct buffer_head *bh); -- Jan Kara <jack@suse.cz> SUSE Labs, CR
WARNING: multiple messages have this Message-ID (diff)
From: Jan Kara <jack@suse.cz> To: cluster-devel.redhat.com Subject: [Cluster-devel] [patch 3/5] fs: add nofail variant of alloc_buffer_head Date: Tue, 24 Aug 2010 14:17:03 +0200 [thread overview] Message-ID: <20100824121702.GC3713@quack.suse.cz> (raw) In-Reply-To: <alpine.DEB.2.00.1008240347070.19596@chino.kir.corp.google.com> On Tue 24-08-10 03:50:30, David Rientjes wrote: > Add alloc_buffer_head_nofail(). This function is equivalent to > alloc_buffer_head(), except that it will never return NULL and instead > loop forever trying to allocate memory. > > If the first allocation attempt fails, a warning will be emitted, > including a call trace. Subsequent failures will suppress this warning. > > This was added as a helper function for documentation and auditability. > No future callers should be added. Acked-by: Jan Kara <jack@suse.cz> for the JBD part here as well. Honza > > Signed-off-by: David Rientjes <rientjes@google.com> > --- > fs/buffer.c | 18 ++++++++++++++++++ > fs/gfs2/log.c | 2 +- > fs/jbd/journal.c | 2 +- > include/linux/buffer_head.h | 1 + > 4 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/fs/buffer.c b/fs/buffer.c > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -3238,6 +3238,24 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags) > } > EXPORT_SYMBOL(alloc_buffer_head); > > +/* > + * NOTE: no new callers of this function should be implemented! > + * All memory allocations should be failable whenever possible. > + */ > +struct buffer_head *alloc_buffer_head_nofail(gfp_t gfp_flags) > +{ > + struct buffer_head *ret; > + > + for (;;) { > + ret = alloc_buffer_head(gfp_flags); > + if (ret) > + return ret; > + WARN_ONCE(1, "Out of memory; no fallback implemented " > + "(flags=0x%x)\n", > + gfp_flags); > + } > +} > + > void free_buffer_head(struct buffer_head *bh) > { > BUG_ON(!list_empty(&bh->b_assoc_buffers)); > diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c > --- a/fs/gfs2/log.c > +++ b/fs/gfs2/log.c > @@ -523,7 +523,7 @@ struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, > u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); > struct buffer_head *bh; > > - bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); > + bh = alloc_buffer_head_nofail(GFP_NOFS); > atomic_set(&bh->b_count, 1); > bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock); > set_bh_page(bh, real->b_page, bh_offset(real)); > diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c > --- a/fs/jbd/journal.c > +++ b/fs/jbd/journal.c > @@ -301,7 +301,7 @@ int journal_write_metadata_buffer(transaction_t *transaction, > */ > J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in)); > > - new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL); > + new_bh = alloc_buffer_head_nofail(GFP_NOFS); > /* keep subsequent assertions sane */ > new_bh->b_state = 0; > init_buffer(new_bh, NULL, NULL); > diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h > --- a/include/linux/buffer_head.h > +++ b/include/linux/buffer_head.h > @@ -176,6 +176,7 @@ void __breadahead(struct block_device *, sector_t block, unsigned int size); > struct buffer_head *__bread(struct block_device *, sector_t block, unsigned size); > void invalidate_bh_lrus(void); > struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); > +struct buffer_head *alloc_buffer_head_nofail(gfp_t gfp_flags); > void free_buffer_head(struct buffer_head * bh); > void unlock_buffer(struct buffer_head *bh); > void __lock_buffer(struct buffer_head *bh); -- Jan Kara <jack@suse.cz> SUSE Labs, CR
next prev parent reply other threads:[~2010-08-24 12:17 UTC|newest] Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-08-24 10:50 [patch 1/5] mm: add nofail variants of kmalloc kcalloc and kzalloc David Rientjes 2010-08-24 10:50 ` [patch 2/5] mm: add nofail variant of kmem_cache_zalloc David Rientjes 2010-08-24 10:50 ` [patch 3/5] fs: add nofail variant of alloc_buffer_head David Rientjes 2010-08-24 12:17 ` Jan Kara [this message] 2010-08-24 12:17 ` [Cluster-devel] " Jan Kara 2010-08-24 10:50 ` [patch 4/5] btrfs: add nofail variant of set_extent_dirty David Rientjes 2010-08-24 13:30 ` Peter Zijlstra 2010-08-24 10:50 ` [patch 5/5] ntfs: remove dependency on __GFP_NOFAIL David Rientjes 2010-08-24 12:15 ` [patch 1/5] mm: add nofail variants of kmalloc kcalloc and kzalloc Jan Kara 2010-08-24 12:15 ` [Cluster-devel] " Jan Kara 2010-08-24 13:29 ` Peter Zijlstra 2010-08-24 13:33 ` Jens Axboe 2010-08-24 20:11 ` David Rientjes 2010-08-24 20:11 ` David Rientjes 2010-08-25 11:24 ` Ted Ts'o 2010-08-25 11:35 ` Peter Zijlstra 2010-08-25 11:57 ` Ted Ts'o 2010-08-25 12:48 ` Peter Zijlstra 2010-08-25 12:52 ` Peter Zijlstra 2010-08-25 13:20 ` Theodore Tso 2010-08-25 13:31 ` Peter Zijlstra 2010-08-25 20:43 ` David Rientjes 2010-08-25 20:55 ` Peter Zijlstra 2010-08-25 21:11 ` David Rientjes 2010-08-25 21:27 ` Peter Zijlstra 2010-08-25 23:11 ` David Rientjes 2010-08-26 0:19 ` Ted Ts'o 2010-08-26 0:30 ` David Rientjes 2010-08-26 0:30 ` David Rientjes 2010-08-26 0:30 ` David Rientjes 2010-08-26 0:30 ` David Rientjes 2010-08-26 1:48 ` Ted Ts'o 2010-08-26 3:09 ` David Rientjes 2010-08-26 3:09 ` David Rientjes 2010-08-26 3:09 ` David Rientjes 2010-08-26 3:09 ` David Rientjes 2010-08-26 3:09 ` David Rientjes 2010-08-26 7:06 ` Dave Chinner 2010-08-26 8:29 ` Peter Zijlstra 2010-08-26 6:38 ` Dave Chinner 2010-08-26 6:38 ` Dave Chinner 2010-08-26 6:38 ` Dave Chinner 2010-08-26 6:38 ` Dave Chinner 2010-08-26 6:38 ` Dave Chinner 2010-08-26 0:30 ` David Rientjes 2010-08-25 13:34 ` Peter Zijlstra 2010-08-25 13:24 ` Dave Chinner 2010-08-25 13:35 ` Peter Zijlstra 2010-08-25 20:53 ` Ted Ts'o 2010-08-25 20:59 ` David Rientjes 2010-08-25 20:59 ` David Rientjes 2010-08-25 20:59 ` David Rientjes 2010-08-25 20:59 ` David Rientjes 2010-08-25 20:59 ` David Rientjes 2010-08-25 21:35 ` Peter Zijlstra 2010-08-25 20:58 ` David Rientjes 2010-08-25 21:11 ` Christoph Lameter 2010-08-25 21:21 ` Peter Zijlstra 2010-08-25 21:23 ` David Rientjes 2010-08-25 21:35 ` Christoph Lameter 2010-08-25 23:05 ` David Rientjes 2010-08-26 1:30 ` Christoph Lameter 2010-08-26 3:12 ` David Rientjes 2010-08-26 14:16 ` Christoph Lameter 2010-08-26 22:31 ` David Rientjes 2010-08-26 0:09 ` Dave Chinner 2010-08-25 14:13 ` Peter Zijlstra 2010-08-24 13:55 ` Dave Chinner 2010-08-24 14:03 ` Peter Zijlstra 2010-08-24 20:12 ` David Rientjes 2010-08-24 20:08 ` David Rientjes 2010-09-02 1:02 ` [patch v2 " David Rientjes 2010-09-02 1:03 ` [patch v2 2/5] mm: add nofail variant of kmem_cache_zalloc David Rientjes 2010-09-02 1:03 ` [patch v2 3/5] fs: add nofail variant of alloc_buffer_head David Rientjes 2010-09-02 1:03 ` [patch v2 4/5] btrfs: add nofail variant of set_extent_dirty David Rientjes 2010-09-02 1:03 ` [patch v2 5/5] ntfs: remove dependency on __GFP_NOFAIL David Rientjes 2010-09-02 9:08 ` Anton Altaparmakov 2010-09-05 22:55 ` David Rientjes 2010-09-02 7:59 ` [patch v2 1/5] mm: add nofail variants of kmalloc kcalloc and kzalloc Jiri Slaby 2010-09-02 14:51 ` Jan Kara 2010-09-02 14:51 ` [Cluster-devel] " Jan Kara 2010-09-02 21:15 ` Neil Brown 2010-09-02 21:15 ` [Cluster-devel] " Neil Brown 2010-09-02 21:15 ` Neil Brown 2010-09-05 23:03 ` David Rientjes 2010-09-05 23:01 ` David Rientjes 2010-09-06 9:05 ` David Rientjes
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=20100824121702.GC3713@quack.suse.cz \ --to=jack@suse.cz \ --cc=akpm@linux-foundation.org \ --cc=cluster-devel@redhat.com \ --cc=jaxboe@fusionio.com \ --cc=linux-ext4@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=rientjes@google.com \ --cc=swhiteho@redhat.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.