Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp727886lqb; Fri, 15 Mar 2024 05:07:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIxHZpeejL6y8G4xDXYqSL2sCcktOH4ZNBmn6V+3iBEFWsduA0RRC2P0ZhHCvrhJANjPH/Zas089WT0AWm2QooSPxzYaRipkrELAMbwg== X-Google-Smtp-Source: AGHT+IG10d+HVdDT0+aB4/z70p33e9NM7CxIyaLgkJqQ4DjK9r78la6qm3RfuApLLRO7jel9wtI/ X-Received: by 2002:a05:6a00:1804:b0:6e4:fddf:c1d9 with SMTP id y4-20020a056a00180400b006e4fddfc1d9mr3649900pfa.27.1710504429796; Fri, 15 Mar 2024 05:07:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710504429; cv=pass; d=google.com; s=arc-20160816; b=NDs9DOfOrTuQXH6hExB8yNd3LjNPQL2GcClLGYawO0oIFzEekZtdxRLzrm4SW8txUj IRv5SA4EmcZIYOU1ATAsTRnkdzUW/YkkJ55MPqZizXeBg+mpstjw+Cs5WqYOmlgs8elk FGMO09p08Yybo7LHm+RQXbfqWaT6UUicFmHHXCm2BpCa37KT7VuwlqffjpU8wkcpKOh6 pPWRBtehAr3DPZDa8ygE/suOkQfVYYjwnLibaZCFeuQesf0zUG7d2iBmseGq4Z+GgTfl OZzgDT20WxZuR6L83Ktb9eOkvrfDhJPp6tAaeAlv/BR4fWkssDq83BHiny/N/ZpqKIE7 cKLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=JgZo4i1woWyuhmtSaeGRs1WrTXw0txS1uGzmej/Q018=; fh=rfTn4WwMSgOaUWua22ET2M2+kub3oQeQtR0iwNhvArE=; b=TIKAmXbZ1rK/ltEcRVb9zFr4LLiShmjJ7AFs3YcRWD53SKLYbL3Ow9qoOxZHqfE4L+ jZ3mPQlMPpcaSzgv06AWri0yzhN8WXzZ8EuR3W8nKvh8rjq5YyyQusDxUPZDGEK9vY9e zCaomWbF/muDrQB0gqeg0SHan0NMFtwHdMB5WXpgMO2GgEkXSSJqzxxwseeY5scdu09a z/aIQqgXCBFR4UYASujjSemEFs4woWDP9XhRkF7ho/ui9gOYSXdaTvIivopvOSJnohsW sntJW5I4JD7OoDNnwWNjX5xYMEFsJRNPU2R91DCjnfjUeYtBnBeMcublIHJL7l2MMxfn 8i/w==; 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-104378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e14-20020aa78c4e000000b006e6b6a8c299si3445891pfd.64.2024.03.15.05.07.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 05:07:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-104378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104378-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5FE9D283914 for ; Fri, 15 Mar 2024 12:07:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 441E61C28B; Fri, 15 Mar 2024 12:07:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC5391862B for ; Fri, 15 Mar 2024 12:07:02 +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=1710504424; cv=none; b=ZDV0lxGICxFd1V6GG7LEbmAuO8GQR/1Btv7g3FUjRcONLoxhyHDej6AjJD9ypUTf3kLzCZoBw5YKUQeM7SBvosMaYsAN9xmV+gxQjaXwCbjxi3w4qawAxEFIwegIX3n/ZVaNLUrEIBBfBHltHJuOthQa9JceGLE0DG43Sv3NBDE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710504424; c=relaxed/simple; bh=fDvkF6jTJliuGLyCOJH9oxGu1/dL9N3lMa65J0e/pOY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KlDdar57lBpok6o41rtakIx9XVSPyIwOZh3TjyQlu6dv666jfzqLvLFKKd5R6s5buBzsGukvuLQ3PyZA+tYEKpXcPpmgGC4leBnlOt6nAcsxTdLHDHFsseVbA6O82q2BQ4AZwDeBwd7o6/s+1TYJ7foCgTGX5+FawmvHdiY6O/g= 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 E8D65C15; Fri, 15 Mar 2024 05:07:32 -0700 (PDT) Received: from [10.57.69.160] (unknown [10.57.69.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 83D3F3F73F; Fri, 15 Mar 2024 05:06:53 -0700 (PDT) Message-ID: <4fea8887-b3a1-4b32-8484-c3eeb74cf2e0@arm.com> Date: Fri, 15 Mar 2024 12:06:51 +0000 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: [RFC PATCH v3 5/5] mm: support large folios swapin as a whole Content-Language: en-GB To: Barry Song <21cnbao@gmail.com>, "Huang, Ying" Cc: Matthew Wilcox , akpm@linux-foundation.org, linux-mm@kvack.org, chengming.zhou@linux.dev, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, kasong@tencent.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhocko@suse.com, nphamcs@gmail.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, xiang@kernel.org, yosryahmed@google.com, yuzhao@google.com, Chuanhua Han , Barry Song References: <20240304081348.197341-1-21cnbao@gmail.com> <20240304081348.197341-6-21cnbao@gmail.com> <87wmq3yji6.fsf@yhuang6-desk2.ccr.corp.intel.com> <87sf0rx3d6.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 15/03/2024 10:01, Barry Song wrote: > On Fri, Mar 15, 2024 at 10:17 PM Huang, Ying wrote: >> >> Barry Song <21cnbao@gmail.com> writes: >> >>> On Fri, Mar 15, 2024 at 9:43 PM Huang, Ying wrote: >>>> >>>> Barry Song <21cnbao@gmail.com> writes: >>>> >>>>> From: Chuanhua Han >>>>> >>>>> On an embedded system like Android, more than half of anon memory is >>>>> actually in swap devices such as zRAM. For example, while an app is >>>>> switched to background, its most memory might be swapped-out. >>>>> >>>>> Now we have mTHP features, unfortunately, if we don't support large folios >>>>> swap-in, once those large folios are swapped-out, we immediately lose the >>>>> performance gain we can get through large folios and hardware optimization >>>>> such as CONT-PTE. >>>>> >>>>> This patch brings up mTHP swap-in support. Right now, we limit mTHP swap-in >>>>> to those contiguous swaps which were likely swapped out from mTHP as a >>>>> whole. >>>>> >>>>> Meanwhile, the current implementation only covers the SWAP_SYCHRONOUS >>>>> case. It doesn't support swapin_readahead as large folios yet since this >>>>> kind of shared memory is much less than memory mapped by single process. >>>> >>>> In contrast, I still think that it's better to start with normal swap-in >>>> path, then expand to SWAP_SYCHRONOUS case. >>> >>> I'd rather try the reverse direction as non-sync anon memory is only around >>> 3% in a phone as my observation. >> >> Phone is not the only platform that Linux is running on. > > I suppose it's generally true that forked shared anonymous pages only > constitute a > small portion of all anonymous pages. The majority of anonymous pages are within > a single process. > > I agree phones are not the only platform. But Rome wasn't built in a > day. I can only get > started on a hardware which I can easily reach and have enough hardware/test > resources on it. So we may take the first step which can be applied on > a real product > and improve its performance, and step by step, we broaden it and make it > widely useful to various areas in which I can't reach :-) > > so probably we can have a sysfs "enable" entry with default "n" or > have a maximum > swap-in order as Ryan's suggestion [1] at the beginning, I wasn't neccessarily suggesting that we should hard-code an upper limit. I was just pointing out that we likely need some policy somewhere because the right thing very likely depends on the folio size and workload. And there is likely similar policy needed for CoW. We already have per-thp-size directories in sysfs, so there is a natural place to add new controls as you suggest - that would fit well. Of course if we can avoid exposing yet more controls that would be preferable. > > " > So in the common case, swap-in will pull in the same size of folio as was > swapped-out. Is that definitely the right policy for all folio sizes? Certainly > it makes sense for "small" large folios (e.g. up to 64K IMHO). But I'm not sure > it makes sense for 2M THP; As the size increases the chances of actually needing > all of the folio reduces so chances are we are wasting IO. There are similar > arguments for CoW, where we currently copy 1 page per fault - it probably makes > sense to copy the whole folio up to a certain size. > " >