writeback: Fix occasional slow sync(1)

In case when system contains no dirty pages, wakeup_flusher_threads()
will submit WB_SYNC_NONE writeback for 0 pages so wb_writeback() exits
immediately without doing anything. Thus sync(1) will write all the
dirty inodes from a WB_SYNC_ALL writeback pass which is slow.

Fix the problem by using get_nr_dirty_pages() in
wakeup_flusher_threads() instead of calculating number of dirty pages
manually. That function also takes number of dirty inodes into account.

Change-Id: I458027ae08d9a5a93202a7b97ace1f8da7a18a07
CC: stable@vger.kernel.org
Reported-by: Paul Taysom <taysom@chromium.org>
Signed-off-by: Jan Kara <jack@suse.cz>
 writeback: fix race that cause writeback hung

There is a race between mark inode dirty and writeback thread, see the
following scenario.  In this case, writeback thread will not run though
there is dirty_io.

__mark_inode_dirty()                                          bdi_writeback_workfn()
	...                                                       	...
	spin_lock(&inode->i_lock);
	...
	if (bdi_cap_writeback_dirty(bdi)) {
	    <<< assume wb has dirty_io, so wakeup_bdi is false.
	    <<< the following inode_dirty also have wakeup_bdi false.
	    if (!wb_has_dirty_io(&bdi->wb))
		    wakeup_bdi = true;
	}
	spin_unlock(&inode->i_lock);
	                                                            <<< assume last dirty_io is removed here.
	                                                            pages_written = wb_do_writeback(wb);
	                                                            ...
	                                                            <<< work_list empty and wb has no dirty_io,
	                                                            <<< delayed_work will not be queued.
	                                                            if (!list_empty(&bdi->work_list) ||
	                                                                (wb_has_dirty_io(wb) && dirty_writeback_interval))
	                                                                queue_delayed_work(bdi_wq, &wb->dwork,
	                                                                    msecs_to_jiffies(dirty_writeback_interval * 10));
	spin_lock(&bdi->wb.list_lock);
	inode->dirtied_when = jiffies;
	<<< new dirty_io is added.
	list_move(&inode->i_wb_list, &bdi->wb.b_dirty);
	spin_unlock(&bdi->wb.list_lock);

	<<< though there is dirty_io, but wakeup_bdi is false,
	<<< so writeback thread will not be waked up and
	<<< the new dirty_io will not be flushed.
	if (wakeup_bdi)
	    bdi_wakeup_thread_delayed(bdi);

Writeback will run until there is a new flush work queued.  This may cause
a lot of dirty pages stay in memory for a long time.

Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>

Change-Id: I973fcba5381881a003a035ffff48f64348660079
 (CR) msm_fb: display: reduce turn-on display time.

    When turning on panel, increase its priority and restore it
    after panel has been turned on to reduce Turn-on display
    time when press power key.

    cherry pick commit:c43ca6a4 from main-jb-qc branch.

Change-Id: Ie0e8e55fc7498a6b2d43ad9e1995fa96c609c81e
Reviewed-on: http://gerrit.pcs.mot.com/500101
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Bang Nguyen <BNGUYEN1@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>

Conflicts:

	drivers/video/msm/mipi_dsi.c

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
 msm: camera: Fix for camera crash

In msm_server_control function add a check for src
and dest before calling memcpy function to avoid
kernel crash

Change-Id: I814f654c223892a21d585fef31bd6ef75254c108
CRs-Fixed: 444081
Signed-off-by: Suresh Vankadara <svankada@codeaurora.org>
Merge "Rotator getting stuck leading to fence timeout"

Change-Id: I1fc328e3e07c56fb406e9522920cdeb2b212248d
Merge "msm: camera: Clear frame stucture before use"

Change-Id: I7f03b6d71ed9abd5cbb29b797906c382e8227fdf
 msm: rotator: signal timeline when rotator prepare fails.

When rotator prepare fails, timeline is not signalled causing fence
timeout on the rotator release fence. This patch fixes the issue.

Change-Id: I6023393d768dbb1a0a9095bb1822ac504632ed64
Signed-off-by: Vishnuvardhan Prodduturi <vproddut@codeaurora.org>
Signed-off-by: Naseer Ahmed <naseer@codeaurora.org>
Merge "msm: rotator: Add support to YCBYCR rotator format"

Change-Id: I434e64e65d713a5ccc5502bec27361729ddf952c