From: Uladzislau Rezki <urezki@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Uladzislau Rezki <urezki@gmail.com>,
linux-mm@kvack.org
Subject: Re: [PATCH 09/10] mm: split __vunmap
Date: Thu, 19 Jan 2023 19:50:09 +0100 [thread overview]
Message-ID: <Y8mQ4dhA4TWCwQta@pc636> (raw)
In-Reply-To: <20230119100226.789506-10-hch@lst.de>
On Thu, Jan 19, 2023 at 11:02:25AM +0100, Christoph Hellwig wrote:
> vunmap only needs to find and free the vmap_area and vm_strut, so open
> code that there and merge the rest of the code into vfree.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> mm/vmalloc.c | 85 ++++++++++++++++++++++++++--------------------------
> 1 file changed, 42 insertions(+), 43 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 4cb189bdd51499..791d906d7e407c 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2666,45 +2666,6 @@ static void va_remove_mappings(struct vm_struct *area, int deallocate_pages)
> set_area_direct_map(area, set_direct_map_default_noflush);
> }
>
> -static void __vunmap(const void *addr, int deallocate_pages)
> -{
> - struct vm_struct *area;
> -
> - if (!addr)
> - return;
> -
> - area = remove_vm_area(addr);
> - if (unlikely(!area)) {
> - WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
> - addr);
> - return;
> - }
> -
> - va_remove_mappings(area, deallocate_pages);
> -
> - if (deallocate_pages) {
> - int i;
> -
> - for (i = 0; i < area->nr_pages; i++) {
> - struct page *page = area->pages[i];
> -
> - BUG_ON(!page);
> - mod_memcg_page_state(page, MEMCG_VMALLOC, -1);
> - /*
> - * High-order allocs for huge vmallocs are split, so
> - * can be freed as an array of order-0 allocations
> - */
> - __free_pages(page, 0);
> - cond_resched();
> - }
> - atomic_long_sub(area->nr_pages, &nr_vmalloc_pages);
> -
> - kvfree(area->pages);
> - }
> -
> - kfree(area);
> -}
> -
> static void delayed_vfree_work(struct work_struct *w)
> {
> struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
> @@ -2757,6 +2718,9 @@ void vfree_atomic(const void *addr)
> */
> void vfree(const void *addr)
> {
> + struct vm_struct *vm;
> + int i;
> +
> if (unlikely(in_interrupt())) {
> vfree_atomic(addr);
> return;
> @@ -2766,8 +2730,32 @@ void vfree(const void *addr)
> kmemleak_free(addr);
> might_sleep();
>
> - if (addr)
> - __vunmap(addr, 1);
> + if (!addr)
> + return;
> +
> + vm = remove_vm_area(addr);
> + if (unlikely(!vm)) {
> + WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
> + addr);
> + return;
> + }
> +
> + va_remove_mappings(vm, true);
> + for (i = 0; i < vm->nr_pages; i++) {
> + struct page *page = vm->pages[i];
> +
> + BUG_ON(!page);
> + mod_memcg_page_state(page, MEMCG_VMALLOC, -1);
> + /*
> + * High-order allocs for huge vmallocs are split, so
> + * can be freed as an array of order-0 allocations
> + */
> + __free_pages(page, 0);
> + cond_resched();
> + }
> + atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages);
> + kvfree(vm->pages);
> + kfree(vm);
> }
> EXPORT_SYMBOL(vfree);
>
> @@ -2782,10 +2770,21 @@ EXPORT_SYMBOL(vfree);
> */
> void vunmap(const void *addr)
> {
> + struct vm_struct *vm;
> +
> BUG_ON(in_interrupt());
> might_sleep();
> - if (addr)
> - __vunmap(addr, 0);
> +
> + if (!addr)
> + return;
> + vm = remove_vm_area(addr);
> + if (unlikely(!vm)) {
> + WARN(1, KERN_ERR "Trying to vunmap() nonexistent vm area (%p)\n",
> + addr);
> + return;
> + }
> + WARN_ON_ONCE(vm->flags & VM_FLUSH_RESET_PERMS);
> + kfree(vm);
> }
> EXPORT_SYMBOL(vunmap);
>
> --
> 2.39.0
>
After this patch same check in the end of the vunmap() becomes odd
because we fail a vmap() call on its entry if VM_FLUSH_RESET_PERMS
flag is set. See the [1] patch in this series.
Is there any reason for such duplication?
--
Uladzislau Rezki
next prev parent reply other threads:[~2023-01-19 18:50 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 10:02 cleanup vfree and vunmap Christoph Hellwig
2023-01-19 10:02 ` [PATCH 01/10] vmalloc: reject vmap with VM_FLUSH_RESET_PERMS Christoph Hellwig
2023-01-19 18:46 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 02/10] mm: remove __vfree Christoph Hellwig
2023-01-19 18:47 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 03/10] mm: remove __vfree_deferred Christoph Hellwig
2023-01-19 18:47 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 04/10] mm: move vmalloc_init and free_work down in vmalloc.c Christoph Hellwig
2023-01-19 18:48 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 05/10] mm: call vfree instead of __vunmap from delayed_vfree_work Christoph Hellwig
2023-01-19 18:48 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 06/10] mm: move __remove_vm_area out of va_remove_mappings Christoph Hellwig
2023-01-19 18:48 ` Uladzislau Rezki
2023-01-20 7:41 ` Christoph Hellwig
2023-01-20 11:32 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 07/10] mm: use remove_vm_area in __vunmap Christoph Hellwig
2023-01-19 18:49 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 08/10] mm: move debug checks from __vunmap to remove_vm_area Christoph Hellwig
2023-01-19 18:49 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 09/10] mm: split __vunmap Christoph Hellwig
2023-01-19 18:50 ` Uladzislau Rezki [this message]
2023-01-20 7:42 ` Christoph Hellwig
2023-01-20 11:32 ` Uladzislau Rezki
2023-01-19 10:02 ` [PATCH 10/10] mm: refactor va_remove_mappings Christoph Hellwig
2023-01-19 18:50 ` Uladzislau Rezki
2023-01-19 16:45 ` cleanup vfree and vunmap Uladzislau Rezki
2023-01-21 7:10 Christoph Hellwig
2023-01-21 7:10 ` [PATCH 09/10] mm: split __vunmap Christoph Hellwig
2023-01-23 10:47 ` David Hildenbrand
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=Y8mQ4dhA4TWCwQta@pc636 \
--to=urezki@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=linux-mm@kvack.org \
/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