remove magic numbers for fault return codes
Subsystems (2)
The return codes from fault handling functions are open-coded in memory.c and arch/i386/mm/fault.c.
This patch removes them in favor of defining integer constants with mnemonic names and using them as the return codes and in dispatches on the return values from handle_mm_fault(), and also removing some of the associated comments explaining what the magic numbers mean at various points where they were formerly used. In addition two redundant variables were removed, a comment was added to the bad_wp_page: label to explain to onlookers more of what the printk() there means, and failure to match the return code with a value in the various switch() statements on the return code was flagged as a BUG() at various points.
Quoted 1 line
From what I saw in
page_alloc.clast time, since these hit the same
lines, they might as well all go out in one batch. I am, of course, willing to adjust/separate various bits as desired.
Cheers,
Bill
===== include/linux/mm.h 1.55 vs edited =====
include/linux/mm.h +10 -0
@@ -305,6 +305,16 @@#define NOPAGE_SIGBUS (NULL)#define NOPAGE_OOM ((struct page *) (-1)) +/* +* Different kinds of faults, as returned by handle_mm_fault(). +* Used to decide whether a process gets delivered SIGBUS or +* just gets major/minor fault counters bumped up. +*/ +#define VM_FAULT_OOM (-1) +#define VM_FAULT_SIGBUS 0 +#define VM_FAULT_MINOR 1 +#define VM_FAULT_MAJOR 2 +/* The array of struct pages */ extern struct page *mem_map;
===== mm/memory.c 1.70 vs edited =====
mm/memory.c +36 -28
169 lines not on this page · raw message
===== arch/i386/mm/fault.c 1.13 vs edited =====
arch/i386/mm/fault.c +20 -14
@@ -56,12 +56,16 @@for (;;) { survive: - { -int fault =handle_mm_fault (current->mm, vma, start,1 ); -if (!fault) +switch (handle_mm_fault (current->mm, vma, start,1 )) { +case VM_FAULT_SIGBUS : goto bad_area; -if (fault <0 ) +case VM_FAULT_OOM : goto out_of_memory; +case VM_FAULT_MINOR : +case VM_FAULT_MAJOR : +break ; +default : +BUG (); }if (!size)break ;
@@ -239,16 +243,18 @@* the fault. */ switch (handle_mm_fault (mm, vma, address, write)) { -case 1 : - tsk->min_flt++; -break ; -case 2 : - tsk->maj_flt++; -break ; -case 0 : - goto do_sigbus; -default : - goto out_of_memory; +case VM_FAULT_MINOR : + tsk->min_flt++; +break ; +case VM_FAULT_MAJOR : + tsk->maj_flt++; +break ; +case VM_FAULT_SIGBUS : + goto do_sigbus; +case VM_FAULT_OOM : + goto out_of_memory; +default : +BUG (); }/*
Quoted 9 lines · William Lee Irwin III
This patch removes them in favor of defining integer constants with mnemonic names and using them as the return codes and in dispatches on the return values from
handle_mm_fault(), and also removing some of the associated comments explaining what the magic numbers mean at various points where they were formerly used. In addition two redundant variables were removed, a comment was added to thebad_wp_page: label to explain to onlookers more of what theprintk()there means, and failure to match the return code with a value in the variousswitch()statements on the return code was flagged as aBUG()at various points.
This is against 2.5.20, sorry for not mentioning that before.
Cheers,
Bill