On Tue, Aug 06, 2019 at 11:50:42AM -0700, Linus Torvalds wrote:
In fact, I do note that a lot of the users don't actually use the "void *private" argument at all - they just want the walker - and just pass in a NULL private pointer. So we have things like this:
if (walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops,
NULL)) {
and in a perfect world we'd have arguments with default values so that we could skip those entirely for when people just don't need it.
I'm not a huge fan of C++ because of a lot of the complexity (and some really bad decisions), but many of the _syntactic_ things in C++ would be nice to use. This one doesn't seem to be one that the gcc people have picked up as an extension ;(
Yes, yes, we could do it with a macro, I guess.
#define walk_page_range(mm, start,end, ops, ...) \ __walk_page_range(mm, start, end, (NULL , ## __VA_ARGS__))
but I'm not sure it's worthwhile.
Has anyone looked at turning the interface inside-out? ie something like:
struct mm_walk_state state = { .mm = mm, .start = start, .end = end, };
for_each_page_range(&state, page) { ... do something with page ... }
with appropriate macrology along the lines of:
#define for_each_page_range(state, page) \ while ((page = page_range_walk_next(state)))
Then you don't need to package anything up into structs that are shared between the caller and the iterated function.