From: "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Ira Weiny <ira.weiny@intel.com>
Subject: Re: [PATCH 1006/1007] mm/swapfile: Replace kmap_atomic() with kmap_local_page()
Date: Mon, 27 Nov 2023 16:51:07 +0100 [thread overview]
Message-ID: <12332144.O9o76ZdvQC@fdefranc-mobl3> (raw)
In-Reply-To: <20231127154601.585849-1-fabio.maria.de.francesco@linux.intel.com>
Please discard this patch for a mistake in the subject.
Fabio
On Monday, 27 November 2023 16:45:53 CET Fabio M. De Francesco wrote:
> kmap_atomic() has been deprecated in favor of kmap_local_page().
>
> Therefore, replace kmap_atomic() with kmap_local_page() in
> swapfile.c.
>
> kmap_atomic() is implemented like a kmap_local_page() which also
> disables page-faults and preemption (the latter only in !PREEMPT_RT
> kernels). The kernel virtual addresses returned by these two API are
> only valid in the context of the callers (i.e., they cannot be handed to
> other threads).
>
> With kmap_local_page() the mappings are per thread and CPU local like
> in kmap_atomic(); however, they can handle page-faults and can be called
> from any context (including interrupts). The tasks that call
> kmap_local_page() can be preempted and, when they are scheduled to run
> again, the kernel virtual addresses are restored and are still valid.
>
> In mm/swapfile.c, the blocks of code between the mappings and un-mappings
> do not depend on the above-mentioned side effects of kmap_aatomic(), so
> that the mere replacements of the old API with the new one is all that is
> required (i.e., there is no need to explicitly call pagefault_disable()
> and/or preempt_disable()).
>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Fabio M. De Francesco
> <fabio.maria.de.francesco@linux.intel.com> ---
> mm/swapfile.c | 34 +++++++++++++++++-----------------
> 1 file changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 4bc70f459164..8be70912e298 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1495,9 +1495,9 @@ int swp_swapcount(swp_entry_t entry)
>
> do {
> page = list_next_entry(page, lru);
> - map = kmap_atomic(page);
> + map = kmap_local_page(page);
> tmp_count = map[offset];
> - kunmap_atomic(map);
> + kunmap_local(map);
>
> count += (tmp_count & ~COUNT_CONTINUED) * n;
> n *= (SWAP_CONT_MAX + 1);
> @@ -3477,9 +3477,9 @@ int add_swap_count_continuation(swp_entry_t entry,
> gfp_t gfp_mask) if (!(count & COUNT_CONTINUED))
> goto out_unlock_cont;
>
> - map = kmap_atomic(list_page) + offset;
> + map = kmap_local_page(list_page) + offset;
> count = *map;
> - kunmap_atomic(map);
> + kunmap_local(map);
>
> /*
> * If this continuation count now has some space in it,
> @@ -3529,7 +3529,7 @@ static bool swap_count_continued(struct
> swap_info_struct *si, spin_lock(&si->cont_lock);
> offset &= ~PAGE_MASK;
> page = list_next_entry(head, lru);
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
>
> if (count == SWAP_MAP_MAX) /* initial increment from swap_map */
> goto init_map; /* jump over SWAP_CONT_MAX
checks */
> @@ -3539,27 +3539,27 @@ static bool swap_count_continued(struct
> swap_info_struct *si, * Think of how you add 1 to 999
> */
> while (*map == (SWAP_CONT_MAX | COUNT_CONTINUED)) {
> - kunmap_atomic(map);
> + kunmap_local(map);
> page = list_next_entry(page, lru);
> BUG_ON(page == head);
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
> }
> if (*map == SWAP_CONT_MAX) {
> - kunmap_atomic(map);
> + kunmap_local(map);
> page = list_next_entry(page, lru);
> if (page == head) {
> ret = false; /* add count continuation */
> goto out;
> }
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
> init_map: *map = 0; /* we didn't zero the page */
> }
> *map += 1;
> - kunmap_atomic(map);
> + kunmap_local(map);
> while ((page = list_prev_entry(page, lru)) != head) {
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
> *map = COUNT_CONTINUED;
> - kunmap_atomic(map);
> + kunmap_local(map);
> }
> ret = true; /* incremented */
>
> @@ -3569,21 +3569,21 @@ init_map: *map = 0; /* we didn't
zero the page */
> */
> BUG_ON(count != COUNT_CONTINUED);
> while (*map == COUNT_CONTINUED) {
> - kunmap_atomic(map);
> + kunmap_local(map);
> page = list_next_entry(page, lru);
> BUG_ON(page == head);
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
> }
> BUG_ON(*map == 0);
> *map -= 1;
> if (*map == 0)
> count = 0;
> - kunmap_atomic(map);
> + kunmap_local(map);
> while ((page = list_prev_entry(page, lru)) != head) {
> - map = kmap_atomic(page) + offset;
> + map = kmap_local_page(page) + offset;
> *map = SWAP_CONT_MAX | count;
> count = COUNT_CONTINUED;
> - kunmap_atomic(map);
> + kunmap_local(map);
> }
> ret = count == COUNT_CONTINUED;
> }
prev parent reply other threads:[~2023-11-27 15:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 15:45 Fabio M. De Francesco
2023-11-27 15:51 ` Fabio M. De Francesco [this message]
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=12332144.O9o76ZdvQC@fdefranc-mobl3 \
--to=fabio.maria.de.francesco@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=ira.weiny@intel.com \
--cc=linux-kernel@vger.kernel.org \
--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