Skip to content

Commit

Permalink
Merge branch 'akpm' (patches from Andrew)
Browse files Browse the repository at this point in the history
Merge various fixes from Andrew Morton:
 "10 fixes"

* emailed patches from Andrew Morton <akpm@linux-foundation.org>:
  mm, page_alloc: recalculate the preferred zoneref if the context can ignore memory policies
  mm, page_alloc: reset zonelist iterator after resetting fair zone allocation policy
  mm, oom_reaper: do not use siglock in try_oom_reaper()
  mm, page_alloc: prevent infinite loop in buffered_rmqueue()
  checkpatch: reduce git commit description style false positives
  mm/z3fold.c: avoid modifying HEADLESS page and minor cleanup
  memcg: add RCU locking around css_for_each_descendant_pre() in memcg_offline_kmem()
  mm: check the return value of lookup_page_ext for all call sites
  kdump: fix dmesg gdbmacro to work with record based printk
  mm: fix overflow in vm_map_ram()
  • Loading branch information
torvalds committed Jun 4, 2016
2 parents 8c52b6d + e46e7b7 commit d46d025
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 50 deletions.
93 changes: 82 additions & 11 deletions Documentation/kdump/gdbmacros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,92 @@ document trapinfo
address the kernel panicked.
end

define dump_log_idx
set $idx = $arg0
if ($argc > 1)
set $prev_flags = $arg1
else
set $prev_flags = 0
end
set $msg = ((struct printk_log *) (log_buf + $idx))
set $prefix = 1
set $newline = 1
set $log = log_buf + $idx + sizeof(*$msg)

define dmesg
set $i = 0
set $end_idx = (log_end - 1) & (log_buf_len - 1)
# prev & LOG_CONT && !(msg->flags & LOG_PREIX)
if (($prev_flags & 8) && !($msg->flags & 4))
set $prefix = 0
end

# msg->flags & LOG_CONT
if ($msg->flags & 8)
# (prev & LOG_CONT && !(prev & LOG_NEWLINE))
if (($prev_flags & 8) && !($prev_flags & 2))
set $prefix = 0
end
# (!(msg->flags & LOG_NEWLINE))
if (!($msg->flags & 2))
set $newline = 0
end
end

if ($prefix)
printf "[%5lu.%06lu] ", $msg->ts_nsec / 1000000000, $msg->ts_nsec % 1000000000
end
if ($msg->text_len != 0)
eval "printf \"%%%d.%ds\", $log", $msg->text_len, $msg->text_len
end
if ($newline)
printf "\n"
end
if ($msg->dict_len > 0)
set $dict = $log + $msg->text_len
set $idx = 0
set $line = 1
while ($idx < $msg->dict_len)
if ($line)
printf " "
set $line = 0
end
set $c = $dict[$idx]
if ($c == '\0')
printf "\n"
set $line = 1
else
if ($c < ' ' || $c >= 127 || $c == '\\')
printf "\\x%02x", $c
else
printf "%c", $c
end
end
set $idx = $idx + 1
end
printf "\n"
end
end
document dump_log_idx
Dump a single log given its index in the log buffer. The first
parameter is the index into log_buf, the second is optional and
specified the previous log buffer's flags, used for properly
formatting continued lines.
end

while ($i < logged_chars)
set $idx = (log_end - 1 - logged_chars + $i) & (log_buf_len - 1)
define dmesg
set $i = log_first_idx
set $end_idx = log_first_idx
set $prev_flags = 0

if ($idx + 100 <= $end_idx) || \
($end_idx <= $idx && $idx + 100 < log_buf_len)
printf "%.100s", &log_buf[$idx]
set $i = $i + 100
while (1)
set $msg = ((struct printk_log *) (log_buf + $i))
if ($msg->len == 0)
set $i = 0
else
printf "%c", log_buf[$idx]
set $i = $i + 1
dump_log_idx $i $prev_flags
set $i = $i + $msg->len
set $prev_flags = $msg->flags
end
if ($i == $end_idx)
loop_break
end
end
end
Expand Down
43 changes: 36 additions & 7 deletions include/linux/page_idle.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,62 @@ extern struct page_ext_operations page_idle_ops;

static inline bool page_is_young(struct page *page)
{
return test_bit(PAGE_EXT_YOUNG, &lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return false;

return test_bit(PAGE_EXT_YOUNG, &page_ext->flags);
}

static inline void set_page_young(struct page *page)
{
set_bit(PAGE_EXT_YOUNG, &lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return;

set_bit(PAGE_EXT_YOUNG, &page_ext->flags);
}

static inline bool test_and_clear_page_young(struct page *page)
{
return test_and_clear_bit(PAGE_EXT_YOUNG,
&lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return false;

return test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags);
}

static inline bool page_is_idle(struct page *page)
{
return test_bit(PAGE_EXT_IDLE, &lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return false;

return test_bit(PAGE_EXT_IDLE, &page_ext->flags);
}

static inline void set_page_idle(struct page *page)
{
set_bit(PAGE_EXT_IDLE, &lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return;

set_bit(PAGE_EXT_IDLE, &page_ext->flags);
}

static inline void clear_page_idle(struct page *page)
{
clear_bit(PAGE_EXT_IDLE, &lookup_page_ext(page)->flags);
struct page_ext *page_ext = lookup_page_ext(page);

if (unlikely(!page_ext))
return;

clear_bit(PAGE_EXT_IDLE, &page_ext->flags);
}
#endif /* CONFIG_64BIT */

Expand Down
3 changes: 3 additions & 0 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2896,13 +2896,16 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
* ordering is imposed by list_lru_node->lock taken by
* memcg_drain_all_list_lrus().
*/
rcu_read_lock(); /* can be called from css_free w/o cgroup_mutex */
css_for_each_descendant_pre(css, &memcg->css) {
child = mem_cgroup_from_css(css);
BUG_ON(child->kmemcg_id != kmemcg_id);
child->kmemcg_id = parent->kmemcg_id;
if (!memcg->use_hierarchy)
break;
}
rcu_read_unlock();

memcg_drain_all_list_lrus(kmemcg_id, parent->kmemcg_id);

memcg_free_cache_id(kmemcg_id);
Expand Down
7 changes: 1 addition & 6 deletions mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ void try_oom_reaper(struct task_struct *tsk)
if (atomic_read(&mm->mm_users) > 1) {
rcu_read_lock();
for_each_process(p) {
bool exiting;

if (!process_shares_mm(p, mm))
continue;
if (fatal_signal_pending(p))
Expand All @@ -636,10 +634,7 @@ void try_oom_reaper(struct task_struct *tsk)
* If the task is exiting make sure the whole thread group
* is exiting and cannot acces mm anymore.
*/
spin_lock_irq(&p->sighand->siglock);
exiting = signal_group_exit(p->signal);
spin_unlock_irq(&p->sighand->siglock);
if (exiting)
if (signal_group_exit(p->signal))
continue;

/* Give up */
Expand Down
39 changes: 28 additions & 11 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ static inline void set_page_guard(struct zone *zone, struct page *page,
return;

page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
return;

__set_bit(PAGE_EXT_DEBUG_GUARD, &page_ext->flags);

INIT_LIST_HEAD(&page->lru);
Expand All @@ -673,6 +676,9 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,
return;

page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
return;

__clear_bit(PAGE_EXT_DEBUG_GUARD, &page_ext->flags);

set_page_private(page, 0);
Expand Down Expand Up @@ -2609,11 +2615,12 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
page = list_last_entry(list, struct page, lru);
else
page = list_first_entry(list, struct page, lru);
} while (page && check_new_pcp(page));

__dec_zone_state(zone, NR_ALLOC_BATCH);
list_del(&page->lru);
pcp->count--;
__dec_zone_state(zone, NR_ALLOC_BATCH);
list_del(&page->lru);
pcp->count--;

} while (check_new_pcp(page));
} else {
/*
* We most definitely don't want callers attempting to
Expand Down Expand Up @@ -3023,6 +3030,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
apply_fair = false;
fair_skipped = false;
reset_alloc_batches(ac->preferred_zoneref->zone);
z = ac->preferred_zoneref;
goto zonelist_scan;
}

Expand Down Expand Up @@ -3596,6 +3604,17 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
*/
alloc_flags = gfp_to_alloc_flags(gfp_mask);

/*
* Reset the zonelist iterators if memory policies can be ignored.
* These allocations are high priority and system rather than user
* orientated.
*/
if ((alloc_flags & ALLOC_NO_WATERMARKS) || !(alloc_flags & ALLOC_CPUSET)) {
ac->zonelist = node_zonelist(numa_node_id(), gfp_mask);
ac->preferred_zoneref = first_zones_zonelist(ac->zonelist,
ac->high_zoneidx, ac->nodemask);
}

/* This is the last chance, in general, before the goto nopage. */
page = get_page_from_freelist(gfp_mask, order,
alloc_flags & ~ALLOC_NO_WATERMARKS, ac);
Expand All @@ -3604,12 +3623,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,

/* Allocate without watermarks if the context allows */
if (alloc_flags & ALLOC_NO_WATERMARKS) {
/*
* Ignore mempolicies if ALLOC_NO_WATERMARKS on the grounds
* the allocation is high priority and these type of
* allocations are system rather than user orientated
*/
ac->zonelist = node_zonelist(numa_node_id(), gfp_mask);
page = get_page_from_freelist(gfp_mask, order,
ALLOC_NO_WATERMARKS, ac);
if (page)
Expand Down Expand Up @@ -3808,7 +3821,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
/* Dirty zone balancing only done in the fast path */
ac.spread_dirty_pages = (gfp_mask & __GFP_WRITE);

/* The preferred zone is used for statistics later */
/*
* The preferred zone is used for statistics but crucially it is
* also used as the starting point for the zonelist iterator. It
* may get reset for allocations that ignore memory policies.
*/
ac.preferred_zoneref = first_zones_zonelist(ac.zonelist,
ac.high_zoneidx, ac.nodemask);
if (!ac.preferred_zoneref) {
Expand Down
26 changes: 26 additions & 0 deletions mm/page_owner.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ void __reset_page_owner(struct page *page, unsigned int order)

for (i = 0; i < (1 << order); i++) {
page_ext = lookup_page_ext(page + i);
if (unlikely(!page_ext))
continue;
__clear_bit(PAGE_EXT_OWNER, &page_ext->flags);
}
}

void __set_page_owner(struct page *page, unsigned int order, gfp_t gfp_mask)
{
struct page_ext *page_ext = lookup_page_ext(page);

struct stack_trace trace = {
.nr_entries = 0,
.max_entries = ARRAY_SIZE(page_ext->trace_entries),
.entries = &page_ext->trace_entries[0],
.skip = 3,
};

if (unlikely(!page_ext))
return;

save_stack_trace(&trace);

page_ext->order = order;
Expand All @@ -82,13 +88,21 @@ void __set_page_owner(struct page *page, unsigned int order, gfp_t gfp_mask)
void __set_page_owner_migrate_reason(struct page *page, int reason)
{
struct page_ext *page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
return;

page_ext->last_migrate_reason = reason;
}

gfp_t __get_page_owner_gfp(struct page *page)
{
struct page_ext *page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
/*
* The caller just returns 0 if no valid gfp
* So return 0 here too.
*/
return 0;

return page_ext->gfp_mask;
}
Expand All @@ -99,6 +113,9 @@ void __copy_page_owner(struct page *oldpage, struct page *newpage)
struct page_ext *new_ext = lookup_page_ext(newpage);
int i;

if (unlikely(!old_ext || !new_ext))
return;

new_ext->order = old_ext->order;
new_ext->gfp_mask = old_ext->gfp_mask;
new_ext->nr_entries = old_ext->nr_entries;
Expand Down Expand Up @@ -193,6 +210,11 @@ void __dump_page_owner(struct page *page)
gfp_t gfp_mask = page_ext->gfp_mask;
int mt = gfpflags_to_migratetype(gfp_mask);

if (unlikely(!page_ext)) {
pr_alert("There is not page extension available.\n");
return;
}

if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
pr_alert("page_owner info is not active (free page?)\n");
return;
Expand Down Expand Up @@ -251,6 +273,8 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
}

page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
continue;

/*
* Some pages could be missed by concurrent allocation or free,
Expand Down Expand Up @@ -317,6 +341,8 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
continue;

page_ext = lookup_page_ext(page);
if (unlikely(!page_ext))
continue;

/* Maybe overraping zone */
if (test_bit(PAGE_EXT_OWNER, &page_ext->flags))
Expand Down
Loading

0 comments on commit d46d025

Please sign in to comment.