Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2062864lqz; Tue, 2 Apr 2024 06:23:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW31fpR0PfHmwQpiAqaMtrcMjKY00QOBJr5xiZgR7wM/wSOhS14KmjToTB4JhUKHeFveDY/mvPmWh19uWR4Xyc2oqPtRaHwB9Ga0Q1fTA== X-Google-Smtp-Source: AGHT+IFBK83wjqayP7AieBfWqznZXib5r7ONCTeZBverI1raQ3VO2PQsy/hFs/ZyFhZi23qKSGIq X-Received: by 2002:a05:6358:8313:b0:183:b74a:235d with SMTP id i19-20020a056358831300b00183b74a235dmr8537778rwk.19.1712064188026; Tue, 02 Apr 2024 06:23:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712064187; cv=pass; d=google.com; s=arc-20160816; b=1FJUBls6Z9x2rszNclid3pe93L2mUqsHDyjw7ERgiUBauMLBElosdhFyyH+kFXZDj+ mSVZBvLMhxU2E6bmHz12UKY3QQEEG6l0UlzZOTQU37/PabW1r/MaQPsJapDBezZkA5Kf O8bA4Qcr/0XZnbZxqaI/t2ek7ByrAhRf6vcrhW6RqHH7pjcNH2/5ujWXUzgjAlxEsZ17 bCb3L71ekDzU9/fieNeUgMtJuQCQka5Skypr4OOxHBgueA16NSlgw8P4YHjDYOSB11o3 JxCPxH2YbGBMKitjda0fwfy3vjiZTEOqY4KyqNPpwQtWdeSpMHc5Zyw/c/4QuLCDvcoj Jonw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=0N5m48UJdTu9hnuMyQjCPLZxg5mCohfv9K3w3nogzC0=; fh=3cULz2uNDeJifropYdulCahm9pRRJlGVKjRQ33O9T9A=; b=AlFG3DW4jnQfvwPeZ2XsZ4DaoO7W5siJcJB2QSus5Cei5p/6oOmqdW1Jdyd7lbrv+2 QRK3kFASj91QZ5V+MHP6uhmh8tlfH1YGMWzrL2CQkaX12eJqaNtpEd3fvPpYU0cGvAb0 0JzRM+I2k+E8dJVPsYLTjQ60Qz7BMmiE0w8PGxquaLRBrZfmxykAZ/ZleHDeAsKYBVjN XPudtp/vNikqFdchKQLesqf2nwD6Swpphjs3OByfx6f0MeIVk+95mW8rqszWZAhrnGxj v48aPAGEQNRZEI4i3pON9uAUaEB6A+If6EdaCIBENT6YyfNcUXpJDjCoa8JLWzEmHAsc wTZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-128035-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128035-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f23-20020ab032d7000000b007e33caf0b51si771436uao.137.2024.04.02.06.23.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 06:23:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128035-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-128035-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128035-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 41E2A1C20E80 for ; Tue, 2 Apr 2024 13:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EA3084A41; Tue, 2 Apr 2024 13:22:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABA5383CCD for ; Tue, 2 Apr 2024 13:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712064170; cv=none; b=g5yQMkPEl1jCtNWvtEAkz9mp88qx+ggrX8m1Bfw+7G5M824LV5wECZ8ESt85JjtlP3R67mcrLFrH4vnekcGES4hIecDZf5spApKGtqOwQe6WWpRY6SXRcTIiHHZfNO8yIeSQq9l8YXUZAFpEU9j03+PO5yAL3l5V9SJ3/X+dueo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712064170; c=relaxed/simple; bh=XrfJSTjm4r29iHY8a+jXlQqBx+JfDME8GkZEPPSzEmw=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=CHArMKSSe9sD9HHIRzNlRLWtiAogweDb0LChiFvGB60bSfXZX1B+fDW9x4jeE+KsBsAME0SMN5LjXgCWrAg7dwl2SKLpjK5KdE3T7egYqycuCquZAM0MidngwjNX796gX2acFW++3e0rLg1kZtnRiP6edI7ZwNlMfkMpgw9cbI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B5BC1007; Tue, 2 Apr 2024 06:23:19 -0700 (PDT) Received: from [10.1.38.163] (XHFQ2J9959.cambridge.arm.com [10.1.38.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EB8EE3F766; Tue, 2 Apr 2024 06:22:45 -0700 (PDT) Message-ID: <47fa11db-3c26-48a6-bb7e-5ea59739b691@arm.com> Date: Tue, 2 Apr 2024 14:22:44 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 5/6] mm: vmscan: Avoid split during shrink_folio_list() Content-Language: en-GB From: Ryan Roberts To: Barry Song <21cnbao@gmail.com> Cc: Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Chris Li , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song References: <20240327144537.4165578-1-ryan.roberts@arm.com> <20240327144537.4165578-6-ryan.roberts@arm.com> <63c9caf4-3af4-4149-b3c2-e677788cb11f@arm.com> In-Reply-To: <63c9caf4-3af4-4149-b3c2-e677788cb11f@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 02/04/2024 14:10, Ryan Roberts wrote: > On 28/03/2024 08:18, Barry Song wrote: >> On Thu, Mar 28, 2024 at 3:45 AM Ryan Roberts wrote: >>> >>> Now that swap supports storing all mTHP sizes, avoid splitting large >>> folios before swap-out. This benefits performance of the swap-out path >>> by eliding split_folio_to_list(), which is expensive, and also sets us >>> up for swapping in large folios in a future series. >>> >>> If the folio is partially mapped, we continue to split it since we want >>> to avoid the extra IO overhead and storage of writing out pages >>> uneccessarily. >>> >>> Reviewed-by: David Hildenbrand >>> Reviewed-by: Barry Song >>> Signed-off-by: Ryan Roberts >>> --- >>> mm/vmscan.c | 9 +++++---- >>> 1 file changed, 5 insertions(+), 4 deletions(-) >>> >>> diff --git a/mm/vmscan.c b/mm/vmscan.c >>> index 00adaf1cb2c3..293120fe54f3 100644 >>> --- a/mm/vmscan.c >>> +++ b/mm/vmscan.c >>> @@ -1223,11 +1223,12 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, >>> if (!can_split_folio(folio, NULL)) >>> goto activate_locked; >>> /* >>> - * Split folios without a PMD map right >>> - * away. Chances are some or all of the >>> - * tail pages can be freed without IO. >>> + * Split partially mapped folios right >>> + * away. We can free the unmapped pages >>> + * without IO. >>> */ >>> - if (!folio_entire_mapcount(folio) && >>> + if (data_race(!list_empty( >>> + &folio->_deferred_list)) && >>> split_folio_to_list(folio, >>> folio_list)) >>> goto activate_locked; >> >> Hi Ryan, >> >> Sorry for bringing up another minor issue at this late stage. > > No problem - I'd rather take a bit longer and get it right, rather than rush it > and get it wrong! > >> >> During the debugging of thp counter patch v2, I noticed the discrepancy between >> THP_SWPOUT_FALLBACK and THP_SWPOUT. >> >> Should we make adjustments to the counter? > > Yes, agreed; we want to be consistent here with all the other existing THP > counters; they only refer to PMD-sized THP. I'll make the change for the next > version. > > I guess we will eventually want equivalent counters for per-size mTHP using the > framework you are adding. > >> >> diff --git a/mm/vmscan.c b/mm/vmscan.c >> index 293120fe54f3..d7856603f689 100644 >> --- a/mm/vmscan.c >> +++ b/mm/vmscan.c >> @@ -1241,8 +1241,10 @@ static unsigned int shrink_folio_list(struct >> list_head *folio_list, >> folio_list)) >> goto activate_locked; >> #ifdef CONFIG_TRANSPARENT_HUGEPAGE >> - >> count_memcg_folio_events(folio, THP_SWPOUT_FALLBACK, 1); >> - count_vm_event(THP_SWPOUT_FALLBACK); >> + if (folio_test_pmd_mappable(folio)) { This doesn't quite work because we have already split the folio here, so this will always return false. I've changed it to: if (nr_pages >= HPAGE_PMD_NR) { >> + >> count_memcg_folio_events(folio, THP_SWPOUT_FALLBACK, 1); >> + >> count_vm_event(THP_SWPOUT_FALLBACK); >> + } >> #endif >> if (!add_to_swap(folio)) >> goto activate_locked_split; >> >> >> Because THP_SWPOUT is only for pmd: >> >> static inline void count_swpout_vm_event(struct folio *folio) >> { >> #ifdef CONFIG_TRANSPARENT_HUGEPAGE >> if (unlikely(folio_test_pmd_mappable(folio))) { >> count_memcg_folio_events(folio, THP_SWPOUT, 1); >> count_vm_event(THP_SWPOUT); >> } >> #endif >> count_vm_events(PSWPOUT, folio_nr_pages(folio)); >> } >> >> I can provide per-order counters for this in my THP counter patch. >> >>> -- >>> 2.25.1 >>> >> >> Thanks >> Barry >