From: Jason Gunthorpe <jgg@nvidia.com>
To: Jason Miu <jasonmiu@google.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>,
Alexander Graf <graf@amazon.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <bhe@redhat.com>,
Changyuan Lyu <changyuanl@google.com>,
David Matlack <dmatlack@google.com>,
David Rientjes <rientjes@google.com>,
Joel Granados <joel.granados@kernel.org>,
Marcos Paulo de Souza <mpdesouza@suse.com>,
Mario Limonciello <mario.limonciello@amd.com>,
Mike Rapoport <rppt@kernel.org>, Petr Mladek <pmladek@suse.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
Steven Chen <chenste@linux.microsoft.com>,
Yan Zhao <yan.y.zhao@intel.com>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [RFC v1 1/4] kho: Introduce KHO page table data structures
Date: Fri, 19 Sep 2025 09:56:48 -0300 [thread overview]
Message-ID: <20250919125648.GS1391379@nvidia.com> (raw)
In-Reply-To: <CAHN2nPK+Z5cvQ_waTWyPZiEoeSc9o7e3YnQLLjRzNzrb7VhAqQ@mail.gmail.com>
> 1. Find the `start_level` from the `target_order`. (for example,
> target_order = 10, start_level = 4)
> 2. The path from the root down to the level above `start_level` is
> fixed (index 0 at each of these levels).
> 3. At `start_level`, the index is also fixed, by (1 << (63 -
> PAGE_SHIFT - order)) in a 9 bit slice.
> 4. Then, for all levels *below* `order_level`, the walker iterates
> through all 512 table entries, until the bitmap level.
You don't need any special logic like that, that is my point, the
whole thing is very simple:
static int get_index(unsigned int level, u64 pos)
{
return (pos / (level * ITEMS_PER_TABLE * ITEMS_PER_BITMAP)) %
ITEMS_PER_TABLE;
}
walk_table(u64 *table, unsigned int level, u64 start, u64 last)
{
unsigned int index = get_index(level, start);
unsigned int last_index = get_index(level, last);
do {
if (table[index]) {
u64 *next_table = phys_to_virt(table[index]);
if (level == 1)
walk_bitmap(next_table);
else
walk_table(next_table, level - 1, start, last);
}
index++;
} while (index <= last_index);
}
insert_table(u64 *table, unsigned int level, u64 pos)
{
unsigned int index = get_index(level, start);
u64 *next_table;
if (!table[index]) {
// allocate table[index]
}
else
next_table = phys_to_virt(table[index]);
if (level == 1)
insert_bitmap(next_table, pos);
else
insert_table(next_table, level - 1, pos);
}
That's it.. No special cases requried.
The above is very limited, it only works with certain formulations
of start/last:
start has only one bit set
start & last == true,
last ^ start has bits 0 -> N set N > log2(ITEMS_PER_BITMAP)
Which align to my suggestion for encoding.
Jason
next prev parent reply other threads:[~2025-09-19 12:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 2:50 [RFC v1 0/4] Make KHO Stateless Jason Miu
2025-09-17 2:50 ` [RFC v1 1/4] kho: Introduce KHO page table data structures Jason Miu
2025-09-17 12:21 ` Jason Gunthorpe
2025-09-17 16:18 ` Pasha Tatashin
2025-09-17 16:32 ` Jason Gunthorpe
2025-09-19 6:49 ` Jason Miu
2025-09-19 12:56 ` Jason Gunthorpe [this message]
2025-09-17 2:50 ` [RFC v1 2/4] kho: Adopt KHO page tables and remove serialization Jason Miu
2025-09-17 17:52 ` Mike Rapoport
2025-09-19 6:58 ` Jason Miu
2025-09-19 2:14 ` kernel test robot
2025-09-17 2:50 ` [RFC v1 3/4] memblock: Remove KHO notifier usage Jason Miu
2025-09-18 9:17 ` kernel test robot
2025-09-17 2:50 ` [RFC v1 4/4] kho: Remove notifier system infrastructure Jason Miu
2025-09-17 11:36 ` [RFC v1 0/4] Make KHO Stateless Jason Gunthorpe
2025-09-17 14:48 ` Pasha Tatashin
2025-09-21 22:26 ` Matthew Wilcox
2025-09-21 23:07 ` Pasha Tatashin
2025-09-25 9:19 ` Mike Rapoport
2025-09-25 12:27 ` Pratyush Yadav
2025-09-25 12:33 ` Jason Gunthorpe
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=20250919125648.GS1391379@nvidia.com \
--to=jgg@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=changyuanl@google.com \
--cc=chenste@linux.microsoft.com \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=joel.granados@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mario.limonciello@amd.com \
--cc=mpdesouza@suse.com \
--cc=pasha.tatashin@soleen.com \
--cc=pmladek@suse.com \
--cc=rafael.j.wysocki@intel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=yan.y.zhao@intel.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: link
Be 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.