From: Uladzislau Rezki <urezki@gmail.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Dave Chinner <david@fromorbit.com>, Neil Brown <neilb@suse.de>,
Christoph Hellwig <hch@lst.de>,
Uladzislau Rezki <urezki@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
LKML <linux-kernel@vger.kernel.org>,
Ilya Dryomov <idryomov@gmail.com>,
Jeff Layton <jlayton@kernel.org>, Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH v2 2/4] mm/vmalloc: add support for __GFP_NOFAIL
Date: Tue, 23 Nov 2021 20:01:50 +0100 [thread overview]
Message-ID: <YZ06nna7RirAI+vJ@pc638.lan> (raw)
In-Reply-To: <20211122153233.9924-3-mhocko@kernel.org>
On Mon, Nov 22, 2021 at 04:32:31PM +0100, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Dave Chinner has mentioned that some of the xfs code would benefit from
> kvmalloc support for __GFP_NOFAIL because they have allocations that
> cannot fail and they do not fit into a single page.
>
> The large part of the vmalloc implementation already complies with the
> given gfp flags so there is no work for those to be done. The area
> and page table allocations are an exception to that. Implement a retry
> loop for those.
>
> Add a short sleep before retrying. 1 jiffy is a completely random
> timeout. Ideally the retry would wait for an explicit event - e.g.
> a change to the vmalloc space change if the failure was caused by
> the space fragmentation or depletion. But there are multiple different
> reasons to retry and this could become much more complex. Keep the retry
> simple for now and just sleep to prevent from hogging CPUs.
>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
> mm/vmalloc.c | 22 +++++++++++++++++-----
> 1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 17ca7001de1f..b6aed4f94a85 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2844,6 +2844,8 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
> * more permissive.
> */
> if (!order) {
> + gfp_t bulk_gfp = gfp & ~__GFP_NOFAIL;
> +
> while (nr_allocated < nr_pages) {
> unsigned int nr, nr_pages_request;
>
> @@ -2861,12 +2863,12 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
> * but mempolcy want to alloc memory by interleaving.
> */
> if (IS_ENABLED(CONFIG_NUMA) && nid == NUMA_NO_NODE)
> - nr = alloc_pages_bulk_array_mempolicy(gfp,
> + nr = alloc_pages_bulk_array_mempolicy(bulk_gfp,
> nr_pages_request,
> pages + nr_allocated);
>
> else
> - nr = alloc_pages_bulk_array_node(gfp, nid,
> + nr = alloc_pages_bulk_array_node(bulk_gfp, nid,
> nr_pages_request,
> pages + nr_allocated);
>
> @@ -2921,6 +2923,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> {
> const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
> const gfp_t orig_gfp_mask = gfp_mask;
> + bool nofail = gfp_mask & __GFP_NOFAIL;
> unsigned long addr = (unsigned long)area->addr;
> unsigned long size = get_vm_area_size(area);
> unsigned long array_size;
> @@ -2978,8 +2981,12 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == 0)
> flags = memalloc_noio_save();
>
> - ret = vmap_pages_range(addr, addr + size, prot, area->pages,
> + do {
> + ret = vmap_pages_range(addr, addr + size, prot, area->pages,
> page_shift);
> + if (nofail && (ret < 0))
> + schedule_timeout_uninterruptible(1);
> + } while (nofail && (ret < 0));
>
> if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO)
> memalloc_nofs_restore(flags);
> @@ -3074,9 +3081,14 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
> VM_UNINITIALIZED | vm_flags, start, end, node,
> gfp_mask, caller);
> if (!area) {
> + bool nofail = gfp_mask & __GFP_NOFAIL;
> warn_alloc(gfp_mask, NULL,
> - "vmalloc error: size %lu, vm_struct allocation failed",
> - real_size);
> + "vmalloc error: size %lu, vm_struct allocation failed%s",
> + real_size, (nofail) ? ". Retrying." : "");
> + if (nofail) {
> + schedule_timeout_uninterruptible(1);
> + goto again;
> + }
> goto fail;
> }
>
> --
> 2.30.2
>
I have raised two concerns in our previous discussion about this change,
well that is sad...
--
Vlad Rezki
next prev parent reply other threads:[~2021-11-23 19:01 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 15:32 [PATCH v2 0/4] extend vmalloc support for constrained allocations Michal Hocko
2021-11-22 15:32 ` [PATCH v2 1/4] mm/vmalloc: alloc GFP_NO{FS,IO} for vmalloc Michal Hocko
2021-11-23 19:05 ` Uladzislau Rezki
2021-11-26 15:13 ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 2/4] mm/vmalloc: add support for __GFP_NOFAIL Michal Hocko
2021-11-23 19:01 ` Uladzislau Rezki [this message]
2021-11-23 20:09 ` Michal Hocko
2021-11-24 20:46 ` Uladzislau Rezki
2021-11-24 1:02 ` Andrew Morton
2021-11-24 3:16 ` NeilBrown
2021-11-24 3:48 ` Andrew Morton
2021-11-24 5:23 ` NeilBrown
2021-11-25 0:32 ` Theodore Y. Ts'o
2021-11-26 14:50 ` Vlastimil Babka
2021-11-26 15:09 ` Michal Hocko
2021-11-24 23:45 ` Dave Chinner
2021-11-24 8:43 ` Michal Hocko
2021-11-24 20:37 ` Uladzislau Rezki
2021-11-25 8:48 ` Michal Hocko
2021-11-25 18:40 ` Uladzislau Rezki
2021-11-25 19:21 ` Michal Hocko
2021-11-24 20:11 ` Uladzislau Rezki
2021-11-25 8:46 ` Michal Hocko
2021-11-25 18:02 ` Uladzislau Rezki
2021-11-25 19:24 ` Michal Hocko
2021-11-25 20:03 ` Uladzislau Rezki
2021-11-25 20:13 ` Michal Hocko
2021-11-25 20:21 ` Uladzislau Rezki
2021-11-26 10:48 ` Michal Hocko
2021-11-28 0:00 ` Andrew Morton
2021-11-29 8:56 ` Michal Hocko
2021-11-26 15:32 ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 3/4] mm/vmalloc: be more explicit about supported gfp flags Michal Hocko
2021-11-23 18:58 ` Uladzislau Rezki
2021-11-26 15:39 ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 4/4] mm: allow !GFP_KERNEL allocations for kvmalloc Michal Hocko
2021-11-23 18:57 ` Uladzislau Rezki
2021-11-23 19:02 ` Uladzislau Rezki
2021-11-26 15:50 ` Vlastimil Babka
2021-11-24 22:55 ` [PATCH v2 0/4] extend vmalloc support for constrained allocations Dave Chinner
2021-11-25 8:58 ` Michal Hocko
2021-11-25 9:30 ` Michal Hocko
2021-11-25 21:30 ` Dave Chinner
2021-11-26 9:20 ` Vlastimil Babka
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=YZ06nna7RirAI+vJ@pc638.lan \
--to=urezki@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=neilb@suse.de \
/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).