Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp551150rwr; Wed, 26 Apr 2023 03:10:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Zi4TtggCgRz4bsBYc9shSypX0lGjNnArY//Q07jTYD6I3V9Jx82UR/Gor/4toS8JN7DHt X-Received: by 2002:a17:90a:bf0c:b0:23f:9445:318e with SMTP id c12-20020a17090abf0c00b0023f9445318emr2371072pjs.3.1682503825119; Wed, 26 Apr 2023 03:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682503825; cv=none; d=google.com; s=arc-20160816; b=WoilEIPs6yZ7vN9i2j8+8Sj6vcy85ht4v8x7WUx95Y2TdDjzxkfDXMvR06RHGRk5Lc T3UBVYCfPU4oVDMRUkEtp4onKb+hvuqSQL5/AjmUYVQQ8CBaUZxpkdnL5SN59EVdfGUJ WWAtGpOByaIVVaRSkcauie7zMc4+MlsQBGNFRdpFFRI7e63EWR1VKrJIWKsrUjzCux3T MoB0ro3mQoklpCp1nbmXXS5OBkn5j7MBYOQo0AqGDZhnr1GgGV+WwTO+1qFhU6QXCUKc wQ4zxZ76m0kpazsHxQ9CII/wBHqQRyNC7pAW5VmEr0TclUrA6NEDhxCihrbMTqGaDgQ8 orjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=UG/s7xEQecmcWewG2XLEuHHBK7IY1W9Q/psyJVyiesM=; b=WdGI2tNyOUbQvmHzCvxWn4uq+juv7g1cZ9yw+WY7CPkxJTjgLk7ZeCFvq3dzQh5al9 q07ct2spFyZnViiHxkZwtkn7Xse+CAOkLcdTO5RyvZWUktLmFEVE7VMAYB3Knt9pl2Sv HuXjGC9pxqsLV/1x//Yn1bRA21RC5tUqkpZKelvQArmF+3PBavzLc1Jp03kqudmIhoto 1TCHulOHwPyG1NMnA4IMxq4dpLCWdczS2x8+YlUVXishBrTt5dtSLtgvRbqbVXKEz8p4 qdlGLT2sDcV2TvCX/mjaOQCUN6J2SZhj03w0O/iNtkwXFZT+bxWeJHxxtu4unujAt7CN l6SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a17090a718900b0023d0131c21asi15571846pjk.66.2023.04.26.03.10.11; Wed, 26 Apr 2023 03:10:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240025AbjDZKJ0 (ORCPT + 99 others); Wed, 26 Apr 2023 06:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240445AbjDZKJZ (ORCPT ); Wed, 26 Apr 2023 06:09:25 -0400 Received: from outbound-smtp41.blacknight.com (outbound-smtp41.blacknight.com [46.22.139.224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CC03C39 for ; Wed, 26 Apr 2023 03:09:22 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp41.blacknight.com (Postfix) with ESMTPS id 145C822D7 for ; Wed, 26 Apr 2023 11:09:21 +0100 (IST) Received: (qmail 9114 invoked from network); 26 Apr 2023 10:09:20 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.21.103]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 26 Apr 2023 10:09:20 -0000 Date: Wed, 26 Apr 2023 11:09:18 +0100 From: Mel Gorman To: Doug Anderson Cc: Hillf Danton , Andrew Morton , Alexander Viro , Christian Brauner , Linus Torvalds , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yu Zhao , Matthew Wilcox Subject: Re: [PATCH v2 1/4] mm/filemap: Add folio_lock_timeout() Message-ID: <20230426100918.ku32k6mqoogsnijn@techsingularity.net> References: <20230421221249.1616168-1-dianders@chromium.org> <20230421151135.v2.1.I2b71e11264c5c214bc59744b9e13e4c353bc5714@changeid> <20230422051858.1696-1-hdanton@sina.com> <20230425010917.1984-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 25, 2023 at 07:19:48AM -0700, Doug Anderson wrote: > Hi, > > On Mon, Apr 24, 2023 at 6:09???PM Hillf Danton wrote: > > > > On 24 Apr 2023 09:56:58 -0700 Douglas Anderson > > > On Fri, Apr 21, 2023 at 10:19=E2=80=AFPM Hillf Danton wrote: > > > > If kcompactd is waken > > > > up by kswapd, waiting for slow IO is the right thing to do. > > > > > > I don't have enough intuition here, so I'm happy to take others' > > > advice here. I guess my thought was that kcompactd is explicitly not > > > using the full "sync" and instead choosing the "sync light". To me > > > that means we shouldn't block for _too_ long. > > > > Take a look at another case of lock wait [1]. > > > > [1] https://lore.kernel.org/lkml/CAHk-=wgyL9OujQ72er7oXt_VsMeno4bMKCTydBT1WSaagZ_5CA@mail.gmail.com/ > > So is this an explicit NAK on this approach, then? It still feels > worthwhile to me given the current kcompactd design where there is a > single thread that's in charge of going through and cleaning up all of > memory. Any single pags isn't _that_ important for kcompactd to deal > with and it's nice not to block the whole task's ability to make > progress. kcompactd is already very much designed in this model (which > is why SYNC_LIGHT exists in the first place) and that's why my patch > series was relatively simple/short. That being said, if people really > don't think I should pursue this then I won't send another version and > we can drop it. I don't consider it to be an explicit NAK but lets cc Linus because it's a valid question. Linus, the patch is https://lore.kernel.org/lkml/20230421151135.v2.1.I2b71e11264c5c214bc59744b9e13e4c353bc5714@changeid/ asnd it's adding folio_lock_timeout which in older terms is a lock_page_timout. The intended use is kcompactd doing out-of-line compaction (like kswapd does out-of-line reclaim) to try lock a page in MIGRATE_SYNC_LIGHT mode but if it cannot be locked quickly then give up and move on to another migration candidate. The MIGRATE_SYNC_LIGHT is expected to incur some delays while trying to make forward progress and the overall problem is that kcompactd can sometimes stall for many seconds and sometimes minutes on one page. The reason I don't consider this patch a NAK candidate is that this is not conditional locking as such because no special action is taken if the lock cannot be acquired. In the referenced mail, I think the context for the IO NOWAIT stuff is "try lock and if that fails, delegate the work to an async context". That is not necessarily a universal win and it's potentially complex. It's not a universal win because it's unknown how long it would take to acquire the lock and it may be a short enough period to be cheaper than the setup_for_async+context_switch+completion handler. If that happens often enough in a short window then delegation may be slower overall than doing the work synchronously. It's potentially complex because the setup for async handling and completion needs code that must be maintained. The kcompactd case using folio_lock_timeout is different. If the lock fails, it's not being explicitly delegated to another context, the page is simply ignored and kcompactd moves on. Fair enough, another context may end up migrating the same page in direct compaction or kcompactd at a later time but there is no complex setup for that and it's not explicit delegation. It's vaguely similar to how shrink_folio_list() calls folio_trylock and if that fails, keep the page on the LRU for a future attempt with the main difference being that some time is spent on trylock. This is *also* not necessarily a universal win because kcompactd could find a suitable migration candidate quicker by a plain trylock but that's what MIGRATE_ASYNC is for, MIGRATE_SYNC_LIGHT is expected to delay for short periods of time when MIGRATE_ASYNC fails and the problem being solved is the folio lock taking minutes to acquire. -- Mel Gorman SUSE Labs