From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 965A8C77B61 for ; Fri, 14 Apr 2023 03:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09364900003; Thu, 13 Apr 2023 23:10:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 043BE900002; Thu, 13 Apr 2023 23:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4D69900003; Thu, 13 Apr 2023 23:10:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D52B3900002 for ; Thu, 13 Apr 2023 23:10:41 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A8C081A04E6 for ; Fri, 14 Apr 2023 03:10:41 +0000 (UTC) X-FDA: 80678519082.04.848B7CB Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf28.hostedemail.com (Postfix) with ESMTP id 2D445C000B for ; Fri, 14 Apr 2023 03:10:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DNXe5R5k; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681441839; a=rsa-sha256; cv=none; b=xR/R6ZfpCQ5HgLbItHH5X8SoUKCHPuApbe+fZiFzrhN0hMSWVs0hZMWoAUma0km0216TK/ oFDqvTrNOf5oYYL2WVRQGk0Im/cYzWns6f/SQzIQQQxDRy3KL/9cZMYTLMIHHQbdF/0Dfo 8uCyW7NquZvZ+TCg7q0IxvVIWvQqlLk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DNXe5R5k; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681441839; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fMIrmvteHvSYIB7FqfbPouuWmMmZppYL7ZNmhvmw9Pg=; b=4D1DsgRzTC+JVSm5JW/C6HpWPr4kT1FIQswnOdWSwzZ7+xvF1+ob4OyeglIBXEdu99dKZK SYj7A28d/1kJJxv1mYuGrdnzDgditWljJBqIkT11QEKlek9YM0Y8NVJdssA88Z00KTEzD+ kd8aP1hNt4mQyumvT+1/JU0VTw+dbnQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681441839; x=1712977839; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=dYWvX9si8ZEdJHGpbENtp+EkLrXzXwd/Hz+e5Z7kfxg=; b=DNXe5R5kx2kFkm+rQPocMHaHlq/1HxYLVGiKDpd3SIzrlsdQT8nWl1XW 66/EK8VBNc3JBIxiZtZJgFl5MYPdXknZopYIevcke8BWs93t+q23znK0w gzR5bTkqZgrN+M5ngTe2ebdcms0T8jUYGEulnDbpa7mR59n6r8LOZ8QOC nwBJrlX4q8OI3NjzhNEqAJ1siy+ZzRt0ae2Ul5J/ubgFrEb9RkYBot2H3 Gnhv+xWdkT1Y9QctmTnuP2lQCyLdo4H6lWbtKlJew8dZaHuOezWV1Drw3 zmJB/LWgR2VTK3vtD5wUhAIP753NmTZZA8efnSgbB2lMoghKsRFWIGKOi g==; X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="341870046" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="341870046" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 20:10:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="801027586" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="801027586" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 20:10:35 -0700 From: "Huang, Ying" To: Douglas Anderson Cc: Andrew Morton , Yu Zhao , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH] migrate_pages: Never block waiting for the page lock References: <20230413182313.RFC.1.Ia86ccac02a303154a0b8bc60567e7a95d34c96d3@changeid> Date: Fri, 14 Apr 2023 11:09:26 +0800 In-Reply-To: <20230413182313.RFC.1.Ia86ccac02a303154a0b8bc60567e7a95d34c96d3@changeid> (Douglas Anderson's message of "Thu, 13 Apr 2023 18:23:15 -0700") Message-ID: <87v8hz17o9.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Queue-Id: 2D445C000B X-Rspamd-Server: rspam01 X-Stat-Signature: owhayxyqc8ho4jikcrb1rw7fr5qgir6a X-HE-Tag: 1681441838-353756 X-HE-Meta: U2FsdGVkX1+WjJneq2wvmZqKlxJXTMbqp0edHBcDijRVeWo0ruu5Iif/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oPv1ONGqVfbmLyfiEH4uIiuE1mMowzDVtaqRLXMLs9prqDiM+Y0p1qlRTrLRxo7u4fQezirZdo0InUSbpflCGl9yXvrlrcBEZlDT6Ogr+JujeT/CJjLFN0BvPIsnpkbY3Hs1Begk6bJzL8VC5ziBRzLI06A2YKw9Hjr6EuEmeUhATR+ksTeodo25pvo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Douglas Anderson writes: > Currently when we try to do page migration and we're in "synchronous" > mode (and not doing direct compaction) then we'll wait an infinite > amount of time for a page lock. This does not appear to be a great > idea. > > One issue can be seen when I put a device under extreme memory > pressure. I took a sc7180-trogdor Chromebook (4GB RAM, 8GB zram > swap). I ran the browser along with Android (which runs from a > loopback mounted 128K block-size squashfs "disk"). I then manually ran > the mmm_donut memory pressure tool [1]. The system is completely > unusable both with and without this patch since there are 8 processes > completely thrashing memory, but it was still interesting to look at > how migration was behaving. I put some timing code in and I could see > that we sometimes waited over 25 seconds (in the context of > kcompactd0) for a page lock to become available. Although the 25 > seconds was the high mark, it was easy to see tens, hundreds, or > thousands of milliseconds spent waiting on the lock. > > Instead of waiting, if I bailed out right away (as this patch does), I > could see kcompactd0 move forward to successfully to migrate other > pages instead. This seems like a better use of kcompactd's time. > > Thus, even though this didn't make the system any more usable in my > absurd test case, it still seemed to make migration behave better and > that feels like a win. It also makes the code simpler since we have > one fewer special case. TBH, the test case is too extreme for me. And, we have multiple "sync" mode to deal with latency requirement, for example, we use MIGRATE_SYNC_LIGHT for compaction to avoid too long latency. If you have latency requirement for some users, you may consider to add new "sync" mode. Best Regards, Huang, Ying > The second issue that this patch attempts to fix is one that I haven't > managed to reproduce yet. We have crash reports from the field that > report that kcompactd0 was blocked for more than ~120 seconds on this > exact lock. These crash reports are on devices running older kernels > (5.10 mostly). In most of these crash reports the device is under > memory pressure and many tasks were blocked in squashfs code, ext4 > code, or memory allocation code. While I don't know if unblocking > kcompactd would actually have helped relieve the memory pressure, at > least there was a chance that it could have helped a little bit. > > [1] https://chromium.googlesource.com/chromiumos/platform/microbenchmarks/+/refs/heads/main/mmm_donut.py > > Signed-off-by: Douglas Anderson > --- > > mm/migrate.c | 25 +++++++------------------ > 1 file changed, 7 insertions(+), 18 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index db3f154446af..dfb0a6944181 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1143,26 +1143,15 @@ static int migrate_folio_unmap(new_page_t get_new_page, free_page_t put_new_page > dst->private = NULL; > > if (!folio_trylock(src)) { > - if (mode == MIGRATE_ASYNC) > - goto out; > - > /* > - * It's not safe for direct compaction to call lock_page. > - * For example, during page readahead pages are added locked > - * to the LRU. Later, when the IO completes the pages are > - * marked uptodate and unlocked. However, the queueing > - * could be merging multiple pages for one bio (e.g. > - * mpage_readahead). If an allocation happens for the > - * second or third page, the process can end up locking > - * the same page twice and deadlocking. Rather than > - * trying to be clever about what pages can be locked, > - * avoid the use of lock_page for direct compaction > - * altogether. > + * While there are some modes we could be running in where we > + * could block here waiting for the lock (specifically > + * modes other than MIGRATE_ASYNC and when we're not in > + * direct compaction), it's not worth the wait. Instead of > + * waiting, we'll bail. This will let the caller try to > + * migrate some other pages that aren't contended. > */ > - if (current->flags & PF_MEMALLOC) > - goto out; > - > - folio_lock(src); > + goto out; > } > locked = true;