Messages in this thread | | | Date | Mon, 22 Oct 2012 23:30:25 -0700 | From | Andrew Morton <> | Subject | Re: [rfc 0/2] Introducing VmFlags field into smaps output |
| |
On Tue, 23 Oct 2012 10:13:41 +0400 Cyrill Gorcunov <gorcunov@openvz.org> wrote:
> On Mon, Oct 22, 2012 at 02:51:58PM -0700, Andrew Morton wrote: > ... > > > + __seq_show_vmflag(VM_DONTEXPAND,"de "); > > > + __seq_show_vmflag(VM_ACCOUNT, "ac "); > > > + __seq_show_vmflag(VM_NORESERVE, "nr "); > > > + __seq_show_vmflag(VM_HUGETLB, "ht "); > > > + __seq_show_vmflag(VM_NONLINEAR, "nl "); > > > + __seq_show_vmflag(VM_ARCH_1, "ar "); > > > + __seq_show_vmflag(VM_DONTDUMP, "dd "); > > > + __seq_show_vmflag(VM_MIXEDMAP, "mm "); > > > + __seq_show_vmflag(VM_HUGEPAGE, "hg "); > > > + __seq_show_vmflag(VM_NOHUGEPAGE,"nh "); > ... > > > > This code would be much denser if we did the old > > > > static const char foo[] = "rdwrexshmrmw..."; > > unsigned i; > > > > for (i = 0; i < BITS_PER_LONG; i++) { > > if (flags & (1 << i)) > > seq_printf("%c%c ", foo[i * 2], foo[i * 2 + 1]); > > } > > > > trick. But then we'd have to remember to fix foo[] each time we > > alter the flags, so maybe let's not do that. > > Yup, but not only that, this kind of trick hides associativity between > VM_ constant and mnemonic, so on changes one would have to figure out > which position some flag has in this foo[] array, so I vote for not > use it :-)
Well you could do
struct { char x[2]; } y[] = { [CLOG2(VM_DONTEXPAND)] = { 'd', 'e' }, [CLOG2(VM_ACCOUNT)] = { 'a', 'c' }, [CLOG2(VM_NORESERVE)] = { 'n', 'r' }, };
...
for (i = 0; i < BITS_PER_LONG; i++) { if (flags & (1 << i)) seq_printf("%c%c ", y[i][0], y[i][1]); }
where CLOG2() is extracted from the guts of ilog2().
I'll stop now :)
| |