Skip to content

Commit

Permalink
vmpressure: change vmpressure::sr_lock to spinlock
Browse files Browse the repository at this point in the history
There is nothing that can sleep inside critical sections protected by
this lock and those sections are really small so there doesn't make much
sense to use mutex for them.  Change the log to a spinlock

Signed-off-by: Michal Hocko <[email protected]>
Reported-by: Tejun Heo <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Cc: KOSAKI Motohiro <[email protected]>
Cc: Li Zefan <[email protected]>
Reviewed-by: Tejun Heo <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Michal Hocko authored and torvalds committed Jul 31, 2013
1 parent 62e32ac commit 22f2020
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/linux/vmpressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct vmpressure {
unsigned long scanned;
unsigned long reclaimed;
/* The lock is used to keep the scanned/reclaimed above in sync. */
struct mutex sr_lock;
struct spinlock sr_lock;

/* The list of vmpressure_event structs. */
struct list_head events;
Expand Down
10 changes: 5 additions & 5 deletions mm/vmpressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ static void vmpressure_work_fn(struct work_struct *work)
if (!vmpr->scanned)
return;

mutex_lock(&vmpr->sr_lock);
spin_lock(&vmpr->sr_lock);
scanned = vmpr->scanned;
reclaimed = vmpr->reclaimed;
vmpr->scanned = 0;
vmpr->reclaimed = 0;
mutex_unlock(&vmpr->sr_lock);
spin_unlock(&vmpr->sr_lock);

do {
if (vmpressure_event(vmpr, scanned, reclaimed))
Expand Down Expand Up @@ -240,11 +240,11 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
if (!scanned)
return;

mutex_lock(&vmpr->sr_lock);
spin_lock(&vmpr->sr_lock);
vmpr->scanned += scanned;
vmpr->reclaimed += reclaimed;
scanned = vmpr->scanned;
mutex_unlock(&vmpr->sr_lock);
spin_unlock(&vmpr->sr_lock);

if (scanned < vmpressure_win || work_pending(&vmpr->work))
return;
Expand Down Expand Up @@ -367,7 +367,7 @@ void vmpressure_unregister_event(struct cgroup *cg, struct cftype *cft,
*/
void vmpressure_init(struct vmpressure *vmpr)
{
mutex_init(&vmpr->sr_lock);
spin_lock_init(&vmpr->sr_lock);
mutex_init(&vmpr->events_lock);
INIT_LIST_HEAD(&vmpr->events);
INIT_WORK(&vmpr->work, vmpressure_work_fn);
Expand Down

0 comments on commit 22f2020

Please sign in to comment.