There is really no documentation about how the linked lists in the
lists.h should be used. Specifically, it does not mention the fact
that the head entry of the list should never be used at all. Instead,
the head entry, when being empty, just points to itself.
Now that this fact is clear, a lot of difficult assumptions can be
left out and some overly complicated code can be cleared with the list
handling. This is because the head entry does not have to contain a
valid entry at all.
This also fixes a bug with was caused by the incorrect list handling:
printing the process list always had the head entry missing, since the
list_for_all() functions left the head entry unhandled for purpose.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
struct maps_list *ml;
if (af->pid) {
struct maps_list *ml;
if (af->pid) {
+ if (list_empty(&pf->ml.list)) {
- if (list_empty(&pf->ml->list)) {
- ml = list_to_maps_list(&pf->ml->list);
- if (ml->map->pid == af->pid)
- goto get_stats;
- list_for_each_entry(ml, &pf->ml->list, list) {
+ list_for_each_entry(ml, &pf->ml.list, list) {
if (ml->map->pid == af->pid)
goto get_stats;
}
if (ml->map->pid == af->pid)
goto get_stats;
}
int main(int argc, char *argv[])
{
struct pageframe pf;
int main(int argc, char *argv[])
{
struct pageframe pf;
- struct process *process_list = NULL;
+ struct process process_list;
struct parse_opts opts;
if (getuid()) {
struct parse_opts opts;
if (getuid()) {
}
memset(&pf, 0, sizeof(pf));
}
memset(&pf, 0, sizeof(pf));
+ INIT_LIST_HEAD(&pf.ml.list);
+
+ memset(&process_list, 0, sizeof(process_list));
+ INIT_LIST_HEAD(&process_list.list);
if (scan_all_pids(&pf, &process_list, &opts))
return 1;
if (opts.parse_mask & PARSE_DUMP)
if (scan_all_pids(&pf, &process_list, &opts))
return 1;
if (opts.parse_mask & PARSE_DUMP)
- dump_process_maps(process_list);
+ dump_process_maps(&process_list);
- print_pid_stats(&pf, process_list, &opts);
+ print_pid_stats(&pf, &process_list, &opts);
struct pageframe {
struct bintree tree;
struct pageframe {
struct bintree tree;
- struct maps_list *ml; /* List to mappings which point to this pfn */
+ struct maps_list ml; /* List to mappings which point to this pfn */
unsigned long pfn; /* page frame number */
int swap_type;
int swap_offset;
unsigned long pfn; /* page frame number */
int swap_type;
int swap_offset;
goto err;
clear_pageframe(pageframe);
goto err;
clear_pageframe(pageframe);
+ INIT_LIST_HEAD(&pageframe->ml.list);
* Add a link from the physical page to this
* process's page map
*/
* Add a link from the physical page to this
* process's page map
*/
- if (!match->ml) {
- match->ml = alloc_maplist();
- match->ml->map = map;
- } else {
- tmp = alloc_maplist();
- tmp->map = map;
- list_add(&tmp->list, &match->ml->list);
- }
+ tmp = alloc_maplist();
+ tmp->map = map;
+ list_add(&tmp->list, &match->ml.list);
if (match->page_present)
map->pages_present++;
if (match->page_present)
map->pages_present++;
}
static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
}
static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
- struct process **process_list, struct parse_opts *opts)
+ struct process *process_list, struct parse_opts *opts)
{
struct maps *maps;
struct process *process;
{
struct maps *maps;
struct process *process;
memset(process, 0, sizeof(*process));
INIT_LIST_HEAD(&process->list);
memset(process, 0, sizeof(*process));
INIT_LIST_HEAD(&process->list);
- if (*process_list == NULL)
- *process_list = process;
-
process->pid = pid;
process->tid = tid;
process->pid = pid;
process->tid = tid;
- list_add_tail(&process->list, &(*process_list)->list);
+ list_add_tail(&process->list, &process_list->list);
static int read_pageframe_with_threads(int pid,
struct pageframe *pageframe,
static int read_pageframe_with_threads(int pid,
struct pageframe *pageframe,
- struct process **process_list,
+ struct process *process_list,
struct parse_opts *opts)
{
DIR *dir = NULL;
struct parse_opts *opts)
{
DIR *dir = NULL;
-int scan_all_pids(struct pageframe *pf, struct process **process_list,
+int scan_all_pids(struct pageframe *pf, struct process *process_list,
struct parse_opts *opts)
{
DIR *dir = NULL;
struct parse_opts *opts)
{
DIR *dir = NULL;
-int scan_all_pids(struct pageframe *pf, struct process **process_list,
+int scan_all_pids(struct pageframe *pf, struct process *process_list,
struct parse_opts *opts);
#endif
struct parse_opts *opts);
#endif