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 9B164C25B76 for ; Sat, 8 Jun 2024 04:39:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB5D06B009C; Sat, 8 Jun 2024 00:39:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B656A6B009D; Sat, 8 Jun 2024 00:39:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2C4A6B009E; Sat, 8 Jun 2024 00:39:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 853B66B009C for ; Sat, 8 Jun 2024 00:39:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 25A78A19CE for ; Sat, 8 Jun 2024 04:39:18 +0000 (UTC) X-FDA: 82206467196.11.3E8E0A3 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) by imf21.hostedemail.com (Postfix) with ESMTP id F10F31C0003 for ; Sat, 8 Jun 2024 04:39:14 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=VM5PdSUR; spf=pass (imf21.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717821556; a=rsa-sha256; cv=none; b=atYj4RMBDbk2KjC6v/nQRahhk5SDRdbroFOrBuMNNR1XTz+qISLybgbGNKeGaBb9Q1Sfrq qxGsQoyjvHhVL3+k3Lt+q3CzI5jRVUYpSPbGfkYJc9Oqlf5N4CGAwTFpGVjofzxCp1E0lk /UP085/TMxizlmFvX936SwOpY4+oPGo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=VM5PdSUR; spf=pass (imf21.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717821556; 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=H2TmM8IrQ5a7tztR18Cxx5YmBHs5vMZX2tXrmy3VWxc=; b=aGyQ0sT0S0aSItOHSFWsj7kDxhqY6gwjVDq5/fWWINGwpMt9IA7mwcXc8o7exwgwhIN2bi 5AqV0Rl9JMvztO/2mVQxjDlDnx7My1Uyx+95i9F8DoMk4G+Wt4j6qof/ef65vm5QcYvXe3 ETFkyKCJBHkieJfKC27Lp10XgNBFB8Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Subject:From:Message-ID:Date:MIME-Version: Content-Type; bh=H2TmM8IrQ5a7tztR18Cxx5YmBHs5vMZX2tXrmy3VWxc=; b=VM5PdSURfZDLkOyzsWLxMHROk6mml6+/aX40Dt94B0HJlpGXDpXnA8VdmfADCG epTBQFHU+KlccqWsHoogPx4IoF3+dZfUen+b7eLMzJmsNA5Mbb+7wJqC3TNnwVwP WcFSrnv4Q35IkSkUV13aI8G/w7rO1TE77NKS2Cv9R9xRA= Received: from [172.21.21.216] (unknown [118.242.3.34]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wD3f0BZ4GNmTrjuBA--.40426S2; Sat, 08 Jun 2024 12:38:51 +0800 (CST) Subject: Re: [PATCH] mm/gup: don't check page lru flag before draining it To: David Hildenbrand , Baolin Wang , akpm@linux-foundation.org, Matthew Wilcox Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, liuzixing@hygon.cn References: <1717498121-20926-1-git-send-email-yangge1116@126.com> <0d7a4405-9a2e-4bd1-ba89-a31486155233@redhat.com> <776de760-e817-43b2-bd00-8ce96f4e37a8@redhat.com> <7063920f-963a-4b3e-a3f3-c5cc227bc877@redhat.com> <48150a28-ed48-49ff-9432-9cd30cda4da4@linux.alibaba.com> <11ef3deb-d1e3-46d5-97ed-9ba3c1fbbba9@redhat.com> <697a9bc2-a655-4035-aa5e-7d3acb23e79d@redhat.com> <3a368e38-a4cb-413e-a6d9-41c6b3dbd5ae@redhat.com> From: yangge1116 Message-ID: <48fb0e58-16d1-7956-cf35-74741826617a@126.com> Date: Sat, 8 Jun 2024 12:38:49 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <3a368e38-a4cb-413e-a6d9-41c6b3dbd5ae@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3f0BZ4GNmTrjuBA--.40426S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFykJFyUJw4kKw4xCry5CFg_yoW5Aw4xpF WrGasFkF4DGa1Yywn7tr1DZr1FyrW8ta43CF1fCr98ZF9YvFyIkrW8Ka1a9F48Aws5Gr40 vw4jyFZ7ua4DAaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bOXocUUUUU= X-Originating-IP: [118.242.3.34] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiWQz3G2VLanpPvgABs3 X-Rspamd-Queue-Id: F10F31C0003 X-Rspam-User: X-Rspamd-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xRck/OwaZ6ef+lPXZoN7L78fBvGzD0eH1KjDc2peRJepRYMUhuhn7eCPnwtLMjfCz46yh9X8VXbObnzjcduaPoIDVpGWBM+EXlN6Gk3i1lGAd8YvmDdCoYllCFpeum4UoiRrciE8LYGzi3rHyq7MDUmWhRM3MPbEYhvGEttou9gekxZSFvnghzpMCi0QpJTO61racS6EZ/vMLBq6+okvV3NVruAiAv22UP4Rt/7dp7RFF9DkdDj+NTEaHaYZcluF9Rt2xCAMRuT9itY0KwwhWFcjMA2uzwyZSg== 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: 在 2024/6/6 下午3:56, David Hildenbrand 写道: >>> Some random thoughts about some folio_test_lru() users: >>> >>> mm/khugepaged.c: skips pages if !folio_test_lru(), but would fail skip >>> it either way if there is the unexpected reference from the LRU batch! >>> >>> mm/compaction.c: skips pages if !folio_test_lru(), but would fail skip >>> it either way if there is the unexpected reference from the LRU batch! >>> >>> mm/memory.c: would love to identify this case and to a lru_add_drain() >>> to free up that reference. >>> >>> mm/huge_memory.c: splitting with the additional reference will fail >>> already. Maybe we'd want to drain the LRU batch. >> >> Agree. >> >>> >>> mm/madvise.c: skips pages if !folio_test_lru(). I wonder what happens if >>> we have the same page twice in an LRU batch with different target >>> goals ... >> >> IIUC, LRU batch can ignore this folio since it's LRU flag is cleared by >> folio_isolate_lru(), then will call folios_put() to frop the reference. >> > > I think what's interesting to highlight in the current design is that a > folio might end up in multiple LRU batches, and whatever the result will > be is determined by the sequence of them getting flushed. Doesn't sound > quite right but maybe there was a reason for it (which could just have > been "simpler implementation"). > >> >>> Some other users (there are not that many that don't use it for sanity >>> checks though) might likely be a bit different. > > There are also some PageLRU checks, but not that many. > >> >> mm/page_isolation.c: fail to set pageblock migratetype to isolate if >> !folio_test_lru(), then alloc_contig_range_noprof() can be failed. But >> the original code could set pageblock migratetype to isolate, then >> calling drain_all_pages() in alloc_contig_range_noprof() to drop >> reference of the LRU batch. >> >> mm/vmscan.c: will call lru_add_drain() before calling >> isolate_lru_folios(), so seems no impact. > > lru_add_drain() will only drain the local CPU. So if the folio would be > stuck on another CPU's LRU batch, right now we could isolate it. When > processing that LRU batch while the folio is still isolated, it would > currently simply skip the operation. > > So right now we can call isolate_lru_folios() even if the folio is stuck > on another CPU's LRU batch. > > We cannot really reclaim the folio as long is it is in another CPU's LRU > batch, though (unexpected reference). > >> >> BTW, we also need to look at the usage of folio_isolate_lru(). > > Yes. > >> >> It doesn’t seem to have major obstacles, but there are many details to >> analyze :) > > Yes, we're only scratching the surface. > > Having a way to identify "this folio is very likely some CPU's LRU > batch"  could end up being quite valuable, because likely we don't want > to blindly drain the LRU simply because there is some unexpected > reference on a folio [as we would in this patch]. > Can we add a PG_lru_batch flag to determine whether a page is in lru batch? If we can, seems this problem will be easier.