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 AF93DC77B76 for ; Tue, 18 Apr 2023 03:18:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40B648E0001; Mon, 17 Apr 2023 23:18:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BB086B0072; Mon, 17 Apr 2023 23:18:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 283AF8E0001; Mon, 17 Apr 2023 23:18:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 14FF96B0071 for ; Mon, 17 Apr 2023 23:18:34 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E21E01203E7 for ; Tue, 18 Apr 2023 03:18:33 +0000 (UTC) X-FDA: 80693054106.09.DFC68BF Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf25.hostedemail.com (Postfix) with ESMTP id 360AAA000F for ; Tue, 18 Apr 2023 03:18:30 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=B+XtuCaO; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.115 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=1681787912; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4gQmWpuZAZ5PHL4ZNwoRHldyH9Uwi/EQsItbAZEBNRg=; b=R5Ue5ACcR+XrdbctesPF1/aCliQvBawGniXawzxFWhKE3ricqpBEjDFPtNvbaMGwQKpp3d FG+HFdqx3N2zNkZ9dF+uVwiY1/OPbqconYAmzrTO716p1lvw3lTOu3cIykikO/gDkqiQCJ l3mQz52xwa9Lall42b5QhdIZt+TqDVc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=B+XtuCaO; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.115 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=1681787912; a=rsa-sha256; cv=none; b=oPlbAJ5yNlOCJ84i5pL6Y+h/EW8cTHe99EpD9coQKvRXx1BtA9eE9GIgmDlPwwLvEMUQWH eOwCeyDGqdpu4Fptr3XgcPRpASXUZMUepdfzZ/heXRO98Q+2aparu5yNMk/OpbeSFA0KZf dvtonNe43tLuRHu53RzMsW3CwPJPVBQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681787911; x=1713323911; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version:content-transfer-encoding; bh=W/5Kj2EAfX48G345cd/tj2ACbFyXz/pZDq4aXPDHLTY=; b=B+XtuCaOxIVMFxF9wNdjsjK/fiE1i00f7JPmmr1T9UnObcLTEH3GOjSk kWJTbNBMdkPCDDtdxcN0fdOyQWNac5dgPdyACzivDv/04FpPOVokT8mMk JioPIA2a+JDM3q9FMEnF3pbVKJ23KcOIR7ogsay9keZiRTohS+vJx8btw Rma2dFT2HCmjQ65rfUk4OuDF10cAD2zJcOFRTuCIJJqjYhph7KQcsRHUm OfQt9yXJ5e6JG1XsVvF68oHjTImwxax7d5jt/mMv763dMLCZob3UkKLFx Ii1/XJSB2BXy4FGfU5/FG8Pp/UALuRbKlJMTIJsWQR876b8XGjxeT/L1W g==; X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="345061271" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="345061271" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2023 20:18:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="760203647" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="760203647" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2023 20:18:15 -0700 From: "Huang, Ying" To: Doug 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> <87v8hz17o9.fsf@yhuang6-desk2.ccr.corp.intel.com> <87ildvwbr5.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Tue, 18 Apr 2023 11:17:03 +0800 In-Reply-To: (Doug Anderson's message of "Mon, 17 Apr 2023 07:28:28 -0700") Message-ID: <87edohvpzk.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=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 360AAA000F X-Stat-Signature: bxnanqzi9to8oukxc1bwd1qfwmtjk7sx X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681787910-347867 X-HE-Meta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qiw93DTlCBJRmcepwvjStgByE9e+m27mZ+Z/xB5Xs/d73zIkPEpdObv7eydLdxLiaP42sma/kL4b2wh0Ej2077u8v3R6mCgzCKema7t1+8UttGrvCNgEY93ohQ+FJEIp+sIbj5igsX+dkRTQ/fw8+rDlYukQ0pndm6uVtB5b0e3Ft3mAPfoMyrtfmGc6g36kw1VqqUdQOf+ssf6iHnWsqW6F X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Doug Anderson writes: > Hi, > > On Sun, Apr 16, 2023 at 6:15=E2=80=AFPM Huang, Ying wrote: >> >> Doug Anderson writes: >> >> > Hi, >> > >> > On Thu, Apr 13, 2023 at 8:10=E2=80=AFPM Huang, Ying wrote: >> >> >> >> Douglas Anderson writes: >> >> >> >> > Currently when we try to do page migration and we're in "synchronou= s" >> >> > 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 process= es >> >> > completely thrashing memory, but it was still interesting to look at >> >> > how migration was behaving. I put some timing code in and I could s= ee >> >> > 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 a= nd >> >> > 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. >> > >> > That's fair. That being said, I guess the point I was trying to make >> > is that waiting for this lock could take an unbounded amount of time. >> > Other parts of the system sometimes hold a page lock and then do a >> > blocking operation. At least in the case of kcompactd there are better >> > uses of its time than waiting for any given page. >> > >> >> And, we have multiple "sync" mode to deal with latency requirement, f= or >> >> 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. >> > >> > Sure. kcompactd_do_work() is currently using MIGRATE_SYNC_LIGHT. I >> > guess my first thought would be to avoid adding a new mode and make >> > MIGRATE_SYNC_LIGHT not block here. Then anyone that truly needs to >> > wait for all the pages to be migrated can use the heavier sync modes. >> > It seems to me like the current users of MIGRATE_SYNC_LIGHT would not >> > want to block for an unbounded amount of time here. What do you think? >> >> It appears that you can just use MIGRATE_ASYNC if you think the correct >> behavior is "NOT block at all". I found that there are more >> fine-grained controls on this in compaction code, please take a look at >> "enum compact_priority" and its comments. > > Actually, the more I think about it the more I think the right answer > is to keep kcompactd as using MIGRATE_SYNC_LIGHT and make > MIGRATE_SYNC_LIGHT not block on the folio lock. Then, what is the difference between MIGRATE_SYNC_LIGHT and MIGRATE_ASYNC? > kcompactd can accept some blocking but we don't want long / unbounded > blocking. Reading the comments for MIGRATE_SYNC_LIGHT, this also seems > like it fits pretty well. MIGRATE_SYNC_LIGHT says that the stall time > of writepage() is too much. It's entirely plausible that someone else > holding the lock is doing something as slow as writepage() and thus > waiting on the lock can be just as bad for latency. IIUC, during writepage(), the page/folio will be unlocked. But, during page reading, the page/folio will be locked. I don't really understand why we can wait for page reading but cannot wait for page writeback. Best Regards, Huang, Ying > I'll try to send out a v2 with this approach today and we can see what > people think. > > -Doug