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 9562CC5478C for ; Fri, 1 Mar 2024 17:06:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18EAF6B009B; Fri, 1 Mar 2024 12:06:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 13F8C6B009C; Fri, 1 Mar 2024 12:06:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F222D940007; Fri, 1 Mar 2024 12:06:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD3756B009B for ; Fri, 1 Mar 2024 12:06:13 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 95BCC1602D9 for ; Fri, 1 Mar 2024 17:06:13 +0000 (UTC) X-FDA: 81849098226.29.13CBFE4 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 53506100039 for ; Fri, 1 Mar 2024 17:06:11 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709312771; 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; bh=ABdkYyTinMYSNSSqDtZctULihEnQXLo+jilZi22jTFw=; b=u4YsaaKX/J1cndlRS9hdRLxiogU0BzLyvFceTzT2gbuZ1DCIrzQdYBj6HIoKZQH6UACWeX 2J2lrA49ZtxXQN9HfX8VoJ25MtDRxJZd9/bnNWnjmVFqURJuLurZnBrY5t/8aLpYS2JlXl azGy1hnTVRSiqmEqw1ZQTSzkeCALDYA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709312771; a=rsa-sha256; cv=none; b=rs4ogxTs31WXFjTeg6Y74r9SlVeunKlJ07PmpWXEf50QguGFiLMKk4zcykrw17NDNfPArh zAdc4yg8ixef9uqZHs70XBFxCmReVWkWluPUF5pZU3lu9+wj/4S6NGcwdeyjwB1MpVZ4et gIcmHj9aEoLXu9nMZ2nPqkGO3zkuK2Y= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=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 5AFFF1FB; Fri, 1 Mar 2024 09:06:48 -0800 (PST) Received: from [10.57.68.58] (unknown [10.57.68.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 083873F6C4; Fri, 1 Mar 2024 09:06:07 -0800 (PST) Message-ID: Date: Fri, 1 Mar 2024 17:06:05 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/4] mm: swap: Remove CLUSTER_FLAG_HUGE from swap_cluster_info:flags Content-Language: en-GB From: Ryan Roberts To: Matthew Wilcox Cc: David Hildenbrand , Andrew Morton , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <6541e29b-f25a-48b8-a553-fd8febe85e5a@redhat.com> <2934125a-f2e2-417c-a9f9-3cb1e074a44f@redhat.com> <049818ca-e656-44e4-b336-934992c16028@arm.com> <4a73b16e-9317-477a-ac23-8033004b0637@arm.com> <1195531c-d985-47e2-b7a2-8895fbb49129@redhat.com> <5ebac77a-5c61-481f-8ac1-03bc4f4e2b1d@arm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 53506100039 X-Rspam-User: X-Stat-Signature: 8exadfe984th48tmhyh6aegp7yjp1m9i X-Rspamd-Server: rspam03 X-HE-Tag: 1709312771-442293 X-HE-Meta: U2FsdGVkX18/EDE5e4uH5ojFF55kz6ooJj0VzNr0ZNcyvoElYJulrw561WsYj47YcvAhJ8makUnQ+KICXKVTnEzgzLP9lYM4gSsqd6UKDaK2e+LF2KZBJw0ur8FLyJA5GlvqJRvNtpJLGV8YXeRPaiQU6vBU1p2tknrcc5UOaehyklsiC9hSoOcOOps2Q4s4NM3VPTw+X9Ej1/SBCQQeB5skF4rlpqOMdw6D7rLMJhz6hPJACOpT+h40mx9elM+ak6nNBAKaFfNT/KFm4nChUreM1cD0LzxSNDc9Qev47rVvylFXXMcnzRl9aCSN5IJnafhQsQVXmHMverQ6VQOpS2j5bgkxZICCF5zJ5fwKrratWR7nePOgqQ0cCmL88eOfo0XC7j7aHC9aYTfV9522r0buO6lvumKHpCcLdWIPI7TeRC15+pTCexWMo+2oV3rZ7kIircvgJJ4lJAcOS7AXYJxZcb866E+37Y7kOlXEtVC7Vu9N32XT8HC63xhgavGoXuV9coLM/RS+OuiOfBwIygU9J1A0QF+GPC79sh3qpGFULW0Wd04pYqGeLdykHiw59tscwl6y+Wnzm8Z4Dkz4pydvUWPAWdSR7PQ8WDrXP3wm2OU1YDTbsmgZRRVVd/Aa/8Kem5MOV6yWYjI7JXyvLIPyucaUtXSR8h+BA5J72MPStqIGsBarcdeBUWuCarzm7n+hEGtsrivMh1fZ6aZCXQaabScEPVjY1tdxKooTVb4Jqe5mb4N3fog1ypFDP8vq4Yi2dhIftwbFi3KCaGatz5AqO1O3wFWhzLholkhXLK0k6i84scZxCztcFciqZ/9c93CXJLspLeoq7kX/dOlrh1db9OMSREArSCL1eIEX+F5LA5EYKNGmVjmLL1QhN5HoE6ukEyYdhTE= 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: List-Subscribe: List-Unsubscribe: On 01/03/2024 16:44, Ryan Roberts wrote: > On 01/03/2024 16:31, Matthew Wilcox wrote: >> On Fri, Mar 01, 2024 at 04:27:32PM +0000, Ryan Roberts wrote: >>> I've implemented the batching as David suggested, and I'm pretty confident it's >>> correct. The only problem is that during testing I can't provoke the code to >>> take the path. I've been pouring through the code but struggling to figure out >>> under what situation you would expect the swap entry passed to >>> free_swap_and_cache() to still have a cached folio? Does anyone have any idea? >>> >>> This is the original (unbatched) function, after my change, which caused David's >>> concern that we would end up calling __try_to_reclaim_swap() far too much: >>> >>> int free_swap_and_cache(swp_entry_t entry) >>> { >>> struct swap_info_struct *p; >>> unsigned char count; >>> >>> if (non_swap_entry(entry)) >>> return 1; >>> >>> p = _swap_info_get(entry); >>> if (p) { >>> count = __swap_entry_free(p, entry); >>> if (count == SWAP_HAS_CACHE) >>> __try_to_reclaim_swap(p, swp_offset(entry), >>> TTRS_UNMAPPED | TTRS_FULL); >>> } >>> return p != NULL; >>> } >>> >>> The trouble is, whenever its called, count is always 0, so >>> __try_to_reclaim_swap() never gets called. >>> >>> My test case is allocating 1G anon memory, then doing madvise(MADV_PAGEOUT) over >>> it. Then doing either a munmap() or madvise(MADV_FREE), both of which cause this >>> function to be called for every PTE, but count is always 0 after >>> __swap_entry_free() so __try_to_reclaim_swap() is never called. I've tried for >>> order-0 as well as PTE- and PMD-mapped 2M THP. >> >> I think you have to page it back in again, then it will have an entry in >> the swap cache. Maybe. I know little about anon memory ;-) > > Ahh, I was under the impression that the original folio is put into the swap > cache at swap out, then (I guess) its removed once the IO is complete? I'm sure > I'm miles out... what exactly is the lifecycle of a folio going through swap out? > > I guess I can try forking after swap out, then fault it back in in the child and > exit. Then do the munmap in the parent. I guess that could force it? Thanks for > the tip - I'll have a play. That has sort of solved it, the only problem now is that all the folios in the swap cache are small (because I don't have Barry's large swap-in series). So really I need to figure out how to avoid removing the folio from the cache in the first place... > >> >> If that doesn't work, perhaps use tmpfs, and use some memory pressure to >> force that to swap? >> >>> I'm guessing the swapcache was already reclaimed as part of MADV_PAGEOUT? I'm >>> using a block ram device as my backing store - I think this does synchronous IO >>> so perhaps if I have a real block device with async IO I might have more luck? >>> Just a guess... >>> >>> Or perhaps this code path is a corner case? In which case, perhaps its not worth >>> adding the batching optimization after all? >>> >>> Thanks, >>> Ryan >>> >